rezaali / ofxUI

[DEPRECATED] UI Addon for openFrameworks
http://www.syedrezaali.com/#/ofxui-project-showcase/
518 stars 202 forks source link

Added copy constructor and assignment operator for handling of heap allocation, added missing ofxUIDropDownList constructors, added ofxUIEnvelopeEditor #173

Closed mitchmindtree closed 10 years ago

mitchmindtree commented 10 years ago

In relation to the issue with ofxUI's stack vs heap business - I've worked out a solution that allows a user to create a vector of ofxUICanvas that handles all of the heap allocated memory correctly (should also be able to make a vector of ofxUIWidgets, though I haven't personally tested this yet). I've done this by implementing copy constructors and assignment operators to correctly handle the heap allocation during the copying/assignment process. I've been using it in my node UI framework and it's working like a charm :-D NOTE: if you want to do the following,

ofxUICanvas canvas;
int numOfSuperCanvases = 10;
vector<ofxUISuperCanvas> superCanvases;
superCanvases.reserve(numOfSuperCanvases);
for (int i=0; i < numOfSuperCanvases; i++) {
    superCanvases.push_back(ofxUISuperCanvas(constructorStuff));
    canvas.addWidgetDown(&superCanvases.at(i));
}

remember that your program will try to delete the vector of ofxUISuperCanvases twice (Once when being destructed on the stack, and again in "canvas'" explicit destructor). To get around this, I've added a method -

ofxUICanvas::clearWidgets();

which just clears each of the vectors of ofxUIWidget*'s (without freeing the memory) to ensure that ofxUICanvas doesn't try to free their memory a second time. So, make sure that you call this method in the destructor of the class that you're instantiating your ofxUICanvas in, like so -

~MyClass() {
    canvas.clearEmbeddedWidgets();
    canvas.clearWidgets();
}

Also, I've filled in a few constructors that were missing for the ofxUIDropDownList.

And finally, I've changed the ofxUIEnvelopeEditor over to the new .h / .cpp format. There's a few things in it that need some polishing/tweaking but it is certainly usable as is! Here's an older video of my current project, in which you can see an example of the ofxUIEnvelopeEditor. In this example I'm using it to control the amplitude and frequency of oscillators within a basic audio synth (but you can't hear it sorry).

Anyway, hopefully someone else finds all of this as handy as I do! Thanks again for the awesome addon Reza :-)

rezaali commented 10 years ago

looking into this now.

rezaali commented 10 years ago

looks like ofxUIEnvelopeEditor is throwing some run time errors, before I dive in further, lets talk about the function of ofxUIEnvelopeEditor. What does it do?

mitchmindtree commented 10 years ago

ofxUIEnvelopeEditor is used to edit ofxUIEnvelopes (also included in that pull). You can edit an ofxUIEnvelope by passing a reference into the constructor of an ofxUIEnvelopeEditor or calling ofxUIEnvelopeEditor::setEnvelope(&myEnvelope);

Once set up on a canvas with an ofxUIEnvelope, use ofxUIEnvelopeEditor by:

What is the point of an ofxUIEnvelope?

An example use: I have both an "ofxUIEnvelope amplitude" and "ofxUIEnvelope frequency" within my synth oscillator class. I just scale the duration of the synth oscillator to a percentage and use the getY method to return the amplitude and frequency for any point within the synth oscillator's duration. I use the ofxUIEnvelopeEditor to edit each oscillator within my synth instrument like this, and I can do this in real time while listening back to how it sounds. I then store all of the data for each instrument and it's oscillators (along with waveform, name, etc) into an XML, which I can then load back up when I run the program again.

The ofxUIEnvelopeEditor was made quite a while ago and there may be a couple bugs / a few things that could be fixed and optimised. Most of these things should have comments within the code, though I'll leave a couple of comments on ofxUIEnvelopeEditor now and point out a couple of issues that come to mind.

rezaali commented 10 years ago

okay great, working on refactoring this so it doesn't throw any errors and is more efficient, will push when its ready.

rezaali commented 10 years ago

I see a lot of value in a widget like this, especially for audio applications, but it needs a bit of work so its more efficient and straight forward...took a break mid day till now. I think this widget is experimental and will be awesome soon.

mitchmindtree commented 10 years ago

:+1: Agreed, sounds great!