DPF icon indicating copy to clipboard operation
DPF copied to clipboard

KnobEventHandler motion event handling broken when using log scale

Open sboettner opened this issue 3 years ago • 6 comments

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);

sboettner avatar Nov 15 '22 20:11 sboettner

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

falkTX avatar Nov 15 '22 21:11 falkTX

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: https://github.com/DISTRHO/DPF/blob/f5815166356e85a5fe244f6024c2e401f04b10fa/dgl/src/EventHandlers.cpp#L446-L450

joshsteffen avatar Aug 15 '24 08:08 joshsteffen

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));

Simon-L avatar Mar 21 '25 11:03 Simon-L

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?

falkTX avatar Mar 21 '25 12:03 falkTX

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 avatar Mar 21 '25 14:03 Simon-L

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);

Simon-L avatar Mar 22 '25 10:03 Simon-L