Sync between ValueTree properties


I’ve got two ValueTrees, one in the Processor and one in the Editor. Now, I’d like to synchronize a property between these two trees. I was trying referTo on the property as value, but it doesn’t work. What is the best way to solve this?

// In the processor
: ValueTree processorVT("Processor")
processorVT.setProperty("First", 1.0, nullptr);

//In the Editor
: ValueTree editorVT("Editor")
editorVT.setProperty("First", 1.0, nullptr);

editorVT.getPropertyAsValue("First", nullptr).referTo(p.processorVT.getPropertyAsValue("First",nullptr) );


That final line isn’t doing anything for a couple of reasons. First you’re creating two temporary Value objects that are being immediately destroyed. And second, even if you did store the Values, you wouldn’t have bidirectional synchronisation because when you call referTo you lose one side of the link.

I’d go for an approach using ValueTree::Listeners.


OK, thanks! This makes sense on a second glance.