Getting Automation labeling/scaling to work with an AudioProcessorValueTreeState

Hey all,

Currently I use an AudioProcessorValueTreeState with the createAndAddParameter method as a means of tying together GUI, automation and my processor, as well as for maintaining state when a host reopens a saved project using my plugin.

I’ve had no problems with getting the Editor GUI to display what I want it to; using objects like a SliderAttachment causes the associated Slider to display the correct value range for the associated AudioProcessorParameter.

However, I’m uncertain as to how to get automation lanes in my host to do the same. Currently, all parameters are displayed as going from 0 to 1 in Ableton-

Going by other plugins, I know that the DAW/host is capable of displaying different value ranges. How can I go about doing this with JUCE? For most of the parameters, I simply want them to display the bounds of their NormalisableRange’s,

An additional challenge- currently, all automation parameters move linearly. This is an issue for the gain and cutoff parameters, which should move logarithmically. I was able to overcome this in the GUI via the use of Slider’s setSkewFactorFromMidpoint, but I’m unsure of how to do it with automation. Is this something I must set with the NormalisableRange I use within createAndAddParameter?

One more challenge- The parameters go associated with Dry Gain and Wet Gain go from 0.0 to 4.0 (-∞dB to +6db). I want the automation range to display neither 0 to 1 nor 0 to 4, but rather these logarithmically determined decibel values. Is there a way that can be done?

Thank you for your insight!

Hi,

I’m using this little helper:

AudioProcessorParameter* createAndAddDecibelsParameter (
    AudioProcessorValueTreeState* This,
    String parameterID,
    String parameterName,
    String labelText,
    float defaultValueInDb,
    float minDb = Decibels::gainToDecibels(0.0f),
    float maxDb = Decibels::gainToDecibels(1.0f),
    float dbAtMidPoint = -6.0f,
    std::function<String (float)> valueToTextFunction = {},
    std::function<float (const String&)> textToValueFunction = {}
)
{
    auto skewFactor = log (0.5) / log ((dbAtMidPoint - minDb) / (maxDb - minDb));

    if(!valueToTextFunction)
        valueToTextFunction = [](float value){ return Decibels::toString(value); };

    if(!textToValueFunction)
        textToValueFunction = [](const String& str) { return parseDecibels<float>(str); };

    return This->createAndAddParameter(
        parameterID,
        parameterName,
        labelText,
        NormalisableRange<float>(minDb, maxDb, 0.0f, skewFactor),
        defaultValueInDb,
        valueToTextFunction,
        textToValueFunction
    );
}

And here is how I use it:

createAndAddDecibelsParameter(&state, "dry", "dry", "dry", -6.0f, Decibels::gainToDecibels(0.0f), 0.0f, -6.0f);

Also note, that this commit fixes, that the SliderAttachment was not correctly setting the Skew-Factor of the slider.

this is how that looks in Live:

Best,
Ben

1 Like

Thanks Ben, this helps certainly. It seems that it’s the valueToTextFunction that tells the host/DAW how to display the parameter ranges, yeah? I notice that my Slider’s with appropriate SliderAttachments still just display the bounds of the NormalisableRange rather than the valueToTextFunction’s result, is this intended behavior?

Yes, it’s the valueToTextFunction, at least with VSTs. And yes, AFAIK, that’s by design. So the sliders label would not display the units for example (unfortunately). Note however, that the slider can be made non-linear via the skew factor, so that it works the same way the automation lane does. But I think you got that already :slight_smile:

Best,
Ben