Non-Linear Normalizable Range Interval

Is there any way to have a non-linear interval for Normalizable Range? I would love to have step selections for a gain slider be 2, 4, 6, 9, 12, and 15 dB. Thanks!

Yep! You can use the constructor for NormalisableRange that includes the three function pointers/lambdas: convertFrom0To1Fun, converrtTo0To1Func, and snapToLegalValueFunc, for maximum control of the conversions and allowable values.

Thanks! Would you have an example of how to use these function pointers on hand? I am having trouble implementing them in my AudioProcessorValueTreeState ParameterLayout (APVTS PL). Here’s what I have so far in my PluginProcessor.h:

using ValueRemapFunction = std::function<float(float rangeStart, float rangeEnd, float valueToRemap)>;

juce::NormalisableRange<float> gainSteps2(float rangeStart, float rangeEnd, ValueRemapFunction convertFrom0To1Func, ValueRemapFunction convertTo0To1Func, ValueRemapFunction snapToLegalValueFunc = {});

Here’s what I have currently for my Input Gain in my APVTS PL:

std::vector<std::unique_ptr<juce::RangedAudioParameter>> parameters;

float gainInterval = 3.0f;

auto inputParam = std::make_unique<juce::AudioParameterFloat> (INPUT_GAIN_ID, INPUT_GAIN_NAME, gainSteps(-18.0f, 18.0f, gainInterval), 0.0f);

parameters.push_back (std::move(inputParam));

return { parameters.begin(), parameters.end() };

Here’s what my current gainSteps function looks like:

juce::NormalisableRange<float> GainAudioProcessor::gainSteps(float min, float max, float interval)
{
return { min, max, interval };
}

Thanks for your help!

I would usually do something simpler

const float myDbValues[6] = {2.0, 4.0, 6.0, 9.0, 12.0, 15.0}; //place this in your h file, as a global const variable.

then in your process

const int dbIdx = (int)( (1.0/5.0) * myGainSelectorParam->getValue()); //values go from 0 to 5
const float myNewGain = Decibels::decibelsToGain(myDbValues[dbIdx]);

In this way you have to correct gain value for the selected dB. If you need to value in dB, just remove the “Decibels::decibelsToGain” conversion.

2 Likes

This is great! Works like a charm. Thank you.

The only snag is now my sliders show 0-5, and not the actual value they represent. Is there a work around for this?

I would love it if the pop up bubbles on my sliders could read the values from the array I created and not from the APVTS, or if the values from the APVTS could be interpreted as the gain values in my array. Do you know if something like that is possible?