[SOLVED] Plugin params only loaded with GUI

After saving a project in the DAW and loading it again, my plugin will only restore its internal state after I open the GUI. Before it behaves like it was initialized.
I set the state in setStateInformation() like so:

  std::unique_ptr<XmlElement> xmlState(getXmlFromBinary(data, sizeInBytes));
  if (xmlState.get() != nullptr) {
    if (xmlState->hasTagName(m_value_tree.state.getType()))
      m_value_tree.replaceState(ValueTree::fromXml(*xmlState));
  }

I’m using listeners to the audiotree to set values in my DSP code, but my guess is that replacestate() will not notify the listeners.

Is there a way to notify the listeners, or maybe even make every single parameter act like it was changed, even though it wasn’t?

There is ValueTree::sendPropertyChangeMessage():
https://docs.juce.com/master/classValueTree.html#a164ff183e358b982b1a1f5dd1176ab88

1 Like

Thanks for your answer! The proposed solution works just fine for everything that is not an audioparameter. However, I found that triggering audioparameters on the ValueTree (not on AudioProcessorValueTreeState) doesn’t retrigger the parameter listeners. The problem here might be that I don’t know how the parameters are even stored on the ValueTree. For example, calling

m_value_tree.state.getNumProperties();

returns 0, so it seems to me the audio params are stored in a different way.
I also tried to set the values manually by calling

m_value_tree.getParameter(name)->setValueNotifyingHost(m_value_tree.getParameterAsValue(name).getValue());

but weirdly, this sets the value to either end of the parameter range.

Ok I got it working. The values were set to the limits because I forgot use the conversion function. The working solution is:

m_value_tree.getParameter(name)->setValueNotifyingHost(m_value_tree.getParameter(name)->convertTo0to1(m_value_tree.getParameterAsValue(name).getValue()));