Hi!
I am using functions getStateInformation
and setStateInformation
to save and restore plugin parameters. The issue is that in getStateInformation
a parameter is saved correctly, but it is not restored in setStateInformation
call.
I am using ValueTree
class.
Here is the code of these two methods:
void NewProjectAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
{
// You should use this method to store your parameters in the memory block.
// You could do that either as raw data, or use the XML or ValueTree classes
// as intermediaries to make it easy to save and load complex data.
std::string currentInstanceId = current_instance_information.id;
// return if nothing to store
if (currentInstanceId == "")
return;
String testValue = "this is the test value";
pluginParameters.setProperty("testValue", testValue, nullptr);
String val = pluginParameters["testValue"]; // "this is the test value" (correct value)
std::unique_ptr<juce::XmlElement> xml (pluginParameters.createXml());
pluginParameters.fromXml(*xml);
val = pluginParameters["testValue"]; // "this is the test value" (correct value)
copyXmlToBinary(*xml, destData);
}
void NewProjectAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
// You should use this method to restore your parameters from this memory block,
// whose contents will have been created by the getStateInformation() call.
std::unique_ptr<juce::XmlElement> xml (getXmlFromBinary (data, sizeInBytes));
pluginParameters.fromXml(*xml);
String ip = pluginParameters["testValue"]; // "" (empty value)
}
What am I doing wrong?