I am new to Juce, so I apologize if my question might be trivial.
I managed to exchange data between the processor and the editor (now the editor is updated whenever I need it, for instance when I call some preset files). However I read on the forum that the "getFilter()->removeChangeListener(this); " must be called in the editor destructor if the "addChangeListener(this);" has been used in the editor constructor?
I tried it, but I cannot find the getFilter() method? What is the proper way to do this?
Thanks. I found and tried geAudioProcessor() (and processor, that should be the new way), but neither of the two seam to have the removeChangeListener() method. I found only removeListener().
By the way, before destroying the processor, should I remove all the listeners I created (for the sliders, buttons etc.) or I just have to call the removeChangeListener().
If your AudioProcessor inherits the ChangeBroadcastor class then the removeChangeListener() method will be available to you. With regards to your second question I think you can just call removeAllChangeListeners().
MyAudioProcessorEditor::~MyAudioProcessorEditor()
{
if (VolumeSlider)
VolumeSlider->removeListener(this);
if (RightButton)
RightButton->removeListener(this);
if (LeftButton)
LeftButton->removeListener(this); getAudioProcessor()->removeChangeListener();. deleteAllChildren();
}
But while ownerFilter in the constructor has the removeChangeListener() method, getAudioProcessor()-> does not.
By the way, I am confused about the "lifetime cycle" of a listener. Is the removeListener() always mandatory in the destructor? To be clearer should I always call a removeListener() in the destructor if an addListener() call was present in the constructor?
Is there any way to make the above code cleaner and remove all the listeners that have been created (the ones associated with the slider, the buttons and the filter) at once?
There's actually no real need to remove listeners from a component that you're about to delete, because once deleted it no longer matters what listeners it had. I rarely bother calling removeListener in cases like this.
BTW please avoid deleteAllChildren() - using that method implies that you're not managing your object lifetimes with modern C++ techniques. From your code it look like these sliders should probably be just created as member variables, not pointers. And if they really really do need to be held as pointers for some reason that I can't see here, then you should use a ScopedPointer and not delete them manually. Maybe read my coding style guide!
Thanks! However I still do not understand why the result of getAudioProcessor() (or processor) is different from ownerFilter. Is this supposed to happen?
If you need a pointer to your own subclass of the object, you may want to add something like in the demo JuceDemoPluginAudioProcessorEditor::getProcessor()