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

KnobEventHandler motion event handling broken when using log scale #388

Open
sboettner opened this issue Nov 15, 2022 · 6 comments
Open

Comments

@sboettner
Copy link

If you set a knob to use a logarithmic scale, manipulating the knob value by clicking and dragging the mouse on the knob does not work correctly: The value remains on the minimum value or something very close to it. Changing the value using the mouse wheel works correctly.

Can be reproduced with the CairoUI example by inserting the following lines in the constructor:

fKnob->setRange(1.0f, 100.0f);
fKnob->setUsingLogScale(true);
@falkTX
Copy link
Contributor

falkTX commented Nov 15, 2022

thanks for the report.
it is likely a regression from the recent changes to fix integer behaviour

@joshsteffen
Copy link

I just ran into this and it looks like this commit got rid of some calls to invlogscale().

Adding a matching call to invlogscale() just above this seems to have fixed it, though I'm not familiar enough with the code to be confident that it's the Right Thing to do:

const float divisor = (ev.mod & kModifierControl) ? accel * 10.f : accel;
valueTmp += (maximum - minimum) / divisor * static_cast<float>(movDiff);
if (usingLog)
valueTmp = logscale(valueTmp);

@Simon-L
Copy link
Contributor

Simon-L commented Mar 21, 2025

I think I can confirm this on develop as of today.

Replacing line 505 of EventHandlers.cpp with this seems to fix:
valueTmp = invlogscale(logscale(valueTmp));

@falkTX
Copy link
Contributor

falkTX commented Mar 21, 2025

I think I can confirm this on develop as of today.

Replacing line 505 of EventHandlers.cpp with this seems to fix: valueTmp = invlogscale(logscale(valueTmp));

doesnt that simply revert the changes to valueTmp? or does the scaling and unscaling do some normalized scale in the end?

@Simon-L
Copy link
Contributor

Simon-L commented Mar 21, 2025

You're right, I just checked and the value before and after is actually the same.
While investigating this and testing with AidaKnob, which I had to modify a bit, I realised that setting it to log scale somehow breaks the display of the knob, even when replacing the texture by a rectangle, it just shows a blank space.

I have tried to take inspiration from the scrollEvent handler from a few lines below and did this to no avail, the value instantly jumps to NaN:

        const float divisor = (ev.mod & kModifierControl) ? accel * 10.f : accel;
        valueTmp = (usingLog ? invlogscale(valueTmp) : valueTmp)
                + ((maximum - minimum) / divisor * static_cast<float>(movDiff));
        
        if (usingLog) 
            valueTmp = logscale(valueTmp);

The file has some comments like this: // NOTE: value is assumed to be scaled if using log so maybe my implementation is the issue.

@Simon-L
Copy link
Contributor

Simon-L commented Mar 22, 2025

I misunderstood the solution given above, changing to this fixes log scale as far as I can tell:

        const float divisor = (ev.mod & kModifierControl) ? accel * 10.f : accel;
        
        if (usingLog)
            valueTmp = invlogscale(valueTmp);

        valueTmp += (maximum - minimum) / divisor * static_cast<float>(movDiff);

        if (usingLog)
            valueTmp = logscale(valueTmp);

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

4 participants