ValueTree force parameter update for same value

I’m using the value tree system. I want to retrigger for example sample loading (because the sample file has changed), but the value tree does not trigger the message because the value (in my case the path) is the same.

I often end up doing something like this:

auto pathValue = reeState->state.getPropertyByValue(name);
reeState->state.setProperty(name, "", &undoManager);
reeState->state.setProperty(name, pathValue, &undoManager);

I would prefer a way to retrigger a message with the same value without notifying the whole system with the empty path.

Is there a way to change the property without notification or force the state to resend the same value?

I ended up not using the ValueTree to reload samples in that case and trigger it directly.
I’m still interested in a solution. The same problem also occurs when I try to sync an internal data structure for DSP processing with the ValueTree.
It does not set the default values in that case because the parameters are already set to default.

My solution would be having a (maybe private) loadSamples() method that you either call directly or the ValueTree::Listener calls it.

N.B. the most tricky bit with ValueTree (especially with UndoManager) is IMHO to pedantically trigger everything through the tree. The situation you are having is often because the listener was not yet attached when the tree was filled. E.g. if you call loadSamples only in propertyChanged, but the tree was set entirely before. In that case you would need to do the same when the ValueTree was parsed, probably in the constructor.

TL;DR: try to avoid the situation where you have to re-trigger, that points to a mistake in the flow.

1 Like

Thanks for the reply. I’m using loadSamples() directly now instead of trying to retrigger the ValueTree property. I also think this is the right way to go for this special case.

I will try to avoid this situation in the future also I think it is some kind of optimization that the value tree does not notify the listeners if the value is the same that makes things a bit more complicated.