(avgValue = (lowValue + highValue) * 0.5f, midValue < avgValue - 0.0001f || midValue > avgValue + 0.0001f)
The problem relies on the fact that avgValue (same as lowValue, highValue, etc.) is a float value parsed from the string returned by a call to the VST method getParameterDisplay().
In my framework, I can set how many fractional digits are being returned by getParameterDisplay() and I set it to 2, in this case.
What happens here is this:
- lowValue is parsed from the string "0.01", which is fine.
- highValue is parsed from the string "50.00", which is fine as well.
- midValue is parsed from the string resulting from the conversion of the float value 25.005 to a string of 2 fractional digits, which turns to be "25.01" because of the rounding!
So I have:
midValue = 25.01;
avgValue = 25.005;
and this causes the above check to evaluate to true (because midValue > avgValue + 0.0001f) and reset the parameter range to 0.0 - 1.0.
My question is: is that check really needed? If so, why?
A developer may need to restrict the fractional digits returned by the getParameterDisplay(), for example to make the displayed value more friendly to the user (avoiding stupid values like 25.0049999999992), but that check may cause the rounding to introduce the problem I've described above.
Can this be considered a bug?
Please discuss.
Thanks,
Federico Berti - Ignite Amps