From ad507b93c574f7a9e2d19d9787422c0d6fd1b864 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 20 Oct 2026 20:47:07 +0200 Subject: [PATCH 1/2] Refactor --- src/commands.cpp | 134 +++++++++++++++++++++++------------------------ src/display.cpp | 6 +-- src/loadtrk.cpp | 18 +++---- src/order.cpp | 54 +++++++++---------- src/pattern.cpp | 16 +++--- src/play.cpp | 26 ++++----- src/reloc.cpp | 56 ++++++++++---------- src/song.cpp | 108 +++++++++++++++++++------------------- src/song.h | 9 +++- 9 files changed, 216 insertions(+), 211 deletions(-) diff --git a/src/commands.cpp b/src/commands.cpp index 04648a9..27c7f0f 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -850,7 +850,7 @@ void patterncommands() { for (int c = 0; c < maxChns; c++) { - if (eseditpos < song.len[esnum][c]) espos[c] = eseditpos; + if (eseditpos < song.order[esnum][c].len) espos[c] = eseditpos; if (esend[c] <= espos[c]) esend[c] = 0; } } @@ -1046,50 +1046,50 @@ void orderlistcommands() if (hexnybble >= 0) { - if (eseditpos != song.len[esnum][eschn]) + if (eseditpos != song.order[esnum][eschn].len) { switch(escolumn) { case 0: - song.order[esnum][eschn][eseditpos] &= 0x0f; - song.order[esnum][eschn][eseditpos] |= hexnybble << 4; - if (eseditpos < song.len[esnum][eschn]) + song.order[esnum][eschn].data[eseditpos] &= 0x0f; + song.order[esnum][eschn].data[eseditpos] |= hexnybble << 4; + if (eseditpos < song.order[esnum][eschn].len) { - if (song.order[esnum][eschn][eseditpos] >= MAX_PATT) - song.order[esnum][eschn][eseditpos] = MAX_PATT - 1; + if (song.order[esnum][eschn].data[eseditpos] >= MAX_PATT) + song.order[esnum][eschn].data[eseditpos] = MAX_PATT - 1; } else { - if (song.order[esnum][eschn][eseditpos] >= MAX_SONGLEN) - song.order[esnum][eschn][eseditpos] = MAX_SONGLEN - 1; + if (song.order[esnum][eschn].data[eseditpos] >= MAX_SONGLEN) + song.order[esnum][eschn].data[eseditpos] = MAX_SONGLEN - 1; } break; case 1: - song.order[esnum][eschn][eseditpos] &= 0xf0; - if ((song.order[esnum][eschn][eseditpos] & 0xf0) == 0xd0) + song.order[esnum][eschn].data[eseditpos] &= 0xf0; + if ((song.order[esnum][eschn].data[eseditpos] & 0xf0) == 0xd0) { hexnybble--; if (hexnybble < 0) hexnybble = 0xf; } - if ((song.order[esnum][eschn][eseditpos] & 0xf0) == 0xe0) + if ((song.order[esnum][eschn].data[eseditpos] & 0xf0) == 0xe0) { hexnybble = 16 - hexnybble; hexnybble &= 0xf; } - song.order[esnum][eschn][eseditpos] |= hexnybble; + song.order[esnum][eschn].data[eseditpos] |= hexnybble; - if (eseditpos < song.len[esnum][eschn]) + if (eseditpos < song.order[esnum][eschn].len) { - if (song.order[esnum][eschn][eseditpos] == LOOPSONG) - song.order[esnum][eschn][eseditpos] = LOOPSONG-1; - if (song.order[esnum][eschn][eseditpos] == TRANSDOWN) - song.order[esnum][eschn][eseditpos] = TRANSDOWN+0x0f; + if (song.order[esnum][eschn].data[eseditpos] == LOOPSONG) + song.order[esnum][eschn].data[eseditpos] = LOOPSONG-1; + if (song.order[esnum][eschn].data[eseditpos] == TRANSDOWN) + song.order[esnum][eschn].data[eseditpos] = TRANSDOWN+0x0f; } else { - if (song.order[esnum][eschn][eseditpos] >= MAX_SONGLEN) - song.order[esnum][eschn][eseditpos] = MAX_SONGLEN - 1; + if (song.order[esnum][eschn].data[eseditpos] >= MAX_SONGLEN) + song.order[esnum][eschn].data[eseditpos] = MAX_SONGLEN - 1; } break; } @@ -1097,10 +1097,10 @@ void orderlistcommands() if (escolumn > 1) { escolumn = 0; - if (eseditpos < (song.len[esnum][eschn]+1)) + if (eseditpos < (song.order[esnum][eschn].len+1)) { eseditpos++; - if (eseditpos == song.len[esnum][eschn]) eseditpos++; + if (eseditpos == song.order[esnum][eschn].len) eseditpos++; } } } @@ -1109,25 +1109,25 @@ void orderlistcommands() switch(input.key) { case 'R': - if (eseditpos < song.len[esnum][eschn]) + if (eseditpos < song.order[esnum][eschn].len) { - song.order[esnum][eschn][eseditpos] = REPEAT + 0x01; + song.order[esnum][eschn].data[eseditpos] = REPEAT + 0x01; escolumn = 1; } break; case '+': - if (eseditpos < song.len[esnum][eschn]) + if (eseditpos < song.order[esnum][eschn].len) { - song.order[esnum][eschn][eseditpos] = TRANSUP; + song.order[esnum][eschn].data[eseditpos] = TRANSUP; escolumn = 1; } break; case '-': - if (eseditpos < song.len[esnum][eschn]) + if (eseditpos < song.order[esnum][eschn].len) { - song.order[esnum][eschn][eseditpos] = TRANSDOWN + 0x0F; + song.order[esnum][eschn].data[eseditpos] = TRANSDOWN + 0x0F; escolumn = 1; } break; @@ -1163,13 +1163,13 @@ void orderlistcommands() } if (schn != tchn) { - int lentemp = song.len[esnum][schn]; - song.len[esnum][schn] = song.len[esnum][tchn]; - song.len[esnum][tchn] = lentemp; + int lentemp = song.order[esnum][schn].len; + song.order[esnum][schn].len = song.order[esnum][tchn].len; + song.order[esnum][tchn].len = lentemp; for (int c = 0; c < MAX_SONGLEN+2; c++) { - std::swap(song.order[esnum][schn][c], song.order[esnum][tchn][c]); + std::swap(song.order[esnum][schn].data[c], song.order[esnum][tchn].data[c]); } } } @@ -1187,20 +1187,20 @@ void orderlistcommands() { eseditpos = esmark.start; for (int c = esmark.start; c <= esmark.end; c++) - trackcopybuffer[d++] = song.order[esnum][eschn][c]; + trackcopybuffer[d++] = song.order[esnum][eschn].data[c]; trackcopyrows = d; } else { eseditpos = esmark.end; for (int c = esmark.end; c <= esmark.start; c++) - trackcopybuffer[d++] = song.order[esnum][eschn][c]; + trackcopybuffer[d++] = song.order[esnum][eschn].data[c]; trackcopyrows = d; } - if (trackcopyrows == song.len[esnum][eschn]) + if (trackcopyrows == song.order[esnum][eschn].len) { trackcopywhole = 1; - trackcopyrpos = song.order[esnum][eschn][song.len[esnum][eschn]+1]; + trackcopyrpos = song.order[esnum][eschn].data[song.order[esnum][eschn].len+1]; } else trackcopywhole = 0; for (int c = 0; c < trackcopyrows; c++) deleteorder(); @@ -1218,19 +1218,19 @@ void orderlistcommands() if (esmark.start <= esmark.end) { for (int c = esmark.start; c <= esmark.end; c++) - trackcopybuffer[d++] = song.order[esnum][eschn][c]; + trackcopybuffer[d++] = song.order[esnum][eschn].data[c]; trackcopyrows = d; } else { for (int c = esmark.end; c <= esmark.start; c++) - trackcopybuffer[d++] = song.order[esnum][eschn][c]; + trackcopybuffer[d++] = song.order[esnum][eschn].data[c]; trackcopyrows = d; } - if (trackcopyrows == song.len[esnum][eschn]) + if (trackcopyrows == song.order[esnum][eschn].len) { trackcopywhole = 1; - trackcopyrpos = song.order[esnum][eschn][song.len[esnum][eschn]+1]; + trackcopyrpos = song.order[esnum][eschn].data[song.order[esnum][eschn].len+1]; } else trackcopywhole = 0; esmark.chn = -1; @@ -1241,9 +1241,9 @@ void orderlistcommands() case KEY_V: if (input.shiftpressed) { - int oldlen = song.len[esnum][eschn]; + int oldlen = song.order[esnum][eschn].len; - if (eseditpos < song.len[esnum][eschn]) + if (eseditpos < song.order[esnum][eschn].len) { for (int c = trackcopyrows-1; c >= 0; c--) insertorder(trackcopybuffer[c]); @@ -1254,7 +1254,7 @@ void orderlistcommands() insertorder(trackcopybuffer[c]); } if ((trackcopywhole) && (!oldlen)) - song.order[esnum][eschn][song.len[esnum][eschn]+1] = trackcopyrpos; + song.order[esnum][eschn].data[song.order[esnum][eschn].len+1] = trackcopyrpos; } break; @@ -1265,7 +1265,7 @@ void orderlistcommands() { esmark.chn = eschn; esmark.start = 0; - esmark.end = song.len[esnum][eschn]-1; + esmark.end = song.order[esnum][eschn].len-1; } else esmark.chn = -1; } @@ -1275,14 +1275,14 @@ void orderlistcommands() case KEY_SPACE: if (!input.shiftpressed) { - if (eseditpos < song.len[esnum][eschn]) espos[eschn] = eseditpos; + if (eseditpos < song.order[esnum][eschn].len) espos[eschn] = eseditpos; if (esend[eschn] < espos[eschn]) esend[eschn] = 0; } else { for (int c = 0; c < maxChns; c++) { - if (eseditpos < song.len[esnum][c]) espos[c] = eseditpos; + if (eseditpos < song.order[esnum][c].len) espos[c] = eseditpos; if (esend[c] < espos[c]) esend[c] = 0; } } @@ -1293,7 +1293,7 @@ void orderlistcommands() { if ((esend[eschn] != eseditpos) && (eseditpos > espos[eschn])) { - if (eseditpos < song.len[esnum][eschn]) esend[eschn] = eseditpos; + if (eseditpos < song.order[esnum][eschn].len) esend[eschn] = eseditpos; } else esend[eschn] = 0; } @@ -1303,7 +1303,7 @@ void orderlistcommands() { for (int c = 0; c < maxChns; c++) { - if (eseditpos < song.len[esnum][c]) esend[c] = eseditpos; + if (eseditpos < song.order[esnum][c].len) esend[c] = eseditpos; } } else @@ -1314,12 +1314,12 @@ void orderlistcommands() break; case KEY_ENTER: - if (eseditpos < song.len[esnum][eschn]) + if (eseditpos < song.order[esnum][eschn].len) { if (!input.shiftpressed) { - if (song.order[esnum][eschn][eseditpos] < MAX_PATT) - epnum[eschn] = song.order[esnum][eschn][eseditpos]; + if (song.order[esnum][eschn].data[eseditpos] < MAX_PATT) + epnum[eschn] = song.order[esnum][eschn].data[eseditpos]; } else { @@ -1330,11 +1330,11 @@ void orderlistcommands() if (eseditpos != espos[eschn]) start = eseditpos; else start = espos[c]; - for (int d = start; d < song.len[esnum][c]; d++) + for (int d = start; d < song.order[esnum][c].len; d++) { - if (song.order[esnum][c][d] < MAX_PATT) + if (song.order[esnum][c].data[d] < MAX_PATT) { - epnum[c] = song.order[esnum][c][d]; + epnum[c] = song.order[esnum][c].data[d]; break; } } @@ -1362,14 +1362,14 @@ void orderlistcommands() break; case KEY_HOME: - if (song.len[esnum][eschn]) + if (song.order[esnum][eschn].len) { while ((eseditpos != 0) || (escolumn != 0)) orderleft(); } break; case KEY_END: - while (eseditpos != song.len[esnum][eschn]+1) orderright(); + while (eseditpos != song.order[esnum][eschn].len+1) orderright(); break; case KEY_PGUP: @@ -1393,9 +1393,9 @@ void orderlistcommands() case KEY_UP: eschn--; if (eschn < 0) eschn = maxChns - 1; - if ((eseditpos == song.len[esnum][eschn]) || (eseditpos > song.len[esnum][eschn]+1)) + if ((eseditpos == song.order[esnum][eschn].len) || (eseditpos > song.order[esnum][eschn].len+1)) { - eseditpos = song.len[esnum][eschn]+1; + eseditpos = song.order[esnum][eschn].len+1; escolumn = 0; } if (input.shiftpressed) esmark.chn = -1; @@ -1404,9 +1404,9 @@ void orderlistcommands() case KEY_DOWN: eschn++; if (eschn >= maxChns) eschn = 0; - if ((eseditpos == song.len[esnum][eschn]) || (eseditpos > song.len[esnum][eschn]+1)) + if ((eseditpos == song.order[esnum][eschn].len) || (eseditpos > song.order[esnum][eschn].len+1)) { - eseditpos = song.len[esnum][eschn]+1; + eseditpos = song.order[esnum][eschn].len+1; escolumn = 0; } if (input.shiftpressed) esmark.chn = -1; @@ -2102,7 +2102,7 @@ void tablecommands() void orderleft() { - if ((input.shiftpressed) && (eseditpos < song.len[esnum][eschn])) + if ((input.shiftpressed) && (eseditpos < song.order[esnum][eschn].len)) { if ((esmark.chn != eschn) || (eseditpos != esmark.end)) { @@ -2116,7 +2116,7 @@ void orderleft() if (eseditpos > 0) { eseditpos--; - if (eseditpos == song.len[esnum][eschn]) eseditpos--; + if (eseditpos == song.order[esnum][eschn].len) eseditpos--; escolumn = 1; if (eseditpos < 0) { @@ -2126,12 +2126,12 @@ void orderleft() } else escolumn = 0; } - if ((input.shiftpressed) && (eseditpos < song.len[esnum][eschn])) esmark.end = eseditpos; + if ((input.shiftpressed) && (eseditpos < song.order[esnum][eschn].len)) esmark.end = eseditpos; } void orderright() { - if ((input.shiftpressed) && (eseditpos < song.len[esnum][eschn])) + if ((input.shiftpressed) && (eseditpos < song.order[esnum][eschn].len)) { if ((esmark.chn != eschn) || (eseditpos != esmark.end)) { @@ -2143,14 +2143,14 @@ void orderright() if (escolumn > 1) { escolumn = 0; - if (eseditpos < (song.len[esnum][eschn]+1)) + if (eseditpos < (song.order[esnum][eschn].len+1)) { eseditpos++; - if (eseditpos == song.len[esnum][eschn]) eseditpos++; + if (eseditpos == song.order[esnum][eschn].len) eseditpos++; } else escolumn = 1; } - if ((input.shiftpressed) && (eseditpos < song.len[esnum][eschn])) esmark.end = eseditpos; + if ((input.shiftpressed) && (eseditpos < song.order[esnum][eschn].len)) esmark.end = eseditpos; } void namecommands() diff --git a/src/display.cpp b/src/display.cpp index 724f1fc..1e778d7 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -153,7 +153,7 @@ void printstatus() { for (int c = 0; c < maxChns; c++) { - int currentSonglen = song.len[esnum][c]; + int currentSonglen = song.order[esnum][c].len; int newpos = chn[c].pattptr / 4; if (chn[c].advance) epnum[c] = chn[c].pattnum; @@ -301,8 +301,8 @@ void printstatus() for (int d = 0; d < visibleOrderlist; d++) { int p = esview[c]+d; - unsigned char currentSongorder = song.order[esnum][c][p]; - int currentSonglen = song.len[esnum][c]; + unsigned char currentSongorder = song.order[esnum][c].data[p]; + int currentSonglen = song.order[esnum][c].len; int color = colors.cnormal(); if (isplaying()) { diff --git a/src/loadtrk.cpp b/src/loadtrk.cpp index 0a4f3e7..f226679 100644 --- a/src/loadtrk.cpp +++ b/src/loadtrk.cpp @@ -607,7 +607,7 @@ void mousecommands() { int maxChns = config.getMaxChannels(); - int currentSonglen = song.len[esnum][eschn]; + int currentSonglen = song.order[esnum][eschn].len; if (input.wheel) { @@ -650,7 +650,7 @@ void mousecommands() } else if (input.wheel < 0) { - if ((song.len[esnum][newchn]-esview[newchn]) > config.getVisibleOrderlist()-1) + if ((song.order[esnum][newchn].len-esview[newchn]) > config.getVisibleOrderlist()-1) { esview[newchn]++; if (newchn == eschn) eseditpos++; @@ -1090,7 +1090,7 @@ void generalcommands() case ':': for (int c = 0; c < maxChns; c++) { - currentSonglen = song.len[esnum][c]; + currentSonglen = song.order[esnum][c].len; if (espos[c] < (currentSonglen-1)) espos[c]++; if ((espos[c] - esview[c]) >= visibleOrderlist) @@ -1729,16 +1729,16 @@ void findduplicatepatterns() { for (int f = 0; f < MAX_SONGS; f++) { - if ((song.len[f][0]) && - (song.len[f][1]) && - (song.len[f][2])) + if ((song.order[f][0].len) && + (song.order[f][1].len) && + (song.order[f][2].len)) { for (int g = 0; g < maxChns; g++) { - for (int h = 0; h < song.len[f][g]; h++) + for (int h = 0; h < song.order[f][g].len; h++) { - if (song.order[f][g][h] == d) - song.order[f][g][h] = c; + if (song.order[f][g].data[h] == d) + song.order[f][g].data[h] = c; } } } diff --git a/src/order.cpp b/src/order.cpp index 27364f3..319c174 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -48,25 +48,25 @@ Selection esmark; void insertorder(unsigned char byte) { - int sl = song.len[esnum][eschn]; + int sl = song.order[esnum][eschn].len; if ((sl - eseditpos)-1 >= 0) { if (sl < MAX_SONGLEN) { int len = sl+1; - song.order[esnum][eschn][len+1] = song.order[esnum][eschn][len]; - song.order[esnum][eschn][len] = LOOPSONG; - if (len) song.order[esnum][eschn][len-1] = byte; + song.order[esnum][eschn].data[len+1] = song.order[esnum][eschn].data[len]; + song.order[esnum][eschn].data[len] = LOOPSONG; + if (len) song.order[esnum][eschn].data[len-1] = byte; countthispattern(); } - std::memmove(&song.order[esnum][eschn][eseditpos+1], - &song.order[esnum][eschn][eseditpos], + std::memmove(&song.order[esnum][eschn].data[eseditpos+1], + &song.order[esnum][eschn].data[eseditpos], (sl - eseditpos)-1); - song.order[esnum][eschn][eseditpos] = byte; + song.order[esnum][eschn].data[eseditpos] = byte; int len = sl+1; - if ((song.order[esnum][eschn][len] > eseditpos) && - (song.order[esnum][eschn][len] < (len-2))) - song.order[esnum][eschn][len]++; + if ((song.order[esnum][eschn].data[len] > eseditpos) && + (song.order[esnum][eschn].data[len] < (len-2))) + song.order[esnum][eschn].data[len]++; } else { @@ -74,9 +74,9 @@ void insertorder(unsigned char byte) { if (sl < MAX_SONGLEN) { - song.order[esnum][eschn][eseditpos+1] = song.order[esnum][eschn][eseditpos]; - song.order[esnum][eschn][eseditpos] = LOOPSONG; - if (eseditpos) song.order[esnum][eschn][eseditpos-1] = byte; + song.order[esnum][eschn].data[eseditpos+1] = song.order[esnum][eschn].data[eseditpos]; + song.order[esnum][eschn].data[eseditpos] = LOOPSONG; + if (eseditpos) song.order[esnum][eschn].data[eseditpos-1] = byte; countthispattern(); eseditpos = sl+1; } @@ -86,24 +86,24 @@ void insertorder(unsigned char byte) void deleteorder() { - int sl = song.len[esnum][eschn]; + int sl = song.order[esnum][eschn].len; if ((sl - eseditpos)-1 >= 0) { - std::memmove(&song.order[esnum][eschn][eseditpos], - &song.order[esnum][eschn][eseditpos+1], + std::memmove(&song.order[esnum][eschn].data[eseditpos], + &song.order[esnum][eschn].data[eseditpos+1], (sl - eseditpos)-1); - song.order[esnum][eschn][sl-1] = 0x00; + song.order[esnum][eschn].data[sl-1] = 0x00; if (sl > 0) { - song.order[esnum][eschn][sl-1] = song.order[esnum][eschn][sl]; - song.order[esnum][eschn][sl] = song.order[esnum][eschn][sl+1]; + song.order[esnum][eschn].data[sl-1] = song.order[esnum][eschn].data[sl]; + song.order[esnum][eschn].data[sl] = song.order[esnum][eschn].data[sl+1]; countthispattern(); } if (eseditpos == sl) eseditpos++; int len = sl+1; - if ((song.order[esnum][eschn][len] > eseditpos) && - (song.order[esnum][eschn][len] > 0)) - song.order[esnum][eschn][len]--; + if ((song.order[esnum][eschn].data[len] > eseditpos) && + (song.order[esnum][eschn].data[len] > 0)) + song.order[esnum][eschn].data[len]--; } else { @@ -111,8 +111,8 @@ void deleteorder() { if (sl > 0) { - song.order[esnum][eschn][sl-1] = song.order[esnum][eschn][sl]; - song.order[esnum][eschn][sl] = song.order[esnum][eschn][sl+1]; + song.order[esnum][eschn].data[sl-1] = song.order[esnum][eschn].data[sl]; + song.order[esnum][eschn].data[sl] = song.order[esnum][eschn].data[sl+1]; countthispattern(); eseditpos = sl+1; } @@ -138,7 +138,7 @@ void songchange() { int maxChns = config.getMaxChannels(); - int currentSonglen = song.len[esnum][eschn]; + int currentSonglen = song.order[esnum][eschn].len; for (int c = 0; c < maxChns; c++) { @@ -167,10 +167,10 @@ void updateviewtopos() for (int c = 0; c < maxChns; c++) { - int currentSonglen = song.len[esnum][c]; + int currentSonglen = song.order[esnum][c].len; for (int d = espos[c]; d < currentSonglen; d++) { - int currentSongorder = song.order[esnum][c][d]; + int currentSongorder = song.order[esnum][c].data[d]; if (currentSongorder < MAX_PATT) { epnum[c] = currentSongorder; diff --git a/src/pattern.cpp b/src/pattern.cpp index 32f7c02..3dc422e 100644 --- a/src/pattern.cpp +++ b/src/pattern.cpp @@ -231,11 +231,11 @@ void splitpattern() { for (eschn = 0; eschn < maxChns; eschn++) { - for (eseditpos = 0; eseditpos < song.len[esnum][eschn]; eseditpos++) + for (eseditpos = 0; eseditpos < song.order[esnum][eschn].len; eseditpos++) { - if (song.order[esnum][eschn][eseditpos] == c) + if (song.order[esnum][eschn].data[eseditpos] == c) { - song.order[esnum][eschn][eseditpos] = c+1; + song.order[esnum][eschn].data[eseditpos] = c+1; insertorder(c); } } @@ -253,9 +253,9 @@ void joinpattern() int maxChns = config.getMaxChannels(); if (eschn != epchn) return; - if (song.order[esnum][epchn][eseditpos] != c) return; + if (song.order[esnum][epchn].data[eseditpos] != c) return; - int d = song.order[esnum][epchn][eseditpos + 1]; + int d = song.order[esnum][epchn].data[eseditpos + 1]; if (d >= MAX_PATT) return; if (getPattlen(c) + getPattlen(d) > MAX_PATTROWS) return; @@ -293,12 +293,12 @@ void joinpattern() { for (eschn = 0; eschn < maxChns; eschn++) { - for (eseditpos = 0; eseditpos < song.len[esnum][eschn]; eseditpos++) + for (eseditpos = 0; eseditpos < song.order[esnum][eschn].len; eseditpos++) { - if ((song.order[esnum][eschn][eseditpos] == c) && (song.order[esnum][eschn][eseditpos+1] == d)) + if ((song.order[esnum][eschn].data[eseditpos] == c) && (song.order[esnum][eschn].data[eseditpos+1] == d)) { deleteorder(); - song.order[esnum][eschn][eseditpos] = c+1; + song.order[esnum][eschn].data[eseditpos] = c+1; } } } diff --git a/src/play.cpp b/src/play.cpp index 0fef8d0..e75950b 100644 --- a/src/play.cpp +++ b/src/play.cpp @@ -170,7 +170,7 @@ void playroutine() { for (int c = 0; c < maxChns; c++) { - if (espos[c] >= song.len[psnum][c]) + if (espos[c] >= song.order[psnum][c].len) songinit = PLAY_BEGINNING; } } @@ -235,7 +235,7 @@ void playroutine() songinit = (songinit != PLAY_STOP) ? PLAY_PLAYING : PLAY_STOPPED; for (int c = 0; c < maxChns; c++) { - if (!song.len[psnum][c]) + if (!song.order[psnum][c].len) { songinit = PLAY_STOPPED; // Zero length song break; @@ -1118,10 +1118,10 @@ void sequencer(int c, Chn *cptr) cptr->pattptr = startpattpos * 4; if (!cptr->advance) return; // Song loop - if (song.order[psnum][c][cptr->songptr] == LOOPSONG) + if (song.order[psnum][c].data[cptr->songptr] == LOOPSONG) { - cptr->songptr = song.order[psnum][c][cptr->songptr+1]; - if (cptr->songptr >= song.len[psnum][c]) + cptr->songptr = song.order[psnum][c].data[cptr->songptr+1]; + if (cptr->songptr >= song.order[psnum][c].len) { stopsong(); cptr->songptr = 0; @@ -1129,21 +1129,21 @@ void sequencer(int c, Chn *cptr) } } // Transpose - if ((song.order[psnum][c][cptr->songptr] >= TRANSDOWN) && - (song.order[psnum][c][cptr->songptr] < LOOPSONG)) + if ((song.order[psnum][c].data[cptr->songptr] >= TRANSDOWN) && + (song.order[psnum][c].data[cptr->songptr] < LOOPSONG)) { - cptr->trans = song.order[psnum][c][cptr->songptr]-TRANSUP; + cptr->trans = song.order[psnum][c].data[cptr->songptr]-TRANSUP; cptr->songptr++; } // Repeat - if ((song.order[psnum][c][cptr->songptr] >= REPEAT) && - (song.order[psnum][c][cptr->songptr] < TRANSDOWN)) + if ((song.order[psnum][c].data[cptr->songptr] >= REPEAT) && + (song.order[psnum][c].data[cptr->songptr] < TRANSDOWN)) { - cptr->repeat = song.order[psnum][c][cptr->songptr]-REPEAT; + cptr->repeat = song.order[psnum][c].data[cptr->songptr]-REPEAT; cptr->songptr++; } // Pattern number - cptr->pattnum = song.order[psnum][c][cptr->songptr]; + cptr->pattnum = song.order[psnum][c].data[cptr->songptr]; if (cptr->repeat) cptr->repeat--; else @@ -1163,7 +1163,7 @@ void sequencer(int c, Chn *cptr) (esend[c] > 0) && (esend[c] > espos[c]) && (cptr->songptr > esend[c]) && - (espos[c] < song.len[psnum][c])) + (espos[c] < song.order[psnum][c].len)) cptr->songptr = espos[c]; } } diff --git a/src/reloc.cpp b/src/reloc.cpp index ebfaf63..9175183 100644 --- a/src/reloc.cpp +++ b/src/reloc.cpp @@ -302,14 +302,14 @@ void initreloc() bool checklen(int c, bool dual) { - bool res = (song.len[c][0]) && - (song.len[c][1]) && - (song.len[c][2]); + bool res = (song.order[c][0].len) && + (song.order[c][1].len) && + (song.order[c][2].len); if (dual) { - res &= (song.len[c][3]) && - (song.len[c][4]) && - (song.len[c][5]); + res &= (song.order[c][3].len) && + (song.order[c][4].len) && + (song.order[c][5].len); } return res; } @@ -396,12 +396,12 @@ void relocator(const char* filename) // See which patterns are used in this song for (int d = 0; d < maxChns; d++) { - songdatasize += song.len[c][d]+2; - for (int e = 0; e < song.len[c][d]; e++) + songdatasize += song.order[c][d].len+2; + for (int e = 0; e < song.order[c][d].len; e++) { - if (song.order[c][d][e] < REPEAT) + if (song.order[c][d].data[e] < REPEAT) { - int num = song.order[c][d][e]; + int num = song.order[c][d].data[e]; pattused.set(num); for (int f = 0; f < getPattlen(num); f++) @@ -412,24 +412,24 @@ void relocator(const char* filename) } else { - if (song.order[c][d][e] >= TRANSDOWN) + if (song.order[c][d].data[e] >= TRANSDOWN) { notrans = 0; - if (song.order[c][d][e] < TRANSUP) + if (song.order[c][d].data[e] < TRANSUP) { - int newtransdownrange = -(song.order[c][d][e] - TRANSUP); + int newtransdownrange = -(song.order[c][d].data[e] - TRANSUP); if (newtransdownrange > transdownrange) transdownrange = newtransdownrange; } else { - int newtransuprange = song.order[c][d][e] - TRANSUP; + int newtransuprange = song.order[c][d].data[e] - TRANSUP; if (newtransuprange > transuprange) transuprange = newtransuprange; } } else norepeat = 0; } } - if (song.order[c][d][song.len[c][d]+1] >= song.len[c][d]) + if (song.order[c][d].data[song.order[c][d].len+1] >= song.order[c][d].len) { std::snprintf(textbuffer, MAX_PATHNAME, "ILLEGAL SONG RESTART POSITION! (SUBTUNE %02X, CHANNEL %d)", c, d+1); error(textbuffer); @@ -826,43 +826,43 @@ void relocator(const char* filename) for (int d = 0; d < maxChns; d++) { sng[c][d].offset = songdatasize; - sng[c][d].size = song.len[c][d] + 2; + sng[c][d].size = song.order[c][d].len + 2; int e; - for (e = 0; e < song.len[c][d]; e++) + for (e = 0; e < song.order[c][d].len; e++) { // Pattern - if (song.order[c][d][e] < REPEAT) - songwork[songdatasize++] = pattmap[song.order[c][d][e]]; + if (song.order[c][d].data[e] < REPEAT) + songwork[songdatasize++] = pattmap[song.order[c][d].data[e]]; else { // Transpose - if (song.order[c][d][e] >= TRANSDOWN) + if (song.order[c][d].data[e] >= TRANSDOWN) { - songwork[songdatasize++] = song.order[c][d][e]; + songwork[songdatasize++] = song.order[c][d].data[e]; } // Repeat sequence: must be swapped else { // See that repeat amount is more than 1 - if (song.order[c][d][e] > REPEAT) + if (song.order[c][d].data[e] > REPEAT) { // Insanity check that a pattern indeed follows - if (song.order[c][d][e+1] < REPEAT) + if (song.order[c][d].data[e+1] < REPEAT) { - songwork[songdatasize++] = pattmap[song.order[c][d][e+1]]; - songwork[songdatasize++] = song.order[c][d][e]; + songwork[songdatasize++] = pattmap[song.order[c][d].data[e+1]]; + songwork[songdatasize++] = song.order[c][d].data[e]; e++; } else - songwork[songdatasize++] = song.order[c][d][e]; + songwork[songdatasize++] = song.order[c][d].data[e]; } } } } // Endmark & repeat position - songwork[songdatasize++] = song.order[c][d][e++]; - songwork[songdatasize++] = song.order[c][d][e++]; + songwork[songdatasize++] = song.order[c][d].data[e++]; + songwork[songdatasize++] = song.order[c][d].data[e++]; } } else diff --git a/src/song.cpp b/src/song.cpp index f974e1d..9c2ec13 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -371,13 +371,13 @@ bool savesong() int c = MAX_SONGS - 1; for (;;) { - if ((song.len[c][0]) && - (song.len[c][1]) && - (song.len[c][2])) break; + if ((song.order[c][0].len) && + (song.order[c][1].len) && + (song.order[c][2].len)) break; if ((maxChns == 6) && - (song.len[c][3]) && - (song.len[c][4]) && - (song.len[c][5])) break; + (song.order[c][3].len) && + (song.order[c][4].len) && + (song.order[c][5].len)) break; if (c == 0) break; c--; } @@ -389,11 +389,11 @@ bool savesong() { for (int c = 0; c < maxChns; c++) { - int length = song.len[d][c]+1; + int length = song.order[d][c].len+1; fwrite8(handle, length); int writebytes = length; writebytes++; - std::fwrite(song.order[d][c], writebytes, 1, handle); + std::fwrite(song.order[d][c].data, writebytes, 1, handle); } } // Write amount of instruments @@ -517,7 +517,7 @@ SngType loadsong() { int length = fread8(handle); length++; - std::fread(song.order[d][c], length, 1, handle); + std::fread(song.order[d][c].data, length, 1, handle); } } // Read instruments @@ -574,7 +574,7 @@ SngType loadsong() { int length = fread8(handle); length++; - std::fread(song.order[d][c], length, 1, handle); + std::fread(song.order[d][c].data, length, 1, handle); } } // Read instruments @@ -668,7 +668,7 @@ SngType loadsong() length = fread8(handle); loadsize = length; loadsize++; - std::fread(song.order[d][c], loadsize, 1, handle); + std::fread(song.order[d][c].data, loadsize, 1, handle); } } @@ -1180,14 +1180,14 @@ SngType loadsong() for (int c = 0; c < MAX_SONGS; c++) { - if (song.len[c][0]) + if (song.order[c][0].len) { for (int d = channelstoload; d < MAX_CHN; d++) { - song.order[c][d][0] = emptypatt; - song.order[c][d][1] = 0xff; - song.order[c][d][2] = 0x00; - song.len[c][d] = 1; + song.order[c][d].data[0] = emptypatt; + song.order[c][d].data[1] = 0xff; + song.order[c][d].data[2] = 0x00; + song.order[c][d].len = 1; } } } @@ -1599,18 +1599,18 @@ void clearsong(bool cs, bool cp, bool ci, bool ct, bool cn) std::memset(loadedsongfilename, 0, sizeof loadedsongfilename); for (int d = 0; d < MAX_SONGS; d++) { - std::memset(&song.order[d][c][0], 0, MAX_SONGLEN+2); + std::memset(&song.order[d][c].data[0], 0, MAX_SONGLEN+2); if (!d) { - song.order[d][c][0] = c; - song.order[d][c][1] = LOOPSONG; + song.order[d][c].data[0] = c; + song.order[d][c].data[1] = LOOPSONG; } else { - song.order[d][c][0] = LOOPSONG; + song.order[d][c].data[0] = LOOPSONG; } } - epnum[c] = song.order[0][c][0]; + epnum[c] = song.order[0][c].data[0]; espos[c] = 0; esend[c] = 0; } @@ -1685,14 +1685,14 @@ void countpatternlengths() int d; for (d = 0; d < MAX_SONGLEN; d++) { - if (song.order[e][c][d] >= LOOPSONG) break; - if ((song.order[e][c][d] < REPEAT) && - (song.order[e][c][d] > highestusedpattern)) + if (song.order[e][c].data[d] >= LOOPSONG) break; + if ((song.order[e][c].data[d] < REPEAT) && + (song.order[e][c].data[d] > highestusedpattern)) { - highestusedpattern = song.order[e][c][d]; + highestusedpattern = song.order[e][c].data[d]; } } - song.len[e][c] = d; + song.order[e][c].len = d; } } } @@ -1711,13 +1711,13 @@ void countthispattern() c = eschn; for (d = 0; d < MAX_SONGLEN; d++) { - if (song.order[e][c][d] >= LOOPSONG) break; - if (song.order[e][c][d] > highestusedpattern) + if (song.order[e][c].data[d] >= LOOPSONG) break; + if (song.order[e][c].data[d] > highestusedpattern) { - highestusedpattern = song.order[e][c][d]; + highestusedpattern = song.order[e][c].data[d]; } } - song.len[e][c] = d; + song.order[e][c].len = d; } int insertpattern(int p) @@ -1734,18 +1734,18 @@ int insertpattern(int p) for (int c = 0; c < MAX_SONGS; c++) { - if ((song.len[c][0]) && (song.len[c][1]) && (song.len[c][2])) + if ((song.order[c][0].len) && (song.order[c][1].len) && (song.order[c][2].len)) { for (int d = 0; d < maxChns; d++) { - int tmp = song.len[c][d]; + int tmp = song.order[c][d].len; for (int e = 0; e < tmp; e++) { - if ((song.order[c][d][e] < REPEAT) && - (song.order[c][d][e] > p) && - (song.order[c][d][e] != MAX_PATT-1)) + if ((song.order[c][d].data[e] < REPEAT) && + (song.order[c][d].data[e] > p) && + (song.order[c][d].data[e] != MAX_PATT-1)) { - song.order[c][d][e]++; + song.order[c][d].data[e]++; } } } @@ -1772,17 +1772,17 @@ void deletepattern(int p) for (int c = 0; c < MAX_SONGS; c++) { - if ((song.len[c][0]) && (song.len[c][1]) && (song.len[c][2])) + if ((song.order[c][0].len) && (song.order[c][1].len) && (song.order[c][2].len)) { for (int d = 0; d < maxChns; d++) { - int tmp = song.len[c][d]; + int tmp = song.order[c][d].len; for (int e = 0; e < tmp; e++) { - if ((song.order[c][d][e] < REPEAT) && - (song.order[c][d][e] > p)) + if ((song.order[c][d].data[e] < REPEAT) && + (song.order[c][d].data[e] > p)) { - song.order[c][d][e]--; + song.order[c][d].data[e]--; } } } @@ -1810,16 +1810,16 @@ void findusedpatterns() pattused.reset(); for (int c = 0; c < MAX_SONGS; c++) { - if ((song.len[c][0]) && (song.len[c][1]) && (song.len[c][2])) + if ((song.order[c][0].len) && (song.order[c][1].len) && (song.order[c][2].len)) { for (int d = 0; d < maxChns; d++) { - int tmp = song.len[c][d]; + int tmp = song.order[c][d].len; for (int e = 0; e < tmp; e++) { - if (song.order[c][d][e] < REPEAT) + if (song.order[c][d].data[e] < REPEAT) { - pattused.set(song.order[c][d][e]); + pattused.set(song.order[c][d].data[e]); } } } @@ -1847,13 +1847,13 @@ void mergesong() int c = MAX_SONGS - 1; for (;;) { - if ((song.len[c][0]) && - (song.len[c][1]) && - (song.len[c][2])) break; + if ((song.order[c][0].len) && + (song.order[c][1].len) && + (song.order[c][2].len)) break; if ((maxChns == 6) && - (song.len[c][3]) && - (song.len[c][4]) && - (song.len[c][5])) break; + (song.order[c][3].len) && + (song.order[c][4].len) && + (song.order[c][5].len)) break; if (c == 0) break; c--; } @@ -1892,12 +1892,12 @@ void mergesong() { int length = fread8(handle); length++; - std::fread(song.order[songbase + d][c], length, 1, handle); + std::fread(song.order[songbase + d][c].data, length, 1, handle); // Remap patterns for (int e = 0; e < length - 1; e++) { - if (song.order[songbase + d][c][e] < REPEAT) - song.order[songbase + d][c][e] += pattbase; + if (song.order[songbase + d][c].data[e] < REPEAT) + song.order[songbase + d][c].data[e] += pattbase; } } } diff --git a/src/song.h b/src/song.h index 9f2079f..76575c8 100644 --- a/src/song.h +++ b/src/song.h @@ -39,13 +39,18 @@ enum class SngType DUAL }; +struct SongOrder +{ + unsigned char data[MAX_SONGLEN+2]; + int len; +}; + struct Song { Instr instr[MAX_INSTR]; unsigned char ltable[MAX_TABLES][MAX_TABLELEN]; unsigned char rtable[MAX_TABLES][MAX_TABLELEN]; - unsigned char order[MAX_SONGS][MAX_CHN][MAX_SONGLEN+2]; - int len[MAX_SONGS][MAX_CHN]; + SongOrder order[MAX_SONGS][MAX_CHN]; unsigned char pattern[MAX_PATT][MAX_PATTROWS*4+4]; char title[MAX_STR]; From 114cc492e97d2e7db6f997eb1e4aeb8920d9949d Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Sun, 25 Oct 2026 12:10:56 +0100 Subject: [PATCH 2/2] More refactoring --- src/commands.cpp | 144 ++++++++++----------- src/display.cpp | 10 +- src/play.cpp | 130 +++++++++---------- src/reloc.cpp | 138 ++++++++++----------- src/song.cpp | 316 +++++++++++++++++++++++++---------------------- src/song.h | 9 +- 6 files changed, 383 insertions(+), 364 deletions(-) diff --git a/src/commands.cpp b/src/commands.cpp index 27c7f0f..7591082 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1628,64 +1628,64 @@ void tablecommands() case KEY_Q: if ((input.shiftpressed) && (tables.num() == STBL)) { - int speed = (song.ltable[tables.num()][tables.pos()] << 8) | song.rtable[tables.num()][tables.pos()]; + int speed = (song.fxtable[tables.num()][tables.pos()].l << 8) | song.fxtable[tables.num()][tables.pos()].r; speed *= 34716; speed /= 32768; if (speed > 65535) speed = 65535; - song.ltable[tables.num()][tables.pos()] = speed >> 8; - song.rtable[tables.num()][tables.pos()] = speed & 0xff; + song.fxtable[tables.num()][tables.pos()].l = speed >> 8; + song.fxtable[tables.num()][tables.pos()].r = speed & 0xff; } break; case KEY_A: if ((input.shiftpressed) && (tables.num() == STBL)) { - int speed = (song.ltable[tables.num()][tables.pos()] << 8) | song.rtable[tables.num()][tables.pos()]; + int speed = (song.fxtable[tables.num()][tables.pos()].l << 8) | song.fxtable[tables.num()][tables.pos()].r; speed *= 30929; speed /= 32768; - song.ltable[tables.num()][tables.pos()] = speed >> 8; - song.rtable[tables.num()][tables.pos()] = speed & 0xff; + song.fxtable[tables.num()][tables.pos()].l = speed >> 8; + song.fxtable[tables.num()][tables.pos()].r = speed & 0xff; } break; case KEY_W: if ((input.shiftpressed) && (tables.num() == STBL)) { - int speed = (song.ltable[tables.num()][tables.pos()] << 8) | song.rtable[tables.num()][tables.pos()]; + int speed = (song.fxtable[tables.num()][tables.pos()].l << 8) | song.fxtable[tables.num()][tables.pos()].r; speed *= 2; if (speed > 65535) speed = 65535; - song.ltable[tables.num()][tables.pos()] = speed >> 8; - song.rtable[tables.num()][tables.pos()] = speed & 0xff; + song.fxtable[tables.num()][tables.pos()].l = speed >> 8; + song.fxtable[tables.num()][tables.pos()].r = speed & 0xff; } - if ((input.shiftpressed) && ((tables.num() == PTBL) || (tables.num() == FTBL)) && (song.ltable[tables.num()][tables.pos()] < 0x80)) + if ((input.shiftpressed) && ((tables.num() == PTBL) || (tables.num() == FTBL)) && (song.fxtable[tables.num()][tables.pos()].l < 0x80)) { - int speed = (signed char)(song.rtable[tables.num()][tables.pos()]); + int speed = (signed char)(song.fxtable[tables.num()][tables.pos()].r); speed *= 2; if (speed > 127) speed = 127; if (speed < -128) speed = -128; - song.rtable[tables.num()][tables.pos()] = speed; + song.fxtable[tables.num()][tables.pos()].r = speed; } break; case KEY_S: if ((input.shiftpressed) && (tables.num() == STBL)) { - int speed = (song.ltable[tables.num()][tables.pos()] << 8) | song.rtable[tables.num()][tables.pos()]; + int speed = (song.fxtable[tables.num()][tables.pos()].l << 8) | song.fxtable[tables.num()][tables.pos()].r; speed /= 2; - song.ltable[tables.num()][tables.pos()] = speed >> 8; - song.rtable[tables.num()][tables.pos()] = speed & 0xff; + song.fxtable[tables.num()][tables.pos()].l = speed >> 8; + song.fxtable[tables.num()][tables.pos()].r = speed & 0xff; } - if ((input.shiftpressed) && ((tables.num() == PTBL) || (tables.num() == FTBL)) && (song.ltable[tables.num()][tables.pos()] < 0x80)) + if ((input.shiftpressed) && ((tables.num() == PTBL) || (tables.num() == FTBL)) && (song.fxtable[tables.num()][tables.pos()].l < 0x80)) { - int speed = (signed char)(song.rtable[tables.num()][tables.pos()]); + int speed = (signed char)(song.fxtable[tables.num()][tables.pos()].r); speed /= 2; - song.rtable[tables.num()][tables.pos()] = speed; + song.fxtable[tables.num()][tables.pos()].r = speed; } break; @@ -1751,12 +1751,12 @@ void tablecommands() int d = 0; for (int c = markstart; c <= markend; c++) { - ltablecopybuffer[d] = song.ltable[tables.marknum()][c]; - rtablecopybuffer[d] = song.rtable[tables.marknum()][c]; + ltablecopybuffer[d] = song.fxtable[tables.marknum()][c].l; + rtablecopybuffer[d] = song.fxtable[tables.marknum()][c].r; if (input.rawkey == KEY_X) { - song.ltable[tables.marknum()][c] = 0; - song.rtable[tables.marknum()][c] = 0; + song.fxtable[tables.marknum()][c].l = 0; + song.fxtable[tables.marknum()][c].r = 0; } d++; } @@ -1773,8 +1773,8 @@ void tablecommands() { for (int c = 0; c < tablecopyrows; c++) { - song.ltable[tables.num()][tables.pos()] = ltablecopybuffer[c]; - song.rtable[tables.num()][tables.pos()] = rtablecopybuffer[c]; + song.fxtable[tables.num()][tables.pos()].l = ltablecopybuffer[c]; + song.fxtable[tables.num()][tables.pos()].r = rtablecopybuffer[c]; tables.incpos(); } } @@ -1796,11 +1796,11 @@ void tablecommands() case KEY_R: if (tables.num() == WTBL) { - if (song.ltable[tables.num()][tables.pos()] != 0xff) + if (song.fxtable[tables.num()][tables.pos()].l != 0xff) { // Convert absolute pitch to relative pitch or vice versa int basenote = epoctave * 12; - int note = song.rtable[tables.num()][tables.pos()]; + int note = song.fxtable[tables.num()][tables.pos()].r; if (note >= 0x80) { @@ -1813,7 +1813,7 @@ void tablecommands() note |= 0x80; } - song.rtable[tables.num()][tables.pos()] = note; + song.fxtable[tables.num()][tables.pos()].r = note; } } /* fall through */ @@ -1821,8 +1821,8 @@ void tablecommands() if (tables.num() == PTBL) { int currentpulse = -1; - int targetpulse = song.ltable[tables.num()][tables.pos()] << 4; - int speed = song.rtable[tables.num()][tables.pos()]; + int targetpulse = song.fxtable[tables.num()][tables.pos()].l << 4; + int speed = song.fxtable[tables.num()][tables.pos()].r; if (!speed) break; @@ -1830,10 +1830,10 @@ void tablecommands() // Follow the chain of pulse commands backwards to the nearest set command so we know what current pulse is for (c = tables.pos()-1; c >= 0; c--) { - if (song.ltable[tables.num()][c] == 0xff) break; - if (song.ltable[tables.num()][c] >= 0x80) + if (song.fxtable[tables.num()][c].l == 0xff) break; + if (song.fxtable[tables.num()][c].l >= 0x80) { - currentpulse = (song.ltable[tables.num()][c] << 8) | song.rtable[tables.num()][c]; + currentpulse = (song.fxtable[tables.num()][c].l << 8) | song.fxtable[tables.num()][c].r; currentpulse &= 0xfff; break; } @@ -1843,10 +1843,10 @@ void tablecommands() // Then follow the chain of modulation steps for (; c < tables.pos(); c++) { - if (song.ltable[tables.num()][c] < 0x80) + if (song.fxtable[tables.num()][c].l < 0x80) { - currentpulse += song.ltable[tables.num()][c] * (song.rtable[tables.num()][c] & 0xff); - if (song.rtable[tables.num()][c] >= 0x80) currentpulse -= 256 * song.ltable[tables.num()][c]; + currentpulse += song.fxtable[tables.num()][c].l * (song.fxtable[tables.num()][c].r & 0xff); + if (song.fxtable[tables.num()][c].l >= 0x80) currentpulse -= 256 * song.fxtable[tables.num()][c].r; currentpulse &= 0xfff; } } @@ -1865,15 +1865,15 @@ void tablecommands() { if (std::abs(speed) < 128) { - song.ltable[tables.num()][tables.pos()] = (time < 127) ? time : 127; - song.rtable[tables.num()][tables.pos()] = speed; - time -= song.ltable[tables.num()][tables.pos()]; + song.fxtable[tables.num()][tables.pos()].l = (time < 127) ? time : 127; + song.fxtable[tables.num()][tables.pos()].r = speed; + time -= song.fxtable[tables.num()][tables.pos()].l; } else { currentpulse += speed; - song.ltable[tables.num()][tables.pos()] = 0x80 | ((currentpulse >> 8) & 0xf); - song.rtable[tables.num()][tables.pos()] = currentpulse & 0xff; + song.fxtable[tables.num()][tables.pos()].l = 0x80 | ((currentpulse >> 8) & 0xf); + song.fxtable[tables.num()][tables.pos()].r = currentpulse & 0xff; time--; } tables.incpos(); @@ -1882,8 +1882,8 @@ void tablecommands() if (tables.num() == FTBL) { int currentfilter = -1; - int targetfilter = song.ltable[tables.num()][tables.pos()]; - int speed = song.rtable[tables.num()][tables.pos()] & 0x7f; + int targetfilter = song.fxtable[tables.num()][tables.pos()].l; + int speed = song.fxtable[tables.num()][tables.pos()].r & 0x7f; if (!speed) break; @@ -1891,10 +1891,10 @@ void tablecommands() // Follow the chain of filter commands backwards to the nearest set command so we know what current pulse is for (c = tables.pos()-1; c >= 0; c--) { - if (song.ltable[tables.num()][c] == 0xff) break; - if (song.ltable[tables.num()][c] == 0x00) + if (song.fxtable[tables.num()][c].l == 0xff) break; + if (song.fxtable[tables.num()][c].l == 0x00) { - currentfilter = song.rtable[tables.num()][c]; + currentfilter = song.fxtable[tables.num()][c].r; break; } } @@ -1903,9 +1903,9 @@ void tablecommands() // Then follow the chain of modulation steps for (; c < tables.pos(); c++) { - if (song.ltable[tables.num()][c] < 0x80) + if (song.fxtable[tables.num()][c].l < 0x80) { - currentfilter += song.ltable[tables.num()][c] * song.rtable[tables.num()][c]; + currentfilter += song.fxtable[tables.num()][c].l * song.fxtable[tables.num()][c].r; currentfilter &= 0xff; } } @@ -1921,9 +1921,9 @@ void tablecommands() while (time) { - song.ltable[tables.num()][tables.pos()] = (time < 127) ? time : 127; - song.rtable[tables.num()][tables.pos()] = speed; - time -= song.ltable[tables.num()][tables.pos()]; + song.fxtable[tables.num()][tables.pos()].l = (time < 127) ? time : 127; + song.fxtable[tables.num()][tables.pos()].r = speed; + time -= song.fxtable[tables.num()][tables.pos()].l; tables.incpos(); } } @@ -1936,17 +1936,17 @@ void tablecommands() { // Negate pulse or filter speed case FTBL: - if (!song.ltable[tables.num()][tables.pos()]) break; + if (!song.fxtable[tables.num()][tables.pos()].l) break; /* fall through */ case PTBL: - if (song.ltable[tables.num()][tables.pos()] < 0x80) - song.rtable[tables.num()][tables.pos()] = (song.rtable[tables.num()][tables.pos()] ^ 0xff) + 1; + if (song.fxtable[tables.num()][tables.pos()].l < 0x80) + song.fxtable[tables.num()][tables.pos()].r = (song.fxtable[tables.num()][tables.pos()].r ^ 0xff) + 1; break; // Negate relative note case WTBL: - if ((song.ltable[tables.num()][tables.pos()] != 0xff) && (song.rtable[tables.num()][tables.pos()] < 0x80)) - song.rtable[tables.num()][tables.pos()] = (0x80 - song.rtable[tables.num()][tables.pos()]) & 0x7f; + if ((song.fxtable[tables.num()][tables.pos()].l != 0xff) && (song.fxtable[tables.num()][tables.pos()].r < 0x80)) + song.fxtable[tables.num()][tables.pos()].r = (0x80 - song.fxtable[tables.num()][tables.pos()].r) & 0x7f; break; } } @@ -1966,7 +1966,7 @@ void tablecommands() int table = -1; int mstmode = MST_PORTAMENTO; - switch (song.ltable[tables.num()][tables.pos()]) + switch (song.fxtable[tables.num()][tables.pos()].l) { case WAVECMD + CMD_PORTAUP: case WAVECMD + CMD_PORTADOWN: @@ -2000,22 +2000,22 @@ void tablecommands() return; case STBL: - if (song.rtable[tables.num()][tables.pos()]) + if (song.fxtable[tables.num()][tables.pos()].r) { if (!input.shiftpressed) { - gototable(STBL, song.rtable[tables.num()][tables.pos()] - 1); + gototable(STBL, song.fxtable[tables.num()][tables.pos()].r - 1); return; } else { int oldeditpos = tables.pos(); int oldeditcolumn = tables.column(); - int pos = makespeedtable(song.rtable[tables.num()][tables.pos()], mstmode, true); + int pos = makespeedtable(song.fxtable[tables.num()][tables.pos()].r, mstmode, true); gototable(WTBL, oldeditpos); tables.setcolumn(oldeditcolumn); - song.rtable[tables.num()][tables.pos()] = pos + 1; + song.fxtable[tables.num()][tables.pos()].r = pos + 1; return; } } @@ -2024,7 +2024,7 @@ void tablecommands() int pos = song.findfreespeedtable(); if (pos >= 0) { - song.rtable[tables.num()][tables.pos()] = pos + 1; + song.fxtable[tables.num()][tables.pos()].r = pos + 1; gototable(STBL, pos); return; } @@ -2033,9 +2033,9 @@ void tablecommands() case PTBL: case FTBL: - if (song.rtable[tables.num()][tables.pos()]) + if (song.fxtable[tables.num()][tables.pos()].r) { - gototable(table, song.rtable[tables.num()][tables.pos()] - 1); + gototable(table, song.fxtable[tables.num()][tables.pos()].r - 1); return; } else @@ -2044,7 +2044,7 @@ void tablecommands() { int pos = song.gettablelen(table); if (pos >= MAX_TABLELEN-1) pos = MAX_TABLELEN - 1; - song.rtable[tables.num()][tables.pos()] = pos + 1; + song.fxtable[tables.num()][tables.pos()].r = pos + 1; gototable(table, pos); return; } @@ -2075,20 +2075,20 @@ void tablecommands() switch(tables.column()) { case 0: - song.ltable[tables.num()][tables.pos()] &= 0x0f; - song.ltable[tables.num()][tables.pos()] |= hexnybble << 4; + song.fxtable[tables.num()][tables.pos()].l &= 0x0f; + song.fxtable[tables.num()][tables.pos()].l |= hexnybble << 4; break; case 1: - song.ltable[tables.num()][tables.pos()] &= 0xf0; - song.ltable[tables.num()][tables.pos()] |= hexnybble; + song.fxtable[tables.num()][tables.pos()].l &= 0xf0; + song.fxtable[tables.num()][tables.pos()].l |= hexnybble; break; case 2: - song.rtable[tables.num()][tables.pos()] &= 0x0f; - song.rtable[tables.num()][tables.pos()] |= hexnybble << 4; + song.fxtable[tables.num()][tables.pos()].r &= 0x0f; + song.fxtable[tables.num()][tables.pos()].r |= hexnybble << 4; break; case 3: - song.rtable[tables.num()][tables.pos()] &= 0xf0; - song.rtable[tables.num()][tables.pos()] |= hexnybble; + song.fxtable[tables.num()][tables.pos()].r &= 0xf0; + song.fxtable[tables.num()][tables.pos()].r |= hexnybble; break; } if (tables.inccolumn()) diff --git a/src/display.cpp b/src/display.cpp index 1e778d7..311b987 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -430,22 +430,22 @@ void printstatus() switch (c) { case WTBL: - if (song.ltable[c][p] >= WAVECMD) color = colors.ccommand(); + if (song.fxtable[c][p].l >= WAVECMD) color = colors.ccommand(); break; case PTBL: - if (song.ltable[c][p] >= 0x80) color = colors.ccommand(); + if (song.fxtable[c][p].l >= 0x80) color = colors.ccommand(); break; case FTBL: - if ((song.ltable[c][p] >= 0x80) || ((!song.ltable[c][p]) && (song.rtable[c][p]))) color = colors.ccommand(); + if ((song.fxtable[c][p].l >= 0x80) || ((!song.fxtable[c][p].l) && (song.fxtable[c][p].r))) color = colors.ccommand(); break; } if ((p == tables.pos()) && (tables.num() == c)) color = colors.cedit(); - std::snprintf(textbuffer, MAX_PATHNAME, "%02X:%02X %02X", p+1, song.ltable[c][p], song.rtable[c][p]); + std::snprintf(textbuffer, MAX_PATHNAME, "%02X:%02X %02X", p+1, song.fxtable[c][p].l, song.fxtable[c][p].r); if (config.patterndispmode & 2) { - if (!song.ltable[c][p] && !song.rtable[c][p] && !song.ltable[c][p+1] && !song.rtable[c][p+1]) + if (!song.fxtable[c][p].l && !song.fxtable[c][p].r && !song.fxtable[c][p+1].l && !song.fxtable[c][p+1].r) { std::memset(&textbuffer[3], '.', 2); std::memset(&textbuffer[6], '.', 2); diff --git a/src/play.cpp b/src/play.cpp index e75950b..9338bc5 100644 --- a/src/play.cpp +++ b/src/play.cpp @@ -249,36 +249,36 @@ void playroutine() if (filter.ptr) { // Filter jump - if (song.ltable[FTBL][filter.ptr-1] == 0xff) + if (song.fxtable[FTBL][filter.ptr-1].l == 0xff) { - filter.ptr = song.rtable[FTBL][filter.ptr-1]; + filter.ptr = song.fxtable[FTBL][filter.ptr-1].r; if (!filter.ptr) goto FILTERSTOP; } if (!filter.time) { // Filter set - if (song.ltable[FTBL][filter.ptr-1] >= 0x80) + if (song.fxtable[FTBL][filter.ptr-1].l >= 0x80) { - filter.type = song.ltable[FTBL][filter.ptr-1] & 0x70; - filter.ctrl = song.rtable[FTBL][filter.ptr-1]; + filter.type = song.fxtable[FTBL][filter.ptr-1].l & 0x70; + filter.ctrl = song.fxtable[FTBL][filter.ptr-1].r; filter.ptr++; // Can be combined with cutoff set - if (song.ltable[FTBL][filter.ptr-1] == 0x00) + if (song.fxtable[FTBL][filter.ptr-1].l == 0x00) { - filter.cutoff = song.rtable[FTBL][filter.ptr-1]; + filter.cutoff = song.fxtable[FTBL][filter.ptr-1].r; filter.ptr++; } } else { // New modulation step - if (song.ltable[FTBL][filter.ptr-1]) - filter.time = song.ltable[FTBL][filter.ptr-1]; + if (song.fxtable[FTBL][filter.ptr-1].l) + filter.time = song.fxtable[FTBL][filter.ptr-1].l; else { // Cutoff set - filter.cutoff = song.rtable[FTBL][filter.ptr-1]; + filter.cutoff = song.fxtable[FTBL][filter.ptr-1].r; filter.ptr++; } } @@ -286,7 +286,7 @@ void playroutine() // Filter modulation if (filter.time) { - filter.cutoff += song.rtable[FTBL][filter.ptr-1]; + filter.cutoff += song.fxtable[FTBL][filter.ptr-1].r; filter.time--; if (!filter.time) filter.ptr++; } @@ -300,36 +300,36 @@ void playroutine() if (filter2.ptr) { // Filter jump - if (song.ltable[FTBL][filter2.ptr-1] == 0xff) + if (song.fxtable[FTBL][filter2.ptr-1].l == 0xff) { - filter2.ptr = song.rtable[FTBL][filter2.ptr-1]; + filter2.ptr = song.fxtable[FTBL][filter2.ptr-1].r; if (!filter2.ptr) goto FILTER2STOP; } if (!filter2.time) { // Filter set - if (song.ltable[FTBL][filter2.ptr-1] >= 0x80) + if (song.fxtable[FTBL][filter2.ptr-1].l >= 0x80) { - filter2.type = song.ltable[FTBL][filter2.ptr-1] & 0x70; - filter2.ctrl = song.rtable[FTBL][filter2.ptr-1]; + filter2.type = song.fxtable[FTBL][filter2.ptr-1].l & 0x70; + filter2.ctrl = song.fxtable[FTBL][filter2.ptr-1].r; filter2.ptr++; // Can be combined with cutoff set - if (song.ltable[FTBL][filter2.ptr-1] == 0x00) + if (song.fxtable[FTBL][filter2.ptr-1].l == 0x00) { - filter2.cutoff = song.rtable[FTBL][filter2.ptr-1]; + filter2.cutoff = song.fxtable[FTBL][filter2.ptr-1].r; filter2.ptr++; } } else { // New modulation step - if (song.ltable[FTBL][filter2.ptr-1]) - filter2.time = song.ltable[FTBL][filter2.ptr-1]; + if (song.fxtable[FTBL][filter2.ptr-1].l) + filter2.time = song.fxtable[FTBL][filter2.ptr-1].l; else { // Cutoff set - filter2.cutoff = song.rtable[FTBL][filter2.ptr-1]; + filter2.cutoff = song.fxtable[FTBL][filter2.ptr-1].r; filter2.ptr++; } } @@ -337,7 +337,7 @@ void playroutine() // Filter modulation if (filter2.time) { - filter2.cutoff += song.rtable[FTBL][filter2.ptr-1]; + filter2.cutoff += song.fxtable[FTBL][filter2.ptr-1].r; filter2.time--; if (!filter2.time) filter2.ptr++; } @@ -417,7 +417,7 @@ void playroutine() if (cptr->ptr[WTBL]) { // Stop the song in case of jumping into a jump - if (song.ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) + if (song.fxtable[WTBL][cptr->ptr[WTBL]-1].l == 0xff) stopsong(); } if (iptr->ptr[PTBL]) @@ -427,7 +427,7 @@ void playroutine() if (cptr->ptr[PTBL]) { // Stop the song in case of jumping into a jump - if (song.ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) + if (song.fxtable[PTBL][cptr->ptr[PTBL]-1].l == 0xff) stopsong(); } } @@ -440,7 +440,7 @@ void playroutine() if (filter.ptr) { // Stop the song in case of jumping into a jump - if (song.ltable[FTBL][filter.ptr-1] == 0xff) + if (song.fxtable[FTBL][filter.ptr-1].l == 0xff) stopsong(); } } @@ -451,7 +451,7 @@ void playroutine() if (filter2.ptr) { // Stop the song in case of jumping into a jump - if (song.ltable[FTBL][filter2.ptr-1] == 0xff) + if (song.fxtable[FTBL][filter2.ptr-1].l == 0xff) stopsong(); } } @@ -515,7 +515,7 @@ void playroutine() if (cptr->ptr[WTBL]) { // Stop the song in case of jumping into a jump - if (song.ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) + if (song.fxtable[WTBL][cptr->ptr[WTBL]-1].l == 0xff) stopsong(); } break; @@ -526,7 +526,7 @@ void playroutine() if (cptr->ptr[PTBL]) { // Stop the song in case of jumping into a jump - if (song.ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) + if (song.fxtable[PTBL][cptr->ptr[PTBL]-1].l == 0xff) stopsong(); } break; @@ -539,7 +539,7 @@ void playroutine() if (filter.ptr) { // Stop the song in case of jumping into a jump - if (song.ltable[FTBL][filter.ptr-1] == 0xff) + if (song.fxtable[FTBL][filter.ptr-1].l == 0xff) stopsong(); } } @@ -550,7 +550,7 @@ void playroutine() if (filter2.ptr) { // Stop the song in case of jumping into a jump - if (song.ltable[FTBL][filter2.ptr-1] == 0xff) + if (song.fxtable[FTBL][filter2.ptr-1].l == 0xff) stopsong(); } } @@ -584,8 +584,8 @@ void playroutine() case CMD_FUNKTEMPO: if (cptr->newcmddata) { - funktable[0] = song.ltable[STBL][cptr->newcmddata-1]-1; - funktable[1] = song.rtable[STBL][cptr->newcmddata-1]-1; + funktable[0] = song.fxtable[STBL][cptr->newcmddata-1].l-1; + funktable[1] = song.fxtable[STBL][cptr->newcmddata-1].r-1; } for (int d = 0; d < maxChns; d++) chn[d].tempo = 0; @@ -615,8 +615,8 @@ void playroutine() WAVEEXEC: if (cptr->ptr[WTBL]) { - unsigned char wave = song.ltable[WTBL][cptr->ptr[WTBL]-1]; - unsigned char note = song.rtable[WTBL][cptr->ptr[WTBL]-1]; + unsigned char wave = song.fxtable[WTBL][cptr->ptr[WTBL]-1].l; + unsigned char note = song.fxtable[WTBL][cptr->ptr[WTBL]-1].r; if (wave > WAVELASTDELAY) { @@ -627,7 +627,7 @@ void playroutine() // Command execution from wavetable if ((wave >= WAVECMD) && (wave <= WAVELASTCMD)) { - unsigned char param = song.rtable[WTBL][cptr->ptr[WTBL]-1]; + unsigned char param = song.fxtable[WTBL][cptr->ptr[WTBL]-1].r; switch (wave & 0xf) { case CMD_DONOTHING: @@ -641,13 +641,13 @@ void playroutine() unsigned short speed = 0; if (param) { - speed = (song.ltable[STBL][param-1] << 8) | song.rtable[STBL][param-1]; + speed = (song.fxtable[STBL][param-1].l << 8) | song.fxtable[STBL][param-1].r; } if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= song.rtable[STBL][param-1]; + speed >>= song.fxtable[STBL][param-1].r; } cptr->freq += speed; } @@ -658,13 +658,13 @@ void playroutine() unsigned short speed = 0; if (param) { - speed = (song.ltable[STBL][param-1] << 8) | song.rtable[STBL][param-1]; + speed = (song.fxtable[STBL][param-1].l << 8) | song.fxtable[STBL][param-1].r; } if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= song.rtable[STBL][param-1]; + speed >>= song.fxtable[STBL][param-1].r; } cptr->freq -= speed; } @@ -683,12 +683,12 @@ void playroutine() } else { - speed = (song.ltable[STBL][param-1] << 8) | song.rtable[STBL][param-1]; + speed = (song.fxtable[STBL][param-1].l << 8) | song.fxtable[STBL][param-1].r; if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= song.rtable[STBL][param-1]; + speed >>= song.fxtable[STBL][param-1].r; } if (cptr->freq < targetfreq) { @@ -721,15 +721,15 @@ void playroutine() if (param) { - cmpvalue = song.ltable[STBL][param-1]; - speed = song.rtable[STBL][param-1]; + cmpvalue = song.fxtable[STBL][param-1].l; + speed = song.fxtable[STBL][param-1].r; } if (cmpvalue >= 0x80) { cmpvalue &= 0x7f; speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= song.rtable[STBL][param-1]; + speed >>= song.fxtable[STBL][param-1].r; } if ((cptr->vibtime < 0x80) && (cptr->vibtime > cmpvalue)) @@ -766,7 +766,7 @@ void playroutine() if (cptr->ptr[PTBL]) { // Stop the song in case of jumping into a jump - if (song.ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) + if (song.fxtable[PTBL][cptr->ptr[PTBL]-1].l == 0xff) stopsong(); } break; @@ -779,7 +779,7 @@ void playroutine() if (filter.ptr) { // Stop the song in case of jumping into a jump - if (song.ltable[FTBL][filter.ptr-1] == 0xff) + if (song.fxtable[FTBL][filter.ptr-1].l == 0xff) stopsong(); } } @@ -790,7 +790,7 @@ void playroutine() if (filter2.ptr) { // Stop the song in case of jumping into a jump - if (song.ltable[FTBL][filter2.ptr-1] == 0xff) + if (song.fxtable[FTBL][filter2.ptr-1].l == 0xff) stopsong(); } } @@ -836,9 +836,9 @@ void playroutine() cptr->wavetime = 0; cptr->ptr[WTBL]++; // Wavetable jump - if (song.ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) + if (song.fxtable[WTBL][cptr->ptr[WTBL]-1].l == 0xff) { - cptr->ptr[WTBL] = song.rtable[WTBL][cptr->ptr[WTBL]-1]; + cptr->ptr[WTBL] = song.fxtable[WTBL][cptr->ptr[WTBL]-1].r; } if ((wave >= WAVECMD) && (wave <= WAVELASTCMD)) @@ -867,13 +867,13 @@ void playroutine() unsigned short speed = 0; if (cptr->cmddata) { - speed = (song.ltable[STBL][cptr->cmddata-1] << 8) | song.rtable[STBL][cptr->cmddata-1]; + speed = (song.fxtable[STBL][cptr->cmddata-1].l << 8) | song.fxtable[STBL][cptr->cmddata-1].r; } if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= song.rtable[STBL][cptr->cmddata-1]; + speed >>= song.fxtable[STBL][cptr->cmddata-1].r; } cptr->freq += speed; } @@ -884,13 +884,13 @@ void playroutine() unsigned short speed = 0; if (cptr->cmddata) { - speed = (song.ltable[STBL][cptr->cmddata-1] << 8) | song.rtable[STBL][cptr->cmddata-1]; + speed = (song.fxtable[STBL][cptr->cmddata-1].l << 8) | song.fxtable[STBL][cptr->cmddata-1].r; } if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= song.rtable[STBL][cptr->cmddata-1]; + speed >>= song.fxtable[STBL][cptr->cmddata-1].r; } cptr->freq -= speed; } @@ -912,15 +912,15 @@ void playroutine() if (cptr->cmddata) { - cmpvalue = song.ltable[STBL][cptr->cmddata-1]; - speed = song.rtable[STBL][cptr->cmddata-1]; + cmpvalue = song.fxtable[STBL][cptr->cmddata-1].l; + speed = song.fxtable[STBL][cptr->cmddata-1].r; } if (cmpvalue >= 0x80) { cmpvalue &= 0x7f; speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= song.rtable[STBL][cptr->cmddata-1]; + speed >>= song.fxtable[STBL][cptr->cmddata-1].r; } if ((cptr->vibtime < 0x80) && (cptr->vibtime > cmpvalue)) @@ -946,12 +946,12 @@ void playroutine() } else { - speed = (song.ltable[STBL][cptr->cmddata-1] << 8) | song.rtable[STBL][cptr->cmddata-1]; + speed = (song.fxtable[STBL][cptr->cmddata-1].l << 8) | song.fxtable[STBL][cptr->cmddata-1].r; if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= song.rtable[STBL][cptr->cmddata-1]; + speed >>= song.fxtable[STBL][cptr->cmddata-1].r; } if (cptr->freq < targetfreq) { @@ -994,30 +994,30 @@ void playroutine() } // Pulsetable jump - if (song.ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) + if (song.fxtable[PTBL][cptr->ptr[PTBL]-1].l == 0xff) { - cptr->ptr[PTBL] = song.rtable[PTBL][cptr->ptr[PTBL]-1]; + cptr->ptr[PTBL] = song.fxtable[PTBL][cptr->ptr[PTBL]-1].r; if (!cptr->ptr[PTBL]) goto PULSEEXEC; } if (!cptr->pulsetime) { // Set pulse - if (song.ltable[PTBL][cptr->ptr[PTBL]-1] >= 0x80) + if (song.fxtable[PTBL][cptr->ptr[PTBL]-1].l >= 0x80) { - cptr->pulse = (song.ltable[PTBL][cptr->ptr[PTBL]-1] & 0xf) << 8; - cptr->pulse |= song.rtable[PTBL][cptr->ptr[PTBL]-1]; + cptr->pulse = (song.fxtable[PTBL][cptr->ptr[PTBL]-1].l & 0xf) << 8; + cptr->pulse |= song.fxtable[PTBL][cptr->ptr[PTBL]-1].r; cptr->ptr[PTBL]++; } else { - cptr->pulsetime = song.ltable[PTBL][cptr->ptr[PTBL]-1]; + cptr->pulsetime = song.fxtable[PTBL][cptr->ptr[PTBL]-1].l; } } // Pulse modulation if (cptr->pulsetime) { - unsigned char speed = song.rtable[PTBL][cptr->ptr[PTBL]-1]; + unsigned char speed = song.fxtable[PTBL][cptr->ptr[PTBL]-1].r; if (speed < 0x80) { cptr->pulse += speed; diff --git a/src/reloc.cpp b/src/reloc.cpp index 9175183..6cea8cd 100644 --- a/src/reloc.cpp +++ b/src/reloc.cpp @@ -575,19 +575,19 @@ void relocator(const char* filename) { if (table[WTBL][c+1].used) { - if ((song.ltable[WTBL][c] >= WAVECMD) && (song.ltable[WTBL][c] <= WAVELASTCMD)) + if ((song.fxtable[WTBL][c].l >= WAVECMD) && (song.fxtable[WTBL][c].l <= WAVELASTCMD)) { int d = -1; tableerror = ErrorType::NONE; - switch(song.ltable[WTBL][c] - WAVECMD) + switch(song.fxtable[WTBL][c].l - WAVECMD) { case CMD_PORTAUP: case CMD_PORTADOWN: case CMD_TONEPORTA: case CMD_VIBRATO: d = STBL; - calcspeedtest(song.rtable[WTBL][c]); + calcspeedtest(song.fxtable[WTBL][c].r); break; case CMD_SETPULSEPTR: @@ -603,12 +603,12 @@ void relocator(const char* filename) case CMD_DONOTHING: case CMD_SETWAVEPTR: case CMD_FUNKTEMPO: - std::snprintf(textbuffer, MAX_PATHNAME, "ILLEGAL WAVETABLE COMMAND (ROW %02X, COMMAND %X)", c+1, song.ltable[WTBL][c] - WAVECMD); + std::snprintf(textbuffer, MAX_PATHNAME, "ILLEGAL WAVETABLE COMMAND (ROW %02X, COMMAND %X)", c+1, song.fxtable[WTBL][c].l - WAVECMD); error(textbuffer); goto PRCLEANUP; } - if (d != -1) exectable(d, song.rtable[WTBL][c]); + if (d != -1) exectable(d, song.fxtable[WTBL][c].r); if ((tableerror != ErrorType::NONE) && (taberr.type == ErrorType::NONE)) { @@ -984,12 +984,12 @@ void relocator(const char* filename) if (table[WTBL][c+1].used) { wavetblsize += 2; - if ((song.ltable[WTBL][c] >= WAVEDELAY) && (song.ltable[WTBL][c] <= WAVELASTDELAY)) nowavedelay = 0; - if ((song.ltable[WTBL][c] >= WAVECMD) && (song.ltable[WTBL][c] <= WAVELASTCMD)) + if ((song.fxtable[WTBL][c].l >= WAVEDELAY) && (song.fxtable[WTBL][c].l <= WAVELASTDELAY)) nowavedelay = 0; + if ((song.fxtable[WTBL][c].l >= WAVECMD) && (song.fxtable[WTBL][c].l <= WAVELASTCMD)) { nowavecmd = 0; noeffects = 0; - switch (song.ltable[WTBL][c] - WAVECMD) + switch (song.fxtable[WTBL][c].l - WAVECMD) { case CMD_PORTAUP: case CMD_PORTADOWN: @@ -1037,19 +1037,19 @@ void relocator(const char* filename) break; } } - if (song.ltable[WTBL][c] < WAVECMD) + if (song.fxtable[WTBL][c].l < WAVECMD) { - if (song.rtable[WTBL][c] <= 0x80) + if (song.fxtable[WTBL][c].r <= 0x80) { - int newlastnote = song.rtable[WTBL][c] + patternlastnote; + int newlastnote = song.fxtable[WTBL][c].r + patternlastnote; if (newlastnote > MAX_NOTES - 1) newlastnote = MAX_NOTES - 1; - if (song.rtable[WTBL][c] >= 0x20) firstnote = 0; + if (song.fxtable[WTBL][c].r >= 0x20) firstnote = 0; if (newlastnote > lastnote) lastnote = newlastnote; } else { - int newfirstnote = song.rtable[WTBL][c] & 0x7f; - int newlastnote = song.rtable[WTBL][c] & 0x7f; + int newfirstnote = song.fxtable[WTBL][c].r & 0x7f; + int newlastnote = song.fxtable[WTBL][c].r & 0x7f; if (newlastnote > MAX_NOTES - 1) newlastnote = MAX_NOTES - 1; if (newfirstnote < firstnote) firstnote = newfirstnote; if (newlastnote > lastnote) lastnote = newlastnote; @@ -1062,14 +1062,14 @@ void relocator(const char* filename) if (table[PTBL][c+1].used) { pulsetblsize += 2; - if ((song.ltable[PTBL][c] >= 0x80) && (song.ltable[PTBL][c] != 0xff)) + if ((song.fxtable[PTBL][c].l >= 0x80) && (song.fxtable[PTBL][c].l != 0xff)) { - if (song.rtable[PTBL][c] & 0xf) simplepulse = 0; + if (song.fxtable[PTBL][c].r & 0xf) simplepulse = 0; } - if (song.ltable[PTBL][c] < 0x80) + if (song.fxtable[PTBL][c].l < 0x80) { nopulsemod = 0; - if (song.rtable[PTBL][c] & 0xf) simplepulse = 0; + if (song.fxtable[PTBL][c].r & 0xf) simplepulse = 0; } } } @@ -1078,7 +1078,7 @@ void relocator(const char* filename) if (table[FTBL][c+1].used) { filttblsize += 2; - if (song.ltable[FTBL][c] < 0x80) nofiltermod = 0; + if (song.fxtable[FTBL][c].l < 0x80) nofiltermod = 0; } } for (int c = 0; c < MAX_TABLELEN; c++) @@ -1426,30 +1426,30 @@ void relocator(const char* filename) // In wavetable, convert waveform values for the playroutine case WTBL: { - unsigned char wave = song.ltable[c][d]; - if ((song.ltable[c][d] >= WAVESILENT) && (song.ltable[c][d] <= WAVELASTSILENT)) wave &= 0xf; - if ((song.ltable[c][d] > WAVELASTDELAY) && (song.ltable[c][d] <= WAVELASTSILENT) && (!nowavedelay)) wave += 0x10; + unsigned char wave = song.fxtable[c][d].l; + if ((song.fxtable[c][d].l >= WAVESILENT) && (song.fxtable[c][d].l <= WAVELASTSILENT)) wave &= 0xf; + if ((song.fxtable[c][d].l > WAVELASTDELAY) && (song.fxtable[c][d].l <= WAVELASTSILENT) && (!nowavedelay)) wave += 0x10; insertbyte(wave); } break; case PTBL: - if ((simplepulse) && (song.ltable[c][d] != 0xff) && (song.ltable[c][d] > 0x80)) + if ((simplepulse) && (song.fxtable[c][d].l != 0xff) && (song.fxtable[c][d].l > 0x80)) insertbyte(0x80); else - insertbyte(song.ltable[c][d]); + insertbyte(song.fxtable[c][d].l); break; // In filtesong.rtable, modify passband bits case FTBL: - if ((song.ltable[c][d] != 0xff) && (song.ltable[c][d] > 0x80)) - insertbyte(((song.ltable[c][d] & 0x70) >> 1) | 0x80); + if ((song.fxtable[c][d].l != 0xff) && (song.fxtable[c][d].l > 0x80)) + insertbyte(((song.fxtable[c][d].l & 0x70) >> 1) | 0x80); else - insertbyte(song.ltable[c][d]); + insertbyte(song.fxtable[c][d].l); break; default: - insertbyte(song.ltable[c][d]); + insertbyte(song.fxtable[c][d].l); break; } } @@ -1465,52 +1465,52 @@ void relocator(const char* filename) { if (table[c][d+1].used) { - if ((song.ltable[c][d] != 0xff) || (c == STBL)) + if ((song.fxtable[c][d].l != 0xff) || (c == STBL)) { switch(c) { case WTBL: - if ((song.ltable[c][d] >= WAVECMD) && (song.ltable[c][d] <= WAVELASTCMD)) + if ((song.fxtable[c][d].l >= WAVECMD) && (song.fxtable[c][d].l <= WAVELASTCMD)) { // Remap table-referencing commands - switch (song.ltable[c][d] - WAVECMD) + switch (song.fxtable[c][d].l - WAVECMD) { case CMD_PORTAUP: case CMD_PORTADOWN: case CMD_TONEPORTA: case CMD_VIBRATO: - insertbyte(table[STBL][song.rtable[c][d]].map); + insertbyte(table[STBL][song.fxtable[c][d].r].map); break; case CMD_SETPULSEPTR: - insertbyte(table[PTBL][song.rtable[c][d]].map); + insertbyte(table[PTBL][song.fxtable[c][d].r].map); break; case CMD_SETFILTERPTR: - insertbyte(table[FTBL][song.rtable[c][d]].map); + insertbyte(table[FTBL][song.fxtable[c][d].r].map); break; default: - insertbyte(song.rtable[c][d]); + insertbyte(song.fxtable[c][d].r); break; } } else { // For normal notes, reverse all right side high bits - insertbyte(song.rtable[c][d] ^ 0x80); + insertbyte(song.fxtable[c][d].r ^ 0x80); } break; case PTBL: if (simplepulse) { - if (song.ltable[c][d] >= 0x80) - insertbyte((song.ltable[c][d] & 0x0f) | (song.rtable[c][d] & 0xf0)); + if (song.fxtable[c][d].l >= 0x80) + insertbyte((song.fxtable[c][d].l & 0x0f) | (song.fxtable[c][d].r & 0xf0)); else { - int pulsespeed = song.rtable[c][d] >> 4; - if (song.rtable[c][d] & 0x80) + int pulsespeed = song.fxtable[c][d].r >> 4; + if (song.fxtable[c][d].r & 0x80) { pulsespeed |= 0xf0; pulsespeed--; @@ -1520,16 +1520,16 @@ void relocator(const char* filename) } } else - insertbyte(song.rtable[c][d]); + insertbyte(song.fxtable[c][d].r); break; default: - insertbyte(song.rtable[c][d]); + insertbyte(song.fxtable[c][d].r); break; } } else - insertbyte(table[c][song.rtable[c][d]].map); + insertbyte(table[c][song.fxtable[c][d].r].map); } } } @@ -2244,8 +2244,8 @@ void findtableduplicates(int num) { if (table[num][d].used) { - if ((song.ltable[num][d-1] == song.ltable[num][c-1]) && - (song.rtable[num][d-1] == song.rtable[num][c-1])) + if ((song.fxtable[num][d-1].l == song.fxtable[num][c-1].l) && + (song.fxtable[num][d-1].r == song.fxtable[num][c-1].r)) { // Duplicate found, remove and map to the original table[num][d].used = false; @@ -2276,25 +2276,25 @@ void findtableduplicates(int num) if (e < len-1) { // Is table data the same? - if ((song.ltable[num][d+e-1] != song.ltable[num][c+e-1]) || - (song.rtable[num][d+e-1] != song.rtable[num][c+e-1])) + if ((song.fxtable[num][d+e-1].l != song.fxtable[num][c+e-1].l) || + (song.fxtable[num][d+e-1].r != song.fxtable[num][c+e-1].r)) break; } else { // Do both parts have a jump in the end? - if (song.ltable[num][d+e-1] != song.ltable[num][c+e-1]) + if (song.fxtable[num][d+e-1].l != song.fxtable[num][c+e-1].l) break; // Do both parts end? - if (song.rtable[num][d+e-1] == 0) + if (song.fxtable[num][d+e-1].r == 0) { - if (song.rtable[num][c+e-1] != 0) + if (song.fxtable[num][c+e-1].r != 0) break; } else { // Do both parts loop in the same way? - if ((song.rtable[num][d+e-1] - d) != (song.rtable[num][c+e-1] - c)) + if ((song.fxtable[num][d+e-1].r - d) != (song.fxtable[num][c+e-1].r - c)) break; } } @@ -2332,20 +2332,20 @@ bool isusedandselfcontained(int num, int start) if (!table[num][c].used) return false; } // Check for jump to outside - if (song.rtable[num][end-1] != 0) + if (song.fxtable[num][end-1].r != 0) { - if ((song.rtable[num][end-1] < start) || - (song.rtable[num][end-1] > end)) return false; + if ((song.fxtable[num][end-1].r < start) || + (song.fxtable[num][end-1].r > end)) return false; } // Check for jump from outside for (int c = 1; c < start; c++) - if ((table[num][c].used) && (song.ltable[num][c-1] == 0xff) && - (song.rtable[num][c-1] >= start) && - (song.rtable[num][c-1] <= end)) return false; + if ((table[num][c].used) && (song.fxtable[num][c-1].l == 0xff) && + (song.fxtable[num][c-1].r >= start) && + (song.fxtable[num][c-1].r <= end)) return false; for (int c = end+1; c <= MAX_TABLELEN; c++) - if ((table[num][c].used) && (song.ltable[num][c-1] == 0xff) && - (song.rtable[num][c-1] >= start) && - (song.rtable[num][c-1] <= end)) return false; + if ((table[num][c].used) && (song.fxtable[num][c-1].l == 0xff) && + (song.fxtable[num][c-1].r >= start) && + (song.fxtable[num][c-1].r <= end)) return false; // OK! return true; @@ -2359,7 +2359,7 @@ void calcspeedtest(unsigned char pos) return; } - if (song.ltable[STBL][pos-1] >= 0x80) nocalculatedspeed = 0; + if (song.fxtable[STBL][pos-1].l >= 0x80) nocalculatedspeed = 0; else nonormalspeed = 0; } @@ -2368,7 +2368,7 @@ void exectable(int num, int ptr) // Jump error check if ((num != STBL) && (ptr) && (ptr <= MAX_TABLELEN)) { - if (song.ltable[num][ptr-1] == 0xff) + if (song.fxtable[num][ptr-1].l == 0xff) { tableerror = ErrorType::JUMP; return; @@ -2392,9 +2392,9 @@ void exectable(int num, int ptr) // Go to next ptr. if (num != STBL) { - if (song.ltable[num][ptr-1] == 0xff) + if (song.fxtable[num][ptr-1].l == 0xff) { - ptr = song.rtable[num][ptr-1]; + ptr = song.fxtable[num][ptr-1].r; } else ptr++; } @@ -2433,12 +2433,12 @@ void optimizetable(int num) { if (table[WTBL][c+1].used) { - if ((song.ltable[WTBL][c] >= WAVECMD) && - (song.ltable[WTBL][c] <= WAVELASTCMD)) + if ((song.fxtable[WTBL][c].l >= WAVECMD) && + (song.fxtable[WTBL][c].l <= WAVELASTCMD)) { int d = -1; - switch(song.ltable[WTBL][c] - WAVECMD) + switch(song.fxtable[WTBL][c].l - WAVECMD) { case CMD_PORTAUP: case CMD_PORTADOWN: @@ -2456,7 +2456,7 @@ void optimizetable(int num) break; } - if (d != -1) exectable(d, song.rtable[WTBL][c]); + if (d != -1) exectable(d, song.fxtable[WTBL][c].r); } } } @@ -2464,7 +2464,7 @@ void optimizetable(int num) int c; for (c = MAX_TABLELEN-1; c >= 0; c--) { - if ((song.ltable[num][c]) || (song.rtable[num][c])) break; + if ((song.fxtable[num][c].l) || (song.fxtable[num][c].r)) break; } for (; c >= 0; c--) { diff --git a/src/song.cpp b/src/song.cpp index 9c2ec13..1ebdd86 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -58,7 +58,7 @@ int Song::gettablelen(int num) int c; for (c = MAX_TABLELEN-1; c >= 0; c--) { - if (ltable[num][c] || rtable[num][c]) break; + if (fxtable[num][c].l || fxtable[num][c].r) break; } return c+1; } @@ -71,7 +71,7 @@ int Song::gettablepartlen(int num, int pos) int c; for (c = pos; c < MAX_TABLELEN; c++) { - if (ltable[num][c] == 0xff) + if (fxtable[num][c].l == 0xff) { c++; break; @@ -84,7 +84,7 @@ int Song::findfreespeedtable() { for (int c = 0; c < MAX_TABLELEN; c++) { - if ((!ltable[STBL][c]) && (!rtable[STBL][c])) + if ((!fxtable[STBL][c].l) && (!fxtable[STBL][c].r)) { return c; } @@ -110,9 +110,9 @@ void Song::inserttable(int num, int pos, bool mode) // Shift tablepointers in wavetable commands for (int c = 0; c < MAX_TABLELEN; c++) { - if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) + if ((fxtable[WTBL][c].l >= WAVECMD) && (fxtable[WTBL][c].l <= WAVELASTCMD)) { - int cmd = ltable[WTBL][c] & 0xf; + int cmd = fxtable[WTBL][c].l & 0xf; if (num < STBL) { @@ -120,11 +120,11 @@ void Song::inserttable(int num, int pos, bool mode) { if (!mode) { - if ((rtable[WTBL][c]-1) >= pos) rtable[WTBL][c]++; + if ((fxtable[WTBL][c].r-1) >= pos) fxtable[WTBL][c].r++; } else { - if ((rtable[WTBL][c]-1) > pos) rtable[WTBL][c]++; + if ((fxtable[WTBL][c].r-1) > pos) fxtable[WTBL][c].r++; } } } @@ -134,11 +134,11 @@ void Song::inserttable(int num, int pos, bool mode) { if (!mode) { - if ((rtable[WTBL][c]-1) >= pos) rtable[WTBL][c]++; + if ((fxtable[WTBL][c].r-1) >= pos) fxtable[WTBL][c].r++; } else { - if ((rtable[WTBL][c]-1) > pos) rtable[WTBL][c]++; + if ((fxtable[WTBL][c].r-1) > pos) fxtable[WTBL][c].r++; } } } @@ -187,15 +187,15 @@ void Song::inserttable(int num, int pos, bool mode) { for (int c = 0; c < MAX_TABLELEN; c++) { - if (ltable[num][c] == 0xff) + if (fxtable[num][c].l == 0xff) { if (!mode) { - if ((rtable[num][c]-1) >= pos) rtable[num][c]++; + if ((fxtable[num][c].r-1) >= pos) fxtable[num][c].r++; } else { - if ((rtable[num][c]-1) > pos) rtable[num][c]++; + if ((fxtable[num][c].r-1) > pos) fxtable[num][c].r++; } } } @@ -205,20 +205,20 @@ void Song::inserttable(int num, int pos, bool mode) { if (c > pos) { - ltable[num][c] = ltable[num][c-1]; - rtable[num][c] = rtable[num][c-1]; + fxtable[num][c].l = fxtable[num][c-1].l; + fxtable[num][c].r = fxtable[num][c-1].r; } else { if ((num == WTBL) && (mode == 1)) { - ltable[num][c] = 0xe9; - rtable[num][c] = 0; + fxtable[num][c].l = 0xe9; + fxtable[num][c].r = 0; } else { - ltable[num][c] = 0; - rtable[num][c] = 0; + fxtable[num][c].l = 0; + fxtable[num][c].r = 0; } } } @@ -235,22 +235,22 @@ void Song::deletetable(int num, int pos) // Shift tablepointers in wavetable commands for (int c = 0; c < MAX_TABLELEN; c++) { - if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) + if ((fxtable[WTBL][c].l >= WAVECMD) && (fxtable[WTBL][c].l <= WAVELASTCMD)) { - int cmd = ltable[WTBL][c] & 0xf; + int cmd = fxtable[WTBL][c].l & 0xf; if (num < STBL) { if (cmd == CMD_SETWAVEPTR+num) { - if ((rtable[WTBL][c]-1) > pos) rtable[WTBL][c]--; + if ((fxtable[WTBL][c].r-1) > pos) fxtable[WTBL][c].r--; } } else { if ((cmd == CMD_FUNKTEMPO) || ((cmd >= CMD_PORTAUP) && (cmd <= CMD_VIBRATO))) { - if ((rtable[WTBL][c]-1) > pos) rtable[WTBL][c]--; + if ((fxtable[WTBL][c].r-1) > pos) fxtable[WTBL][c].r--; } } } @@ -284,8 +284,8 @@ void Song::deletetable(int num, int pos) { if (num != STBL) { - if (ltable[num][c] == 0xff) - if ((rtable[num][c]-1) > pos) rtable[num][c]--; + if (fxtable[num][c].l == 0xff) + if ((fxtable[num][c].r-1) > pos) fxtable[num][c].r--; } } @@ -293,13 +293,13 @@ void Song::deletetable(int num, int pos) { if (c+1 < MAX_TABLELEN) { - ltable[num][c] = ltable[num][c+1]; - rtable[num][c] = rtable[num][c+1]; + fxtable[num][c].l = fxtable[num][c+1].l; + fxtable[num][c].r = fxtable[num][c+1].r; } else { - ltable[num][c] = 0; - rtable[num][c] = 0; + fxtable[num][c].l = 0; + fxtable[num][c].r = 0; } } } @@ -417,8 +417,13 @@ bool savesong() { int writebytes = song.gettablelen(c); fwrite8(handle, writebytes); - std::fwrite(song.ltable[c], writebytes, 1, handle); - std::fwrite(song.rtable[c], writebytes, 1, handle); + unsigned char tbl[MAX_TABLELEN]; + for (int i=0; i= 0x8) && (song.ltable[WTBL][fw] <= 0xf)) - song.ltable[WTBL][fw] |= 0xe0; + song.fxtable[WTBL][fw].l = fread8(handle); + song.fxtable[WTBL][fw].r = fread8(handle); + if (song.fxtable[WTBL][fw].l == 0xff) + if (song.fxtable[WTBL][fw].r) song.fxtable[WTBL][fw].r += song.instr[c].ptr[WTBL]-1; + if ((song.fxtable[WTBL][fw].l >= 0x8) && (song.fxtable[WTBL][fw].l <= 0xf)) + song.fxtable[WTBL][fw].l |= 0xe0; fw++; } else @@ -712,14 +727,14 @@ SngType loadsong() } // Remove empty wavetable afterwards - if ((wavelen == 2) && (!song.ltable[WTBL][fw-2]) && (!song.rtable[WTBL][fw-2])) + if ((wavelen == 2) && (!song.fxtable[WTBL][fw-2].l) && (!song.fxtable[WTBL][fw-2].r)) { song.instr[c].ptr[WTBL] = 0; fw -= 2; - song.ltable[WTBL][fw] = 0; - song.rtable[WTBL][fw] = 0; - song.ltable[WTBL][fw+1] = 0; - song.rtable[WTBL][fw+1] = 0; + song.fxtable[WTBL][fw].l = 0; + song.fxtable[WTBL][fw].r = 0; + song.fxtable[WTBL][fw+1].l = 0; + song.fxtable[WTBL][fw+1].r = 0; } // Convert pulsetable @@ -741,8 +756,8 @@ SngType loadsong() // Initial pulse setting if (fp >= MAX_TABLELEN) goto PULSEDONE; song.instr[c].ptr[PTBL] = fp+1; - song.ltable[PTBL][fp] = 0x80 | (pulse[c] >> 4); - song.rtable[PTBL][fp] = pulse[c] << 4; + song.fxtable[PTBL][fp].l = 0x80 | (pulse[c] >> 4); + song.fxtable[PTBL][fp].r = pulse[c] << 4; fp++; // Pulse modulation @@ -761,8 +776,8 @@ SngType loadsong() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = acttime; - song.rtable[PTBL][fp] = pulseadd[c] / 2; + song.fxtable[PTBL][fp].l = acttime; + song.fxtable[PTBL][fp].r = pulseadd[c] / 2; fp++; pulsetime -= acttime; } @@ -780,8 +795,8 @@ SngType loadsong() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = acttime; - song.rtable[PTBL][fp] = -(pulseadd[c] / 2); + song.fxtable[PTBL][fp].l = acttime; + song.fxtable[PTBL][fp].r = -(pulseadd[c] / 2); fp++; pulsetime -= acttime; } @@ -799,16 +814,16 @@ SngType loadsong() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = acttime; - song.rtable[PTBL][fp] = pulseadd[c] / 2; + song.fxtable[PTBL][fp].l = acttime; + song.fxtable[PTBL][fp].r = pulseadd[c] / 2; fp++; pulsetime -= acttime; } } // Pulse jump back to beginning if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = 0xff; - song.rtable[PTBL][fp] = song.instr[c].ptr[PTBL] + 1; + song.fxtable[PTBL][fp].l = 0xff; + song.fxtable[PTBL][fp].r = song.instr[c].ptr[PTBL] + 1; fp++; } else @@ -822,16 +837,16 @@ SngType loadsong() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = acttime; - song.rtable[PTBL][fp] = pulseadd[c] / 2; + song.fxtable[PTBL][fp].l = acttime; + song.fxtable[PTBL][fp].r = pulseadd[c] / 2; fp++; pulsetime -= acttime; } } // Pulse jump back to beginning if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = 0xff; - song.rtable[PTBL][fp] = hlpos + 1; + song.fxtable[PTBL][fp].l = 0xff; + song.fxtable[PTBL][fp].r = hlpos + 1; fp++; } } @@ -839,8 +854,8 @@ SngType loadsong() { // Pulse stopped if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = 0xff; - song.rtable[PTBL][fp] = 0; + song.fxtable[PTBL][fp].l = 0xff; + song.fxtable[PTBL][fp].r = 0; fp++; } PULSEDONE: {} @@ -927,13 +942,13 @@ SngType loadsong() // Filter set if (filtertable[c*4]) { - song.ltable[FTBL][ff] = 0x80 + (filtertable[c*4+1] & 0x70); - song.rtable[FTBL][ff] = filtertable[c*4]; + song.fxtable[FTBL][ff].l = 0x80 + (filtertable[c*4+1] & 0x70); + song.fxtable[FTBL][ff].r = filtertable[c*4]; ff++; if (filtertable[c*4+2]) { - song.ltable[FTBL][ff] = 0x00; - song.rtable[FTBL][ff] = filtertable[c*4+2]; + song.fxtable[FTBL][ff].l = 0x00; + song.fxtable[FTBL][ff].r = filtertable[c*4+2]; ff++; } } @@ -946,8 +961,8 @@ SngType loadsong() { int acttime = time; if (acttime > 127) acttime = 127; - song.ltable[FTBL][ff] = acttime; - song.rtable[FTBL][ff] = filtertable[c*4+2]; + song.fxtable[FTBL][ff].l = acttime; + song.fxtable[FTBL][ff].r = filtertable[c*4+2]; ff++; time -= acttime; } @@ -957,8 +972,8 @@ SngType loadsong() if (filtertable[c*4+3] != c+1) { filterjumppos[c] = ff; - song.ltable[FTBL][ff] = 0xff; - song.rtable[FTBL][ff] = filtertable[c*4+3]; // Fix the jump later + song.fxtable[FTBL][ff].l = 0xff; + song.fxtable[FTBL][ff].r = filtertable[c*4+3]; // Fix the jump later ff++; } } @@ -968,7 +983,7 @@ SngType loadsong() for (int c = 1; c <= numfilter; c++) { if (filterjumppos[c] != -1) - song.rtable[FTBL][filterjumppos[c]] = filtermap[song.rtable[FTBL][filterjumppos[c]]]; + song.fxtable[FTBL][filterjumppos[c]].r = filtermap[song.fxtable[FTBL][filterjumppos[c]].r]; } // Fix filterpointers in instruments @@ -1041,10 +1056,10 @@ SngType loadsong() { for (e = song.instr[i].ptr[WTBL]-1;; e++) { - if (song.ltable[WTBL][e] == 0xff) break; + if (song.fxtable[WTBL][e].l == 0xff) break; if (fw < MAX_TABLELEN) { - song.ltable[WTBL][fw] = song.ltable[WTBL][e]; + song.fxtable[WTBL][fw].l = song.fxtable[WTBL][e].l; fw++; } } @@ -1053,17 +1068,17 @@ SngType loadsong() arploop = fw + 1; if (fw < MAX_TABLELEN-3) { - song.ltable[WTBL][fw] = (param & 0x80) >> 7; - song.rtable[WTBL][fw] = (param & 0x70) >> 4; + song.fxtable[WTBL][fw].l = (param & 0x80) >> 7; + song.fxtable[WTBL][fw].r = (param & 0x70) >> 4; fw++; - song.ltable[WTBL][fw] = (param & 0x80) >> 7; - song.rtable[WTBL][fw] = (param & 0xf); + song.fxtable[WTBL][fw].l = (param & 0x80) >> 7; + song.fxtable[WTBL][fw].r = (param & 0xf); fw++; - song.ltable[WTBL][fw] = (param & 0x80) >> 7; - song.rtable[WTBL][fw] = 0; + song.fxtable[WTBL][fw].l = (param & 0x80) >> 7; + song.fxtable[WTBL][fw].r = 0; fw++; - song.ltable[WTBL][fw] = 0xff; - song.rtable[WTBL][fw] = arploop; + song.fxtable[WTBL][fw].l = 0xff; + song.fxtable[WTBL][fw].r = arploop; fw++; // Create new instrument if possible @@ -1127,13 +1142,13 @@ SngType loadsong() { for (int c = 0; c < MAX_TABLELEN; c++) { - if ((song.ltable[PTBL][c] < 0x80) && (song.rtable[PTBL][c])) + if ((song.fxtable[PTBL][c].l < 0x80) && (song.fxtable[PTBL][c].r)) { - int speed = ((signed char)song.rtable[PTBL][c]); + int speed = ((signed char)song.fxtable[PTBL][c].r); speed <<= 1; if (speed > 127) speed = 127; if (speed < -128) speed = -128; - song.rtable[PTBL][c] = speed; + song.fxtable[PTBL][c].r = speed; } } } @@ -1235,14 +1250,14 @@ void loadinstrument() { int d; for (d = start; (d < start+len) && (d < MAX_TABLELEN); d++) - song.ltable[c][d] = fread8(handle); + song.fxtable[c][d].l = fread8(handle); while (d < start+len) { fread8(handle); d++; } for (d = start; (d < start+len) && (d < MAX_TABLELEN); d++) - song.rtable[c][d] = fread8(handle); + song.fxtable[c][d].r = fread8(handle); while (d < start+len) { fread8(handle); @@ -1252,10 +1267,10 @@ void loadinstrument() { for (int d = start; (d < start+len) && (d < MAX_TABLELEN); d++) { - if (song.ltable[c][d] == 0xff) + if (song.fxtable[c][d].l == 0xff) { - if (song.rtable[c][d]) - song.rtable[c][d] = song.rtable[c][d] - optr[c] + start + 1; + if (song.fxtable[c][d].r) + song.fxtable[c][d].r = song.fxtable[c][d].r - optr[c] + start + 1; } } } @@ -1299,14 +1314,14 @@ void loadinstrument() { int d; for (d = start; (d < start+len) && (d < MAX_TABLELEN); d++) - song.ltable[c][d] = fread8(handle); + song.fxtable[c][d].l = fread8(handle); while (d < start+len) { fread8(handle); d++; } for (d = start; (d < start+len) && (d < MAX_TABLELEN); d++) - song.rtable[c][d] = fread8(handle); + song.fxtable[c][d].r = fread8(handle); while (d < start+len) { fread8(handle); @@ -1314,10 +1329,10 @@ void loadinstrument() } for (int d = start; (d < start+len) && (d < MAX_TABLELEN); d++) { - if (song.ltable[c][d] == 0xff) + if (song.fxtable[c][d].l == 0xff) { - if (song.rtable[c][d]) - song.rtable[c][d] = song.rtable[c][d] - optr[c] + start + 1; + if (song.fxtable[c][d].r) + song.fxtable[c][d].r = song.fxtable[c][d].r - optr[c] + start + 1; } } if (c == PTBL) @@ -1368,10 +1383,10 @@ void loadinstrument() { if (fw < MAX_TABLELEN) { - song.ltable[WTBL][fw] = fread8(handle); - song.rtable[WTBL][fw] = fread8(handle); - if (song.ltable[WTBL][fw] == 0xff) - if (song.rtable[WTBL][fw]) song.rtable[WTBL][fw] += song.instr[einum].ptr[WTBL]-1; + song.fxtable[WTBL][fw].l = fread8(handle); + song.fxtable[WTBL][fw].r = fread8(handle); + if (song.fxtable[WTBL][fw].l == 0xff) + if (song.fxtable[WTBL][fw].r) song.fxtable[WTBL][fw].r += song.instr[einum].ptr[WTBL]-1; fw++; } else @@ -1382,14 +1397,14 @@ void loadinstrument() } // Remove empty wavetable afterwards - if ((wavelen == 2) && (!song.ltable[WTBL][fw-2]) && (!song.rtable[WTBL][fw-2])) + if ((wavelen == 2) && (!song.fxtable[WTBL][fw-2].l) && (!song.fxtable[WTBL][fw-2].r)) { song.instr[einum].ptr[WTBL] = 0; fw -= 2; - song.ltable[WTBL][fw] = 0; - song.rtable[WTBL][fw] = 0; - song.ltable[WTBL][fw+1] = 0; - song.rtable[WTBL][fw+1] = 0; + song.fxtable[WTBL][fw].l = 0; + song.fxtable[WTBL][fw].r = 0; + song.fxtable[WTBL][fw+1].l = 0; + song.fxtable[WTBL][fw+1].r = 0; } // Convert pulsetable @@ -1400,8 +1415,8 @@ void loadinstrument() if (fp >= MAX_TABLELEN) goto PULSEDONE; pulsestart = fp; song.instr[einum].ptr[PTBL] = fp+1; - song.ltable[PTBL][fp] = 0x80 | (pulse >> 4); - song.rtable[PTBL][fp] = pulse << 4; + song.fxtable[PTBL][fp].l = 0x80 | (pulse >> 4); + song.fxtable[PTBL][fp].r = pulse << 4; fp++; // Pulse modulation @@ -1420,8 +1435,8 @@ void loadinstrument() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = acttime; - song.rtable[PTBL][fp] = pulseadd / 2; + song.fxtable[PTBL][fp].l = acttime; + song.fxtable[PTBL][fp].r = pulseadd / 2; fp++; pulsetime -= acttime; } @@ -1439,8 +1454,8 @@ void loadinstrument() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = acttime; - song.rtable[PTBL][fp] = -(pulseadd / 2); + song.fxtable[PTBL][fp].l = acttime; + song.fxtable[PTBL][fp].r = -(pulseadd / 2); fp++; pulsetime -= acttime; } @@ -1458,16 +1473,16 @@ void loadinstrument() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = acttime; - song.rtable[PTBL][fp] = pulseadd / 2; + song.fxtable[PTBL][fp].l = acttime; + song.fxtable[PTBL][fp].r = pulseadd / 2; fp++; pulsetime -= acttime; } } // Pulse jump back to beginning if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = 0xff; - song.rtable[PTBL][fp] = song.instr[einum].ptr[PTBL] + 1; + song.fxtable[PTBL][fp].l = 0xff; + song.fxtable[PTBL][fp].r = song.instr[einum].ptr[PTBL] + 1; fp++; } else @@ -1481,16 +1496,16 @@ void loadinstrument() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = acttime; - song.rtable[PTBL][fp] = pulseadd / 2; + song.fxtable[PTBL][fp].l = acttime; + song.fxtable[PTBL][fp].r = pulseadd / 2; fp++; pulsetime -= acttime; } } // Pulse jump back to beginning if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = 0xff; - song.rtable[PTBL][fp] = hlpos + 1; + song.fxtable[PTBL][fp].l = 0xff; + song.fxtable[PTBL][fp].r = hlpos + 1; fp++; } } @@ -1498,8 +1513,8 @@ void loadinstrument() { // Pulse stopped if (fp >= MAX_TABLELEN) goto PULSEDONE; - song.ltable[PTBL][fp] = 0xff; - song.rtable[PTBL][fp] = 0; + song.fxtable[PTBL][fp].l = 0xff; + song.fxtable[PTBL][fp].r = 0; fp++; } PULSEDONE: @@ -1513,13 +1528,13 @@ void loadinstrument() // Filter set if (filtertemp[0]) { - song.ltable[FTBL][ff] = 0x80 + (filtertemp[1] & 0x70); - song.rtable[FTBL][ff] = filtertemp[0]; + song.fxtable[FTBL][ff].l = 0x80 + (filtertemp[1] & 0x70); + song.fxtable[FTBL][ff].r = filtertemp[0]; ff++; if (filtertemp[2]) { - song.ltable[FTBL][ff] = 0x00; - song.rtable[FTBL][ff] = filtertemp[2]; + song.fxtable[FTBL][ff].l = 0x00; + song.fxtable[FTBL][ff].r = filtertemp[2]; ff++; } } @@ -1532,16 +1547,16 @@ void loadinstrument() { int acttime = time; if (acttime > 127) acttime = 127; - song.ltable[FTBL][ff] = acttime; - song.rtable[FTBL][ff] = filtertemp[2]; + song.fxtable[FTBL][ff].l = acttime; + song.fxtable[FTBL][ff].r = filtertemp[2]; ff++; time -= acttime; } } // Jump to next step: always end the filter - song.ltable[FTBL][ff] = 0xff; - song.rtable[FTBL][ff] = 0; + song.fxtable[FTBL][ff].l = 0xff; + song.fxtable[FTBL][ff].r = 0; ff++; } } @@ -1553,13 +1568,13 @@ void loadinstrument() { for (int c = pulsestart; (c < pulseend) && (c < MAX_TABLELEN); c++) { - if ((song.ltable[PTBL][c] < 0x80) && (song.rtable[PTBL][c])) + if ((song.fxtable[PTBL][c].l < 0x80) && (song.fxtable[PTBL][c].r)) { - int speed = ((signed char)song.rtable[PTBL][c]); + int speed = ((signed char)song.fxtable[PTBL][c].r); speed <<= 1; if (speed > 127) speed = 127; if (speed < -128) speed = -128; - song.rtable[PTBL][c] = speed; + song.fxtable[PTBL][c].r = speed; } } } @@ -1651,8 +1666,7 @@ void clearsong(bool cs, bool cp, bool ci, bool ct, bool cn) { for (int c = MAX_TABLES-1; c >= 0; c--) { - std::memset(song.ltable[c], 0, MAX_TABLELEN); - std::memset(song.rtable[c], 0, MAX_TABLELEN); + std::memset(song.fxtable[c], 0, MAX_TABLELEN*sizeof(FxTable)); tables.settableview(c, 0); } } @@ -1932,24 +1946,24 @@ void mergesong() int loadsize = fread8(handle); if (loadsize + tablebase[c] > MAX_TABLELEN) goto ABORT; - std::fread(&song.ltable[c][tablebase[c]], loadsize, 1, handle); - std::fread(&song.rtable[c][tablebase[c]], loadsize, 1, handle); + std::fread(&song.fxtable[c][tablebase[c]].l, loadsize, 1, handle); + std::fread(&song.fxtable[c][tablebase[c]].r, loadsize, 1, handle); // Remap jumps and tablecommands for (int d = tablebase[c]; d < tablebase[c] + loadsize; d++) { - if (song.ltable[c][d] == 0xff && song.rtable[c][d] > 0) - song.rtable[c][d] += tablebase[c]; - if (c == 0 && (song.ltable[c][d] >= WAVECMD && song.ltable[c][d] <= WAVELASTCMD)) + if (song.fxtable[c][d].l == 0xff && song.fxtable[c][d].r > 0) + song.fxtable[c][d].r += tablebase[c]; + if (c == 0 && (song.fxtable[c][d].l >= WAVECMD && song.fxtable[c][d].l <= WAVELASTCMD)) { - int cmd = song.ltable[c][d] & 0xf; - if (cmd == CMD_SETWAVEPTR && song.rtable[c][d] > 0) - song.rtable[c][d] += tablebase[WTBL]; - if (cmd == CMD_SETPULSEPTR && song.rtable[c][d] > 0) - song.rtable[c][d] += tablebase[PTBL]; - if (cmd == CMD_SETFILTERPTR && song.rtable[c][d] > 0) - song.rtable[c][d] += tablebase[FTBL]; - if (((cmd >= CMD_PORTAUP && cmd <= CMD_VIBRATO) || cmd == CMD_FUNKTEMPO) && song.rtable[c][d] > 0) - song.rtable[c][d] += tablebase[STBL]; + int cmd = song.fxtable[c][d].l & 0xf; + if (cmd == CMD_SETWAVEPTR && song.fxtable[c][d].r > 0) + song.fxtable[c][d].r += tablebase[WTBL]; + if (cmd == CMD_SETPULSEPTR && song.fxtable[c][d].r > 0) + song.fxtable[c][d].r += tablebase[PTBL]; + if (cmd == CMD_SETFILTERPTR && song.fxtable[c][d].r > 0) + song.fxtable[c][d].r += tablebase[FTBL]; + if (((cmd >= CMD_PORTAUP && cmd <= CMD_VIBRATO) || cmd == CMD_FUNKTEMPO) && song.fxtable[c][d].r > 0) + song.fxtable[c][d].r += tablebase[STBL]; } } } @@ -2059,17 +2073,17 @@ int makespeedtable(unsigned data, int mode, bool makenew) { for (int c = 0; c < MAX_TABLELEN; c++) { - if ((song.ltable[STBL][c] == l) && (song.rtable[STBL][c] == r)) + if ((song.fxtable[STBL][c].l == l) && (song.fxtable[STBL][c].r == r)) return c; } } for (int c = 0; c < MAX_TABLELEN; c++) { - if ((!song.ltable[STBL][c]) && (!song.rtable[STBL][c])) + if ((!song.fxtable[STBL][c].l) && (!song.fxtable[STBL][c].r)) { - song.ltable[STBL][c] = l; - song.rtable[STBL][c] = r; + song.fxtable[STBL][c].l = l; + song.fxtable[STBL][c].r = r; tables.settableview(STBL, c); return c; diff --git a/src/song.h b/src/song.h index 76575c8..b46cf50 100644 --- a/src/song.h +++ b/src/song.h @@ -45,11 +45,16 @@ struct SongOrder int len; }; +struct FxTable +{ + unsigned char l; + unsigned char r; +}; + struct Song { Instr instr[MAX_INSTR]; - unsigned char ltable[MAX_TABLES][MAX_TABLELEN]; - unsigned char rtable[MAX_TABLES][MAX_TABLELEN]; + FxTable fxtable[MAX_TABLES][MAX_TABLELEN]; SongOrder order[MAX_SONGS][MAX_CHN]; unsigned char pattern[MAX_PATT][MAX_PATTROWS*4+4];