Better params values documentation

Could you please rename the ‘value’ arguments (to something like ‘float normalisedValue’, or float fullRangeValue) of the parameters functions to make it clear when the values are normalised or not?
And also always specify in the documentation?

it’s been a decade i’m using juce, and I still can’t get it right.

Im talking about those methods for instance:

AudioProcessorValueTreeState::Listener::parameterChanged (const String& parameterID, float newValue)

AudioProcessorParameter::Listener::parameterValueChanged (int parameterIndex, float newValue)

AudioParameterFloat::get()

AudioProcessorParameter::setValue()
2 Likes

Would love that as well!

A strong type for normalised values might be the right way to go.

That way, passing a value of the wrong type would resulting in a compilation error, showing immediately where the mistake is in the code.

1 Like

Just worked through another normalization confusion in my code… what do you think of this approach?

using ParamValNormalised = float;
using ParamValDeNormalised = float;

That won’t solve the issue because you are only creating alias names for the type, which remains float.
You could assign one ParamValNormalised value to a ParamValDeNormalised variable, for example, and the compiler would not complain.

One slightly better approach to have compilation errors whenever the types are mixed up, is to have something like:

struct ParamValNormalised
{
    float normalised;
}
struct ParamValDeNormalised
{
    float denormalised;
}

Those types still have the size of a float, but are different types in the eyes of the compiler, thus you get a compilation error if you try to assign one denormalised struct to a normalised one. Sure, you have to avoid code that does silly things with the variable members like

n.normalised = d.denormalised

but that’s up to you and the names of the variable members are of help, for sure.

I doubt one such solution would be taken in consideration by the JUCE team “as is”, because it’s basically a poor man’s version of what a strong type is.