When (and how often) is the AudioProcessorEditor constructor called?

Is the AudioProcessorEditor constructor called just once (or twice, as I’ve read), when the host loads the plugin for the first time, or is it called every time you open the (already loaded) plugin’s GUI?

Thanks :slight_smile:

Not sure about other DAWs, but in Ableton it gets destroyed and created every time you close / open the plugin window.

Actually, I just checked and it goes as follows:

  • Constructor gets called
  • Destructor gets called
  • Constructor gets called
  • Windows is open
  • User closes window
  • Destructor is called

Why the initial construction and destruction I wonder?
If you switch to another track in Ableton it does not call the destructor and just hides the plugin.

I read that many DAW’s open and close it once to get a peek at the window size and other things they might like to know before recalling the constructor.

So basically, I should assume that the constructor and destructor of the editor gets called “at random”?

I’m assuming the editor constructor always gets called after the processor constructor.

Twice correct.
Otherwise it wouldn’t be legit to call with a reference to the processor, if it wasn’t guaranteed, that the AudioProcessor outlives the AudioProcessorEditor.

To be safest and most compatible that assumption is relevant to many aspects of an audio plug-in.

  • Never expect to have sample-rate on your AudioProcessorEditor (it might be constructed and have a valid processor but it was never preparedToPlay or set).

  • Never expect to be guaranteed your state load/save will be called from the same audio thread. (AAX for example would call them on another thread).

  • Never expect the AudioProcessorEditor to be persistent. Store any state in your AudioProcessor as a model.

  • Make sure any listeners between your AudioProcessorEditor and AudioProcessor are being added & removed in proper order within constructor / deconstructor.


couldn’t you just do this to find out:

class AudioProcessorEditor
        DBG( "num instantiations: " << i );
        i += 1;
    static int i = 0;

That would show, how it was this time. However, that doesn’t extrapolate

  • if it is always happening like this
  • if another host will behave the same

it is giving a hint at best, better follow @ttg’s summary…