AU Wrapper Parameter Text String Length

Was having issues with display strings showing up in my AU after making my own parameter subclasses, and I noticed in the AU wrapper:

case kAudioUnitProperty_ParameterStringFromValue:
{
    if (AudioUnitParameterStringFromValue* pv = (AudioUnitParameterStringFromValue*) outData)
    {
        if (juceFilter != nullptr)
        {
            if (auto* param = getParameterForAUParameterID (pv->inParamID))
            {
                const float value = (float) *(pv->inValue);
                String text;

                if (LegacyAudioParameter::isLegacy (param))
                    text = String (value);
                else
                    text = param->getText (value / getMaximumParameterValue (param), 0);

                pv->outString = text.toCFString();

                return noErr;
            }
        }
    }
}
break;

getText() is called with a length of 0… since I do abide by that length arg in my param classes it was just returning an empty string every call.

Is there a reason for 0 or should I be considering a 0 value as “unrestricted” length?

1 Like

I should note this only applies if you’re writing your own text/value conversion functions and actually applying that length argument.

The default parameters in JUCE (AudioParameterChoice, AudioParameterInt, etc.) don’t utilize the length argument in their default text/value conversion functions, as seen in the various class constructors in this file:

Yes, the length restrictions are distributed a little sporadically around the API. Interpret a length of 0 as unlimited.

2 Likes