Hi there!
Here’s a MWE of the problem, written as a small GoogleTest:
// create ValueTree and set a property
ValueTree treeA("myValueTree");
treeA.setProperty("myProperty", 1, nullptr);
// connect a juce::Value to this property
Value connectedValue;
connectedValue.referTo(treeA.getPropertyAsValue("myProperty", nullptr, true));
EXPECT_EQ(connectedValue.getValue().operator int(), 1);
// simulate loading the state of the tree from XML by replacing
// the entire tree with a new one with different data in it
ValueTree treeB("myValueTree");
treeB.setProperty("myProperty", 5, nullptr);
treeA = treeB;
// This fails.
EXPECT_EQ(connectedValue.getValue().operator int(), 5);
The solution would be to overwrite void valueTreeRedirected(...)
in ValueTreePropertyValueSource
AND/OR to make ValueTree::operator=()
send a ValueTree::Listener::valueTreePropertyChanged(...)
callback to its listeners.
I know I can use ValueTree::copyPropertiesAndChildrenFrom()
but it is not very intuitive why I must do this.
Interestingly, the AudioProcessorValueTreeState
has the exact same problem: When loading the state of the tree from XML (which is the recommended way of doing it - see the tutorials), internally, operator=()
is used - showing the same problems. See here: APVTS: Value returned by getParameterAsValue() breaks connection to the tree