# Non-Linear Normalizable Range Interval

**URL:** https://forum.juce.com/t/non-linear-normalizable-range-interval/44370
**Category:** Audio Plugins
**Created:** [February 11, 2021, 2:44am UTC](https://forum.juce.com/t/non-linear-normalizable-range-interval/44370 "2021-02-11T02:44:15Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![baintonaj](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@baintonaj](https://forum.juce.com/u/baintonaj)
#### Post date: [February 11, 2021, 2:44am UTC](https://forum.juce.com/t/non-linear-normalizable-range-interval/44370/1 "2021-02-11T02:44:15Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)
#### Post date: [February 11, 2021, 2:49pm UTC](https://forum.juce.com/t/non-linear-normalizable-range-interval/44370/2 "2021-02-11T14:49:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![baintonaj](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@baintonaj](https://forum.juce.com/u/baintonaj)
#### Post date: [February 11, 2021, 7:17pm UTC](https://forum.juce.com/t/non-linear-normalizable-range-interval/44370/3 "2021-02-11T19:17:11Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![lcapozzi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lcapozzi/32/10960_2.png) [@lcapozzi](https://forum.juce.com/u/lcapozzi)
#### Post date: [February 11, 2021, 8:32pm UTC](https://forum.juce.com/t/non-linear-normalizable-range-interval/44370/4 "2021-02-11T20:32:43Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![baintonaj](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@baintonaj](https://forum.juce.com/u/baintonaj)
#### Post date: [February 11, 2021, 10:54pm UTC](https://forum.juce.com/t/non-linear-normalizable-range-interval/44370/5 "2021-02-11T22:54:24Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![baintonaj](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@baintonaj](https://forum.juce.com/u/baintonaj)
#### Post date: [February 12, 2021, 1:25am UTC](https://forum.juce.com/t/non-linear-normalizable-range-interval/44370/6 "2021-02-12T01:25:28Z")

</div>

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?
