Hi, I’m making a plugin and I’m using a ValueTree in order to maintain the state of the plugin. However I’m not sure how to get saving/loading to work as it does in this tutorial:
https://docs.juce.com/master/tutorial_audio_processor_value_tree_state.html
here is the code I have in getStateInformation and setStateInformation:
void ProteusAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
{
std::unique_ptr<juce::XmlElement> xml(state.createXml());
copyXmlToBinary(*xml, destData);
}
void ProteusAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
std::unique_ptr<juce::XmlElement> xmlState(getXmlFromBinary(data, sizeInBytes));
if (xmlState.get() != nullptr)
{
if (xmlState->hasTagName(state.getType()))
{
juce::ValueTree& newState = juce::ValueTree::fromXml(*xmlState);
state.copyPropertiesAndChildrenFrom(newState, nullptr);
}
}
}
This approach is not working however. When I load the state then the UI does not update and and I get no output when I press on my midi keyboard(its a synth btw) even if the state I saved did have output.
In order to connect my value tree to UI elements I have done this sort of thing:
juce::Value& valueToControl = state.getChild(<index>).getPropertyAsValue(<property>);
slider->getValueObject().referTo(valueToControl);
I would assume that when I call copyPropertiesAndChildrenFrom() then it would update all my UI elements but apparently my assumption was wrong.
Anyone know what I can do to get this to work?
Thanks in advance