@@ -157,6 +157,8 @@ namespace lsp
157157 sInvertMouseVScroll (&sProperties )
158158 {
159159 nLastY = -1 ;
160+ fLastValue = 0 .0f ;
161+ fDelta = 0 .0f ;
160162 nState = 0 ;
161163 nButtons = 0 ;
162164
@@ -263,16 +265,6 @@ namespace lsp
263265 return (self != NULL ) ? self->on_end_edit () : STATUS_BAD_ARGUMENTS ;
264266 }
265267
266- void Knob::update_value (float delta)
267- {
268- // lsp_trace("value=%f, delta=%f", sValue.get(), delta);
269-
270- // Check that value is in range
271- float old = sValue .add (delta, sCycling .get ());
272- if (old != sValue .get ())
273- sSlots .execute (SLOT_CHANGE , this );
274- }
275-
276268 void Knob::on_click (ssize_t x, ssize_t y)
277269 {
278270 x -= sSize .nLeft ;
@@ -397,10 +389,11 @@ namespace lsp
397389 if (nState != S_NONE )
398390 sSlots .execute (SLOT_BEGIN_EDIT , this );
399391 }
392+ nLastY = e->nTop ;
393+ fLastValue = sValue .get ();
400394 }
401395
402396 nButtons |= (size_t (1 ) << e->nCode );
403- nLastY = e->nTop ;
404397
405398 return STATUS_OK ;
406399 }
@@ -417,6 +410,8 @@ namespace lsp
417410 if (nState != S_NONE )
418411 sSlots .execute (SLOT_END_EDIT , this );
419412 nState = S_NONE ;
413+
414+ fDelta = 0 .0f ;
420415 }
421416
422417 return STATUS_OK ;
@@ -431,13 +426,15 @@ namespace lsp
431426 return STATUS_OK ;
432427
433428 // Update value
434- float scaling = lsp_max (0 .0f , sScaling .get ());
435- bool accel = (e->nState & ws::MCF_CONTROL );
436- bool decel = bool (e->nState & ws::MCF_SHIFT ) != bool (nButtons & ws::MCF_RIGHT );
429+ const float scaling = lsp_max (0 .0f , sScaling .get ());
430+ const bool accel = (e->nState & ws::MCF_CONTROL );
431+ const bool decel = bool (e->nState & ws::MCF_SHIFT ) != bool (nButtons & ws::MCF_RIGHT );
432+ const float step = sStep .get (accel, decel);
437433
438- float step = sStep .get (accel, decel);
439- update_value (step * (nLastY - e->nTop ) / scaling);
440- nLastY = e->nTop ;
434+ // Update value
435+ const float old = sValue .set (fLastValue + step * (nLastY - e->nTop ) / scaling, sCycling .get ());
436+ if (old != sValue .get ())
437+ sSlots .execute (SLOT_CHANGE , this );
441438 }
442439 else if (nState == S_CLICK )
443440 {
@@ -455,13 +452,15 @@ namespace lsp
455452// lsp_trace("x=%d, y=%d, state=%x, code=%x", int(e->nLeft), int(e->nTop), int(e->nState), int(e->nCode));
456453 if (!sEditable .get ())
457454 return STATUS_OK ;
455+ if (nButtons != 0 )
456+ return STATUS_OK ;
458457
459458 float step = sStep .get (e->nState & ws::MCF_CONTROL , e->nState & ws::MCF_SHIFT );
460459 if (sInvertMouseVScroll .get ())
461460 step = -step;
462461
463462 // Compute delta
464- float delta = 0.0 ;
463+ float delta = 0 .0f ;
465464 if (e->nCode == ws::MCD_UP )
466465 delta = step;
467466 else if (e->nCode == ws::MCD_DOWN )
@@ -470,9 +469,20 @@ namespace lsp
470469 return STATUS_OK ;
471470
472471 // Update value
473- sSlots .execute (SLOT_BEGIN_EDIT , this );
474- update_value (delta);
475- sSlots .execute (SLOT_END_EDIT , this );
472+ if (fDelta == 0 .0f )
473+ fLastValue = sValue .get ();
474+ fDelta += delta;
475+
476+ const float old = sValue .set (fLastValue + fDelta , sCycling .get ());
477+ if (old != sValue .get ())
478+ {
479+ fLastValue = sValue .get ();
480+ fDelta = 0 .0f ;
481+
482+ sSlots .execute (SLOT_BEGIN_EDIT , this );
483+ sSlots .execute (SLOT_CHANGE , this );
484+ sSlots .execute (SLOT_END_EDIT , this );
485+ }
476486
477487 return STATUS_OK ;
478488 }
0 commit comments