From ba937623d5868dd33c5d11a7f05b933680a1217b Mon Sep 17 00:00:00 2001 From: PhoenixBound Date: Sun, 11 Feb 2024 17:43:42 -0600 Subject: [PATCH] Support transposing notes in F9 commands Also makes the code around here use more structured control flow --- src/tracker.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/tracker.c b/src/tracker.c index 673e70c..5509c24 100644 --- a/src/tracker.c +++ b/src/tracker.c @@ -1190,18 +1190,28 @@ void editor_command(int id) { case ID_TRANSPOSE: { int delta = DialogBox(hinstance, MAKEINTRESOURCE(IDD_TRANSPOSE), hwndMain, TransposeDlgProc); - if (delta == 0) break; - for (BYTE *p = sel_start; p < sel_end; p = next_code(p)) { - int note = *p - 0x80; - if (note < 0 || note >= 0x48) continue; - note += delta; - note %= 0x48; - if (note < 0) note += 0x48; - *p = 0x80 + note; + if (delta != 0) { + for (BYTE *p = sel_start; p < sel_end; p = next_code(p)) { + BYTE *note_ptr = NULL; + if (*p == 0xF9) { + // F9 is a pitch bend to a specific note + note_ptr = &p[3]; + } else if (*p >= 0x80 && *p < 0xC8) { + // This is a command to play a given note + note_ptr = p; + } + if (note_ptr) { + int note = *note_ptr - 0x80; + note += delta; + note %= 0x48; + if (note < 0) note += 0x48; + *note_ptr = 0x80 + note; + } + } + cur_song.changed = TRUE; + show_track_text(); + InvalidateRect(hwndTracker, NULL, FALSE); } - cur_song.changed = TRUE; - show_track_text(); - InvalidateRect(hwndTracker, NULL, FALSE); break; } case ID_ZOOM_IN: