How to access AudioProcessorValueTreeState parameters en masse?


#1

I’m working on a plug-in which has over 500 parameters (a not-at-all unusual number AFAIK) and utilises the AudioProcessorValueTreeState system. How can I access parameters en masse? For example: suppose I want to smooth parameter changes using LinearSmoothedValue - am I supposed to use 500 lines of code like:

volume.setValue (*valueTreeState.getRawParameterValue ("volume"));
osc1Frq.setValue (*valueTreeState.getRawParameterValue ("osc1Frq"));
// and so on...

Or is there a more practical way?


#2

AudioProcesorValueTreeState isn’t the fastest.

If your process() call is heavy you can optimize it by getting the pointers prior to the actual callback to avoid overhead of searching parameters each time.

Eg (on constructor / prepareToPlay() )

float* m_volume_param = (*valueTreeState.getRawParameterValue ("volume");

and then (on processBlock() )
volume.setValue (m_volume_param);


#3

Hi ttg, thanks for your comment. Yes, I’ve noticed that getRawParameterValue() is pretty slow, even half a dozen accesses at my control rate noticeably increases CPU use so thanks for that suggestion. I’m still stuck with 500 lines of code though!


#4

So you are still better off than your user, he/she is supposed to manage 500 entries in his automation setup dialogues… I can’t really see that helpful, but without knowing your usecase…
You are probably aware, that you only need to add parameters for values, that the DAW is supposed to handle, and that the user would eventually automate in the hosts UI.
Isn’t there a way to provide higher level values, that have an effect on a bunch of values?

So that’s probably not the answer you had hoped for…


#5

How about using:

  • an array of 500 LinearSmoothedValue objects
  • attach a listener to the parameter in the AudioProcessorValueTreeState
  • in the listener callback set the appropriate LinearSmoothedValue value (you could use a HashMap to map the parameterID string to the array index)
  • in the audio callback access your LinearSmoothedValue objects for audio processing

Most of this can be done using for loops so < 500 lines of code…


#6

Whenever you have a big list of things in your code and you need to auto-generate various bits of other code to list or operate on them all, the X macro is your friend:


#7

Hi daniel, I’ve never had a user contact me and ask to have a feature removed :slight_smile: But I get your point about automation, I’ve never thought about parameters in that way before.


#8

Glad you got me the right way :slight_smile: I know it is always a tradeoff between getting a lot of freedom or having only little options to find the result you are happy with. For both there is good reason…


#9

Hi martinrobinson, thank you for your suggestions. I actually started using a listener callback but didn’t like the idea of a 500 entries-long if-else statement! Maybe your HashMap suggestion is what I’m looking for. The only problem I’d be left with is how to add 500 listeners - that’s another 500 lines of code :slight_smile: This was all much easier in the old VST2 system with enums and switch cases…


#10

Hi jules, I’ve never heard of “X Macros” before so thanks for the link. I’m actually doing something similar to add the parameters in the first place by using StringArrays for IDs and Names. Presumably I could use the X Macro idea to insert the Ranges and other stuff. Seems kind-of naughty to use macros though!


#11

IMHO the X macro is the only defensible use of macros in modern C++, because it can help DRY your codebase by localising all the information about a set of things in one big table.