AudioParameterInt restrict values?

Dear Juce community,

I want to save one of those ints as an AudioParameterInt : 14, 18, 28, 38 or 58. The AudioParameterInt shall not contain/return any other value. Ideally it should be linked to a ComboBox via a ComboBoxParameterAttachment
I tried several things but cannot get my head around those normalised float calculations to get this working correctly.

Any hint would be very much appreciated.


I think AudioParameterChoice is what you’re looking for.

1 Like

thanks eyalamir.
AudioParameterChoice is only creating an indexed choice of strings I can select from. Sure, I can create an array of ints somewhere else and use the index to return the value, but I would prefer to store the value in the APVTS directly (I’m using CachedValue<int> and another synced ValueTree in my other classes).

AudioParameterInt is made for continuous ranges of integers -you can see in its constructor that the range interval is set to 1, and snapToLegalValueFunction uses roundToInt. You’d have to make another subclass of RangedAudioParameter to get the behaviour you describe. Between the available options, AudioParameterChoice seems more fit.

after reviewing and testing different scenarios with subclasses of RangedAudioParameter and custom ParamterAttachment, none of my attempts were very successful. So I refactored my code, changed my valueTree to not hold the value itself but instead the index of an array of the values. This has indeed a lot of advantages, especially how the parameter is presented to the host.

Thanks everybody your help.