[NEVER MIND] Rounding in NormalisableRange<float> causing off-by-one when loading old data

When loading old (pre-JUCE) session data, the value I get from the old session data in one particular instance is 0.419230759, which converts to 120.61526216 (with a range of 20 to 260, and increment and skew of 1). But the code below then rounds that value up, causing the resulting value to be 121, even though the original value was 120.

    ValueType snapToLegalValue (ValueType v) const noexcept
{
    if (snapToLegalValueFunction != nullptr)
        return snapToLegalValueFunction (start, end, v);

    if (interval > ValueType())
        v = start + interval * std::floor ((v - start) / interval + static_cast<ValueType> (0.5));

    return (v <= start || end <= start) ? start : (v >= end ? end : v);
}

The rounding occurs because “if (interval > ValueTye())” is true. I have no idea what that line is really doing. This is a float value range, btw.

Is there a way to prevent this rounding up, without breaking the otherwise working parameter and its attached slider?

Never mind. The problem was that our old software had a bug, and the new software has no way to know that the data is bad for that value. We’ll just live with the off-by-one in that case.

1 Like