AudioParameterInt interval (to, at least, 1)?


It seems that the interval of a Slider's range is not automatically set when using SliderAttachment between the Slider and an AudioParameterInt. Maybe a default setting of 1 could be used? In my case, I’m using IncDecButtons and found out I had to manually call something like incDecSlider.setRange(incDecSlider.getRange(), 1); after making the attachment to have the plus/minus buttons working as expected. Am I missing something?


It seems to me that you have perfectly understood, the slider has no reason to take into account the fact that your audioparameters is an int. For my part, I would do the same as you, using the setRange function.

(Note: using latest tip on develop branch)

It (the Slider) certainly would have a reason to take this into account because his NormalisableRange member would be bound to the AudioParameterInt's one upon attaching.

I have the feeling that something is missing. If you take a look at the AudioParameterFloat class, it has two constructors, the second one arbitrarily sets the interval to 0.01f (which works well with my inc/dec buttons if I change my parameter type to this one, of course). Why wouldn’t there be such a constructor for AudioParameterInt?

I’m not sure that’s the right answer, but it seems to me that the definition of normalisableRange is made up of float, maybe that’s the explanation

Seems like this may be two things causing the issue…

The construction of the NormalisableRange<float> member in AudioParameterInt uses the constructor that takes the conversion lambdas… but that constructor leaves the interval at its default (and doesn’t even provide an argument for it):

In the SliderAttachment class it checks if the interval is non-zero and uses it if so:

Does it fix your issue if you add a range.interval = 1.0f inside the constructor of AudioParameterInt?

Unfortunately, no. Plus, this requires to remove the const qualifier on the member.

Sorry, YES, it does work. I first tested with an AudioParameterChoice and modified AudioParameterInt's constructor by mistake, but well, isn’t it exactly the same concern for AudioParameterChoice after all?

Anyway, this “fix” works, but still requires to remove the const qualifier for range.

I suppose if the reasoning is correct, that could be corrected in an official way?

Thanks for your help!

1 Like

I’ve run into annoyances myself with that particular NormalisableRange constructor requiring non-const declarations and putting the interval on the next line down :slight_smile:

Perhaps @t0m has some input? Is the interval left out since a snapping function can be provided in that constructor?

Ok, I’ve been trying to get a better understanding of all this, starting from the Slider code. When a Slider is in IncDecButtons style and then plus/minus button gets clicked, incrementOrDecrement is called using normRange.interval which is natural but from there on, if interval is not set accordingly, nothing’s gonna happen.

So, again, we need to be able to set it when creating an AudioParameterInt. This has nothing to do with the NormalisableRange.snapToLegalValueFunction lambda.

And I also definitely see no reason why an AudioParameterInt couldn’t have a default interval of 1. Only makes sense IMHO.

1 Like

Yes, this is something we could improve.

However, simply setting range.interval = 1.0f means that we take the branch indicated in TonyAtHarrison’s post and we don’t get the value snapping behaviour we expect, so we need to do something a bit more involved.

@t0m what is the purpose of the conditional? It seems like a NormalisableRange<double> could be created by mapping all the attributes of the parameter range (like it’s doing with the conversion functions in the else body) and then set using Slider::setNormalisableRange()

I believe it was to preserve backwards compatibility in some cases.


Works like a charm. Thanks a lot, Tom!