diff --git a/src/uibuttons.h b/src/uibuttons.h index 47d128d..dcca424 100644 --- a/src/uibuttons.h +++ b/src/uibuttons.h @@ -26,7 +26,7 @@ #include "config.h" #define BUTTONS_UPDATE_NUM_TICKS 100 -#define DEBOUNCE_TIME 100 +#define DEBOUNCE_TIME 300 #define MAX_GPIO_BUTTONS 9 // 5 UI buttons, 4 Program/TG Select buttons #define MAX_MIDI_BUTTONS 9 #define MAX_BUTTONS (MAX_GPIO_BUTTONS+MAX_MIDI_BUTTONS) diff --git a/src/uimenu.cpp b/src/uimenu.cpp index 431ba9e..8c3e92e 100644 --- a/src/uimenu.cpp +++ b/src/uimenu.cpp @@ -716,6 +716,11 @@ CUIMenu::CUIMenu (CUserInterface *pUI, CMiniDexed *pMiniDexed) #endif } +void CUIMenu::SetStepCount (unsigned StepCount) +{ + m_nStepCount = StepCount; +} + void CUIMenu::EventHandler (TMenuEvent Event) { switch (Event) @@ -1535,7 +1540,7 @@ void CUIMenu::EditTGMidiFXParameter (CUIMenu *pUIMenu, TMenuEvent Event) case MenuEventPressAndStepDown: nValue -= rParam.Increment * 9; case MenuEventStepDown: - nValue -= rParam.Increment; + nValue -= rParam.Increment * pUIMenu->m_nStepCount; if (nValue < rParam.Minimum) { nValue = rParam.Minimum; @@ -1546,7 +1551,7 @@ void CUIMenu::EditTGMidiFXParameter (CUIMenu *pUIMenu, TMenuEvent Event) case MenuEventPressAndStepUp: nValue += rParam.Increment * 9; case MenuEventStepUp: - nValue += rParam.Increment; + nValue += rParam.Increment * pUIMenu->m_nStepCount; if (nValue > rParam.Maximum) { nValue = rParam.Maximum; @@ -1679,7 +1684,7 @@ void CUIMenu::EditTGFXParameter (CUIMenu *pUIMenu, TMenuEvent Event) case MenuEventPressAndStepDown: nValue -= rParam.Increment * 9; case MenuEventStepDown: - nValue -= rParam.Increment; + nValue -= rParam.Increment * pUIMenu->m_nStepCount; if (nValue < rParam.Minimum) { nValue = rParam.Minimum; @@ -1690,7 +1695,7 @@ void CUIMenu::EditTGFXParameter (CUIMenu *pUIMenu, TMenuEvent Event) case MenuEventPressAndStepUp: nValue += rParam.Increment * 9; case MenuEventStepUp: - nValue += rParam.Increment; + nValue += rParam.Increment * pUIMenu->m_nStepCount; if (nValue > rParam.Maximum) { nValue = rParam.Maximum; @@ -1815,7 +1820,7 @@ void CUIMenu::EditSendFXParameter (CUIMenu *pUIMenu, TMenuEvent Event) case MenuEventPressAndStepDown: nValue -= rParam.Increment * 9; case MenuEventStepDown: - nValue -= rParam.Increment; + nValue -= rParam.Increment * pUIMenu->m_nStepCount; if (nValue < rParam.Minimum) { nValue = rParam.Minimum; @@ -1826,7 +1831,7 @@ void CUIMenu::EditSendFXParameter (CUIMenu *pUIMenu, TMenuEvent Event) case MenuEventPressAndStepUp: nValue += rParam.Increment * 9; case MenuEventStepUp: - nValue += rParam.Increment; + nValue += rParam.Increment * pUIMenu->m_nStepCount; if (nValue > rParam.Maximum) { nValue = rParam.Maximum; diff --git a/src/uimenu.h b/src/uimenu.h index f7714dd..ae86499 100644 --- a/src/uimenu.h +++ b/src/uimenu.h @@ -56,6 +56,7 @@ public: CUIMenu (CUserInterface *pUI, CMiniDexed *pMiniDexed); void EventHandler (TMenuEvent Event); + void SetStepCount (unsigned StepCount); private: typedef void TMenuHandler (CUIMenu *pUIMenu, TMenuEvent Event); @@ -224,6 +225,7 @@ private: unsigned m_nSelectedPerformanceID =0; unsigned m_nSelectedPerformanceBankID =0; bool m_bSplashShow=false; + int m_nStepCount = 1; }; diff --git a/src/userinterface.cpp b/src/userinterface.cpp index 9e7c112..c1e6d5f 100644 --- a/src/userinterface.cpp +++ b/src/userinterface.cpp @@ -218,6 +218,8 @@ bool CUserInterface::Initialize (void) return false; } + m_nRotaryEncoderLastReadTime = 0; + m_nRotaryEncoderCounter = 0; m_pRotaryEncoder->RegisterEventHandler (EncoderEventStub, this); LOGDBG ("Rotary encoder initialized"); @@ -310,6 +312,7 @@ void CUserInterface::LCDWrite (const char *pString) void CUserInterface::EncoderEventHandler (CKY040::TEvent Event) { + unsigned nReadTime = CTimer::GetClockTicks (); switch (Event) { case CKY040::EventSwitchDown: @@ -321,6 +324,12 @@ void CUserInterface::EncoderEventHandler (CKY040::TEvent Event) break; case CKY040::EventClockwise: + if (nReadTime - m_nRotaryEncoderLastReadTime > 100000 || m_nRotaryEncoderCounter < 0) { + m_nRotaryEncoderCounter = 0; + } + m_nRotaryEncoderLastReadTime = nReadTime; + m_nRotaryEncoderCounter++; + m_Menu.SetStepCount(std::max((m_nRotaryEncoderCounter / 6) * 5, 1)); if (m_bSwitchPressed) { // We must reset the encoder switch button to prevent events from being // triggered after the encoder is rotated @@ -334,6 +343,12 @@ void CUserInterface::EncoderEventHandler (CKY040::TEvent Event) break; case CKY040::EventCounterclockwise: + if (nReadTime - m_nRotaryEncoderLastReadTime > 100000 || m_nRotaryEncoderCounter > 0) { + m_nRotaryEncoderCounter = 0; + } + m_nRotaryEncoderLastReadTime = nReadTime; + m_nRotaryEncoderCounter--; + m_Menu.SetStepCount(std::max(((m_nRotaryEncoderCounter * -1) / 6) * 5, 1)); if (m_bSwitchPressed) { m_pUIButtons->ResetButton(m_pConfig->GetButtonPinShortcut()); m_Menu.EventHandler(CUIMenu::MenuEventPressAndStepDown); @@ -370,10 +385,12 @@ void CUserInterface::UIButtonsEventHandler (CUIButton::BtnEvent Event) switch (Event) { case CUIButton::BtnEventPrev: + m_Menu.SetStepCount(1); m_Menu.EventHandler (CUIMenu::MenuEventStepDown); break; case CUIButton::BtnEventNext: + m_Menu.SetStepCount(1); m_Menu.EventHandler (CUIMenu::MenuEventStepUp); break; @@ -433,6 +450,7 @@ void CUserInterface::UIMIDICmdHandler (unsigned nMidiCh, unsigned nMidiCmd, unsi if (m_pUIButtons) { + m_Menu.SetStepCount(1); m_pUIButtons->BtnMIDICmdHandler (nMidiCmd, nMidiData1, nMidiData2); } } diff --git a/src/userinterface.h b/src/userinterface.h index a8026db..8c5081c 100644 --- a/src/userinterface.h +++ b/src/userinterface.h @@ -31,6 +31,7 @@ #include #include #include +#include class CMiniDexed; @@ -86,6 +87,8 @@ private: CKY040 *m_pRotaryEncoder; bool m_bSwitchPressed; + unsigned m_nRotaryEncoderLastReadTime; + int m_nRotaryEncoderCounter=0; CUIMenu m_Menu; };