Passing around an AudioProcessorValueTreeState


I know that a normal JUCE ValueTree is safe to pass round by value since it is reference counted. Is this the same for an AudioProcessorValueTreeState? I understand that it uses an underlying ValueTree so if I create a second APVTS and assign it the first one will it simply refer to the same underlying ValueTree?


APVTS is not reference counted, and is declared non-copyable. There are two main parts to APVTS: the ValueTree state, and a map of parameter adapters which connect the ValueTree with AudioProcessor parameters. This machinery is not intended to be duplicated for each AudioProcessor.

So for accessing parameters in the editor would you recommend not using a reference to the APVTS?

If you mean a C++ reference, as in type APVTS&, then yes, you can use that. What you can’t have is a new APVTS object made from another one -you literally can’t, because it’s non-copyable, and even if you could it wouldn’t refer to the same “underlying data” as with ValueTree or Value. Both of these hold a ReferenceCountedObjectPtr to an underlying type (ValueTree::SharedObject, Value::ValueSource) that inherits ReferenceCountedObject -that’s why you can copy them without duplicating their actual content.