# Setting parameters using value tree state

**URL:** <https://forum.juce.com/t/setting-parameters-using-value-tree-state/24143>\
**Category:** Audio Plugins\
**Created:** [September 11, 2017, 7:55pm UTC](https://forum.juce.com/t/setting-parameters-using-value-tree-state/24143 "2017-09-11T19:55:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fenderfan7](https://avatars.discourse-cdn.com/v4/letter/f/ee7513/32.png) [@Fenderfan7](https://forum.juce.com/u/Fenderfan7)\
**Post date:** [September 11, 2017, 7:55pm UTC](https://forum.juce.com/t/setting-parameters-using-value-tree-state/24143/1 "2017-09-11T19:55:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [September 11, 2017, 8:52pm UTC](https://forum.juce.com/t/setting-parameters-using-value-tree-state/24143/2 "2017-09-11T20:52:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Fenderfan7](https://avatars.discourse-cdn.com/v4/letter/f/ee7513/32.png) [@Fenderfan7](https://forum.juce.com/u/Fenderfan7)\
**Post date:** [September 11, 2017, 9:17pm UTC](https://forum.juce.com/t/setting-parameters-using-value-tree-state/24143/3 "2017-09-11T21:17:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [September 11, 2017, 9:38pm UTC](https://forum.juce.com/t/setting-parameters-using-value-tree-state/24143/4 "2017-09-11T21:38:29Z")

</div>

> [@Fenderfan7](#):
>
> AudioProcessorValueTreeState

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

with your AudioProcessorValueTreeState instance:

```auto
APVTS.state.setProperty(...)

```

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

[https://juce.com/doc/classValueTree#ad236114dc2a8c41c799f1fc51d1614bd](https://juce.com/doc/classValueTree#ad236114dc2a8c41c799f1fc51d1614bd)

unless i’m not understanding…?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [September 12, 2017, 8:55am UTC](https://forum.juce.com/t/setting-parameters-using-value-tree-state/24143/5 "2017-09-12T08:55:31Z")

</div>

> [@Fenderfan7](#):
>
> 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().

They share the same common parent, using [AudioProcessorValueTreeState::createAndAddParameter()](https://juce.com/doc/classAudioProcessorValueTreeState#a23222d417ef62e3dcb76d4cd9a25c2d3) returns a [AudioProcessorParameterWithID](https://juce.com/doc/classAudioProcessorParameterWithID), 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).

---

<div class="post-metadata">

**Author:** ![Fenderfan7](https://avatars.discourse-cdn.com/v4/letter/f/ee7513/32.png) [@Fenderfan7](https://forum.juce.com/u/Fenderfan7)\
**Post date:** [September 12, 2017, 5:00pm UTC](https://forum.juce.com/t/setting-parameters-using-value-tree-state/24143/6 "2017-09-12T17:00:29Z")

</div>

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”, …)

---

<div class="post-metadata">

**Author:** ![Fenderfan7](https://avatars.discourse-cdn.com/v4/letter/f/ee7513/32.png) [@Fenderfan7](https://forum.juce.com/u/Fenderfan7)\
**Post date:** [September 12, 2017, 5:07pm UTC](https://forum.juce.com/t/setting-parameters-using-value-tree-state/24143/7 "2017-09-12T17:07:39Z")

</div>

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 😃

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [September 12, 2017, 10:04pm UTC](https://forum.juce.com/t/setting-parameters-using-value-tree-state/24143/8 "2017-09-12T22:04:11Z")

</div>

> [@Fenderfan7](#):
>
> Then I changed the parameter Value by using the pointer and the setValueNotifyingHost method.

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

There is also another construct, which is the Value object, using [AudioProcessorValueTreeState::getParameterAsValue();](https://juce.com/doc/classAudioProcessorValueTreeState#ae5e957008fef2fd920be6737ae520538)  
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…
