# AudioProcessorValueTreeState and child valuetrees

**URL:** <https://forum.juce.com/t/audioprocessorvaluetreestate-and-child-valuetrees/18062>\
**Category:** General JUCE discussion\
**Created:** [June 11, 2016, 1:31pm UTC](https://forum.juce.com/t/audioprocessorvaluetreestate-and-child-valuetrees/18062 "2016-06-11T13:31:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![olilarkin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/olilarkin/32/7142_2.png) [@olilarkin](https://forum.juce.com/u/olilarkin)\
**Post date:** [June 11, 2016, 1:31pm UTC](https://forum.juce.com/t/audioprocessorvaluetreestate-and-child-valuetrees/18062/1 "2016-06-11T13:31:06Z")

</div>

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.createAndAddParameter(...)
mAPVTS.createAndAddParameter(...)
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?

Thanks

---

<div class="post-metadata">

**Author:** ![olilarkin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/olilarkin/32/7142_2.png) [@olilarkin](https://forum.juce.com/u/olilarkin)\
**Post date:** [June 12, 2016, 2:35pm UTC](https://forum.juce.com/t/audioprocessorvaluetreestate-and-child-valuetrees/18062/2 "2016-06-12T14:35:22Z")

</div>

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;
  }
}
```

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [June 12, 2016, 3:39pm UTC](https://forum.juce.com/t/audioprocessorvaluetreestate-and-child-valuetrees/18062/3 "2016-06-12T15:39:45Z")

</div>

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:

> <https://github.com/ffAudio/ffGuiAttachments/blob/master/ff_gui_attachments/ValueTreeDebugListener.h#L40>
