I’m using a ValueTree to store a bunch of parameters for some gui interaction, which are then sent through to the DSP via a lock free buffering system, and I’m interested to hear what the standard way to use a ValueTree for this.
Let’s say we have a PluginEditor with a single ValueTree tree;
with one Identifier id_sliderval;
and double value for the slider value for that property, and we have a Slider that is somewhere in a SubPanel that the PluginEditor doesn’t have to know about directly.
Both the SubPanel that holds the slider, and the PluginEditor that holds the SubPanel would want to add themselves as a Listener to the ValueTree, so the PluginEditor listener can push values to the DSP, and the SubPanel can update the position of the slider when the valueTreePropertyChanged
call is made (eg when undo / redo changes the property and the slider needs to reflect what is there):
void SubPanel::valueTreePropertyChanged(ValueTree& treeWhosePropertyHasChanged, const Identifier& property)
{
if (treeWhosePropertyHasChanged == tree && property == id_slider)
{
slider.setValue(double(tree.getProperty(id_sliderval)), NotificationType::dontSendNotification);
}
}
Now when the sub panel receives a sliderValueChanged
message from the slider it will naturally want to call:
void SubPanel::sliderValueChanged(Slider* s)
{
if (s == &slider)
{
tree.setProperty(id_sliderval, slider.getValue(), &undomanager);
}
}
and this will correctly call down to the PluginEditor, but it will also call back to the SubPanel valueTreePropertyChanged, which is not ideal, especially when the situation is a little more complicated with multiple trees all interacting, possibly multiplying the number of updates going round.
Is there an easy way to re-structure things so this sort of thing doesn’t happen without having to resort to hacks like temporarily adding / removing listeners. Is it best just to let the loop happen once, with the terminating condition of no notification being sent on the second call to slider.setValue?
I figured this sort of thing should be standard practice by now, so to save time on my part I thought I’d ask you guys what it is