AudioProcessorValueTreeState and child valuetrees

I have been trying to use AudioProcessorValueTreeState to manage the state of a plugin. I need to store the contents of some other ValueTrees in the state that are arbitrary data not linked to parameters.

in my processor constructor, i have something like this

mAPVTS.state = ValueTree("root");
mAPVTS.state.getOrCreateChildWithName("child1", nullptr);
mAPVTS.state.getOrCreateChildWithName("child2", nullptr);

In set state / get state information I serialise and restore the main APVTS value tree.

I have a UI component that stores it’s state into one of the child value trees, and when the plugin state is restored, the component seems to refer to a different value tree.

What is the best way to deal with multiple value trees in this situation and keep them all referring to the correct things?


1 Like

so making my UI component a ValueTree::Listener I could update the state member with a new reference in valueTreeRedirected() when the state is restored.

void valueTreeRedirected (ValueTree &treeWhichHasBeenChanged) override
  if(treeWhichHasBeenChanged.getType() == mState.getType())
    mState = treeWhichHasBeenChanged;

cool, I was wondering, what would work, but didn’t have the time to try things.
But that’s a nice solution…
BTW. I added a ValueTreeDebugListener to the module you just contributed to. So you can easily check, what callbacks are issued from a ValueTree: