AudioValueTreeState and addParameter syntax

Hi, i want to know if i can use the AudioValueTreeState to save and restore the state of the plugin if i have my parameters created with:

addParameter (inputVolumeParam = new AudioParameterFloat ( etc....

like the DspModulePluginDemo, instead of:

parameters.createAndAddParameter( etc...

i initialized as in the tutorial:



AudioProcessorValueTreeState parameters;


// Default Initialization

parameters(this, nullptr)


addParameter (parameter1 = new AudioParameterFloat...;

addParameter (parameter2 = new AudioParameterFloat...;

addParameter (parameter3 = new AudioParameterFloat...;

parameters.state = ValueTree(Identifier("myParams"));

but when i lauch the host and load the plugin i get an exception in Juce_AudioProcessorValueTreeState.cpp

jassert (dynamic_cast<Parameter*> (ap) != nullptr);

so i was wondering if i have to add all the parameters with the createAndAddParameter method or i can manage to use it with the actual addParameter ( etc…

thx all!

The AudioProcessorValueTreeState has it’s own private class AudioProcessorValueTreeState::Parameter. It inherits AudioParameterWithID.
AudioParameterFloat is also an AudioParameterWithID, but not an AudioProcessorValueTreeState::Parameter, that’s why the assert fires.

So to use the AudioProcessorValueTreeState, you have to use the AudioProcessorValueTreeState::createAndAddParameter() version.


Thx for a so fast answer daniel, that make total sense, i was scared that i had to recreate all the parameters with the other method, this will require so many fixes in the code, so, is there any workaround to save the state and restore keeping this syntax or createAndAddParameter() is the way to go?

IMHO createAndAddParameter() is the way to go. I didn’t find anything possible with AudioParameterFloat etc. that wasn’t possible with the AudioProcessorValueTreeState.
Also connecting the the AudioProcessorValueTreeState (can we just call it ProcessorState, please?) using the SliderAttachment/ComboBoxAttachment etc. is extremely helpful.

So I never look back… Sure, everything has room for improvement (undo/redo seems to have issues, I would love to have the slider using the textToValue lambdas from the parameter automatically, etc…)

sure you can call ProcessorState :smiley: probably i will take a deep breath and rebuild all the parameters and adapt the code, now that you mention it, hopefully i don’t go offtopic, can i ask about the ComboBoxAttachment? will that allow me to update the items list of the ComboBox in real time in the parameter? because with the AudioparameterChoices untill i’m so stupid i could not find anything to change the list once the parameter was created, thx so much for your time!

lol, that prayer went rather to the juce people…
I can call “using ProcessorState = AudioProcessorValueTreeState;”, but my problem is rather the forum, where I don’t have code completion…

I would advise against it. In the host the parameters are usually normalised to 0…1 values. Hence the number of items in the combobox parameter needs to stay constant in order to successfully load and save the parameter. As a workaround you can define a fixed max number of options, but only show a subset of options in the combo box.

But it sounds a bit like it is a parameter, that you don’t necessarily want to automate. In which case I would suggest to create a simple ValueTree leaf under the AudioProcessorValueTreeState::state. I created an alternative attachment for attaching comboboxes to normal ValueTrees, not AudioProcessorValueTreeState::Parameters:

1 Like

for my needs what i need are just 2 items in the list, i want to populate the ComboBox with file names based on a chosen directory using an open file manager, so i thought that need an AudioParameterChoice with just the directory path and the selected item name, and fill the ComboBox based on that infos but still to keep the settings with multiple instances of the plugin i need a parameter, something like AudioParameterString, that in this case i thought AudioParameterChoice considering that has an array of strings, no automations needed, but again if i cant change the values is useless for this case, i will give a look to your code, thx as always for your help :slight_smile: