Plugin state resets when reopening a saved session

Hi all, l’m relatively new to JUCE and after successfully creating some audio plugins l’ve come across this -l suppose- very basic problem… l’ve searched around in the forum but still don’t know how to solve it

Right, so the problem is simple… (l’m using Logic btw but l’m guessing it’d be the same in other DAWs): when l load the plugin in the channel strip it works fine, l change the sliders’ values, and when l close it and reopen it the values are preserved… however, when l save the session and open it again the next day, the plugin values are set to their default. (this also happens when l drag the plugin to a different position).

Just for reference, l’m creating the variable ‘value’ in PluginProcessor.h inside the public section like this

// a lot of default code
double value;

and then initialising its value inside PluginProcessor.cpp

// default code
value = 0;

l have to give it an initial value otherwise it would throw an error, but l suppose here is where the value gets reset each time… now l’ve looked for similar posts in here and l’ve read a lot about ValueTreeState and l guess l should dig deeper into that to solve this problem, but l just wanted to know if l’m not missing something obvious here before l dive into it, which can be quite long…

Okay that’s all really, sorry for the long post about something that l reckon must be simple as you start learning more… thanks for any advice

1 Like

Check out the getStateInformation and setStateInformation functions in the AudioProcessor class. These will be called whenever the host wants to save/load the plugin state, e.g. when saving/opening projects.

1 Like

The constructor of an object can never be called twice.
Also note, since C++11 you can initialise members in the class declaration (header file) like that:

class Effect1AudioProcessor : public AudioProcessor
    // yada yada
    double value = 0;                                      // initialise to scalar value
    AudioProcessorValueTreeState state { *this, nullptr }; // call the member's constructor with said arguments

Follow @reuk’s advice and additionally make sure you don’t set the parameters somewhere else, like when opening the PluginEditor, best to leave that to the SliderAttachments, they will make sure everything is synchronised.

1 Like

thanks reek l’ll look into that

1 Like

thank you for replying… l moved the initialisation to the header file but that was apparently not the problem… the slider associated to this value, as you might have guessed, is also reset to zero each time

l will be checking the getStateInformation and setStateInformation functions now to see what l can do there

thanks guys