AudioParameterFloat getDefaultValue()

I am defining some AudioParameterFloats like so:

addParameter (myParam = new AudioParameterFloat ("myParam", 
                                                 "My Param", 

Elsewhere in my code I iterate over my AudioParameterFloats and dynamically construct a slider for each one.

When doing so, I can access the first 4 parameters that were passed to the AudioParameterFloat constructor, namely:


However I cannot access the 5th parameter, which is the AudioParameterFloat’s default value. AudioParameterFloat has a defaultValue member, and a getDefaultValue() method, but they are both private.

The reason I want to access the default value is so that I can do something like this:

mySlider->setDoubleClickReturnValue(true, param->defaultValue); // No go

Before I implement a workaround, I want to check that there is in fact no way to retrieve an AudioParameterFloat’s default value once it has been set?

with getDefaultValue() you get the “normalized” value (between 0…1), i guess thats why its hidden.

To get the natural value you could dynamic_cast the AudioParameterFloat to AudioProcessorParameterWithID and than call getDefaultValue(), and than call AudioParameterFloat.range.convertFrom0to1 to retrieve the natural value.

But it would be easier if something like this would be implemented as member function inside AudioParameterFloat


dynamic_cast<AudioProcessorParameterWithID*> worked! Thank you so much.

I’m confused as to why upcasting worked, though. Does upcasting to the base class allow us to access private members of the derived class? Seems kind of sneaky, but I’ll take it!

N.B. The dynamic_cast will figure out, if the object is actually an AudioProcessorParameterWithID, otherwise return a nullptr. Therefore you should always wrap that block to check.
If you only used instances derived from AudioProcessorParameterWithID - which is the normal case - it will always work.

if (auto* paramWithID = dynamic_cast<AudioProcessorParameterWithID*> (param))
    // do stuff
else jassertfalse;
1 Like

Thanks Daniel, that is a very helpful tip. I have included the error checking.

Why exactly is AudioParameterFloat::getDefaultValue() private? cc: @jules @ed95 @t0m

I just ran into this…odd design choice, and am glad the dynamic_cast suggestion was given as a work-around…


Can somebody please explain this design choice? Why is everything private here?