diff --git a/src/pt2_keyboard.c b/src/pt2_keyboard.c index 330aecf..65e3217 100644 --- a/src/pt2_keyboard.c +++ b/src/pt2_keyboard.c @@ -394,13 +394,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode) { if (ui.posEdScreenShown) { - if (song->currPos > 0) - { - if (song->currPos-(POSED_LIST_SIZE-1) > 0) - modSetPos(song->currPos-(POSED_LIST_SIZE-1), DONT_SET_ROW); - else - modSetPos(0, DONT_SET_ROW); - } + posEdPageUp(); } else if (ui.diskOpScreenShown) { @@ -435,13 +429,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode) { if (ui.posEdScreenShown) { - if (song->currPos != song->header.songLength-1) - { - if (song->currPos+(POSED_LIST_SIZE-1) <= song->header.songLength-1) - modSetPos(song->currPos+(POSED_LIST_SIZE-1), DONT_SET_ROW); - else - modSetPos(song->header.songLength - 1, DONT_SET_ROW); - } + posEdPageDown(); } else if (ui.diskOpScreenShown) { @@ -472,8 +460,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode) { if (ui.posEdScreenShown) { - if (song->currPos > 0) - modSetPos(0, DONT_SET_ROW); + posEdScrollToTop(); } else if (ui.diskOpScreenShown) { @@ -495,7 +482,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode) { if (ui.posEdScreenShown) { - modSetPos(song->header.songLength - 1, DONT_SET_ROW); + posEdScrollToBottom(); } else if (ui.diskOpScreenShown) { @@ -1696,14 +1683,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode) } else if (ui.posEdScreenShown) { - if (song->currPos != song->header.songLength-1) - { - if (++song->currPos > song->header.songLength-1) - song->currPos = song->header.songLength-1; - - modSetPos(song->currPos, DONT_SET_ROW); - ui.updatePosEd = true; - } + posEdScrollDown(); if (!keyb.repeatKey) keyb.delayCounter = 0; @@ -1745,11 +1725,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode) } else if (ui.posEdScreenShown) { - if (song->currPos > 0) - { - modSetPos(song->currPos - 1, DONT_SET_ROW); - ui.updatePosEd = true; - } + posEdScrollUp(); if (!keyb.repeatKey) keyb.delayCounter = 0; @@ -2969,10 +2945,7 @@ void handleKeyRepeat(SDL_Scancode scancode) if (ui.posEdScreenShown) { - if (song->currPos-(POSED_LIST_SIZE-1) > 0) - modSetPos(song->currPos-(POSED_LIST_SIZE-1), DONT_SET_ROW); - else - modSetPos(0, DONT_SET_ROW); + posEdPageUp(); } else if (ui.diskOpScreenShown) { @@ -3006,10 +2979,7 @@ void handleKeyRepeat(SDL_Scancode scancode) if (ui.posEdScreenShown) { - if (song->currPos+(POSED_LIST_SIZE-1) <= song->header.songLength-1) - modSetPos(song->currPos+(POSED_LIST_SIZE-1), DONT_SET_ROW); - else - modSetPos(song->header.songLength - 1, DONT_SET_ROW); + posEdPageDown(); } else if (ui.diskOpScreenShown) { @@ -3167,11 +3137,7 @@ void handleKeyRepeat(SDL_Scancode scancode) if (keyb.repeatCounter >= 3) { keyb.repeatCounter = 0; - if (song->currPos > 0) - { - modSetPos(song->currPos - 1, DONT_SET_ROW); - ui.updatePosEd = true; - } + posEdScrollUp(); } } else if (!ui.samplerScreenShown) @@ -3220,15 +3186,7 @@ void handleKeyRepeat(SDL_Scancode scancode) if (keyb.repeatCounter >= 3) { keyb.repeatCounter = 0; - - if (song->currPos != song->header.songLength-1) - { - if (++song->currPos > song->header.songLength-1) - song->currPos = song->header.songLength-1; - - modSetPos(song->currPos, DONT_SET_ROW); - ui.updatePosEd = true; - } + posEdScrollDown(); } } else if (!ui.samplerScreenShown) diff --git a/src/pt2_mouse.c b/src/pt2_mouse.c index 78951ad..64a5c7d 100644 --- a/src/pt2_mouse.c +++ b/src/pt2_mouse.c @@ -1901,9 +1901,9 @@ void mouseWheelUpHandler(void) ui.updateDiskOpFileList = true; } } - else if (ui.posEdScreenShown && song->currPos > 0) + else if (ui.posEdScreenShown) { - modSetPos(song->currPos - 1, DONT_SET_ROW); + posEdScrollUp(); } } else if (ui.samplerScreenShown) // lower part of screen @@ -1933,9 +1933,9 @@ void mouseWheelDownHandler(void) ui.updateDiskOpFileList = true; } } - else if (ui.posEdScreenShown && song->currPos < song->header.songLength-1) + else if (ui.posEdScreenShown) { - modSetPos(song->currPos + 1, DONT_SET_ROW); + posEdScrollDown(); } } else if (ui.samplerScreenShown) // lower part of screen @@ -3043,34 +3043,10 @@ static bool handleGUIButtons(int32_t button) // are you prepared to enter the ju break; case PTB_PE_PATTNAME: posEdEditName(); break; - - case PTB_PE_SCROLLTOP: - { - if (song->currPos != 0) - modSetPos(0, DONT_SET_ROW); - } - break; - - case PTB_PE_SCROLLUP: - { - if (song->currPos > 0) - modSetPos(song->currPos - 1, DONT_SET_ROW); - } - break; - - case PTB_PE_SCROLLDOWN: - { - if (song->currPos < song->header.songLength-1) - modSetPos(song->currPos + 1, DONT_SET_ROW); - } - break; - - case PTB_PE_SCROLLBOT: - { - if (song->currPos != song->header.songLength-1) - modSetPos(song->header.songLength - 1, DONT_SET_ROW); - } - break; + case PTB_PE_SCROLLTOP: posEdScrollToTop(); break; + case PTB_PE_SCROLLUP: posEdScrollUp(); break; + case PTB_PE_SCROLLDOWN: posEdScrollDown(); break; + case PTB_PE_SCROLLBOT: posEdScrollToBottom(); break; case PTB_PE_EXIT: { @@ -4626,8 +4602,7 @@ static void handleRepeatedGUIButtons(void) if (mouse.repeatCounter >= 2) { mouse.repeatCounter = 0; - if (song->currPos > 0) - modSetPos(song->currPos - 1, DONT_SET_ROW); + posEdScrollUp(); } } break; @@ -4637,8 +4612,7 @@ static void handleRepeatedGUIButtons(void) if (mouse.repeatCounter >= 2) { mouse.repeatCounter = 0; - if (song->currPos < song->header.songLength-1) - modSetPos(song->currPos + 1, DONT_SET_ROW); + posEdScrollDown(); } } break; diff --git a/src/pt2_posed.c b/src/pt2_posed.c index 7079306..080d3bb 100644 --- a/src/pt2_posed.c +++ b/src/pt2_posed.c @@ -12,6 +12,74 @@ static char posEdNames[MAX_PATTERNS][16]; +void posEdScrollDown(void) +{ + const uint16_t scrollAmount = mouse.rightButtonPressed ? 10 : 1; + + if (song->currPos < song->header.songLength-1) + { + int16_t pos = song->currPos + scrollAmount; + if (pos > song->header.songLength-1) + pos = song->header.songLength-1; + + modSetPos(pos, DONT_SET_ROW); + } +} + +void posEdScrollUp(void) +{ + const uint16_t scrollAmount = mouse.rightButtonPressed ? 10 : 1; + + if (song->currPos > 0) + { + int16_t pos = song->currPos - scrollAmount; + if (pos < 0) + pos = 0; + + modSetPos(pos, DONT_SET_ROW); + } +} + +void posEdPageUp(void) +{ + const uint16_t scrollAmount = POSED_LIST_SIZE; + + if (song->currPos > 0) + { + int16_t pos = song->currPos - scrollAmount; + if (pos < 0) + pos = 0; + + modSetPos(pos, DONT_SET_ROW); + } +} + +void posEdPageDown(void) +{ + const uint16_t scrollAmount = POSED_LIST_SIZE; + + if (song->currPos < song->header.songLength-1) + { + int16_t pos = song->currPos + scrollAmount; + if (pos > song->header.songLength-1) + pos = song->header.songLength-1; + + modSetPos(pos, DONT_SET_ROW); + } +} + +void posEdScrollToTop(void) +{ + if (song->currPos > 0) + modSetPos(0, DONT_SET_ROW); +} + +void posEdScrollToBottom(void) +{ + if (song->currPos < song->header.songLength-1) + modSetPos(song->header.songLength-1, DONT_SET_ROW); +} + void posEdClearNames(void) { memset(posEdNames, 0, sizeof (posEdNames)); diff --git a/src/pt2_posed.h b/src/pt2_posed.h index eb7543c..74c91b8 100644 --- a/src/pt2_posed.h +++ b/src/pt2_posed.h @@ -2,6 +2,12 @@ #define POSED_LIST_SIZE 12 +void posEdScrollDown(void); +void posEdScrollUp(void); +void posEdScrollToTop(void); +void posEdScrollToBottom(void); +void posEdPageUp(void); +void posEdPageDown(void); void posEdClearNames(void); void posEdEditName(void); void posEdInsert(void);