I have a plugin that in addition to handling parameters the usual way (via an
AudioProcessorValueTreeState) also has to keep track of a bunch of extra things (last editor size, selected colour scheme, last preset etc.).
Putting together some advice found on this forum, I ended up storing the info inside
Basically when I need to save extra state I call something like this from the editor (which has a reference to the processor’s
auto editorSettings = apvts.state.getOrCreateChildWithName ("editorSettings", nullptr); editorSettings.setProperty ("theme", myTheme, nullptr); editorSettings.setProperty ("width",lastWidth, nullptr); // ...
Then, in the editor’s constructor I load the info:
auto editorSettings = apvts.state.getOrCreateChildWithName ("editorSettings", nullptr); auto selectedTheme = editorSettings.getProperty ("theme", "light"); auto lastWidth = editorSettings.getProperty ("width", 800); // ... set editor size, set colour theme etc.
This seems to work except in one situation: the first time the plugin is loaded in a DAW, in which case we get the default values, as if the stuff in
apvts.state wasn’t loaded yet; If I then close and reopen the editor again, it will start working fine (i.e. I can close and reopen the editor as many times as I want and it will preserve size and theme).
So it looks like I’m trying to access the data in the
ValueTree too early, but why? The processor has been created before the editor is opened, and the plugin parameters are loaded correctly even when opening the editor for the first time (meaning that
setStateInformation has been called, which if I understand correctly should load the parameters as well as the extra data since they are stored in the same
So what am I doing wrong? Am I missing something?
Note that I tried making the editor inherit from
ValueTree::Listener and having it fetch the data when the value tree changes, which seems to “fix” the issue. I’ve got the feeling, however, that I might be overcomplicating it - is there’s a simpler, better solution?
Thanks in advance!