Setting parameters using value tree state


#1

I have attached a slider to a value tree state, just like in the AudioProcessorValueTreeState class tutorial. This works perfectly.
Now, when I save the parameters, I would like to save all but one parameter. The parameter, that is not saved, should be set to its default value, when the plugin is restored.
How should I implement this? I have seen no method to directly change parameter using Value Trees, so that I could set it to default after restoring the value tree.

I would also like to know, if there is any way to influence a parameter attached to a slider from inside the plugin, for example via timer callbacks. Of course the parameter should still be automatable. So for example, if I have a slider, that under certain circumstances should not go over half of its range.
Is there any way to do this sensibly? Or should I reconsider my design decisions?

Hopefully I did not confuse the terms too much, I am still very new to the value tree state class etc.


#2

why not just ‘parameter.setValue(defaultValue)’ after your value tree is restored?


#3

As far as I understand it, this would use the AudioParameter Class, which would not work with the Value Tree State class. I definitely cannot use this method on my parameter, since it is not initialised as Audio Parameter, but as a part of the value tree using AudioProcessorValueTreeState::createAndAddParameter().
Or am I misunderstanding something here?
Thanks for your fast answer, though.


#4

https://juce.com/doc/classAudioProcessorValueTreeState#ad7de02052d045956f56018e009dc50c6
contains a ValueTree member, so…

with your AudioProcessorValueTreeState instance:

APVTS.state.setProperty(...)

that’s how you set individual properties of your tree after it’s restored…

https://juce.com/doc/classValueTree#ad236114dc2a8c41c799f1fc51d1614bd

unless i’m not understanding…?


#5

They share the same common parent, using AudioProcessorValueTreeState::createAndAddParameter() returns a AudioProcessorParameterWithID, so all methods of the AudioProcessorParameter are available, especially setValue and setValueNotifyingHost.

I would advise against using setValue directly, because then the host and the plugin may have different states, leading to data loss of subsequent automation (i.e. the host not sending changes, because it assumes, the plugin has already that state, if that makes sense).


#6

I’ve tried to do that with .setProperty, the problem is, that this function takes a node of the value tree as input, not the parameter ID. The parameter ID is the only thing I have, since I set it on creation of that parameter by using createAndAddParameter(). I believe this is why it doesn’t work if I call that using APVTS.state.setProperty(“gain”, 0.0, nullptr), assuming I used APVTS.createAndAddParameter(“gain”, …)


#7

Ah, ok, so would you also advice against using setValueNotifyingHost?
I would have to make a pointer or something like that, that is assigned to the parameterWithID, so I can access it, right? There is no way I can get a pointer to the parameterWithID from of the Value Tree?
Thanks for the answers by the way, I did not really look at the return value of createAndAddParameter yet

Edit: Okay, I think I got it to work by creating a AudioParameterWithID pointer and than setting it to the address return by createAndAddParameter. Then I changed the parameter Value by using the pointer and the setValueNotifyingHost method.
Still have to run more tests, to make sure this construction is stable :smiley:


#8

Yes, that’s what I meant, glad you figured that out.

There is also another construct, which is the Value object, using AudioProcessorValueTreeState::getParameterAsValue();
Even though I never used that:

Value gain = state.getParameterAsValue ("gain");
gain = 0.7f;

This will automatically notify the state… just another option to play with…