Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uiSlider bug: Maximum value not reached when Minimum value negative #650

Open
mtarenskeen opened this issue Jun 10, 2024 · 4 comments
Open

Comments

@mtarenskeen
Copy link

When I create a uiSlider (rotary, linear bar, inc/dec button) and set Minimum value to a negative value (for example -99) and the maximum value to a positive value (for example 99) the maximum can not the be reached by moving the slider/knob/incdec.
It will only go from -99 to +98.

I am running Ctrlr 5.7.1, built myself from GIT sources, on Linux Fedora 40. Also tried pre-built recent Ctrlr versions on Windows, same issue.
Older "stable" version 5.3.201 on Windows does not have this issue. (Ctrlr Version 5.3.201 has become unusable on my Linux Fedora (mouseclicks not responding) but that's a totally different issue, not releated to the bug I am reporting here)

There is a workaround for this issue: Setting the Maximum value to 99.0001 or 99.1 solves the problem.
The problem also does not arise when Minimum value=0. Only when Minimum value is a negative number.

@damiensellier
Copy link

damiensellier commented Jun 16, 2024

I think ctrlr considers value 0 as a positive value, with negative value it maps -99 to -1 for neg and 0 to 98 for positive.
setting max value to 100 is a nice workaround :)
I'll take a look at the code and see if I can fix that because it's definitely a bug.

EDIT: it's because of the mapping of the different values is not properly rounded.

5.2.198
Capture d’écran, le 2024-06-15 à 22 15 47

5.6.30
Capture d’écran, le 2024-06-15 à 22 14 45

It makes no sens :) I'll take a look at it, it's in my to-do list for CtrlrX

Thanks for reporting

Damien

@damiensellier
Copy link

I fixed the problem for the wrong values mapped on the slider :

SEE : damiensellier#24 (comment)

else if (property == Ids::uiSliderInterval || property == Ids::uiSliderMax || property == Ids::uiSliderMin)

else if (property == Ids::uiSliderInterval || property == Ids::uiSliderMax || property == Ids::uiSliderMin)
    {
        // This was the script in v5.2.198
        //ctrlrSlider.setRange ( (float) getProperty (Ids::uiSliderMin), (float) getProperty (Ids::uiSliderMax), (float) getProperty (Ids::uiSliderInterval) ); // Added back from v5.2.198 to v5.6.31 with float instead of double. Note: Float (32bit) is less precise than double (64bit).
        //owner.setProperty (Ids::modulatorMax, ctrlrSlider.getMaximum());
        //owner.setProperty (Ids::modulatorMin, ctrlrSlider.getMinimum());
        
        // The following script is different since v5.6.26+
        float max = getProperty (Ids::uiSliderMax); // v5.6.31 (float) instead of (double). (double) was giving false values when negative
        float min = getProperty (Ids::uiSliderMin); // v5.6.31 (float) instead of (const double). (const double) was giving false values when negative
        float interval = getProperty (Ids::uiSliderInterval); // v5.6.31 (float) instead of (double). (double) was giving false values when negative
        if (interval == 0)
            interval = std::abs(max-min) + 1;
        // For JUCE MAX must be >= min
        if (max <= min) {
            // samething between 0.5 and 1 times the interval
            // to avoid rounding errors
            max = min + interval * 0.66;
        }
        ctrlrSlider.setRange ( min, max, interval );
        owner.setProperty (Ids::modulatorMax, ctrlrSlider.getMaximum());
        owner.setProperty (Ids::modulatorMin, ctrlrSlider.getMinimum());
    }

@damiensellier
Copy link

damiensellier commented Jun 27, 2024

NOTE :
Same problem is happening in CtrlrImageSlider.cpp for uiImageSlider :

Source/UIComponents/CtrlrComponents/Sliders/CtrlrImageSlider.cpp#L173

FIX :

else if (property == Ids::uiSliderInterval || property == Ids::uiSliderMax || property == Ids::uiSliderMin)
    {
        ctrlrSlider->setRange ( (float) getProperty (Ids::uiSliderMin), (float) getProperty (Ids::uiSliderMax), (float) getProperty (Ids::uiSliderInterval) );  // v5.6.31 (float) instead of plain values. plain values and (double) were giving false values when negative.
        owner.setProperty (Ids::modulatorMax, ctrlrSlider->getMaximum());
        owner.setProperty (Ids::modulatorMin, ctrlrSlider->getMinimum());
    }

@mtarenskeen
Copy link
Author

Thanks for the suggested fixes.
Can someone turn these fixes into proper pullrequest(s) so that they can be pushed to the git sources? (I still need to learn how all these Git commands work...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants