Getting AudioParameters out of an APVTS

#1

How to get various types of AudioParameter values out of an APVTS? (I’ve managed to get them in and attached to their respective controllers.)

This tutorial shows use of getRawParameterValue(“parameterID”), which kinda works, although returns a float* rather than an AudioParameterFloat.

Same for AudioParameterBool’s and AudioParameterChoice’s. Could use examples of accessing current non-normalized values for each AudioParameter type from an APVTS, for plugin processor to utilize. Thanks.

0 Likes

#2
RangedAudioParameter *parameter = state.getParameter("gain");

AudioParameterFloat *parameterFloat = dynamic_cast<AudioParameterFloat*>(parameter);

if (parameterFloat)
{
  DBG("parameterFloat: " << parameterFloat->paramID << " = " << parameterFloat->get());
}
0 Likes

#3

That is a good way to see, what’s happening. But you can also condense it into one(+) line:

if (auto* parameterFloat = dynamic_cast<AudioParameterFloat*> (state.getParameter("gain")))
{
  DBG("parameterFloat: " << parameterFloat->paramID << " = " << parameterFloat->get());
}
0 Likes

#4

Thank you both. Another related question:

Is there a way, within the APVTS initializer, to assign Processor’s own pointers to each object created by std::make_unique<AudioParameterFloat>(…), so Processor would have direct access, rather than “getting” from the tree and dynamic casting?

Or is that the opposite of the whole concept of the tree?

0 Likes

#5

I’ll answer my own question :grinning:. It is possible, and the pattern is here: AudioProcessorValueTreeState Improvements

0 Likes