How to call function on plugin load but NOT on reload?

I am trying to set a couple of variables once a plugin is loaded in prepareToPlay (because I need the totalNumOutputChannels value), but I want these variables to be set ONLY when the plugin is loaded the very first time in the track but not when the plugin is “reloaded” (i.e. plugin is loaded, user saves project, user reloads project).

Is that possible?

Should be able to do something like add a flag variable which gets set at the end of prepareToPlay(). Store that state in your data, like you would with other parameters, then recall that state with your other parameters. Check this state at the start of prepareToPlay(), which will tell you if it’s the first load or not.

Edit: I meant to say prepareToPlay(), not processBlock()

Sorry, it’s late here. Fixed the above. ProcessBlock() was a typo.

1 Like

Private member of your processor: bool firstLoad = true;

Add this to your save data in getStateInformation, and load it in setStateInformation.

Then in prepare to play:

If (firstLoad == true)
{
    //do your stuff
}

firstLoad = false;

So the very first time you instance the plug-in, that if statement will execute. Then as long as you set up the save/load correctly, any reloaded sessions will have that flag set to false for the first call to prepareToPlay.

Lmk if you need further clarification and I will write up something better in the morning!

1 Like

Sound clear enough! Will try those and report back! Thanks for the support!

Ok this worked perfect - Thank you!

1 Like