Skip to content

Commit

Permalink
Support transposing notes in F9 commands
Browse files Browse the repository at this point in the history
Also makes the code around here use more structured control flow
  • Loading branch information
PhoenixBound committed Jul 7, 2024
1 parent 703a6e0 commit a3e3b77
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,18 +1190,29 @@ 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)) {
if (*p == 0xF9) {
// F9 is a pitch bend to a specific note.
// To make transpose a reversible operation and prevent unwanted consequences,
// don't wrap around from B6 to C1 for these commands. (The composer might've
// used a note outside of that range.)
p[3] += delta;
} else if (*p >= 0x80 && *p < 0xC8) {
// This is a command to play a given note
int note = *p - 0x80;
note += delta;
// Wrap around note commands, so that transposing C1 one semitone down yields
// a B6
note %= 0x48;
if (note < 0) note += 0x48;
*p = 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:
Expand Down

0 comments on commit a3e3b77

Please sign in to comment.