From cf3138a4414c393160b458e0bcf19bebd4ff91b0 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Mon, 13 Jul 2026 22:44:02 +0200 Subject: [PATCH 1/4] Cleanup --- src/display.cpp | 81 +++----- src/instr.cpp | 8 +- src/loadtrk.cpp | 24 ++- src/song.cpp | 6 +- src/table.cpp | 497 ++++++++++++++++++++++++++---------------------- src/table.h | 56 ++++-- 6 files changed, 355 insertions(+), 317 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index f5c93c8..c4f01f7 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -168,15 +168,11 @@ void printstatus() if (optimizerealtime) printtext(dpos.statusTopFvX+6, dpos.statusTopY, colors.CHEADER, "RO"); - if (ntsc) - printtext(dpos.statusTopFvX+9, dpos.statusTopY, colors.CHEADER, "NTSC"); - else - printtext(dpos.statusTopFvX+9, dpos.statusTopY, colors.CHEADER, " PAL"); + const char *clk = ntsc ? "NTSC" : "PAL"; + printtext(dpos.statusTopFvX+9, dpos.statusTopY, colors.CHEADER, clk); - if (!sidmodel) - printtext(dpos.statusTopFvX+14, dpos.statusTopY, colors.CHEADER, "6581"); - else - printtext(dpos.statusTopFvX+14, dpos.statusTopY, colors.CHEADER, "8580"); + const char *model = sidmodel ? "8580" : "6581"; + printtext(dpos.statusTopFvX+14, dpos.statusTopY, colors.CHEADER, model); std::sprintf(textbuffer, "HR:%04X", adparam); printtext(dpos.statusTopFvX+19, dpos.statusTopY, colors.CHEADER, textbuffer); @@ -354,10 +350,8 @@ void printstatus() printtext(dpos.orderlistX+31, dpos.orderlistY, colors.CEDIT|(colors.CHDRBG<<4), textbuffer); std::sprintf(textbuffer, ")"); printtext(dpos.orderlistX+33, dpos.orderlistY, colors.CTITLE|(colors.CHDRBG<<4), textbuffer); - if (numsids == 2) - std::sprintf(textbuffer, " "); - else - std::sprintf(textbuffer, " "); + const char *olhdr = (numsids == 1) ? " " : " "; + std::sprintf(textbuffer, olhdr); printtext(dpos.orderlistX+34, dpos.orderlistY, colors.CTITLE|(colors.CHDRBG<<4), textbuffer); for (int c = 0; c < maxChns; c++) @@ -500,7 +494,7 @@ void printstatus() { for (int d = 0; d < VISIBLETABLEROWS; d++) { - int p = etview[c]+d; + int p = tables.view(c)+d; int color = colors.CNORMAL; switch (c) @@ -517,7 +511,7 @@ void printstatus() if ((ltable[c][p] >= 0x80) || ((!ltable[c][p]) && (rtable[c][p]))) color = colors.CCOMMAND; break; } - if ((p == etpos) && (etnum == c)) color = colors.CEDIT; + if ((p == tables.pos()) && (tables.num() == c)) color = colors.CEDIT; std::sprintf(textbuffer, "%02X:%02X %02X", p+1, ltable[c][p], rtable[c][p]); if (patterndispmode & 2) { @@ -529,16 +523,16 @@ void printstatus() } printtext(dpos.instrumentsX+12*c, dpos.instrumentsY+8+d, color, textbuffer); - if (etmarknum == c) + if (tables.marknum() == c) { - if (etmarkstart <= etmarkend) + if (tables.markstart() <= tables.markend()) { - if ((p >= etmarkstart) && (p <= etmarkend)) + if ((p >= tables.markstart()) && (p <= tables.markend())) printbg(dpos.instrumentsX+3+12*c, dpos.instrumentsY+8+d, colors.CHDRBG, 5); } else { - if ((p <= etmarkstart) && (p >= etmarkend)) + if ((p <= tables.markstart()) && (p >= tables.markend())) printbg(dpos.instrumentsX+3+12*c, dpos.instrumentsY+8+d, colors.CHDRBG, 5); } } @@ -547,7 +541,7 @@ void printstatus() if (editmode == EDIT_TABLES) { - if (!eamode) printbg(dpos.instrumentsX+3+etnum*12+(etcolumn & 1)+(etcolumn/2)*3, dpos.instrumentsY+8+etpos-etview[etnum], cc, 1); + if (!eamode) printbg(dpos.instrumentsX+3+tables.num()*12+tables.column(), dpos.instrumentsY+8+tables.pos()-tables.curview(), cc, 1); } // Info view @@ -599,46 +593,31 @@ void printstatus() break; } - if (recordmode) printtext(dpos.octaveX, dpos.octaveY+1, color, "EDITMODE"); - else printtext(dpos.octaveX, dpos.octaveY+1, color, "JAM MODE"); + const char *edtmode = recordmode ? "EDITMODE" : "JAM MODE"; + printtext(dpos.octaveX, dpos.octaveY+1, color, edtmode); - if (isplaying()) printtext(dpos.octaveX+10, dpos.octaveY, colors.CTITLE, "PLAYING"); - else printtext(dpos.octaveX+10, dpos.octaveY, colors.CTITLE, "STOPPED"); + const char *playmode = isplaying() ? "PLAYING" : "STOPPED"; + printtext(dpos.octaveX+10, dpos.octaveY, colors.CTITLE, playmode); + int idx; if (multiplier) { - if (!ntsc) - std::sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[timeframe/(25*multiplier) & 1], timesec); - else - std::sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[timeframe/(30*multiplier) & 1], timesec); + idx = (ntsc ? 30 : 25) * multiplier; } else { - if (!ntsc) - std::sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[(timeframe/13) & 1], timesec); - else - std::sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[(timeframe/15) & 1], timesec); + idx = ntsc ? 15 : 13; } + std::sprintf(textbuffer, " %02d%c%02d ", timemin, timechar[(timeframe/idx) & 1], timesec); printtext(dpos.octaveX+10, dpos.octaveY+1, colors.CEDIT, textbuffer); - if (numsids == 1) - { - printtext( - dpos.channelsX, - dpos.channelsY, - colors.CTITLE, - " CHN1 CHN2 CHN3 " - ); - } - else if (numsids == 2) - { - printtext( - dpos.channelsX, - dpos.channelsY, - colors.CTITLE, - " CHN1 CHN2 CHN3 CHN4 CHN5 CHN6 " - ); - } + const char *chnls = (numsids == 1) ? " CHN1 CHN2 CHN3 " : " CHN1 CHN2 CHN3 CHN4 CHN5 CHN6 "; + printtext( + dpos.channelsX, + dpos.channelsY, + colors.CTITLE, + chnls + ); for (int c = 0; c < maxChns; c++) { int chnpos = chn[c].songptr; @@ -653,8 +632,8 @@ void printstatus() printtext(dpos.channelsX+7*c, dpos.channelsY+1, chn[c].mute ? colors.CMUTE : colors.CEDIT, textbuffer); } - if (etlock) printtext(dpos.channelsX-2, dpos.channelsY+1, colors.CTITLE, " "); - else printtext(dpos.channelsX-2, dpos.channelsY+1, colors.CTITLE, "U"); + const char *lock = tables.islocked() ? " " : "U"; + printtext(dpos.channelsX-2, dpos.channelsY+1, colors.CTITLE, lock); } diff --git a/src/instr.cpp b/src/instr.cpp index f2be071..1f7f274 100644 --- a/src/instr.cpp +++ b/src/instr.cpp @@ -151,8 +151,8 @@ void instrumentcommands() case KEY_U: if (shiftpressed) { - etlock ^= 1; - validatetableview(); + tables.fliplock(); + tables.validatetableview(); } break; @@ -279,12 +279,12 @@ void previnstr() void showinstrtable() { - if (!etlock) + if (!tables.islocked()) { for (int c = MAX_TABLES-1; c >= 0; c--) { if (instr[einum].ptr[c]) - settableviewfirst(c, instr[einum].ptr[c] - 1); + tables.settableviewfirst(c, instr[einum].ptr[c] - 1); } } } diff --git a/src/loadtrk.cpp b/src/loadtrk.cpp index 1f286c3..1877e8a 100644 --- a/src/loadtrk.cpp +++ b/src/loadtrk.cpp @@ -564,9 +564,9 @@ void mousecommands() (mousex <= dpos.instrumentsX+7+(MAX_TABLES-1)*12)) { if (win_mouseywheel > 0.f) - tableup(); + tables.tableup(shiftpressed); else if (win_mouseywheel < 0.f) - tabledown(); + tables.tabledown(shiftpressed); } } @@ -729,7 +729,7 @@ void mousecommands() (mousex >= dpos.instrumentsX+3+c*12) && (mousex <= dpos.instrumentsX+7+c*12)) { - int newpos = mousey-(dpos.instrumentsY+8)+etview[etnum]; + int newpos = mousey-(dpos.instrumentsY+8)+tables.curview(); if (newpos < 0) newpos = 0; if (newpos >= MAX_TABLELEN) newpos = MAX_TABLELEN-1; @@ -737,23 +737,21 @@ void mousecommands() if ((mouseb & (MOUSEB_RIGHT|MOUSEB_MIDDLE)) && (!prevmouseb)) { - if ((etmarknum != etnum) || (newpos != etmarkend)) + if ((tables.marknum() != tables.num()) || (newpos != tables.markend())) { - etmarknum = c; - etmarkstart = etmarkend = newpos; + tables.setmarknum(c); + tables.setmarkstart(newpos); + tables.setmarkend(newpos); } } if (mouseb & MOUSEB_LEFT) { - etnum = c; - etpos = mousey-(dpos.instrumentsY+8)+etview[etnum]; - etcolumn = mousex-(dpos.instrumentsX+3+c*12); + tables.setnum(c); + tables.setpos(mousey-(dpos.instrumentsY+8)+tables.curview()); + tables.setcolumn(mousex-(dpos.instrumentsX+3+c*12)); } - if (etcolumn >= 2) etcolumn--; - if (etpos < 0) etpos = 0; - if (etpos > MAX_TABLELEN-1) etpos = MAX_TABLELEN-1; - if (mouseb & (MOUSEB_RIGHT|MOUSEB_MIDDLE)) etmarkend = newpos; + if (mouseb & (MOUSEB_RIGHT|MOUSEB_MIDDLE)) tables.setmarkend(newpos); } } diff --git a/src/song.cpp b/src/song.cpp index 08c65c2..24f7828 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -840,7 +840,7 @@ void loadsong() std::strcpy(loadedsongfilename, songfilename); // Reset table views - for (int c = 0; c < MAX_TABLES; c++) settableview(c, 0); + for (int c = 0; c < MAX_TABLES; c++) tables.settableview(c, 0); // Convert pulsemodulation speed of < v2.4 songs if (ident[3] < '4') @@ -1309,7 +1309,7 @@ void clearsong(bool cs, bool cp, bool ci, bool ct, bool cn) masterfader = 0x0f; epmarkchn = -1; - etmarknum = -1; + tables.clear(); esmarkchn = -1; followplay = false; @@ -1383,7 +1383,7 @@ void clearsong(bool cs, bool cp, bool ci, bool ct, bool cn) { std::memset(ltable[c], 0, MAX_TABLELEN); std::memset(rtable[c], 0, MAX_TABLELEN); - settableview(c, 0); + tables.settableview(c, 0); } } countpatternlengths(); diff --git a/src/table.cpp b/src/table.cpp index ad0a373..c77b6f3 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -41,14 +41,7 @@ unsigned char ltablecopybuffer[MAX_TABLELEN]; unsigned char rtablecopybuffer[MAX_TABLELEN]; int tablecopyrows = 0; -int etview[MAX_TABLES]; -int etnum; -int etpos; -int etcolumn; -int etlock = 1; -int etmarknum = -1; -int etmarkstart; -int etmarkend; +Tables tables; void inserttable(int num, int pos, int mode); void deletetable(int num, int pos); @@ -58,66 +51,66 @@ void tablecommands() switch(rawkey) { case KEY_Q: - if ((shiftpressed) && (etnum == STBL)) + if ((shiftpressed) && (tables.m_num == STBL)) { - int speed = (ltable[etnum][etpos] << 8) | rtable[etnum][etpos]; + int speed = (ltable[tables.m_num][tables.m_pos] << 8) | rtable[tables.m_num][tables.m_pos]; speed *= 34716; speed /= 32768; if (speed > 65535) speed = 65535; - ltable[etnum][etpos] = speed >> 8; - rtable[etnum][etpos] = speed & 0xff; + ltable[tables.m_num][tables.m_pos] = speed >> 8; + rtable[tables.m_num][tables.m_pos] = speed & 0xff; } break; case KEY_A: - if ((shiftpressed) && (etnum == STBL)) + if ((shiftpressed) && (tables.m_num == STBL)) { - int speed = (ltable[etnum][etpos] << 8) | rtable[etnum][etpos]; + int speed = (ltable[tables.m_num][tables.m_pos] << 8) | rtable[tables.m_num][tables.m_pos]; speed *= 30929; speed /= 32768; - ltable[etnum][etpos] = speed >> 8; - rtable[etnum][etpos] = speed & 0xff; + ltable[tables.m_num][tables.m_pos] = speed >> 8; + rtable[tables.m_num][tables.m_pos] = speed & 0xff; } break; case KEY_W: - if ((shiftpressed) && (etnum == STBL)) + if ((shiftpressed) && (tables.m_num == STBL)) { - int speed = (ltable[etnum][etpos] << 8) | rtable[etnum][etpos]; + int speed = (ltable[tables.m_num][tables.m_pos] << 8) | rtable[tables.m_num][tables.m_pos]; speed *= 2; if (speed > 65535) speed = 65535; - ltable[etnum][etpos] = speed >> 8; - rtable[etnum][etpos] = speed & 0xff; + ltable[tables.m_num][tables.m_pos] = speed >> 8; + rtable[tables.m_num][tables.m_pos] = speed & 0xff; } - if ((shiftpressed) && ((etnum == PTBL) || (etnum == FTBL)) && (ltable[etnum][etpos] < 0x80)) + if ((shiftpressed) && ((tables.m_num == PTBL) || (tables.m_num == FTBL)) && (ltable[tables.m_num][tables.m_pos] < 0x80)) { - int speed = (signed char)(rtable[etnum][etpos]); + int speed = (signed char)(rtable[tables.m_num][tables.m_pos]); speed *= 2; if (speed > 127) speed = 127; if (speed < -128) speed = -128; - rtable[etnum][etpos] = speed; + rtable[tables.m_num][tables.m_pos] = speed; } break; case KEY_S: - if ((shiftpressed) && (etnum == STBL)) + if ((shiftpressed) && (tables.m_num == STBL)) { - int speed = (ltable[etnum][etpos] << 8) | rtable[etnum][etpos]; + int speed = (ltable[tables.m_num][tables.m_pos] << 8) | rtable[tables.m_num][tables.m_pos]; speed /= 2; - ltable[etnum][etpos] = speed >> 8; - rtable[etnum][etpos] = speed & 0xff; + ltable[tables.m_num][tables.m_pos] = speed >> 8; + rtable[tables.m_num][tables.m_pos] = speed & 0xff; } - if ((shiftpressed) && ((etnum == PTBL) || (etnum == FTBL)) && (ltable[etnum][etpos] < 0x80)) + if ((shiftpressed) && ((tables.m_num == PTBL) || (tables.m_num == FTBL)) && (ltable[tables.m_num][tables.m_pos] < 0x80)) { - int speed = (signed char)(rtable[etnum][etpos]); + int speed = (signed char)(rtable[tables.m_num][tables.m_pos]); speed /= 2; - rtable[etnum][etpos] = speed; + rtable[tables.m_num][tables.m_pos] = speed; } break; @@ -129,93 +122,93 @@ void tablecommands() break; case KEY_RIGHT: - etcolumn++; - if (etcolumn > 3) + tables.m_column++; + if (tables.m_column > 3) { - etpos -= etview[etnum]; - etcolumn = 0; - etnum++; - if (etnum >= MAX_TABLES) etnum = 0; - etpos += etview[etnum]; + tables.m_pos -= tables.m_view[tables.m_num]; + tables.m_column = 0; + tables.m_num++; + if (tables.m_num >= MAX_TABLES) tables.m_num = 0; + tables.m_pos += tables.m_view[tables.m_num]; } - if (shiftpressed) etmarknum = -1; + if (shiftpressed) tables.m_marknum = -1; break; case KEY_LEFT: - etcolumn--; - if (etcolumn < 0) + tables.m_column--; + if (tables.m_column < 0) { - etpos -= etview[etnum]; - etcolumn = 3; - etnum--; - if (etnum < 0) etnum = MAX_TABLES - 1; - etpos += etview[etnum]; + tables.m_pos -= tables.m_view[tables.m_num]; + tables.m_column = 3; + tables.m_num--; + if (tables.m_num < 0) tables.m_num = MAX_TABLES - 1; + tables.m_pos += tables.m_view[tables.m_num]; } - if (shiftpressed) etmarknum = -1; + if (shiftpressed) tables.m_marknum = -1; break; case KEY_HOME: - while (etpos != 0) tableup(); + while (tables.m_pos != 0) tables.tableup(shiftpressed); break; case KEY_END: - while (etpos != MAX_TABLELEN-1) tabledown(); + while (tables.m_pos != MAX_TABLELEN-1) tables.tabledown(shiftpressed); break; case KEY_PGUP: - for (int c = 0; c < PGUPDNREPEAT; c++) tableup(); + for (int c = 0; c < PGUPDNREPEAT; c++) tables.tableup(shiftpressed); break; case KEY_PGDN: - for (int c = 0; c < PGUPDNREPEAT; c++) tabledown(); + for (int c = 0; c < PGUPDNREPEAT; c++) tables.tabledown(shiftpressed); break; case KEY_UP: - tableup(); + tables.tableup(shiftpressed); break; case KEY_DOWN: - tabledown(); + tables.tabledown(shiftpressed); break; case KEY_X: case KEY_C: if (shiftpressed) { - if (etmarknum != -1) + if (tables.m_marknum != -1) { int d = 0; - if (etmarkstart <= etmarkend) + if (tables.m_markstart <= tables.m_markend) { - for (int c = etmarkstart; c <= etmarkend; c++) + for (int c = tables.m_markstart; c <= tables.m_markend; c++) { - ltablecopybuffer[d] = ltable[etmarknum][c]; - rtablecopybuffer[d] = rtable[etmarknum][c]; + ltablecopybuffer[d] = ltable[tables.m_marknum][c]; + rtablecopybuffer[d] = rtable[tables.m_marknum][c]; if (rawkey == KEY_X) { - ltable[etmarknum][c] = 0; - rtable[etmarknum][c] = 0; + ltable[tables.m_marknum][c] = 0; + rtable[tables.m_marknum][c] = 0; } d++; } } else { - for (int c = etmarkend; c <= etmarkstart; c++) + for (int c = tables.m_markend; c <= tables.m_markstart; c++) { - ltablecopybuffer[d] = ltable[etmarknum][c]; - rtablecopybuffer[d] = rtable[etmarknum][c]; + ltablecopybuffer[d] = ltable[tables.m_marknum][c]; + rtablecopybuffer[d] = rtable[tables.m_marknum][c]; if (rawkey == KEY_X) { - ltable[etmarknum][c] = 0; - rtable[etmarknum][c] = 0; + ltable[tables.m_marknum][c] = 0; + rtable[tables.m_marknum][c] = 0; } d++; } } tablecopyrows = d; } - etmarknum = -1; + tables.m_marknum = -1; } break; @@ -226,35 +219,35 @@ void tablecommands() { for (int c = 0; c < tablecopyrows; c++) { - ltable[etnum][etpos] = ltablecopybuffer[c]; - rtable[etnum][etpos] = rtablecopybuffer[c]; - etpos++; - if (etpos >= MAX_TABLELEN) etpos = MAX_TABLELEN-1; + ltable[tables.m_num][tables.m_pos] = ltablecopybuffer[c]; + rtable[tables.m_num][tables.m_pos] = rtablecopybuffer[c]; + tables.m_pos++; + if (tables.m_pos >= MAX_TABLELEN) tables.m_pos = MAX_TABLELEN-1; } } } break; case KEY_O: - if (shiftpressed) optimizetable(etnum); + if (shiftpressed) optimizetable(tables.m_num); break; case KEY_U: if (shiftpressed) { - etlock ^= 1; - validatetableview(); + tables.fliplock(); + tables.validatetableview(); } break; case KEY_R: - if (etnum == WTBL) + if (tables.m_num == WTBL) { - if (ltable[etnum][etpos] != 0xff) + if (ltable[tables.m_num][tables.m_pos] != 0xff) { // Convert absolute pitch to relative pitch or vice versa int basenote = epoctave * 12; - int note = rtable[etnum][etpos]; + int note = rtable[tables.m_num][tables.m_pos]; if (note >= 0x80) { @@ -267,16 +260,16 @@ void tablecommands() note |= 0x80; } - rtable[etnum][etpos] = note; + rtable[tables.m_num][tables.m_pos] = note; } } /* fall through */ case KEY_L: - if (etnum == PTBL) + if (tables.m_num == PTBL) { int currentpulse = -1; - int targetpulse = ltable[etnum][etpos] << 4; - int speed = rtable[etnum][etpos]; + int targetpulse = ltable[tables.m_num][tables.m_pos] << 4; + int speed = rtable[tables.m_num][tables.m_pos]; int time; int steps; @@ -284,12 +277,12 @@ void tablecommands() int c; // Follow the chain of pulse commands backwards to the nearest set command so we know what current pulse is - for (c = etpos-1; c >= 0; c--) + for (c = tables.m_pos-1; c >= 0; c--) { - if (ltable[etnum][c] == 0xff) break; - if (ltable[etnum][c] >= 0x80) + if (ltable[tables.m_num][c] == 0xff) break; + if (ltable[tables.m_num][c] >= 0x80) { - currentpulse = (ltable[etnum][c] << 8) | rtable[etnum][c]; + currentpulse = (ltable[tables.m_num][c] << 8) | rtable[tables.m_num][c]; currentpulse &= 0xfff; break; } @@ -297,12 +290,12 @@ void tablecommands() if (currentpulse == -1) break; // Then follow the chain of modulation steps - for (; c < etpos; c++) + for (; c < tables.m_pos; c++) { - if (ltable[etnum][c] < 0x80) + if (ltable[tables.m_num][c] < 0x80) { - currentpulse += ltable[etnum][c] * (rtable[etnum][c] & 0xff); - if (rtable[etnum][c] >= 0x80) currentpulse -= 256 * ltable[etnum][c]; + currentpulse += ltable[tables.m_num][c] * (rtable[tables.m_num][c] & 0xff); + if (rtable[tables.m_num][c] >= 0x80) currentpulse -= 256 * ltable[tables.m_num][c]; currentpulse &= 0xfff; } } @@ -314,37 +307,37 @@ void tablecommands() steps = time; if (!steps) break; - if (etpos + steps > MAX_TABLELEN) break; + if (tables.m_pos + steps > MAX_TABLELEN) break; if (targetpulse < currentpulse) speed = -speed; // Make room in the table - for (c = steps; c > 1; c--) inserttable(etnum, etpos, 1); + for (c = steps; c > 1; c--) inserttable(tables.m_num, tables.m_pos, 1); while (time) { if (std::abs(speed) < 128) { - if (time < 127) ltable[etnum][etpos] = time; - else ltable[etnum][etpos] = 127; - rtable[etnum][etpos] = speed; - time -= ltable[etnum][etpos]; - etpos++; + if (time < 127) ltable[tables.m_num][tables.m_pos] = time; + else ltable[tables.m_num][tables.m_pos] = 127; + rtable[tables.m_num][tables.m_pos] = speed; + time -= ltable[tables.m_num][tables.m_pos]; + tables.m_pos++; } else { currentpulse += speed; - ltable[etnum][etpos] = 0x80 | ((currentpulse >> 8) & 0xf); - rtable[etnum][etpos] = currentpulse & 0xff; + ltable[tables.m_num][tables.m_pos] = 0x80 | ((currentpulse >> 8) & 0xf); + rtable[tables.m_num][tables.m_pos] = currentpulse & 0xff; time--; - etpos++; + tables.m_pos++; } } } - if (etnum == FTBL) + if (tables.m_num == FTBL) { int currentfilter = -1; - int targetfilter = ltable[etnum][etpos]; - int speed = rtable[etnum][etpos] & 0x7f; + int targetfilter = ltable[tables.m_num][tables.m_pos]; + int speed = rtable[tables.m_num][tables.m_pos] & 0x7f; int time; int steps; @@ -352,23 +345,23 @@ void tablecommands() int c; // Follow the chain of filter commands backwards to the nearest set command so we know what current pulse is - for (c = etpos-1; c >= 0; c--) + for (c = tables.m_pos-1; c >= 0; c--) { - if (ltable[etnum][c] == 0xff) break; - if (ltable[etnum][c] == 0x00) + if (ltable[tables.m_num][c] == 0xff) break; + if (ltable[tables.m_num][c] == 0x00) { - currentfilter = rtable[etnum][c]; + currentfilter = rtable[tables.m_num][c]; break; } } if (currentfilter == -1) break; // Then follow the chain of modulation steps - for (; c < etpos; c++) + for (; c < tables.m_pos; c++) { - if (ltable[etnum][c] < 0x80) + if (ltable[tables.m_num][c] < 0x80) { - currentfilter += ltable[etnum][c] * rtable[etnum][c]; + currentfilter += ltable[tables.m_num][c] * rtable[tables.m_num][c]; currentfilter &= 0xff; } } @@ -376,19 +369,19 @@ void tablecommands() time = std::abs(targetfilter - currentfilter) / speed; steps = (time + 126) / 127; if (!steps) break; - if (etpos + steps > MAX_TABLELEN) break; + if (tables.m_pos + steps > MAX_TABLELEN) break; if (targetfilter < currentfilter) speed = -speed; // Make room in the table - for (c = steps; c > 1; c--) inserttable(etnum, etpos, 1); + for (c = steps; c > 1; c--) inserttable(tables.m_num, tables.m_pos, 1); while (time) { - if (time < 127) ltable[etnum][etpos] = time; - else ltable[etnum][etpos] = 127; - rtable[etnum][etpos] = speed; - time -= ltable[etnum][etpos]; - etpos++; + if (time < 127) ltable[tables.m_num][tables.m_pos] = time; + else ltable[tables.m_num][tables.m_pos] = 127; + rtable[tables.m_num][tables.m_pos] = speed; + time -= ltable[tables.m_num][tables.m_pos]; + tables.m_pos++; } } break; @@ -396,41 +389,41 @@ void tablecommands() case KEY_N: if (shiftpressed) { - switch (etnum) + switch (tables.m_num) { // Negate pulse or filter speed case FTBL: - if (!ltable[etnum][etpos]) break; + if (!ltable[tables.m_num][tables.m_pos]) break; /* fall through */ case PTBL: - if (ltable[etnum][etpos] < 0x80) - rtable[etnum][etpos] = (rtable[etnum][etpos] ^ 0xff) + 1; + if (ltable[tables.m_num][tables.m_pos] < 0x80) + rtable[tables.m_num][tables.m_pos] = (rtable[tables.m_num][tables.m_pos] ^ 0xff) + 1; break; // Negate relative note case WTBL: - if ((ltable[etnum][etpos] != 0xff) && (rtable[etnum][etpos] < 0x80)) - rtable[etnum][etpos] = (0x80 - rtable[etnum][etpos]) & 0x7f; + if ((ltable[tables.m_num][tables.m_pos] != 0xff) && (rtable[tables.m_num][tables.m_pos] < 0x80)) + rtable[tables.m_num][tables.m_pos] = (0x80 - rtable[tables.m_num][tables.m_pos]) & 0x7f; break; } } break; case KEY_DEL: - deletetable(etnum, etpos); + deletetable(tables.m_num, tables.m_pos); break; case KEY_INS: - inserttable(etnum, etpos, shiftpressed); + inserttable(tables.m_num, tables.m_pos, shiftpressed); break; case KEY_ENTER: - if (etnum == WTBL) + if (tables.m_num == WTBL) { int table = -1; int mstmode = MST_PORTAMENTO; - switch (ltable[etnum][etpos]) + switch (ltable[tables.m_num][tables.m_pos]) { case WAVECMD + CMD_PORTAUP: case WAVECMD + CMD_PORTADOWN: @@ -460,26 +453,26 @@ void tablecommands() { default: editmode = EDIT_INSTRUMENT; - eipos = etnum + 2; + eipos = tables.m_num + 2; return; case STBL: - if (rtable[etnum][etpos]) + if (rtable[tables.m_num][tables.m_pos]) { if (!shiftpressed) { - gototable(STBL, rtable[etnum][etpos] - 1); + gototable(STBL, rtable[tables.m_num][tables.m_pos] - 1); return; } else { - int oldeditpos = etpos; - int oldeditcolumn = etcolumn; - int pos = makespeedtable(rtable[etnum][etpos], mstmode, true); + int oldeditpos = tables.m_pos; + int oldeditcolumn = tables.m_column; + int pos = makespeedtable(rtable[tables.m_num][tables.m_pos], mstmode, true); gototable(WTBL, oldeditpos); - etcolumn = oldeditcolumn; + tables.m_column = oldeditcolumn; - rtable[etnum][etpos] = pos + 1; + rtable[tables.m_num][tables.m_pos] = pos + 1; return; } } @@ -488,7 +481,7 @@ void tablecommands() int pos = findfreespeedtable(); if (pos >= 0) { - rtable[etnum][etpos] = pos + 1; + rtable[tables.m_num][tables.m_pos] = pos + 1; gototable(STBL, pos); return; } @@ -497,9 +490,9 @@ void tablecommands() case PTBL: case FTBL: - if (rtable[etnum][etpos]) + if (rtable[tables.m_num][tables.m_pos]) { - gototable(table, rtable[etnum][etpos] - 1); + gototable(table, rtable[tables.m_num][tables.m_pos] - 1); return; } else @@ -508,7 +501,7 @@ void tablecommands() { int pos = gettablelen(table); if (pos >= MAX_TABLELEN-1) pos = MAX_TABLELEN - 1; - rtable[etnum][etpos] = pos + 1; + rtable[tables.m_num][tables.m_pos] = pos + 1; gototable(table, pos); return; } @@ -518,7 +511,7 @@ void tablecommands() else { editmode = EDIT_INSTRUMENT; - eipos = etnum + 2; + eipos = tables.m_num + 2; return; } break; @@ -526,51 +519,51 @@ void tablecommands() case KEY_APOST2: if (shiftpressed) { - etpos -= etview[etnum]; - etnum--; - if (etnum < 0) etnum = MAX_TABLES-1; - etpos += etview[etnum]; + tables.m_pos -= tables.m_view[tables.m_num]; + tables.m_num--; + if (tables.m_num < 0) tables.m_num = MAX_TABLES-1; + tables.m_pos += tables.m_view[tables.m_num]; } else { - etpos -= etview[etnum]; - etnum++; - if (etnum >= MAX_TABLES) etnum = 0; - etpos += etview[etnum]; + tables.m_pos -= tables.m_view[tables.m_num]; + tables.m_num++; + if (tables.m_num >= MAX_TABLES) tables.m_num = 0; + tables.m_pos += tables.m_view[tables.m_num]; } } if (hexnybble >= 0) { - switch(etcolumn) + switch(tables.m_column) { case 0: - ltable[etnum][etpos] &= 0x0f; - ltable[etnum][etpos] |= hexnybble << 4; + ltable[tables.m_num][tables.m_pos] &= 0x0f; + ltable[tables.m_num][tables.m_pos] |= hexnybble << 4; break; case 1: - ltable[etnum][etpos] &= 0xf0; - ltable[etnum][etpos] |= hexnybble; + ltable[tables.m_num][tables.m_pos] &= 0xf0; + ltable[tables.m_num][tables.m_pos] |= hexnybble; break; case 2: - rtable[etnum][etpos] &= 0x0f; - rtable[etnum][etpos] |= hexnybble << 4; + rtable[tables.m_num][tables.m_pos] &= 0x0f; + rtable[tables.m_num][tables.m_pos] |= hexnybble << 4; break; case 3: - rtable[etnum][etpos] &= 0xf0; - rtable[etnum][etpos] |= hexnybble; + rtable[tables.m_num][tables.m_pos] &= 0xf0; + rtable[tables.m_num][tables.m_pos] |= hexnybble; break; } - etcolumn++; - if (etcolumn > 3) + tables.m_column++; + if (tables.m_column > 3) { - etcolumn = 0; - etpos++; - if (etpos >= MAX_TABLELEN) etpos = MAX_TABLELEN-1; + tables.m_column = 0; + tables.m_pos++; + if (tables.m_pos >= MAX_TABLELEN) tables.m_pos = MAX_TABLELEN-1; } } - validatetableview(); + tables.validatetableview(); } void deletetable(int num, int pos) @@ -930,7 +923,7 @@ int makespeedtable(unsigned data, int mode, bool makenew) ltable[STBL][c] = l; rtable[STBL][c] = r; - settableview(STBL, c); + tables.settableview(STBL, c); return c; } } @@ -963,75 +956,6 @@ void deleteinstrtable(int i) } } -void gototable(int num, int pos) -{ - editmode = EDIT_TABLES; - settableview(num, pos); -} - -void settableview(int num, int pos) -{ - etnum = num; - etcolumn = 0; - etpos = pos; - - validatetableview(); -} - -void settableviewfirst(int num, int pos) -{ - etview[num] = pos; - settableview(num, pos); -} - -void validatetableview(void) -{ - if (etpos - etview[etnum] < 0) - etview[etnum] = etpos; - if (etpos - etview[etnum] >= VISIBLETABLEROWS) - etview[etnum] = etpos - VISIBLETABLEROWS + 1; - - // Table view lock? - if (etlock) - { - for (int c = 0; c < MAX_TABLES; c++) etview[c] = etview[etnum]; - } -} - -void tableup() -{ - if (shiftpressed) - { - if ((etmarknum != etnum) || (etpos != etmarkend)) - { - etmarknum = etnum; - etmarkstart = etmarkend = etpos; - } - } - etpos--; - if (etpos < 0) etpos = 0; - if (shiftpressed) etmarkend = etpos; - - validatetableview(); -} - -void tabledown() -{ - if (shiftpressed) - { - if ((etmarknum != etnum) || (etpos != etmarkend)) - { - etmarknum = etnum; - etmarkstart = etmarkend = etpos; - } - } - etpos++; - if (etpos >= MAX_TABLELEN) etpos = MAX_TABLELEN-1; - if (shiftpressed) etmarkend = etpos; - - validatetableview(); -} - void exectable(int num, int ptr) { // Jump error check @@ -1083,3 +1007,116 @@ int findfreespeedtable() return -1; } +void gototable(int num, int pos) +{ + editmode = EDIT_TABLES; + tables.settableview(num, pos); +} + +void Tables::settableview(int num, int pos) +{ + m_num = num; + m_column = 0; + m_pos = pos; + + validatetableview(); +} + +void Tables::settableviewfirst(int num, int pos) +{ + m_view[num] = pos; + settableview(num, pos); +} + +void Tables::validatetableview() +{ + if (m_pos - m_view[m_num] < 0) + m_view[m_num] = m_pos; + if (m_pos - m_view[m_num] >= VISIBLETABLEROWS) + m_view[m_num] = m_pos - VISIBLETABLEROWS + 1; + + // Table view lock? + if (m_lock) + { + for (int c = 0; c < MAX_TABLES; c++) m_view[c] = m_view[m_num]; + } +} + +void Tables::tableup(bool shiftpressed) +{ + if (shiftpressed) + { + if ((m_marknum != m_num) || (m_pos != m_markend)) + { + m_marknum = m_num; + m_markstart = m_pos; + m_markend = m_pos; + } + } + m_pos--; + if (m_pos < 0) m_pos = 0; + if (shiftpressed) m_markend = m_pos; + + validatetableview(); +} + +void Tables::tabledown(bool shiftpressed) +{ + if (shiftpressed) + { + if ((m_marknum != m_num) || (m_pos != m_markend)) + { + m_marknum = m_num; + m_markstart = m_pos; + m_markend = m_pos; + } + } + m_pos++; + if (m_pos >= MAX_TABLELEN) m_pos = MAX_TABLELEN-1; + if (shiftpressed) m_markend = m_pos; + + validatetableview(); +} + +void Tables::setnum(int num) +{ + m_num = num; +} + +void Tables::setpos(int pos) +{ + m_pos = pos; + if (m_pos < 0) m_pos = 0; + if (m_pos > MAX_TABLELEN-1) m_pos = MAX_TABLELEN-1; +} + +void Tables::setcolumn(int column) +{ + m_column = column; + if (m_column >= 2) m_column--; +} + +void Tables::setmarknum(int marknum) +{ + m_marknum = marknum; +} + +void Tables::setmarkstart(int markstart) +{ + m_markstart = markstart; +} + +void Tables::setmarkend(int markend) +{ + m_markend = markend; +} + +void Tables::fliplock() +{ + m_lock = !m_lock; +} + +void Tables::clear() +{ + m_marknum = -1; +} diff --git a/src/table.h b/src/table.h index c914ab5..3a749f5 100644 --- a/src/table.h +++ b/src/table.h @@ -30,17 +30,6 @@ enum MST_RAW = 4 }; -#ifndef TABLE_C -extern int etview[MAX_TABLES]; -extern int etnum; -extern int etpos; -extern int etcolumn; -extern int etlock; -extern int etmarknum; -extern int etmarkstart; -extern int etmarkend; -#endif - void tablecommands(); int makespeedtable(unsigned data, int mode, bool makenew); void optimizetable(int num); @@ -48,12 +37,47 @@ void deleteinstrtable(int i); int gettablelen(int num); int gettablepartlen(int num, int pos); void gototable(int num, int pos); -void tableup(); -void tabledown(); -void settableview(int num, int pos); -void settableviewfirst(int num, int pos); -void validatetableview(); void exectable(int num, int ptr); int findfreespeedtable(); +class Tables +{ +public: + int m_view[MAX_TABLES]; + int m_num; + int m_pos; + int m_column; + int m_marknum = -1; + int m_markstart; + int m_markend; + bool m_lock = true; + +public: + inline int view(int num) const { return m_view[num]; } + inline int curview() const { return m_view[m_num]; } + inline int num() const { return m_num; } + inline int pos() const { return m_pos; } + inline int column() const { return (m_column & 1)+(m_column/2)*3; } + inline int marknum() const { return m_marknum; } + inline int markstart() const { return m_markstart; } + inline int markend() const { return m_markend; } + inline bool islocked() const { return m_lock; } + void setnum(int num); + void setpos(int pos); + void setcolumn(int column); + void setmarknum(int marknum); + void setmarkstart(int markstart); + void setmarkend(int markend); + void fliplock(); + void clear(); + + void validatetableview(); + void tableup(bool shiftpressed); + void tabledown(bool shiftpressed); + void settableview(int num, int pos); + void settableviewfirst(int num, int pos); +}; + +extern Tables tables; + #endif From 037ddae93129a1c3056f293a1690e6f5a572ff09 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 14 Jul 2026 18:23:14 +0200 Subject: [PATCH 2/4] More cleanup --- src/display.cpp | 3 +- src/instr.cpp | 11 ++ src/instr.h | 2 +- src/loadtrk.cpp | 7 +- src/order.cpp | 58 +++++------ src/song.cpp | 8 +- src/table.cpp | 261 ++++++++++++++++++++++++------------------------ src/table.h | 8 +- 8 files changed, 180 insertions(+), 178 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index c4f01f7..1435393 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -627,8 +627,7 @@ void printstatus() if (chnrow > getPattlen(chn[c].pattnum)) chnrow = getPattlen(chn[c].pattnum); if (chnrow >= 100) chnrow -= 100; - std::sprintf(textbuffer, "%03X/%02X", - chnpos,chnrow); + std::sprintf(textbuffer, "%03X/%02X", chnpos, chnrow); printtext(dpos.channelsX+7*c, dpos.channelsY+1, chn[c].mute ? colors.CMUTE : colors.CEDIT, textbuffer); } diff --git a/src/instr.cpp b/src/instr.cpp index 1f7f274..ac790b8 100644 --- a/src/instr.cpp +++ b/src/instr.cpp @@ -251,6 +251,17 @@ void clearinstr(int num) } } +void clearinstr() +{ + for (int c = 0; c < MAX_INSTR; c++) + clearinstr(c); + std::memset(&instrcopybuffer, 0, sizeof(INSTR)); + eipos = 0; + eicolumn = 0; + eirow = 1; + einum = 1; +} + void gotoinstr(int i) { if ((i < 0) || (i >= MAX_INSTR)) return; diff --git a/src/instr.h b/src/instr.h index 668039f..5f4e0c4 100644 --- a/src/instr.h +++ b/src/instr.h @@ -28,12 +28,12 @@ extern int einum; extern int eirow; extern int eipos; extern int eicolumn; -extern INSTR instrcopybuffer; #endif void instrumentcommands(); void nextinstr(); void previnstr(); +void clearinstr(); void clearinstr(int num); void gotoinstr(int i); void showinstrtable(); diff --git a/src/loadtrk.cpp b/src/loadtrk.cpp index 1877e8a..5e824df 100644 --- a/src/loadtrk.cpp +++ b/src/loadtrk.cpp @@ -737,12 +737,7 @@ void mousecommands() if ((mouseb & (MOUSEB_RIGHT|MOUSEB_MIDDLE)) && (!prevmouseb)) { - if ((tables.marknum() != tables.num()) || (newpos != tables.markend())) - { - tables.setmarknum(c); - tables.setmarkstart(newpos); - tables.setmarkend(newpos); - } + tables.setmarkstart(c, newpos); } if (mouseb & MOUSEB_LEFT) { diff --git a/src/order.cpp b/src/order.cpp index 1b5f7ff..fa120f1 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -469,38 +469,37 @@ void namecommands() void insertorder(unsigned char byte) { - if ((songlen[esnum][eschn] - eseditpos)-1 >= 0) + int sl = songlen[esnum][eschn]; + if ((sl - eseditpos)-1 >= 0) { - if (songlen[esnum][eschn] < MAX_SONGLEN) + if (sl < MAX_SONGLEN) { - int len = songlen[esnum][eschn]+1; - songorder[esnum][eschn][len+1] = - songorder[esnum][eschn][len]; + int len = sl+1; + songorder[esnum][eschn][len+1] = songorder[esnum][eschn][len]; songorder[esnum][eschn][len] = LOOPSONG; if (len) songorder[esnum][eschn][len-1] = byte; countthispattern(); } std::memmove(&songorder[esnum][eschn][eseditpos+1], &songorder[esnum][eschn][eseditpos], - (songlen[esnum][eschn] - eseditpos)-1); + (sl - eseditpos)-1); songorder[esnum][eschn][eseditpos] = byte; - int len = songlen[esnum][eschn]+1; + int len = sl+1; if ((songorder[esnum][eschn][len] > eseditpos) && - (songorder[esnum][eschn][len] < (len-2))) + (songorder[esnum][eschn][len] < (len-2))) songorder[esnum][eschn][len]++; } else { - if (eseditpos > songlen[esnum][eschn]) + if (eseditpos > sl) { - if (songlen[esnum][eschn] < MAX_SONGLEN) + if (sl < MAX_SONGLEN) { - songorder[esnum][eschn][eseditpos+1] = - songorder[esnum][eschn][eseditpos]; + songorder[esnum][eschn][eseditpos+1] = songorder[esnum][eschn][eseditpos]; songorder[esnum][eschn][eseditpos] = LOOPSONG; if (eseditpos) songorder[esnum][eschn][eseditpos-1] = byte; countthispattern(); - eseditpos = songlen[esnum][eschn]+1; + eseditpos = sl+1; } } } @@ -508,38 +507,35 @@ void insertorder(unsigned char byte) void deleteorder() { - if ((songlen[esnum][eschn] - eseditpos)-1 >= 0) + int sl = songlen[esnum][eschn]; + if ((sl - eseditpos)-1 >= 0) { std::memmove(&songorder[esnum][eschn][eseditpos], &songorder[esnum][eschn][eseditpos+1], - (songlen[esnum][eschn] - eseditpos)-1); - songorder[esnum][eschn][songlen[esnum][eschn]-1] = 0x00; - if (songlen[esnum][eschn] > 0) + (sl - eseditpos)-1); + songorder[esnum][eschn][sl-1] = 0x00; + if (sl > 0) { - songorder[esnum][eschn][songlen[esnum][eschn]-1] = - songorder[esnum][eschn][songlen[esnum][eschn]]; - songorder[esnum][eschn][songlen[esnum][eschn]] = - songorder[esnum][eschn][songlen[esnum][eschn]+1]; + songorder[esnum][eschn][sl-1] = songorder[esnum][eschn][sl]; + songorder[esnum][eschn][sl] = songorder[esnum][eschn][sl+1]; countthispattern(); } - if (eseditpos == songlen[esnum][eschn]) eseditpos++; - int len = songlen[esnum][eschn]+1; + if (eseditpos == sl) eseditpos++; + int len = sl+1; if ((songorder[esnum][eschn][len] > eseditpos) && - (songorder[esnum][eschn][len] > 0)) + (songorder[esnum][eschn][len] > 0)) songorder[esnum][eschn][len]--; } else { - if (eseditpos > songlen[esnum][eschn]) + if (eseditpos > sl) { - if (songlen[esnum][eschn] > 0) + if (sl > 0) { - songorder[esnum][eschn][songlen[esnum][eschn]-1] = - songorder[esnum][eschn][songlen[esnum][eschn]]; - songorder[esnum][eschn][songlen[esnum][eschn]] = - songorder[esnum][eschn][songlen[esnum][eschn]+1]; + songorder[esnum][eschn][sl-1] = songorder[esnum][eschn][sl]; + songorder[esnum][eschn][sl] = songorder[esnum][eschn][sl+1]; countthispattern(); - eseditpos = songlen[esnum][eschn]+1; + eseditpos = sl+1; } } } diff --git a/src/song.cpp b/src/song.cpp index 24f7828..144f7b1 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -1369,13 +1369,7 @@ void clearsong(bool cs, bool cp, bool ci, bool ct, bool cn) } if (ci) { - for (int c = 0; c < MAX_INSTR; c++) - clearinstr(c); - std::memset(&instrcopybuffer, 0, sizeof(INSTR)); - eipos = 0; - eicolumn = 0; - eirow = 1; - einum = 1; + clearinstr(); } if (ct == 1) { diff --git a/src/table.cpp b/src/table.cpp index c77b6f3..d8f776a 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -51,66 +51,66 @@ void tablecommands() switch(rawkey) { case KEY_Q: - if ((shiftpressed) && (tables.m_num == STBL)) + if ((shiftpressed) && (tables.num() == STBL)) { - int speed = (ltable[tables.m_num][tables.m_pos] << 8) | rtable[tables.m_num][tables.m_pos]; + int speed = (ltable[tables.num()][tables.pos()] << 8) | rtable[tables.num()][tables.pos()]; speed *= 34716; speed /= 32768; if (speed > 65535) speed = 65535; - ltable[tables.m_num][tables.m_pos] = speed >> 8; - rtable[tables.m_num][tables.m_pos] = speed & 0xff; + ltable[tables.num()][tables.pos()] = speed >> 8; + rtable[tables.num()][tables.pos()] = speed & 0xff; } break; case KEY_A: - if ((shiftpressed) && (tables.m_num == STBL)) + if ((shiftpressed) && (tables.num() == STBL)) { - int speed = (ltable[tables.m_num][tables.m_pos] << 8) | rtable[tables.m_num][tables.m_pos]; + int speed = (ltable[tables.num()][tables.pos()] << 8) | rtable[tables.num()][tables.pos()]; speed *= 30929; speed /= 32768; - ltable[tables.m_num][tables.m_pos] = speed >> 8; - rtable[tables.m_num][tables.m_pos] = speed & 0xff; + ltable[tables.num()][tables.pos()] = speed >> 8; + rtable[tables.num()][tables.pos()] = speed & 0xff; } break; case KEY_W: - if ((shiftpressed) && (tables.m_num == STBL)) + if ((shiftpressed) && (tables.num() == STBL)) { - int speed = (ltable[tables.m_num][tables.m_pos] << 8) | rtable[tables.m_num][tables.m_pos]; + int speed = (ltable[tables.num()][tables.pos()] << 8) | rtable[tables.num()][tables.pos()]; speed *= 2; if (speed > 65535) speed = 65535; - ltable[tables.m_num][tables.m_pos] = speed >> 8; - rtable[tables.m_num][tables.m_pos] = speed & 0xff; + ltable[tables.num()][tables.pos()] = speed >> 8; + rtable[tables.num()][tables.pos()] = speed & 0xff; } - if ((shiftpressed) && ((tables.m_num == PTBL) || (tables.m_num == FTBL)) && (ltable[tables.m_num][tables.m_pos] < 0x80)) + if ((shiftpressed) && ((tables.num() == PTBL) || (tables.num() == FTBL)) && (ltable[tables.num()][tables.pos()] < 0x80)) { - int speed = (signed char)(rtable[tables.m_num][tables.m_pos]); + int speed = (signed char)(rtable[tables.num()][tables.pos()]); speed *= 2; if (speed > 127) speed = 127; if (speed < -128) speed = -128; - rtable[tables.m_num][tables.m_pos] = speed; + rtable[tables.num()][tables.pos()] = speed; } break; case KEY_S: - if ((shiftpressed) && (tables.m_num == STBL)) + if ((shiftpressed) && (tables.num() == STBL)) { - int speed = (ltable[tables.m_num][tables.m_pos] << 8) | rtable[tables.m_num][tables.m_pos]; + int speed = (ltable[tables.num()][tables.pos()] << 8) | rtable[tables.num()][tables.pos()]; speed /= 2; - ltable[tables.m_num][tables.m_pos] = speed >> 8; - rtable[tables.m_num][tables.m_pos] = speed & 0xff; + ltable[tables.num()][tables.pos()] = speed >> 8; + rtable[tables.num()][tables.pos()] = speed & 0xff; } - if ((shiftpressed) && ((tables.m_num == PTBL) || (tables.m_num == FTBL)) && (ltable[tables.m_num][tables.m_pos] < 0x80)) + if ((shiftpressed) && ((tables.num() == PTBL) || (tables.num() == FTBL)) && (ltable[tables.num()][tables.pos()] < 0x80)) { - int speed = (signed char)(rtable[tables.m_num][tables.m_pos]); + int speed = (signed char)(rtable[tables.num()][tables.pos()]); speed /= 2; - rtable[tables.m_num][tables.m_pos] = speed; + rtable[tables.num()][tables.pos()] = speed; } break; @@ -125,34 +125,34 @@ void tablecommands() tables.m_column++; if (tables.m_column > 3) { - tables.m_pos -= tables.m_view[tables.m_num]; + tables.m_pos -= tables.curview(); tables.m_column = 0; tables.m_num++; - if (tables.m_num >= MAX_TABLES) tables.m_num = 0; - tables.m_pos += tables.m_view[tables.m_num]; + if (tables.num() >= MAX_TABLES) tables.m_num = 0; + tables.m_pos += tables.curview(); } - if (shiftpressed) tables.m_marknum = -1; + if (shiftpressed) tables.resetmarknum(); break; case KEY_LEFT: tables.m_column--; if (tables.m_column < 0) { - tables.m_pos -= tables.m_view[tables.m_num]; + tables.m_pos -= tables.curview(); tables.m_column = 3; tables.m_num--; - if (tables.m_num < 0) tables.m_num = MAX_TABLES - 1; - tables.m_pos += tables.m_view[tables.m_num]; + if (tables.num() < 0) tables.m_num = MAX_TABLES - 1; + tables.m_pos += tables.curview(); } - if (shiftpressed) tables.m_marknum = -1; + if (shiftpressed) tables.resetmarknum(); break; case KEY_HOME: - while (tables.m_pos != 0) tables.tableup(shiftpressed); + while (tables.pos() != 0) tables.tableup(shiftpressed); break; case KEY_END: - while (tables.m_pos != MAX_TABLELEN-1) tables.tabledown(shiftpressed); + while (tables.pos() != MAX_TABLELEN-1) tables.tabledown(shiftpressed); break; case KEY_PGUP: @@ -175,40 +175,40 @@ void tablecommands() case KEY_C: if (shiftpressed) { - if (tables.m_marknum != -1) + if (tables.marknum() != -1) { int d = 0; - if (tables.m_markstart <= tables.m_markend) + if (tables.markstart() <= tables.markend()) { - for (int c = tables.m_markstart; c <= tables.m_markend; c++) + for (int c = tables.markstart(); c <= tables.markend(); c++) { - ltablecopybuffer[d] = ltable[tables.m_marknum][c]; - rtablecopybuffer[d] = rtable[tables.m_marknum][c]; + ltablecopybuffer[d] = ltable[tables.marknum()][c]; + rtablecopybuffer[d] = rtable[tables.marknum()][c]; if (rawkey == KEY_X) { - ltable[tables.m_marknum][c] = 0; - rtable[tables.m_marknum][c] = 0; + ltable[tables.marknum()][c] = 0; + rtable[tables.marknum()][c] = 0; } d++; } } else { - for (int c = tables.m_markend; c <= tables.m_markstart; c++) + for (int c = tables.markend(); c <= tables.markstart(); c++) { - ltablecopybuffer[d] = ltable[tables.m_marknum][c]; - rtablecopybuffer[d] = rtable[tables.m_marknum][c]; + ltablecopybuffer[d] = ltable[tables.marknum()][c]; + rtablecopybuffer[d] = rtable[tables.marknum()][c]; if (rawkey == KEY_X) { - ltable[tables.m_marknum][c] = 0; - rtable[tables.m_marknum][c] = 0; + ltable[tables.marknum()][c] = 0; + rtable[tables.marknum()][c] = 0; } d++; } } tablecopyrows = d; } - tables.m_marknum = -1; + tables.resetmarknum(); } break; @@ -219,17 +219,17 @@ void tablecommands() { for (int c = 0; c < tablecopyrows; c++) { - ltable[tables.m_num][tables.m_pos] = ltablecopybuffer[c]; - rtable[tables.m_num][tables.m_pos] = rtablecopybuffer[c]; + ltable[tables.num()][tables.pos()] = ltablecopybuffer[c]; + rtable[tables.num()][tables.pos()] = rtablecopybuffer[c]; tables.m_pos++; - if (tables.m_pos >= MAX_TABLELEN) tables.m_pos = MAX_TABLELEN-1; + if (tables.pos() >= MAX_TABLELEN) tables.m_pos = MAX_TABLELEN-1; } } } break; case KEY_O: - if (shiftpressed) optimizetable(tables.m_num); + if (shiftpressed) optimizetable(tables.num()); break; case KEY_U: @@ -241,13 +241,13 @@ void tablecommands() break; case KEY_R: - if (tables.m_num == WTBL) + if (tables.num() == WTBL) { - if (ltable[tables.m_num][tables.m_pos] != 0xff) + if (ltable[tables.num()][tables.pos()] != 0xff) { // Convert absolute pitch to relative pitch or vice versa int basenote = epoctave * 12; - int note = rtable[tables.m_num][tables.m_pos]; + int note = rtable[tables.num()][tables.pos()]; if (note >= 0x80) { @@ -260,16 +260,16 @@ void tablecommands() note |= 0x80; } - rtable[tables.m_num][tables.m_pos] = note; + rtable[tables.num()][tables.pos()] = note; } } /* fall through */ case KEY_L: - if (tables.m_num == PTBL) + if (tables.num() == PTBL) { int currentpulse = -1; - int targetpulse = ltable[tables.m_num][tables.m_pos] << 4; - int speed = rtable[tables.m_num][tables.m_pos]; + int targetpulse = ltable[tables.num()][tables.pos()] << 4; + int speed = rtable[tables.num()][tables.pos()]; int time; int steps; @@ -277,12 +277,12 @@ void tablecommands() int c; // Follow the chain of pulse commands backwards to the nearest set command so we know what current pulse is - for (c = tables.m_pos-1; c >= 0; c--) + for (c = tables.pos()-1; c >= 0; c--) { - if (ltable[tables.m_num][c] == 0xff) break; - if (ltable[tables.m_num][c] >= 0x80) + if (ltable[tables.num()][c] == 0xff) break; + if (ltable[tables.num()][c] >= 0x80) { - currentpulse = (ltable[tables.m_num][c] << 8) | rtable[tables.m_num][c]; + currentpulse = (ltable[tables.num()][c] << 8) | rtable[tables.num()][c]; currentpulse &= 0xfff; break; } @@ -290,12 +290,12 @@ void tablecommands() if (currentpulse == -1) break; // Then follow the chain of modulation steps - for (; c < tables.m_pos; c++) + for (; c < tables.pos(); c++) { - if (ltable[tables.m_num][c] < 0x80) + if (ltable[tables.num()][c] < 0x80) { - currentpulse += ltable[tables.m_num][c] * (rtable[tables.m_num][c] & 0xff); - if (rtable[tables.m_num][c] >= 0x80) currentpulse -= 256 * ltable[tables.m_num][c]; + currentpulse += ltable[tables.num()][c] * (rtable[tables.num()][c] & 0xff); + if (rtable[tables.num()][c] >= 0x80) currentpulse -= 256 * ltable[tables.num()][c]; currentpulse &= 0xfff; } } @@ -307,37 +307,37 @@ void tablecommands() steps = time; if (!steps) break; - if (tables.m_pos + steps > MAX_TABLELEN) break; + if (tables.pos() + steps > MAX_TABLELEN) break; if (targetpulse < currentpulse) speed = -speed; // Make room in the table - for (c = steps; c > 1; c--) inserttable(tables.m_num, tables.m_pos, 1); + for (c = steps; c > 1; c--) inserttable(tables.num(), tables.pos(), 1); while (time) { if (std::abs(speed) < 128) { - if (time < 127) ltable[tables.m_num][tables.m_pos] = time; - else ltable[tables.m_num][tables.m_pos] = 127; - rtable[tables.m_num][tables.m_pos] = speed; - time -= ltable[tables.m_num][tables.m_pos]; + if (time < 127) ltable[tables.num()][tables.pos()] = time; + else ltable[tables.num()][tables.pos()] = 127; + rtable[tables.num()][tables.pos()] = speed; + time -= ltable[tables.num()][tables.pos()]; tables.m_pos++; } else { currentpulse += speed; - ltable[tables.m_num][tables.m_pos] = 0x80 | ((currentpulse >> 8) & 0xf); - rtable[tables.m_num][tables.m_pos] = currentpulse & 0xff; + ltable[tables.num()][tables.pos()] = 0x80 | ((currentpulse >> 8) & 0xf); + rtable[tables.num()][tables.pos()] = currentpulse & 0xff; time--; tables.m_pos++; } } } - if (tables.m_num == FTBL) + if (tables.num() == FTBL) { int currentfilter = -1; - int targetfilter = ltable[tables.m_num][tables.m_pos]; - int speed = rtable[tables.m_num][tables.m_pos] & 0x7f; + int targetfilter = ltable[tables.num()][tables.pos()]; + int speed = rtable[tables.num()][tables.pos()] & 0x7f; int time; int steps; @@ -345,23 +345,23 @@ void tablecommands() int c; // Follow the chain of filter commands backwards to the nearest set command so we know what current pulse is - for (c = tables.m_pos-1; c >= 0; c--) + for (c = tables.pos()-1; c >= 0; c--) { - if (ltable[tables.m_num][c] == 0xff) break; - if (ltable[tables.m_num][c] == 0x00) + if (ltable[tables.num()][c] == 0xff) break; + if (ltable[tables.num()][c] == 0x00) { - currentfilter = rtable[tables.m_num][c]; + currentfilter = rtable[tables.num()][c]; break; } } if (currentfilter == -1) break; // Then follow the chain of modulation steps - for (; c < tables.m_pos; c++) + for (; c < tables.pos(); c++) { - if (ltable[tables.m_num][c] < 0x80) + if (ltable[tables.num()][c] < 0x80) { - currentfilter += ltable[tables.m_num][c] * rtable[tables.m_num][c]; + currentfilter += ltable[tables.num()][c] * rtable[tables.num()][c]; currentfilter &= 0xff; } } @@ -369,18 +369,18 @@ void tablecommands() time = std::abs(targetfilter - currentfilter) / speed; steps = (time + 126) / 127; if (!steps) break; - if (tables.m_pos + steps > MAX_TABLELEN) break; + if (tables.pos() + steps > MAX_TABLELEN) break; if (targetfilter < currentfilter) speed = -speed; // Make room in the table - for (c = steps; c > 1; c--) inserttable(tables.m_num, tables.m_pos, 1); + for (c = steps; c > 1; c--) inserttable(tables.num(), tables.pos(), 1); while (time) { - if (time < 127) ltable[tables.m_num][tables.m_pos] = time; - else ltable[tables.m_num][tables.m_pos] = 127; - rtable[tables.m_num][tables.m_pos] = speed; - time -= ltable[tables.m_num][tables.m_pos]; + if (time < 127) ltable[tables.num()][tables.pos()] = time; + else ltable[tables.num()][tables.pos()] = 127; + rtable[tables.num()][tables.pos()] = speed; + time -= ltable[tables.num()][tables.pos()]; tables.m_pos++; } } @@ -389,41 +389,41 @@ void tablecommands() case KEY_N: if (shiftpressed) { - switch (tables.m_num) + switch (tables.num()) { // Negate pulse or filter speed case FTBL: - if (!ltable[tables.m_num][tables.m_pos]) break; + if (!ltable[tables.num()][tables.pos()]) break; /* fall through */ case PTBL: - if (ltable[tables.m_num][tables.m_pos] < 0x80) - rtable[tables.m_num][tables.m_pos] = (rtable[tables.m_num][tables.m_pos] ^ 0xff) + 1; + if (ltable[tables.num()][tables.pos()] < 0x80) + rtable[tables.num()][tables.pos()] = (rtable[tables.num()][tables.pos()] ^ 0xff) + 1; break; // Negate relative note case WTBL: - if ((ltable[tables.m_num][tables.m_pos] != 0xff) && (rtable[tables.m_num][tables.m_pos] < 0x80)) - rtable[tables.m_num][tables.m_pos] = (0x80 - rtable[tables.m_num][tables.m_pos]) & 0x7f; + if ((ltable[tables.num()][tables.pos()] != 0xff) && (rtable[tables.num()][tables.pos()] < 0x80)) + rtable[tables.num()][tables.pos()] = (0x80 - rtable[tables.num()][tables.pos()]) & 0x7f; break; } } break; case KEY_DEL: - deletetable(tables.m_num, tables.m_pos); + deletetable(tables.num(), tables.pos()); break; case KEY_INS: - inserttable(tables.m_num, tables.m_pos, shiftpressed); + inserttable(tables.num(), tables.pos(), shiftpressed); break; case KEY_ENTER: - if (tables.m_num == WTBL) + if (tables.num() == WTBL) { int table = -1; int mstmode = MST_PORTAMENTO; - switch (ltable[tables.m_num][tables.m_pos]) + switch (ltable[tables.num()][tables.pos()]) { case WAVECMD + CMD_PORTAUP: case WAVECMD + CMD_PORTADOWN: @@ -453,26 +453,26 @@ void tablecommands() { default: editmode = EDIT_INSTRUMENT; - eipos = tables.m_num + 2; + eipos = tables.num() + 2; return; case STBL: - if (rtable[tables.m_num][tables.m_pos]) + if (rtable[tables.num()][tables.pos()]) { if (!shiftpressed) { - gototable(STBL, rtable[tables.m_num][tables.m_pos] - 1); + gototable(STBL, rtable[tables.num()][tables.pos()] - 1); return; } else { - int oldeditpos = tables.m_pos; + int oldeditpos = tables.pos(); int oldeditcolumn = tables.m_column; - int pos = makespeedtable(rtable[tables.m_num][tables.m_pos], mstmode, true); + int pos = makespeedtable(rtable[tables.num()][tables.pos()], mstmode, true); gototable(WTBL, oldeditpos); tables.m_column = oldeditcolumn; - rtable[tables.m_num][tables.m_pos] = pos + 1; + rtable[tables.num()][tables.pos()] = pos + 1; return; } } @@ -481,7 +481,7 @@ void tablecommands() int pos = findfreespeedtable(); if (pos >= 0) { - rtable[tables.m_num][tables.m_pos] = pos + 1; + rtable[tables.num()][tables.pos()] = pos + 1; gototable(STBL, pos); return; } @@ -490,9 +490,9 @@ void tablecommands() case PTBL: case FTBL: - if (rtable[tables.m_num][tables.m_pos]) + if (rtable[tables.num()][tables.pos()]) { - gototable(table, rtable[tables.m_num][tables.m_pos] - 1); + gototable(table, rtable[tables.num()][tables.pos()] - 1); return; } else @@ -501,7 +501,7 @@ void tablecommands() { int pos = gettablelen(table); if (pos >= MAX_TABLELEN-1) pos = MAX_TABLELEN - 1; - rtable[tables.m_num][tables.m_pos] = pos + 1; + rtable[tables.num()][tables.pos()] = pos + 1; gototable(table, pos); return; } @@ -511,7 +511,7 @@ void tablecommands() else { editmode = EDIT_INSTRUMENT; - eipos = tables.m_num + 2; + eipos = tables.num() + 2; return; } break; @@ -519,17 +519,17 @@ void tablecommands() case KEY_APOST2: if (shiftpressed) { - tables.m_pos -= tables.m_view[tables.m_num]; + tables.m_pos -= tables.curview(); tables.m_num--; - if (tables.m_num < 0) tables.m_num = MAX_TABLES-1; - tables.m_pos += tables.m_view[tables.m_num]; + if (tables.num() < 0) tables.m_num = MAX_TABLES-1; + tables.m_pos += tables.curview(); } else { - tables.m_pos -= tables.m_view[tables.m_num]; + tables.m_pos -= tables.curview(); tables.m_num++; - if (tables.m_num >= MAX_TABLES) tables.m_num = 0; - tables.m_pos += tables.m_view[tables.m_num]; + if (tables.num() >= MAX_TABLES) tables.m_num = 0; + tables.m_pos += tables.curview(); } } @@ -538,20 +538,20 @@ void tablecommands() switch(tables.m_column) { case 0: - ltable[tables.m_num][tables.m_pos] &= 0x0f; - ltable[tables.m_num][tables.m_pos] |= hexnybble << 4; + ltable[tables.num()][tables.pos()] &= 0x0f; + ltable[tables.num()][tables.pos()] |= hexnybble << 4; break; case 1: - ltable[tables.m_num][tables.m_pos] &= 0xf0; - ltable[tables.m_num][tables.m_pos] |= hexnybble; + ltable[tables.num()][tables.pos()] &= 0xf0; + ltable[tables.num()][tables.pos()] |= hexnybble; break; case 2: - rtable[tables.m_num][tables.m_pos] &= 0x0f; - rtable[tables.m_num][tables.m_pos] |= hexnybble << 4; + rtable[tables.num()][tables.pos()] &= 0x0f; + rtable[tables.num()][tables.pos()] |= hexnybble << 4; break; case 3: - rtable[tables.m_num][tables.m_pos] &= 0xf0; - rtable[tables.m_num][tables.m_pos] |= hexnybble; + rtable[tables.num()][tables.pos()] &= 0xf0; + rtable[tables.num()][tables.pos()] |= hexnybble; break; } tables.m_column++; @@ -559,7 +559,7 @@ void tablecommands() { tables.m_column = 0; tables.m_pos++; - if (tables.m_pos >= MAX_TABLELEN) tables.m_pos = MAX_TABLELEN-1; + if (tables.pos() >= MAX_TABLELEN) tables.m_pos = MAX_TABLELEN-1; } } @@ -1096,14 +1096,19 @@ void Tables::setcolumn(int column) if (m_column >= 2) m_column--; } -void Tables::setmarknum(int marknum) +void Tables::resetmarknum() { - m_marknum = marknum; + m_marknum = -1; } -void Tables::setmarkstart(int markstart) +void Tables::setmarkstart(int num, int markstart) { - m_markstart = markstart; + if ((m_marknum != m_num) || (markstart != m_markend)) + { + m_marknum = num; + m_markstart = markstart; + m_markend = markstart; + } } void Tables::setmarkend(int markend) diff --git a/src/table.h b/src/table.h index 3a749f5..7b24c56 100644 --- a/src/table.h +++ b/src/table.h @@ -42,11 +42,13 @@ int findfreespeedtable(); class Tables { -public: +private: int m_view[MAX_TABLES]; +public: int m_num; int m_pos; int m_column; +private: int m_marknum = -1; int m_markstart; int m_markend; @@ -65,8 +67,8 @@ class Tables void setnum(int num); void setpos(int pos); void setcolumn(int column); - void setmarknum(int marknum); - void setmarkstart(int markstart); + void resetmarknum(); + void setmarkstart(int num, int markstart); void setmarkend(int markend); void fliplock(); void clear(); From 36d6ff25edff1c89eaf216221a85c1ff16a40cb0 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 14 Jul 2026 20:36:11 +0200 Subject: [PATCH 3/4] More cleanup --- src/display.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 1435393..f86c066 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -246,7 +246,6 @@ void printstatus() { int p = epview+d; int color = colors.CNORMAL; - int color2; if ((epnum[c] == chn[c].pattnum) && (isplaying())) { int chnrow = chn[c].pattptr / 4; @@ -294,18 +293,11 @@ void printstatus() } } textbuffer[3] = 0; - if (p%stepsize) - { - printtext(dpos.patternsX-1+c*13, dpos.patternsY+1+d, colors.CNORMAL, textbuffer); - } - else - { - printtext(dpos.patternsX-1+c*13, dpos.patternsY+1+d, colors.CCOMMAND, textbuffer); - } - if (color == colors.CNORMAL) - color2 = colors.CCOMMAND; - else - color2 = color; + + int color2 = (p%stepsize) ? colors.CNORMAL : colors.CCOMMAND; + printtext(dpos.patternsX-1+c*13, dpos.patternsY+1+d, color2, textbuffer); + + color2 = (color == colors.CNORMAL) ? colors.CCOMMAND : color; printtext(dpos.patternsX+3+c*13, dpos.patternsY+1+d, color2, &textbuffer[4]); printtext(dpos.patternsX+7+c*13, dpos.patternsY+1+d, color, &textbuffer[8]); printtext(dpos.patternsX+9+c*13, dpos.patternsY+1+d, color2, &textbuffer[10]); From 33852cd4ef1215980d23d88ac61548f1698945b2 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Tue, 14 Jul 2026 21:54:03 +0200 Subject: [PATCH 4/4] Cleanup --- src/reloc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/reloc.cpp b/src/reloc.cpp index 94f7d01..2821105 100644 --- a/src/reloc.cpp +++ b/src/reloc.cpp @@ -581,7 +581,7 @@ void relocator() // Select playroutine options clearscreen(); printblankc(0, 0, colors.CHEADER, MAX_COLUMNS); - if (!strlen(loadedsongfilename)) + if (!std::strlen(loadedsongfilename)) sprintf(textbuffer, "%s Packer/Relocator", programname); else sprintf(textbuffer, "%s Packer/Relocator - %s", programname, loadedsongfilename); @@ -1498,7 +1498,7 @@ void relocator() // Print results clearscreen(); printblankc(0, 0, colors.CHEADER, MAX_COLUMNS); - if (!strlen(loadedsongfilename)) + if (!std::strlen(loadedsongfilename)) sprintf(textbuffer, "%s Packer/Relocator", programname); else sprintf(textbuffer, "%s Packer/Relocator - %s", programname, loadedsongfilename);