Hello,
Is there any convinient way to change Range of AudioParameterFloat?
I have release time parameter with range defined in the constructor:
std::make_unique<AudioParameterFloat>(ParameterID(RELEASE_ID, 1),
RELEASE_NAME,
NormalisableRange<float>( RE_MIN, RE_MAX, RE_STEP),
RE_DEFAULT)
But I also have auto release option. And after auto release is engaged I don’t want to turn off release time knob, but change the range of it little bit.
I see NormalisableRange<float> range
is public component of AudioParameterFloat
. But is it good idea to just call:
AudioParameterFloat* prm = dynamic_cast<AudioParameterFloat*>(pajParams.getParameter(RELEASE_ID));
if(prm != nullptr)
{
prm->range = NormalisableRange<float>(newMin, newMax, newInterval);
prm->range.setSkewForCentre(newSkew);
}
For any advice great thanks in advance.
Best Regards
You have two viable solutions:
-
Let your parameter having a 0~1 range and just change what is displayed to the user. You’ll deal with the normalisation outside your parameter class. This is what I do today when needed.
-
Changing your parameter range when needed. I successfully used this technique on a commercial plugin I released years ago.
I have a method in the processor that I call when I need to change a parameter’s range. I have my own float parameter class with some customisations:
void MyAudioProcessor::changeParameterRange(AudioProcessorParameter* par, const float start, const float end,
const float skew, const String& paramUnit, const float defValue)
{
My_NewFloatParameter* fp = dynamic_cast<My_NewFloatParameter*>(par);
fp->changeRange(start, end, skew, paramUnit);
fp->setDefaultValue(defValue);
}
In my custom parameter class I have this method:
void changeRange(const float start, const float end, const float skew, const String& paramUnit)
{
paramRange.start = start;
paramRange.end = end;
paramRange.skew = skew;
unitString = paramUnit;
}
So, when you need to change the parameter you can just call the first method, being sure it needs to be updated:
if(currentState != lastState)
{
changeParameterRange(param1, 0.0f, 100.0f, 1.0f, "%", 50.0f);
lastState = currentState;
}
In this way you’ll avoid to constantly changing the param range every time the user changes a parameter.
Hope this helps.
Luca
1 Like
Hmm… great thanks for such detailed and helpful answer.
But due to 2. solution. I see you are actually do the same as it is in my code. But you don’t create new range as I do. You instead just assigning new values to start, end and skew. I wonder if it makes any difference.
But what is more frustrating I found out issue in juce::Slider
when changing the range of attached parram. The scenario looks as following:
When I attach param to Slider
and param at it’s current state has narrow range, than when I change the range to be wider the slider still remember old narrow range. And I am not sure what is the best solution for that. Should I reattach param to slider or update range of slider by myself?
At the moment I just make sure that param has wider range when initialising Slider
. But it is stupid because when plugin editor is closed, and range of param is narrow, then during opening editor I need to reset range to be wider, attach it to slider and then back range to be narrow. And I am not sure what happen when there are some automations currently changing the param in real time.
Have you managed such issue before?
By the way I also wonder what exactly is in your code the paramRange
? Is it juce::NormalisableRange<float>
?
Or something more customised?
Best Regards
I don’t use ranges on my sliders, since almost all of them are filmstrip based. Basically I set them this way:
mySlider->setRange(0.0, 1.0, knobResolution);
where “knobResolution” is usually 1.0/(float)(numFrames-1)
Hmm ok, it seems reasonable.
Great thanks for help.