NormalisableRange not suited for integer values

It would be nice if we could use integer types for specializations of juce::NormalisableRange. Right now, the function convertTo0to1 returns a ValueType, and convertFrom0to1 takes a ValueType parameter, which obviously doesn’t make much sense when ValueType is, for example, int.

My use case is a custom NumericProperty class, which is basically a generic class similar to juce::Value, having a NormalisedRange baked directly into it. I would appreciate being able to use the NormalisedRange's nice features like skew factor without having to use NormalisedRange<float> even for integer types, and doing my own rounding/casting.

IMO, it would make sense to have the following function signatures:
float convertTo0to1(ValueType v)
ValueType convertFrom0to1(float proportion)

Without checking the code I suspect some template specialisation could be done to achieve that.

Or probably a slightly easier change, just add a second template argument, something like…

template<ValueType, FloatType = ValueType>

and the function signatures would be…

FloatType convertTo0to1 (ValueType v)
ValueType convertFrom0to1 (FloatType proportion)

Then you could do NormalisedRange<int, float>, or NormalisedRange<int, double> if you so wish, and it shouldn’t break anything.

I do know how to fix the existing class, I just wanted to make the JUCE devs aware of this use case and start a conversation, so that we can perhaps improve the library itself :slight_smile:

1 Like