Best way to get a value from an AudioProcessorValueTreeState instance

Hi everyone!

Sorry for such a newbie question but, I’m currently working on a plugin for myself and I am using an APVTS to handle all of my parameters. I was wondering what would be the best way to get a value from this tree?

I know there is the getRawParameterValue() method but it always returns an atomic float and sometimes, I am using parameters that aren’t floats. It feels strange to me to cast the atomic float to the correct corresponding type of the parameter from which I want the value of. I also know that the getParameterAsValue() method exists as well but it always brings me to the same kind of solution.

For context, I want to get the value of a parameter to then process the main audio buffer. For example, one of these parameters may be an AudioParameterInt (like a time in milliseconds).

Thank you for your help!

The getRawParameter is indeed a bad choice.
Ideally you dynamic_cast the parameter once to the correct subtype and keep it as member. Then you can call get(), which returns the right type in the right range. This method can’t be virtual, because C++ cannot overload with different return types.

// member
juce::AudioParameterInt choice = nullptr;

// in constructor
choice = dynamic_cast<juce::AudioParameterInt*>(apvts.getParameter("myChoice"));
// doube check here once in case the parameter doesn't exist or was changed
jassert (choice);

// use it, returns a real int:
switch (choice->get())
{
case 0:
}

HTH

Thank you @daniel! I knew something felt wrong about this solution.