When to save or load a preset automatically ? First run, previously saved by DAW,

Hello,
Actually i don’t know how to start but i really need a reliable way to do this :slight_smile:
I have my own preset manager.(I think mention this in my topics a lot :smiley: ) I am able to save and load presets but i have some problems about the “correct time” to save or load them.
Normally every time my plugin is loaded, it checks a variable that is created and increased only once in the constructor of the processor. Every time the editor is closed it is again being increased on the editor side.

processor header
int creationCounter=0;
in the processor constructor:
creationCounter =1;

in the editor deconstructor
creationCounter+=1;

So if this variable is smaller than 2, it means that this is the first time that processor is initialized. Then go to preset folder, read the default preset and load it.
if it is larger then 2, it means that the plugin window has been closed and re-opened. So do not load the default preset. Go with the last state.

For the scenario above, it works, But if user closes the DAW without saving the preset in my preset manager but save the host state(it means that the last state of my plugin also should be memorized and kept for the next run), since my plugin will check the creationCounter(it will be 1 because processor was destroyed when the user closed the host), it will load the default preset. if i knew if the user saved or did not save the host state, i would be able to do somethings for it but i think i cannot know that.

So my question is how should i deal with these kind of issues? Do you have any different approaches?
Mine looks very primitive, i am sure that there are better ones. What do you think ?
Thanks in advance.:pray:

Disclaimer: Im a Juce Beginner.

if i knew if the user saved or did not save the host state, i would be able to do somethings for it but i think i cannot know that.

The getStateInformation function of the Processor is called everytime the hosts saves isnt it?

but i have some problems about the “correct time” to save or load them.

saving

  • save a preset only when the user chooses to save a preset on your disk
  • save the current state in the getStateInformation function

loading

  • load a preset only when the user opens a new preset from your manager - not when loading up your plugin
  • load the latest state of your plugin from setStateInformation when there was a state before

or is there something I didnt get I can learn now?

1 Like

Yes, actually it is calling it very often. When the daw itself is closed. It stores the data. And when it opens it tries to set that data.

i do, but unfortunately, it should also remember the state if you close the plugin window and then open it. So you have to know if the plugin is closed or the whole GUI is closed. So when the plugin is loaded, it needs to know that, then according to that situation it will either load the default preset(if it is the first time you load to track) or load the last state. So I cannot only save or load when the user wants to save or load.

  • load a preset only when the user opens a new preset from your manager - not when loading up your plugin
  • load the latest state of your plugin from setStateInformation when there was a state before

But my presets are in an external folder. If it is the first time that the current plugin instance is being loaded, then it should not load the value from the getStateInformation or setStateInformation. It should go to the preset folder and load the default preset. you close the plugin window or if you save the session from our daw and then re-open it, it should not load the values from the preset folder. İt should use the values from daw. Because values have changed and maybe user didn’t save it as a new preset in my preset manager. So it is tricky :confused:

Just load it once on creation of the processor – the editor should have nothing to do with it.

When setStateInformation is called from the DAW – it will overwrite the preset you have loaded by default, if it’s not called there’s no state to the session and it will remain on your default.

1 Like

Thanks for the answer. To be honest, previously I was not aware of many things on the DAW side. So generally I was putting breakpoints and some debug texts to see what exactly DAW is going.
Nowadays I am working on the communication between the plugin and the DAW. I am using a combo box based preset manager. That’s why I put it on the editor side. I wıll try to run it from the processor. If this sımply solves my problem, It will be great :smiley:

When getStateInformation is called by the DAW, you can add some specific information to the XML, like the current preset being used and if it has been modified by the user for example. You can declare these information as private members of your processor and use them when it’s required. This way, when you open the project and setStateInformation is called, you can read this extra information and know what was the current preset. And by doing this you can keep the user changes without overriding your preset settings. If there’s no information retrieved by setStateInformation, you know you can load the init preset or whatever you want :slight_smile:

1 Like

@stfufane @jakemumu @moritzsur

Hello again, I tried to move my preset manager into processor constructor. It solved almost all problems :slight_smile: Again i tried to save a stateholder variable in valuetreestate of my paratmeters. Now i am much more confident , my code is cleaner. I am really happy now :smiley: Thank you very much :pray:

2 Likes