From ffb9c7cca8fd023cf810a9108920cae3213a9e5a Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Thu, 28 Nov 2024 09:41:32 +0100 Subject: [PATCH] significant performance-fix for realtime sliders --- src/tracker/DialogSliders.cpp | 45 +++++++++++++++++++++-------------- src/tracker/DialogSliders.h | 2 ++ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/tracker/DialogSliders.cpp b/src/tracker/DialogSliders.cpp index b8a53864..2bc73d41 100644 --- a/src/tracker/DialogSliders.cpp +++ b/src/tracker/DialogSliders.cpp @@ -44,6 +44,8 @@ DialogSliders::DialogSliders(PPScreen *parentScreen, DialogResponder *toolHandle { needUpdate = false; preview = false; + clicked = false; + valueChanged = false; numSliders = sliders; responder = toolHandlerResponder; screen = parentScreen; @@ -107,24 +109,31 @@ pp_int32 DialogSliders::handleEvent(PPObject* sender, PPEvent* event) { char v[255]; pp_uint32 id = reinterpret_cast(sender)->getID(); - if( id >= MESSAGEBOX_CONTROL_USER1 && id <= MESSAGEBOX_CONTROL_USER1+numSliders ){ - pp_uint32 slider = id-MESSAGEBOX_CONTROL_USER1; - float val = getSlider( slider ); - sprintf(v,"%i",(int)val); - listBoxes[slider]->updateItem( 0, PPString(v) ); - listBoxes[slider]->commitChanges(); - update(); - needUpdate = true; - }else if( event->getID() == eCommand && id == PP_MESSAGEBOX_BUTTON_CANCEL ){ - sampleEditor->undo(); - } - if( event->getID() == eLMouseUp ){ - needUpdate = true; - } - if( needUpdate ){ - process(); - update(); - } + pp_uint32 eID = event->getID(); + + // state management needed (because +/- buttons reflect change after emitting mouseup) + if( eID == eLMouseUp ) clicked = true; + if( eID == eValueChanged ) valueChanged = true; + + if( id >= MESSAGEBOX_CONTROL_USER1 && id <= MESSAGEBOX_CONTROL_USER1+numSliders ){ + pp_uint32 slider = id-MESSAGEBOX_CONTROL_USER1; + float val = getSlider( slider ); + sprintf(v,"%i",(int)val); + listBoxes[slider]->updateItem( 0, PPString(v) ); + listBoxes[slider]->commitChanges(); + needUpdate = true; + } + if( eID == eCommand && id == PP_MESSAGEBOX_BUTTON_CANCEL ){ + sampleEditor->undo(); + update(); + }else{ + if( clicked && valueChanged ){ + process(); + clicked = false; + valueChanged = false; + } + } + if( needUpdate ) update(); return PPDialogBase::handleEvent(sender, event); } diff --git a/src/tracker/DialogSliders.h b/src/tracker/DialogSliders.h index a8c3096b..22f040fe 100644 --- a/src/tracker/DialogSliders.h +++ b/src/tracker/DialogSliders.h @@ -55,6 +55,8 @@ class DialogSliders : public PPDialogBase bool needUpdate; bool preview; + bool valueChanged; + bool clicked; virtual pp_int32 handleEvent(PPObject* sender, PPEvent* event);