Basic advice needed on restoring APVTS state when plugin is reloaded by DAW..?

I’m saving my state:

void myplugin::getStateInformation (juce::MemoryBlock& destData)
{
    juce::MemoryOutputStream mos(destData, true);      
    apvts.state.writeToStream(mos);                     
}

And then restoring:

void myplugin::setStateInformation (const void* data, int sizeInBytes)
{
    auto tree = juce::ValueTree::readFromData(data, sizeInBytes);
	if (tree.isValid())                                 //load the parameters from the previous time
	{                                                   //the plugin was used
		apvts.replaceState(tree);
//here I update parameters
	}
}

So, where I have //here I update parameters I have to restore silder.setValue() perhaps. I can change variables in my PluginProcessor but what about changing them in PluginEditor and triggering a repaint()?
I saw this as one way of gaining access to the editor… but is it OK:

if (auto* editor = dynamic_cast<mypluginAudioProcessorEditor*>(getActiveEditor()))
{
    editor->updateUIFromParameters();        //this will be my update method in PluginEditor
}

Or how about setting a flag in the PluginProcessor and have the PluginEditor pick up that flag in a timercallback()?

Maybe you could use parameter attachments for your GUI elements?

For example:
https://docs.juce.com/master/classAudioProcessorValueTreeState_1_1SliderAttachment.html

1 Like