AudioParameterFloat getDefaultValue()


#1

I am defining some AudioParameterFloats like so:

addParameter (myParam = new AudioParameterFloat ("myParam", 
                                                 "My Param", 
                                                 0.0f,
                                                 100.0f,
                                                 50.0f));

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:

param->paramID
param->name
param->range.start
param->range.end

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?


#2

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


#3

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!


#4

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;

#5

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