diff --git a/src/display.cpp b/src/display.cpp index d48ac52..ae98bb9 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -204,7 +204,7 @@ void printstatus() { for (int c = 0; c < maxChns; c++) { - int currentSonglen = songlen[esnum][c]; + int currentSonglen = song.len[esnum][c]; int newpos = chn[c].pattptr / 4; if (chn[c].advance) epnum[c] = chn[c].pattnum; @@ -271,7 +271,7 @@ void printstatus() else std::sprintf(textbuffer, " %02X", p); - if (pattern[epnum[c]][p*4] == ENDPATT) + if (song.pattern[epnum[c]][p*4] == ENDPATT) { std::sprintf(&textbuffer[3], " PATT. END"); if (color == colors.CNORMAL) color = colors.CCOMMAND; @@ -279,15 +279,15 @@ void printstatus() else { std::sprintf(&textbuffer[3], " %s %02X%01X%02X", - notename[pattern[epnum[c]][p*4]-FIRSTNOTE], - pattern[epnum[c]][p*4+1], - pattern[epnum[c]][p*4+2], - pattern[epnum[c]][p*4+3]); + notename[song.pattern[epnum[c]][p*4]-FIRSTNOTE], + song.pattern[epnum[c]][p*4+1], + song.pattern[epnum[c]][p*4+2], + song.pattern[epnum[c]][p*4+3]); if (patterndispmode & 2) { - if (!pattern[epnum[c]][p*4+1]) + if (!song.pattern[epnum[c]][p*4+1]) std::memset(&textbuffer[8], '.', 2); - if (!pattern[epnum[c]][p*4+2]) + if (!song.pattern[epnum[c]][p*4+2]) std::memset(&textbuffer[10], '.', 3); } } @@ -351,8 +351,8 @@ void printstatus() for (int d = 0; d < visibleOrderlist; d++) { int p = esview+d; - unsigned char currentSongorder = songorder[esnum][c][p]; - int currentSonglen = songlen[esnum][c]; + unsigned char currentSongorder = song.order[esnum][c][p]; + int currentSonglen = song.len[esnum][c]; int color = colors.CNORMAL; if (isplaying()) { @@ -437,16 +437,16 @@ void printstatus() int color = insnum == einum ? colors.CEDIT : colors.CNORMAL; std::sprintf(textbuffer, "%2d %-16s %02X %02X %02X %02X %02X %02X %02X %02X %02X", insnum, - instr[insnum].name, - instr[insnum].ad, - instr[insnum].sr, - instr[insnum].ptr[WTBL], - instr[insnum].ptr[PTBL], - instr[insnum].ptr[FTBL], - instr[insnum].ptr[STBL], - instr[insnum].vibdelay, - instr[insnum].gatetimer, - instr[insnum].firstwave + song.instr[insnum].name, + song.instr[insnum].ad, + song.instr[insnum].sr, + song.instr[insnum].ptr[WTBL], + song.instr[insnum].ptr[PTBL], + song.instr[insnum].ptr[FTBL], + song.instr[insnum].ptr[STBL], + song.instr[insnum].vibdelay, + song.instr[insnum].gatetimer, + song.instr[insnum].firstwave ); printtext(dpos.instrumentsX, dpos.instrumentsY+1+i, color, textbuffer); } @@ -462,7 +462,7 @@ void printstatus() else { // Instr name - if (!eamode) printbg(dpos.instrumentsX+3+std::strlen(instr[einum].name), dpos.instrumentsY+1+selpos, cc, 1); + if (!eamode) printbg(dpos.instrumentsX+3+std::strlen(song.instr[einum].name), dpos.instrumentsY+1+selpos, cc, 1); } } @@ -480,22 +480,22 @@ void printstatus() switch (c) { case WTBL: - if (ltable[c][p] >= WAVECMD) color = colors.CCOMMAND; + if (song.ltable[c][p] >= WAVECMD) color = colors.CCOMMAND; break; case PTBL: - if (ltable[c][p] >= 0x80) color = colors.CCOMMAND; + if (song.ltable[c][p] >= 0x80) color = colors.CCOMMAND; break; case FTBL: - if ((ltable[c][p] >= 0x80) || ((!ltable[c][p]) && (rtable[c][p]))) color = colors.CCOMMAND; + if ((song.ltable[c][p] >= 0x80) || ((!song.ltable[c][p]) && (song.rtable[c][p]))) color = colors.CCOMMAND; break; } if ((p == tables.pos()) && (tables.num() == c)) color = colors.CEDIT; - std::sprintf(textbuffer, "%02X:%02X %02X", p+1, ltable[c][p], rtable[c][p]); + std::sprintf(textbuffer, "%02X:%02X %02X", p+1, song.ltable[c][p], song.rtable[c][p]); if (patterndispmode & 2) { - if (!ltable[c][p] && !rtable[c][p] && !ltable[c][p+1] && !rtable[c][p+1]) + if (!song.ltable[c][p] && !song.rtable[c][p] && !song.ltable[c][p+1] && !song.rtable[c][p+1]) { std::memset(&textbuffer[3], '.', 2); std::memset(&textbuffer[6], '.', 2); @@ -524,15 +524,15 @@ void printstatus() // Info view printtext(dpos.instrumentsX, dpos.instrumentsY+8+VISIBLETABLEROWS+1, colors.CTITLE, "NAME "); - std::sprintf(textbuffer, "%-32s", songname); + std::sprintf(textbuffer, "%-32s", song.title); printtext(dpos.instrumentsX+9, dpos.instrumentsY+8+VISIBLETABLEROWS+1, colors.CEDIT, textbuffer); printtext(dpos.instrumentsX, dpos.instrumentsY+8+VISIBLETABLEROWS+2, colors.CTITLE, "AUTHOR "); - std::sprintf(textbuffer, "%-32s", authorname); + std::sprintf(textbuffer, "%-32s", song.author); printtext(dpos.instrumentsX+9, dpos.instrumentsY+8+VISIBLETABLEROWS+2, colors.CEDIT, textbuffer); printtext(dpos.instrumentsX, dpos.instrumentsY+8+VISIBLETABLEROWS+3, colors.CTITLE, "RELEASED "); - std::sprintf(textbuffer, "%-32s", copyrightname); + std::sprintf(textbuffer, "%-32s", song.released); printtext(dpos.instrumentsX+9, dpos.instrumentsY+8+VISIBLETABLEROWS+3, colors.CEDIT, textbuffer); if ((editmode == EDIT_NAMES) && (!eamode)) @@ -540,13 +540,13 @@ void printstatus() switch(enpos) { case 0: - printbg(dpos.instrumentsX+9+std::strlen(songname), dpos.instrumentsY+8+VISIBLETABLEROWS+1, cc, 1); + printbg(dpos.instrumentsX+9+std::strlen(song.title), dpos.instrumentsY+8+VISIBLETABLEROWS+1, cc, 1); break; case 1: - printbg(dpos.instrumentsX+9+std::strlen(authorname), dpos.instrumentsY+8+VISIBLETABLEROWS+2, cc, 1); + printbg(dpos.instrumentsX+9+std::strlen(song.author), dpos.instrumentsY+8+VISIBLETABLEROWS+2, cc, 1); break; case 2: - printbg(dpos.instrumentsX+9+std::strlen(copyrightname), dpos.instrumentsY+8+VISIBLETABLEROWS+3, cc, 1); + printbg(dpos.instrumentsX+9+std::strlen(song.released), dpos.instrumentsY+8+VISIBLETABLEROWS+3, cc, 1); break; } } diff --git a/src/instr.cpp b/src/instr.cpp index ac790b8..2e7d5ce 100644 --- a/src/instr.cpp +++ b/src/instr.cpp @@ -61,7 +61,7 @@ void instrumentcommands() if ((einum) && (shiftpressed) && (eipos < 9)) { cutinstr = einum; - std::memcpy(&instrcopybuffer, &instr[einum], sizeof(INSTR)); + std::memcpy(&instrcopybuffer, &song.instr[einum], sizeof(INSTR)); clearinstr(einum); } break; @@ -70,20 +70,20 @@ void instrumentcommands() if ((einum) && (shiftpressed) && (eipos < 9)) { cutinstr = -1; - std::memcpy(&instrcopybuffer, &instr[einum], sizeof(INSTR)); + std::memcpy(&instrcopybuffer, &song.instr[einum], sizeof(INSTR)); } break; case KEY_S: if ((einum) && (shiftpressed) && (eipos < 9)) { - std::memcpy(&instr[einum], &instrcopybuffer, sizeof(INSTR)); + std::memcpy(&song.instr[einum], &instrcopybuffer, sizeof(INSTR)); if (cutinstr != -1) { for (int c = 0; c < MAX_PATT; c++) { for (int d = 0; d < getPattlen(c); d++) - if (pattern[c][d*4+1] == cutinstr) pattern[c][d*4+1] = einum; + if (song.pattern[c][d*4+1] == cutinstr) song.pattern[c][d*4+1] = einum; } } } @@ -92,7 +92,7 @@ void instrumentcommands() case KEY_V: if ((einum) && (shiftpressed) && (eipos < 9)) { - std::memcpy(&instr[einum], &instrcopybuffer, sizeof(INSTR)); + std::memcpy(&song.instr[einum], &instrcopybuffer, sizeof(INSTR)); } break; @@ -177,20 +177,20 @@ void instrumentcommands() { int pos; - if (instr[einum].ptr[eipos-2]) + if (song.instr[einum].ptr[eipos-2]) { if ((eipos == 5) && (shiftpressed)) { - instr[einum].ptr[STBL] = makespeedtable(instr[einum].ptr[STBL], finevibrato, true) + 1; + song.instr[einum].ptr[STBL] = makespeedtable(song.instr[einum].ptr[STBL], finevibrato, true) + 1; break; } - pos = instr[einum].ptr[eipos-2] - 1; + pos = song.instr[einum].ptr[eipos-2] - 1; } else { pos = gettablelen(eipos-2); if (pos >= MAX_TABLELEN-1) pos = MAX_TABLELEN - 1; - if (shiftpressed) instr[einum].ptr[eipos-2] = pos + 1; + if (shiftpressed) song.instr[einum].ptr[eipos-2] = pos + 1; } gototable(eipos-2, pos); } @@ -202,10 +202,10 @@ void instrumentcommands() } break; } - if ((eipos == 9) && (einum)) editstring(instr[einum].name, MAX_INSTRNAMELEN); + if ((eipos == 9) && (einum)) editstring(song.instr[einum].name, MAX_INSTRNAMELEN); if ((hexnybble >= 0) && (eipos < 9) && (einum)) { - unsigned char *ptr = &instr[einum].ad; + unsigned char *ptr = &song.instr[einum].ad; ptr += eipos; switch(eicolumn) @@ -232,22 +232,22 @@ void instrumentcommands() // Validate instrument parameters if (einum) { - if (!(instr[einum].gatetimer & 0x3f)) instr[einum].gatetimer |= 1; + if (!(song.instr[einum].gatetimer & 0x3f)) song.instr[einum].gatetimer |= 1; } } void clearinstr(int num) { - std::memset(&instr[num], 0, sizeof(INSTR)); + std::memset(&song.instr[num], 0, sizeof(INSTR)); if (num) { if (multiplier) - instr[num].gatetimer = 2 * multiplier; + song.instr[num].gatetimer = 2 * multiplier; else - instr[num].gatetimer = 1; + song.instr[num].gatetimer = 1; - instr[num].firstwave = 0x9; + song.instr[num].firstwave = 0x9; } } @@ -294,8 +294,8 @@ void showinstrtable() { for (int c = MAX_TABLES-1; c >= 0; c--) { - if (instr[einum].ptr[c]) - tables.settableviewfirst(c, instr[einum].ptr[c] - 1); + if (song.instr[einum].ptr[c]) + tables.settableviewfirst(c, song.instr[einum].ptr[c] - 1); } } } diff --git a/src/loadtrk.cpp b/src/loadtrk.cpp index 08054e8..b67b318 100644 --- a/src/loadtrk.cpp +++ b/src/loadtrk.cpp @@ -508,7 +508,7 @@ void mousecommands() { int maxChns = getMaxChannels(); - int currentSonglen = songlen[esnum][eschn]; + int currentSonglen = song.len[esnum][eschn]; if (win_mouseywheel != 0.f) { @@ -550,7 +550,7 @@ void mousecommands() } else if (win_mouseywheel < 0.f) { - if ((songlen[esnum][eschn]-esview) > getVisibleOrderlist()-1) + if ((song.len[esnum][eschn]-esview) > getVisibleOrderlist()-1) { esview++; eseditpos++; @@ -956,7 +956,7 @@ void generalcommands() case ':': for (int c = 0; c < maxChns; c++) { - currentSonglen = songlen[esnum][c]; + currentSonglen = song.len[esnum][c]; if (espos[c] < (currentSonglen-1)) espos[c]++; if ((espos[c] - esview) >= visibleOrderlist) @@ -1162,10 +1162,10 @@ void save() // Repeat until quit or save successful while (!done) { - if ((!std::strlen(instrfilename)) && (strlen(instr[einum].name))) + if ((!std::strlen(instrfilename)) && (std::strlen(song.instr[einum].name))) { useinstrname = 1; - std::strcpy(instrfilename, instr[einum].name); + std::strcpy(instrfilename, song.instr[einum].name); std::strcat(instrfilename, ".ins"); std::strcpy(tempfilename, instrfilename); } @@ -1683,9 +1683,9 @@ void optimizeeverything() { for (int d = 0; d < MAX_PATTROWS; d++) { - if (pattern[c][d*4] == ENDPATT) break; - if (pattern[c][d*4+1]) - instrused[pattern[c][d*4+1]] = 1; + if (song.pattern[c][d*4] == ENDPATT) break; + if (song.pattern[c][d*4+1]) + instrused[song.pattern[c][d*4+1]] = 1; } } else deletepattern(c); @@ -1701,14 +1701,14 @@ void optimizeeverything() if (c < MAX_INSTR-2) { - std::memmove(&instr[c], &instr[c+1], (MAX_INSTR-2-c) * sizeof(INSTR)); + std::memmove(&song.instr[c], &song.instr[c+1], (MAX_INSTR-2-c) * sizeof(INSTR)); clearinstr(MAX_INSTR-2); for (int d = 0; d < MAX_PATT; d++) { for (int e = 0; e < getPattlen(d); e++) { - if ((pattern[d][e*4+1] > c) && (pattern[d][e*4+1] != MAX_INSTR-1)) - pattern[d][e*4+1]--; + if ((song.pattern[d][e*4+1] > c) && (song.pattern[d][e*4+1] != MAX_INSTR-1)) + song.pattern[d][e*4+1]--; } } } @@ -1732,20 +1732,20 @@ void findduplicatepatterns() { if (getPattlen(d) == getPattlen(c)) { - if (!std::memcmp(pattern[c], pattern[d], getPattlen(c)*4)) + if (!std::memcmp(song.pattern[c], song.pattern[d], getPattlen(c)*4)) { for (int f = 0; f < MAX_SONGS; f++) { - if ((songlen[f][0]) && - (songlen[f][1]) && - (songlen[f][2])) + if ((song.len[f][0]) && + (song.len[f][1]) && + (song.len[f][2])) { for (int g = 0; g < maxChns; g++) { - for (int h = 0; h < songlen[f][g]; h++) + for (int h = 0; h < song.len[f][g]; h++) { - if (songorder[f][g][h] == d) - songorder[f][g][h] = c; + if (song.order[f][g][h] == d) + song.order[f][g][h] = c; } } } diff --git a/src/order.cpp b/src/order.cpp index ae42112..41efbd1 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -61,50 +61,50 @@ void orderlistcommands() if (hexnybble >= 0) { - if (eseditpos != songlen[esnum][eschn]) + if (eseditpos != song.len[esnum][eschn]) { switch(escolumn) { case 0: - songorder[esnum][eschn][eseditpos] &= 0x0f; - songorder[esnum][eschn][eseditpos] |= hexnybble << 4; - if (eseditpos < songlen[esnum][eschn]) + song.order[esnum][eschn][eseditpos] &= 0x0f; + song.order[esnum][eschn][eseditpos] |= hexnybble << 4; + if (eseditpos < song.len[esnum][eschn]) { - if (songorder[esnum][eschn][eseditpos] >= MAX_PATT) - songorder[esnum][eschn][eseditpos] = MAX_PATT - 1; + if (song.order[esnum][eschn][eseditpos] >= MAX_PATT) + song.order[esnum][eschn][eseditpos] = MAX_PATT - 1; } else { - if (songorder[esnum][eschn][eseditpos] >= MAX_SONGLEN) - songorder[esnum][eschn][eseditpos] = MAX_SONGLEN - 1; + if (song.order[esnum][eschn][eseditpos] >= MAX_SONGLEN) + song.order[esnum][eschn][eseditpos] = MAX_SONGLEN - 1; } break; case 1: - songorder[esnum][eschn][eseditpos] &= 0xf0; - if ((songorder[esnum][eschn][eseditpos] & 0xf0) == 0xd0) + song.order[esnum][eschn][eseditpos] &= 0xf0; + if ((song.order[esnum][eschn][eseditpos] & 0xf0) == 0xd0) { hexnybble--; if (hexnybble < 0) hexnybble = 0xf; } - if ((songorder[esnum][eschn][eseditpos] & 0xf0) == 0xe0) + if ((song.order[esnum][eschn][eseditpos] & 0xf0) == 0xe0) { hexnybble = 16 - hexnybble; hexnybble &= 0xf; } - songorder[esnum][eschn][eseditpos] |= hexnybble; + song.order[esnum][eschn][eseditpos] |= hexnybble; - if (eseditpos < songlen[esnum][eschn]) + if (eseditpos < song.len[esnum][eschn]) { - if (songorder[esnum][eschn][eseditpos] == LOOPSONG) - songorder[esnum][eschn][eseditpos] = LOOPSONG-1; - if (songorder[esnum][eschn][eseditpos] == TRANSDOWN) - songorder[esnum][eschn][eseditpos] = TRANSDOWN+0x0f; + 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; } else { - if (songorder[esnum][eschn][eseditpos] >= MAX_SONGLEN) - songorder[esnum][eschn][eseditpos] = MAX_SONGLEN - 1; + if (song.order[esnum][eschn][eseditpos] >= MAX_SONGLEN) + song.order[esnum][eschn][eseditpos] = MAX_SONGLEN - 1; } break; } @@ -112,10 +112,10 @@ void orderlistcommands() if (escolumn > 1) { escolumn = 0; - if (eseditpos < (songlen[esnum][eschn]+1)) + if (eseditpos < (song.len[esnum][eschn]+1)) { eseditpos++; - if (eseditpos == songlen[esnum][eschn]) eseditpos++; + if (eseditpos == song.len[esnum][eschn]) eseditpos++; } } } @@ -124,25 +124,25 @@ void orderlistcommands() switch(key) { case 'R': - if (eseditpos < songlen[esnum][eschn]) + if (eseditpos < song.len[esnum][eschn]) { - songorder[esnum][eschn][eseditpos] = REPEAT + 0x01; + song.order[esnum][eschn][eseditpos] = REPEAT + 0x01; escolumn = 1; } break; case '+': - if (eseditpos < songlen[esnum][eschn]) + if (eseditpos < song.len[esnum][eschn]) { - songorder[esnum][eschn][eseditpos] = TRANSUP; + song.order[esnum][eschn][eseditpos] = TRANSUP; escolumn = 1; } break; case '-': - if (eseditpos < songlen[esnum][eschn]) + if (eseditpos < song.len[esnum][eschn]) { - songorder[esnum][eschn][eseditpos] = TRANSDOWN + 0x0F; + song.order[esnum][eschn][eseditpos] = TRANSDOWN + 0x0F; escolumn = 1; } break; @@ -175,15 +175,15 @@ void orderlistcommands() if (rawkey == KEY_3) tchn = 2; if (schn != tchn) { - int lentemp = songlen[esnum][schn]; - songlen[esnum][schn] = songlen[esnum][tchn]; - songlen[esnum][tchn] = lentemp; + int lentemp = song.len[esnum][schn]; + song.len[esnum][schn] = song.len[esnum][tchn]; + song.len[esnum][tchn] = lentemp; for (int c = 0; c < MAX_SONGLEN+2; c++) { - unsigned char temp = songorder[esnum][schn][c]; - songorder[esnum][schn][c] = songorder[esnum][tchn][c]; - songorder[esnum][tchn][c] = temp; + unsigned char temp = song.order[esnum][schn][c]; + song.order[esnum][schn][c] = song.order[esnum][tchn][c]; + song.order[esnum][tchn][c] = temp; } } } @@ -201,20 +201,20 @@ void orderlistcommands() { eseditpos = esmarkstart; for (int c = esmarkstart; c <= esmarkend; c++) - trackcopybuffer[d++] = songorder[esnum][eschn][c]; + trackcopybuffer[d++] = song.order[esnum][eschn][c]; trackcopyrows = d; } else { eseditpos = esmarkend; for (int c = esmarkend; c <= esmarkstart; c++) - trackcopybuffer[d++] = songorder[esnum][eschn][c]; + trackcopybuffer[d++] = song.order[esnum][eschn][c]; trackcopyrows = d; } - if (trackcopyrows == songlen[esnum][eschn]) + if (trackcopyrows == song.len[esnum][eschn]) { trackcopywhole = 1; - trackcopyrpos = songorder[esnum][eschn][songlen[esnum][eschn]+1]; + trackcopyrpos = song.order[esnum][eschn][song.len[esnum][eschn]+1]; } else trackcopywhole = 0; for (int c = 0; c < trackcopyrows; c++) deleteorder(); @@ -232,19 +232,19 @@ void orderlistcommands() if (esmarkstart <= esmarkend) { for (int c = esmarkstart; c <= esmarkend; c++) - trackcopybuffer[d++] = songorder[esnum][eschn][c]; + trackcopybuffer[d++] = song.order[esnum][eschn][c]; trackcopyrows = d; } else { for (int c = esmarkend; c <= esmarkstart; c++) - trackcopybuffer[d++] = songorder[esnum][eschn][c]; + trackcopybuffer[d++] = song.order[esnum][eschn][c]; trackcopyrows = d; } - if (trackcopyrows == songlen[esnum][eschn]) + if (trackcopyrows == song.len[esnum][eschn]) { trackcopywhole = 1; - trackcopyrpos = songorder[esnum][eschn][songlen[esnum][eschn]+1]; + trackcopyrpos = song.order[esnum][eschn][song.len[esnum][eschn]+1]; } else trackcopywhole = 0; esmarkchn = -1; @@ -255,9 +255,9 @@ void orderlistcommands() case KEY_V: if (shiftpressed) { - int oldlen = songlen[esnum][eschn]; + int oldlen = song.len[esnum][eschn]; - if (eseditpos < songlen[esnum][eschn]) + if (eseditpos < song.len[esnum][eschn]) { for (int c = trackcopyrows-1; c >= 0; c--) insertorder(trackcopybuffer[c]); @@ -268,7 +268,7 @@ void orderlistcommands() insertorder(trackcopybuffer[c]); } if ((trackcopywhole) && (!oldlen)) - songorder[esnum][eschn][songlen[esnum][eschn]+1] = trackcopyrpos; + song.order[esnum][eschn][song.len[esnum][eschn]+1] = trackcopyrpos; } break; @@ -279,7 +279,7 @@ void orderlistcommands() { esmarkchn = eschn; esmarkstart = 0; - esmarkend = songlen[esnum][eschn]-1; + esmarkend = song.len[esnum][eschn]-1; } else esmarkchn = -1; } @@ -289,14 +289,14 @@ void orderlistcommands() case KEY_SPACE: if (!shiftpressed) { - if (eseditpos < songlen[esnum][eschn]) espos[eschn] = eseditpos; + if (eseditpos < song.len[esnum][eschn]) espos[eschn] = eseditpos; if (esend[eschn] < espos[eschn]) esend[eschn] = 0; } else { for (int c = 0; c < maxChns; c++) { - if (eseditpos < songlen[esnum][c]) espos[c] = eseditpos; + if (eseditpos < song.len[esnum][c]) espos[c] = eseditpos; if (esend[c] < espos[c]) esend[c] = 0; } } @@ -307,7 +307,7 @@ void orderlistcommands() { if ((esend[eschn] != eseditpos) && (eseditpos > espos[eschn])) { - if (eseditpos < songlen[esnum][eschn]) esend[eschn] = eseditpos; + if (eseditpos < song.len[esnum][eschn]) esend[eschn] = eseditpos; } else esend[eschn] = 0; } @@ -317,7 +317,7 @@ void orderlistcommands() { for (int c = 0; c < maxChns; c++) { - if (eseditpos < songlen[esnum][c]) esend[c] = eseditpos; + if (eseditpos < song.len[esnum][c]) esend[c] = eseditpos; } } else @@ -328,12 +328,12 @@ void orderlistcommands() break; case KEY_ENTER: - if (eseditpos < songlen[esnum][eschn]) + if (eseditpos < song.len[esnum][eschn]) { if (!shiftpressed) { - if (songorder[esnum][eschn][eseditpos] < MAX_PATT) - epnum[eschn] = songorder[esnum][eschn][eseditpos]; + if (song.order[esnum][eschn][eseditpos] < MAX_PATT) + epnum[eschn] = song.order[esnum][eschn][eseditpos]; } else { @@ -344,11 +344,11 @@ void orderlistcommands() if (eseditpos != espos[eschn]) start = eseditpos; else start = espos[c]; - for (int d = start; d < songlen[esnum][c]; d++) + for (int d = start; d < song.len[esnum][c]; d++) { - if (songorder[esnum][c][d] < MAX_PATT) + if (song.order[esnum][c][d] < MAX_PATT) { - epnum[c] = songorder[esnum][c][d]; + epnum[c] = song.order[esnum][c][d]; break; } } @@ -376,14 +376,14 @@ void orderlistcommands() break; case KEY_HOME: - if (songlen[esnum][eschn]) + if (song.len[esnum][eschn]) { while ((eseditpos != 0) || (escolumn != 0)) orderleft(); } break; case KEY_END: - while (eseditpos != songlen[esnum][eschn]+1) orderright(); + while (eseditpos != song.len[esnum][eschn]+1) orderright(); break; case KEY_PGUP: @@ -407,9 +407,9 @@ void orderlistcommands() case KEY_UP: eschn--; if (eschn < 0) eschn = maxChns - 1; - if ((eseditpos == songlen[esnum][eschn]) || (eseditpos > songlen[esnum][eschn]+1)) + if ((eseditpos == song.len[esnum][eschn]) || (eseditpos > song.len[esnum][eschn]+1)) { - eseditpos = songlen[esnum][eschn]+1; + eseditpos = song.len[esnum][eschn]+1; escolumn = 0; } if (shiftpressed) esmarkchn = -1; @@ -418,9 +418,9 @@ void orderlistcommands() case KEY_DOWN: eschn++; if (eschn >= maxChns) eschn = 0; - if ((eseditpos == songlen[esnum][eschn]) || (eseditpos > songlen[esnum][eschn]+1)) + if ((eseditpos == song.len[esnum][eschn]) || (eseditpos > song.len[esnum][eschn]+1)) { - eseditpos = songlen[esnum][eschn]+1; + eseditpos = song.len[esnum][eschn]+1; escolumn = 0; } if (shiftpressed) esmarkchn = -1; @@ -455,40 +455,40 @@ void namecommands() switch(enpos) { case 0: - editstring(songname, MAX_STR); + editstring(song.title, MAX_STR); break; case 1: - editstring(authorname, MAX_STR); + editstring(song.author, MAX_STR); break; case 2: - editstring(copyrightname, MAX_STR); + editstring(song.released, MAX_STR); break; } } void insertorder(unsigned char byte) { - int sl = songlen[esnum][eschn]; + int sl = song.len[esnum][eschn]; if ((sl - eseditpos)-1 >= 0) { if (sl < MAX_SONGLEN) { 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; + 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; countthispattern(); } - std::memmove(&songorder[esnum][eschn][eseditpos+1], - &songorder[esnum][eschn][eseditpos], + std::memmove(&song.order[esnum][eschn][eseditpos+1], + &song.order[esnum][eschn][eseditpos], (sl - eseditpos)-1); - songorder[esnum][eschn][eseditpos] = byte; + song.order[esnum][eschn][eseditpos] = byte; int len = sl+1; - if ((songorder[esnum][eschn][len] > eseditpos) && - (songorder[esnum][eschn][len] < (len-2))) - songorder[esnum][eschn][len]++; + if ((song.order[esnum][eschn][len] > eseditpos) && + (song.order[esnum][eschn][len] < (len-2))) + song.order[esnum][eschn][len]++; } else { @@ -496,9 +496,9 @@ void insertorder(unsigned char byte) { if (sl < MAX_SONGLEN) { - songorder[esnum][eschn][eseditpos+1] = songorder[esnum][eschn][eseditpos]; - songorder[esnum][eschn][eseditpos] = LOOPSONG; - if (eseditpos) songorder[esnum][eschn][eseditpos-1] = byte; + 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; countthispattern(); eseditpos = sl+1; } @@ -508,24 +508,24 @@ void insertorder(unsigned char byte) void deleteorder() { - int sl = songlen[esnum][eschn]; + int sl = song.len[esnum][eschn]; if ((sl - eseditpos)-1 >= 0) { - std::memmove(&songorder[esnum][eschn][eseditpos], - &songorder[esnum][eschn][eseditpos+1], + std::memmove(&song.order[esnum][eschn][eseditpos], + &song.order[esnum][eschn][eseditpos+1], (sl - eseditpos)-1); - songorder[esnum][eschn][sl-1] = 0x00; + song.order[esnum][eschn][sl-1] = 0x00; if (sl > 0) { - songorder[esnum][eschn][sl-1] = songorder[esnum][eschn][sl]; - songorder[esnum][eschn][sl] = songorder[esnum][eschn][sl+1]; + song.order[esnum][eschn][sl-1] = song.order[esnum][eschn][sl]; + song.order[esnum][eschn][sl] = song.order[esnum][eschn][sl+1]; countthispattern(); } if (eseditpos == sl) eseditpos++; int len = sl+1; - if ((songorder[esnum][eschn][len] > eseditpos) && - (songorder[esnum][eschn][len] > 0)) - songorder[esnum][eschn][len]--; + if ((song.order[esnum][eschn][len] > eseditpos) && + (song.order[esnum][eschn][len] > 0)) + song.order[esnum][eschn][len]--; } else { @@ -533,8 +533,8 @@ void deleteorder() { if (sl > 0) { - songorder[esnum][eschn][sl-1] = songorder[esnum][eschn][sl]; - songorder[esnum][eschn][sl] = songorder[esnum][eschn][sl+1]; + song.order[esnum][eschn][sl-1] = song.order[esnum][eschn][sl]; + song.order[esnum][eschn][sl] = song.order[esnum][eschn][sl+1]; countthispattern(); eseditpos = sl+1; } @@ -544,7 +544,7 @@ void deleteorder() void orderleft() { - if ((shiftpressed) && (eseditpos < songlen[esnum][eschn])) + if ((shiftpressed) && (eseditpos < song.len[esnum][eschn])) { if ((esmarkchn != eschn) || (eseditpos != esmarkend)) { @@ -558,7 +558,7 @@ void orderleft() if (eseditpos > 0) { eseditpos--; - if (eseditpos == songlen[esnum][eschn]) eseditpos--; + if (eseditpos == song.len[esnum][eschn]) eseditpos--; escolumn = 1; if (eseditpos < 0) { @@ -568,12 +568,12 @@ void orderleft() } else escolumn = 0; } - if ((shiftpressed) && (eseditpos < songlen[esnum][eschn])) esmarkend = eseditpos; + if ((shiftpressed) && (eseditpos < song.len[esnum][eschn])) esmarkend = eseditpos; } void orderright() { - if ((shiftpressed) && (eseditpos < songlen[esnum][eschn])) + if ((shiftpressed) && (eseditpos < song.len[esnum][eschn])) { if ((esmarkchn != eschn) || (eseditpos != esmarkend)) { @@ -585,14 +585,14 @@ void orderright() if (escolumn > 1) { escolumn = 0; - if (eseditpos < (songlen[esnum][eschn]+1)) + if (eseditpos < (song.len[esnum][eschn]+1)) { eseditpos++; - if (eseditpos == songlen[esnum][eschn]) eseditpos++; + if (eseditpos == song.len[esnum][eschn]) eseditpos++; } else escolumn = 1; } - if ((shiftpressed) && (eseditpos < songlen[esnum][eschn])) esmarkend = eseditpos; + if ((shiftpressed) && (eseditpos < song.len[esnum][eschn])) esmarkend = eseditpos; } void nextsong() @@ -613,7 +613,7 @@ void songchange() { int maxChns = getMaxChannels(); - int currentSonglen = songlen[esnum][eschn]; + int currentSonglen = song.len[esnum][eschn]; for (int c = 0; c < maxChns; c++) { @@ -640,10 +640,10 @@ void updateviewtopos() for (int c = 0; c < maxChns; c++) { - int currentSonglen = songlen[esnum][c]; + int currentSonglen = song.len[esnum][c]; for (int d = espos[c]; d < currentSonglen; d++) { - int currentSongorder = songorder[esnum][c][d]; + int currentSongorder = song.order[esnum][c][d]; if (currentSongorder < MAX_PATT) { epnum[c] = currentSongorder; diff --git a/src/pattern.cpp b/src/pattern.cpp index d4ceea5..50e2f40 100644 --- a/src/pattern.cpp +++ b/src/pattern.cpp @@ -35,6 +35,8 @@ #include "bme_main.h" +#include + #include unsigned char notekeytbl1[] = {KEY_Z, KEY_S, KEY_X, KEY_D, KEY_C, KEY_V, @@ -78,19 +80,19 @@ void insertnote(int newnote) { if (recordmode && (eppos < getPattlen(epnum[epchn]))) { - pattern[epnum[epchn]][eppos*4] = newnote; + song.pattern[epnum[epchn]][eppos*4] = newnote; if (newnote < REST) { - pattern[epnum[epchn]][eppos*4+1] = einum; + song.pattern[epnum[epchn]][eppos*4+1] = einum; } else { - pattern[epnum[epchn]][eppos*4+1] = 0; + song.pattern[epnum[epchn]][eppos*4+1] = 0; } if ((shiftpressed) && (newnote == REST)) { - pattern[epnum[epchn]][eppos*4+2] = 0; - pattern[epnum[epchn]][eppos*4+3] = 0; + song.pattern[epnum[epchn]][eppos*4+2] = 0; + song.pattern[epnum[epchn]][eppos*4+3] = 0; } } @@ -194,20 +196,20 @@ void patterncommands() case 1: case 2: - if (pattern[epnum[epchn]][eppos*4+1]) + if (song.pattern[epnum[epchn]][eppos*4+1]) { - gotoinstr(pattern[epnum[epchn]][eppos*4+1]); + gotoinstr(song.pattern[epnum[epchn]][eppos*4+1]); return; } break; default: - switch (pattern[epnum[epchn]][eppos*4+2]) + switch (song.pattern[epnum[epchn]][eppos*4+2]) { case CMD_SETWAVEPTR: - if (pattern[epnum[epchn]][eppos*4+3]) + if (song.pattern[epnum[epchn]][eppos*4+3]) { - gototable(WTBL, pattern[epnum[epchn]][eppos*4+3] - 1); + gototable(WTBL, song.pattern[epnum[epchn]][eppos*4+3] - 1); return; } else @@ -216,7 +218,7 @@ void patterncommands() { int pos = gettablelen(WTBL); if (pos >= MAX_TABLELEN-1) pos = MAX_TABLELEN - 1; - pattern[epnum[epchn]][eppos*4+3] = pos + 1; + song.pattern[epnum[epchn]][eppos*4+3] = pos + 1; gototable(WTBL, pos); return; } @@ -224,9 +226,9 @@ void patterncommands() break; case CMD_SETPULSEPTR: - if (pattern[epnum[epchn]][eppos*4+3]) + if (song.pattern[epnum[epchn]][eppos*4+3]) { - gototable(PTBL, pattern[epnum[epchn]][eppos*4+3] - 1); + gototable(PTBL, song.pattern[epnum[epchn]][eppos*4+3] - 1); return; } else @@ -235,7 +237,7 @@ void patterncommands() { int pos = gettablelen(PTBL); if (pos >= MAX_TABLELEN-1) pos = MAX_TABLELEN - 1; - pattern[epnum[epchn]][eppos*4+3] = pos + 1; + song.pattern[epnum[epchn]][eppos*4+3] = pos + 1; gototable(PTBL, pos); return; } @@ -243,9 +245,9 @@ void patterncommands() break; case CMD_SETFILTERPTR: - if (pattern[epnum[epchn]][eppos*4+3]) + if (song.pattern[epnum[epchn]][eppos*4+3]) { - gototable(FTBL, pattern[epnum[epchn]][eppos*4+3] - 1); + gototable(FTBL, song.pattern[epnum[epchn]][eppos*4+3] - 1); return; } else @@ -254,7 +256,7 @@ void patterncommands() { int pos = gettablelen(FTBL); if (pos >= MAX_TABLELEN-1) pos = MAX_TABLELEN - 1; - pattern[epnum[epchn]][eppos*4+3] = pos + 1; + song.pattern[epnum[epchn]][eppos*4+3] = pos + 1; gototable(FTBL, pos); return; } @@ -262,17 +264,17 @@ void patterncommands() break; case CMD_FUNKTEMPO: - if (pattern[epnum[epchn]][eppos*4+3]) + if (song.pattern[epnum[epchn]][eppos*4+3]) { if (!shiftpressed) { - gototable(STBL, pattern[epnum[epchn]][eppos*4+3] - 1); + gototable(STBL, song.pattern[epnum[epchn]][eppos*4+3] - 1); return; } else { - int pos = makespeedtable(pattern[epnum[epchn]][eppos*4+3], MST_FUNKTEMPO, true); - pattern[epnum[epchn]][eppos*4+3] = pos + 1; + int pos = makespeedtable(song.pattern[epnum[epchn]][eppos*4+3], MST_FUNKTEMPO, true); + song.pattern[epnum[epchn]][eppos*4+3] = pos + 1; } } else @@ -282,7 +284,7 @@ void patterncommands() int pos = findfreespeedtable(); if (pos >= 0) { - pattern[epnum[epchn]][eppos*4+3] = pos + 1; + song.pattern[epnum[epchn]][eppos*4+3] = pos + 1; gototable(STBL, pos); return; } @@ -293,17 +295,17 @@ void patterncommands() case CMD_PORTAUP: case CMD_PORTADOWN: case CMD_TONEPORTA: - if (pattern[epnum[epchn]][eppos*4+3]) + if (song.pattern[epnum[epchn]][eppos*4+3]) { if (!shiftpressed) { - gototable(STBL, pattern[epnum[epchn]][eppos*4+3] - 1); + gototable(STBL, song.pattern[epnum[epchn]][eppos*4+3] - 1); return; } else { - int pos = makespeedtable(pattern[epnum[epchn]][eppos*4+3], MST_PORTAMENTO, true); - pattern[epnum[epchn]][eppos*4+3] = pos + 1; + int pos = makespeedtable(song.pattern[epnum[epchn]][eppos*4+3], MST_PORTAMENTO, true); + song.pattern[epnum[epchn]][eppos*4+3] = pos + 1; } } else @@ -313,7 +315,7 @@ void patterncommands() int pos = findfreespeedtable(); if (pos >= 0) { - pattern[epnum[epchn]][eppos*4+3] = pos + 1; + song.pattern[epnum[epchn]][eppos*4+3] = pos + 1; gototable(STBL, pos); return; } @@ -322,17 +324,17 @@ void patterncommands() break; case CMD_VIBRATO: - if (pattern[epnum[epchn]][eppos*4+3]) + if (song.pattern[epnum[epchn]][eppos*4+3]) { if (!shiftpressed) { - gototable(STBL, pattern[epnum[epchn]][eppos*4+3] - 1); + gototable(STBL, song.pattern[epnum[epchn]][eppos*4+3] - 1); return; } else { - int pos = makespeedtable(pattern[epnum[epchn]][eppos*4+3], finevibrato, true); - pattern[epnum[epchn]][eppos*4+3] = pos + 1; + int pos = makespeedtable(song.pattern[epnum[epchn]][eppos*4+3], finevibrato, true); + song.pattern[epnum[epchn]][eppos*4+3] = pos + 1; } } else @@ -342,7 +344,7 @@ void patterncommands() int pos = findfreespeedtable(); if (pos >= 0) { - pattern[epnum[epchn]][eppos*4+3] = pos + 1; + song.pattern[epnum[epchn]][eppos*4+3] = pos + 1; gototable(STBL, pos); return; } @@ -407,8 +409,8 @@ void patterncommands() for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= getPattlen(epnum[epmarkchn])) break; - cmdcopybuffer[d*4+2] = pattern[epnum[epmarkchn]][c*4+2]; - cmdcopybuffer[d*4+3] = pattern[epnum[epmarkchn]][c*4+3]; + cmdcopybuffer[d*4+2] = song.pattern[epnum[epmarkchn]][c*4+2]; + cmdcopybuffer[d*4+3] = song.pattern[epnum[epmarkchn]][c*4+3]; d++; } cmdcopyrows = d; @@ -419,8 +421,8 @@ void patterncommands() for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= getPattlen(epnum[epmarkchn])) break; - cmdcopybuffer[d*4+2] = pattern[epnum[epmarkchn]][c*4+2]; - cmdcopybuffer[d*4+3] = pattern[epnum[epmarkchn]][c*4+3]; + cmdcopybuffer[d*4+2] = song.pattern[epnum[epmarkchn]][c*4+2]; + cmdcopybuffer[d*4+3] = song.pattern[epnum[epmarkchn]][c*4+3]; d++; } cmdcopyrows = d; @@ -431,8 +433,8 @@ void patterncommands() { if (eppos < getPattlen(epnum[epchn])) { - cmdcopybuffer[2] = pattern[epnum[epchn]][eppos*4+2]; - cmdcopybuffer[3] = pattern[epnum[epchn]][eppos*4+3]; + cmdcopybuffer[2] = song.pattern[epnum[epchn]][eppos*4+2]; + cmdcopybuffer[3] = song.pattern[epnum[epchn]][eppos*4+3]; cmdcopyrows = 1; } } @@ -445,8 +447,8 @@ void patterncommands() for (int c = 0; c < cmdcopyrows; c++) { if (eppos >= getPattlen(epnum[epchn])) break; - pattern[epnum[epchn]][eppos*4+2] = cmdcopybuffer[c*4+2]; - pattern[epnum[epchn]][eppos*4+3] = cmdcopybuffer[c*4+3]; + song.pattern[epnum[epchn]][eppos*4+2] = cmdcopybuffer[c*4+2]; + song.pattern[epnum[epchn]][eppos*4+3] = cmdcopybuffer[c*4+3]; eppos++; } } @@ -455,7 +457,6 @@ void patterncommands() case KEY_I: if (shiftpressed) { - char temp; if (epmarkchn != -1) { if (epmarkstart <= epmarkend) @@ -466,9 +467,7 @@ void patterncommands() if (c >= getPattlen(epnum[epmarkchn])) break; for (int d = 0; d < 4; d++) { - temp = pattern[epnum[epmarkchn]][c*4+d]; - pattern[epnum[epmarkchn]][c*4+d] = pattern[epnum[epmarkchn]][e*4+d]; - pattern[epnum[epmarkchn]][e*4+d] = temp; + std::swap(song.pattern[epnum[epmarkchn]][c*4+d], song.pattern[epnum[epmarkchn]][e*4+d]); } e--; if (e < c) break; @@ -482,9 +481,7 @@ void patterncommands() if (c >= getPattlen(epnum[epmarkchn])) break; for (int d = 0; d < 4; d++) { - temp = pattern[epnum[epmarkchn]][c*4+d]; - pattern[epnum[epmarkchn]][c*4+d] = pattern[epnum[epmarkchn]][e*4+d]; - pattern[epnum[epmarkchn]][e*4+d] = temp; + std::swap(song.pattern[epnum[epmarkchn]][c*4+d], song.pattern[epnum[epmarkchn]][e*4+d]); } e--; if (e < c) break; @@ -498,9 +495,7 @@ void patterncommands() { for (int d = 0; d < 4; d++) { - temp = pattern[epnum[epchn]][c*4+d]; - pattern[epnum[epchn]][c*4+d] = pattern[epnum[epchn]][e*4+d]; - pattern[epnum[epchn]][e*4+d] = temp; + std::swap(song.pattern[epnum[epchn]][c*4+d], song.pattern[epnum[epchn]][e*4+d]); } e--; if (e < c) break; @@ -519,9 +514,9 @@ void patterncommands() for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= getPattlen(epnum[epmarkchn])) break; - if ((pattern[epnum[epmarkchn]][c*4] < LASTNOTE) && - (pattern[epnum[epmarkchn]][c*4] >= FIRSTNOTE)) - pattern[epnum[epmarkchn]][c*4]++; + if ((song.pattern[epnum[epmarkchn]][c*4] < LASTNOTE) && + (song.pattern[epnum[epmarkchn]][c*4] >= FIRSTNOTE)) + song.pattern[epnum[epmarkchn]][c*4]++; } } else @@ -529,9 +524,9 @@ void patterncommands() for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= getPattlen(epnum[epmarkchn])) break; - if ((pattern[epnum[epmarkchn]][c*4] < LASTNOTE) && - (pattern[epnum[epmarkchn]][c*4] >= FIRSTNOTE)) - pattern[epnum[epmarkchn]][c*4]++; + if ((song.pattern[epnum[epmarkchn]][c*4] < LASTNOTE) && + (song.pattern[epnum[epmarkchn]][c*4] >= FIRSTNOTE)) + song.pattern[epnum[epmarkchn]][c*4]++; } } } @@ -539,9 +534,9 @@ void patterncommands() { for (int c = 0; c < getPattlen(epnum[epchn]); c++) { - if ((pattern[epnum[epchn]][c*4] < LASTNOTE) && - (pattern[epnum[epchn]][c*4] >= FIRSTNOTE)) - pattern[epnum[epchn]][c*4]++; + if ((song.pattern[epnum[epchn]][c*4] < LASTNOTE) && + (song.pattern[epnum[epchn]][c*4] >= FIRSTNOTE)) + song.pattern[epnum[epchn]][c*4]++; } } } @@ -557,9 +552,9 @@ void patterncommands() for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= getPattlen(epnum[epmarkchn])) break; - if ((pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && - (pattern[epnum[epmarkchn]][c*4] > FIRSTNOTE)) - pattern[epnum[epmarkchn]][c*4]--; + if ((song.pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && + (song.pattern[epnum[epmarkchn]][c*4] > FIRSTNOTE)) + song.pattern[epnum[epmarkchn]][c*4]--; } } else @@ -567,9 +562,9 @@ void patterncommands() for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= getPattlen(epnum[epmarkchn])) break; - if ((pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && - (pattern[epnum[epmarkchn]][c*4] > FIRSTNOTE)) - pattern[epnum[epmarkchn]][c*4]--; + if ((song.pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && + (song.pattern[epnum[epmarkchn]][c*4] > FIRSTNOTE)) + song.pattern[epnum[epmarkchn]][c*4]--; } } } @@ -577,9 +572,9 @@ void patterncommands() { for (int c = 0; c < getPattlen(epnum[epchn]); c++) { - if ((pattern[epnum[epchn]][c*4] <= LASTNOTE) && - (pattern[epnum[epchn]][c*4] > FIRSTNOTE)) - pattern[epnum[epchn]][c*4]--; + if ((song.pattern[epnum[epchn]][c*4] <= LASTNOTE) && + (song.pattern[epnum[epchn]][c*4] > FIRSTNOTE)) + song.pattern[epnum[epchn]][c*4]--; } } } @@ -595,12 +590,12 @@ void patterncommands() for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= getPattlen(epnum[epmarkchn])) break; - if ((pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && - (pattern[epnum[epmarkchn]][c*4] >= FIRSTNOTE)) + if ((song.pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && + (song.pattern[epnum[epmarkchn]][c*4] >= FIRSTNOTE)) { - pattern[epnum[epmarkchn]][c*4] += 12; - if (pattern[epnum[epmarkchn]][c*4] > LASTNOTE) - pattern[epnum[epmarkchn]][c*4] = LASTNOTE; + song.pattern[epnum[epmarkchn]][c*4] += 12; + if (song.pattern[epnum[epmarkchn]][c*4] > LASTNOTE) + song.pattern[epnum[epmarkchn]][c*4] = LASTNOTE; } } } @@ -609,12 +604,12 @@ void patterncommands() for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= getPattlen(epnum[epmarkchn])) break; - if ((pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && - (pattern[epnum[epmarkchn]][c*4] >= FIRSTNOTE)) + if ((song.pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && + (song.pattern[epnum[epmarkchn]][c*4] >= FIRSTNOTE)) { - pattern[epnum[epmarkchn]][c*4] += 12; - if (pattern[epnum[epmarkchn]][c*4] > LASTNOTE) - pattern[epnum[epmarkchn]][c*4] = LASTNOTE; + song.pattern[epnum[epmarkchn]][c*4] += 12; + if (song.pattern[epnum[epmarkchn]][c*4] > LASTNOTE) + song.pattern[epnum[epmarkchn]][c*4] = LASTNOTE; } } } @@ -623,12 +618,12 @@ void patterncommands() { for (int c = 0; c < getPattlen(epnum[epchn]); c++) { - if ((pattern[epnum[epchn]][c*4] <= LASTNOTE) && - (pattern[epnum[epchn]][c*4] >= FIRSTNOTE)) + if ((song.pattern[epnum[epchn]][c*4] <= LASTNOTE) && + (song.pattern[epnum[epchn]][c*4] >= FIRSTNOTE)) { - pattern[epnum[epchn]][c*4] += 12; - if (pattern[epnum[epchn]][c*4] > LASTNOTE) - pattern[epnum[epchn]][c*4] = LASTNOTE; + song.pattern[epnum[epchn]][c*4] += 12; + if (song.pattern[epnum[epchn]][c*4] > LASTNOTE) + song.pattern[epnum[epchn]][c*4] = LASTNOTE; } } } @@ -645,12 +640,12 @@ void patterncommands() for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= getPattlen(epnum[epmarkchn])) break; - if ((pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && - (pattern[epnum[epmarkchn]][c*4] >= FIRSTNOTE)) + if ((song.pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && + (song.pattern[epnum[epmarkchn]][c*4] >= FIRSTNOTE)) { - pattern[epnum[epmarkchn]][c*4] -= 12; - if (pattern[epnum[epmarkchn]][c*4] < FIRSTNOTE) - pattern[epnum[epmarkchn]][c*4] = FIRSTNOTE; + song.pattern[epnum[epmarkchn]][c*4] -= 12; + if (song.pattern[epnum[epmarkchn]][c*4] < FIRSTNOTE) + song.pattern[epnum[epmarkchn]][c*4] = FIRSTNOTE; } } } @@ -659,12 +654,12 @@ void patterncommands() for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= getPattlen(epnum[epmarkchn])) break; - if ((pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && - (pattern[epnum[epmarkchn]][c*4] >= FIRSTNOTE)) + if ((song.pattern[epnum[epmarkchn]][c*4] <= LASTNOTE) && + (song.pattern[epnum[epmarkchn]][c*4] >= FIRSTNOTE)) { - pattern[epnum[epmarkchn]][c*4] -= 12; - if (pattern[epnum[epmarkchn]][c*4] < FIRSTNOTE) - pattern[epnum[epmarkchn]][c*4] = FIRSTNOTE; + song.pattern[epnum[epmarkchn]][c*4] -= 12; + if (song.pattern[epnum[epmarkchn]][c*4] < FIRSTNOTE) + song.pattern[epnum[epmarkchn]][c*4] = FIRSTNOTE; } } } @@ -673,12 +668,12 @@ void patterncommands() { for (int c = 0; c < getPattlen(epnum[epchn]); c++) { - if ((pattern[epnum[epchn]][c*4] <= LASTNOTE) && - (pattern[epnum[epchn]][c*4] >= FIRSTNOTE)) + if ((song.pattern[epnum[epchn]][c*4] <= LASTNOTE) && + (song.pattern[epnum[epchn]][c*4] >= FIRSTNOTE)) { - pattern[epnum[epchn]][c*4] -= 12; - if (pattern[epnum[epchn]][c*4] < FIRSTNOTE) - pattern[epnum[epchn]][c*4] = FIRSTNOTE; + song.pattern[epnum[epchn]][c*4] -= 12; + if (song.pattern[epnum[epchn]][c*4] < FIRSTNOTE) + song.pattern[epnum[epchn]][c*4] = FIRSTNOTE; } } } @@ -705,24 +700,24 @@ void patterncommands() if (shiftpressed) { int c; - switch (pattern[epnum[epchn]][eppos*4+2]) + switch (song.pattern[epnum[epchn]][eppos*4+2]) { case CMD_PORTAUP: case CMD_PORTADOWN: case CMD_VIBRATO: case CMD_TONEPORTA: - if (pattern[epnum[epchn]][eppos*4+2] == CMD_TONEPORTA) + if (song.pattern[epnum[epchn]][eppos*4+2] == CMD_TONEPORTA) c = eppos-1; else c = eppos; for (; c >= 0; c--) { - if ((pattern[epnum[epchn]][c*4] >= FIRSTNOTE) && - (pattern[epnum[epchn]][c*4] <= LASTNOTE)) + if ((song.pattern[epnum[epchn]][c*4] >= FIRSTNOTE) && + (song.pattern[epnum[epchn]][c*4] <= LASTNOTE)) { - int note = pattern[epnum[epchn]][c*4] - FIRSTNOTE; - int right = pattern[epnum[epchn]][eppos*4+3] & 0xf; - int left = pattern[epnum[epchn]][eppos*4+3] >> 4; + int note = song.pattern[epnum[epchn]][c*4] - FIRSTNOTE; + int right = song.pattern[epnum[epchn]][eppos*4+3] & 0xf; + int left = song.pattern[epnum[epchn]][eppos*4+3] >> 4; if (note > MAX_NOTES-1) note--; int pitch1 = freqtbllo[note] | (freqtblhi[note] << 8); @@ -732,12 +727,12 @@ void patterncommands() while (left--) delta <<= 1; while (right--) delta >>= 1; - if (pattern[epnum[epchn]][eppos*4+2] == CMD_VIBRATO) + if (song.pattern[epnum[epchn]][eppos*4+2] == CMD_VIBRATO) { if (delta > 0xff) delta = 0xff; } int pos = makespeedtable(delta, MST_RAW, true); - pattern[epnum[epchn]][eppos*4+3] = pos + 1; + song.pattern[epnum[epchn]][eppos*4+3] = pos + 1; break; } } @@ -771,16 +766,16 @@ void patterncommands() for (int c = epmarkstart; c <= epmarkend; c++) { if (c >= getPattlen(epnum[epmarkchn])) break; - patterncopybuffer[d*4] = pattern[epnum[epmarkchn]][c*4]; - patterncopybuffer[d*4+1] = pattern[epnum[epmarkchn]][c*4+1]; - patterncopybuffer[d*4+2] = pattern[epnum[epmarkchn]][c*4+2]; - patterncopybuffer[d*4+3] = pattern[epnum[epmarkchn]][c*4+3]; + patterncopybuffer[d*4] = song.pattern[epnum[epmarkchn]][c*4]; + patterncopybuffer[d*4+1] = song.pattern[epnum[epmarkchn]][c*4+1]; + patterncopybuffer[d*4+2] = song.pattern[epnum[epmarkchn]][c*4+2]; + patterncopybuffer[d*4+3] = song.pattern[epnum[epmarkchn]][c*4+3]; if (rawkey == KEY_X) { - pattern[epnum[epmarkchn]][c*4] = REST; - pattern[epnum[epmarkchn]][c*4+1] = 0; - pattern[epnum[epmarkchn]][c*4+2] = 0; - pattern[epnum[epmarkchn]][c*4+3] = 0; + song.pattern[epnum[epmarkchn]][c*4] = REST; + song.pattern[epnum[epmarkchn]][c*4+1] = 0; + song.pattern[epnum[epmarkchn]][c*4+2] = 0; + song.pattern[epnum[epmarkchn]][c*4+3] = 0; } d++; } @@ -792,16 +787,16 @@ void patterncommands() for (int c = epmarkend; c <= epmarkstart; c++) { if (c >= getPattlen(epnum[epmarkchn])) break; - patterncopybuffer[d*4] = pattern[epnum[epmarkchn]][c*4]; - patterncopybuffer[d*4+1] = pattern[epnum[epmarkchn]][c*4+1]; - patterncopybuffer[d*4+2] = pattern[epnum[epmarkchn]][c*4+2]; - patterncopybuffer[d*4+3] = pattern[epnum[epmarkchn]][c*4+3]; + patterncopybuffer[d*4] = song.pattern[epnum[epmarkchn]][c*4]; + patterncopybuffer[d*4+1] = song.pattern[epnum[epmarkchn]][c*4+1]; + patterncopybuffer[d*4+2] = song.pattern[epnum[epmarkchn]][c*4+2]; + patterncopybuffer[d*4+3] = song.pattern[epnum[epmarkchn]][c*4+3]; if (rawkey == KEY_X) { - pattern[epnum[epmarkchn]][c*4] = REST; - pattern[epnum[epmarkchn]][c*4+1] = 0; - pattern[epnum[epmarkchn]][c*4+2] = 0; - pattern[epnum[epmarkchn]][c*4+3] = 0; + song.pattern[epnum[epmarkchn]][c*4] = REST; + song.pattern[epnum[epmarkchn]][c*4+1] = 0; + song.pattern[epnum[epmarkchn]][c*4+2] = 0; + song.pattern[epnum[epmarkchn]][c*4+3] = 0; } d++; } @@ -814,16 +809,16 @@ void patterncommands() int d = 0; for (int c = 0; c < getPattlen(epnum[epchn]); c++) { - patterncopybuffer[d*4] = pattern[epnum[epchn]][c*4]; - patterncopybuffer[d*4+1] = pattern[epnum[epchn]][c*4+1]; - patterncopybuffer[d*4+2] = pattern[epnum[epchn]][c*4+2]; - patterncopybuffer[d*4+3] = pattern[epnum[epchn]][c*4+3]; + patterncopybuffer[d*4] = song.pattern[epnum[epchn]][c*4]; + patterncopybuffer[d*4+1] = song.pattern[epnum[epchn]][c*4+1]; + patterncopybuffer[d*4+2] = song.pattern[epnum[epchn]][c*4+2]; + patterncopybuffer[d*4+3] = song.pattern[epnum[epchn]][c*4+3]; if (rawkey == KEY_X) { - pattern[epnum[epchn]][c*4] = REST; - pattern[epnum[epchn]][c*4+1] = 0; - pattern[epnum[epchn]][c*4+2] = 0; - pattern[epnum[epchn]][c*4+3] = 0; + song.pattern[epnum[epchn]][c*4] = REST; + song.pattern[epnum[epchn]][c*4+1] = 0; + song.pattern[epnum[epchn]][c*4+2] = 0; + song.pattern[epnum[epchn]][c*4+3] = 0; } d++; } @@ -838,10 +833,10 @@ void patterncommands() for (int c = 0; c < patterncopyrows; c++) { if (eppos >= getPattlen(epnum[epchn])) break; - pattern[epnum[epchn]][eppos*4] = patterncopybuffer[c*4]; - pattern[epnum[epchn]][eppos*4+1] = patterncopybuffer[c*4+1]; - pattern[epnum[epchn]][eppos*4+2] = patterncopybuffer[c*4+2]; - pattern[epnum[epchn]][eppos*4+3] = patterncopybuffer[c*4+3]; + song.pattern[epnum[epchn]][eppos*4] = patterncopybuffer[c*4]; + song.pattern[epnum[epchn]][eppos*4+1] = patterncopybuffer[c*4+1]; + song.pattern[epnum[epchn]][eppos*4+2] = patterncopybuffer[c*4+2]; + song.pattern[epnum[epchn]][eppos*4+3] = patterncopybuffer[c*4+3]; eppos++; } } @@ -851,13 +846,13 @@ void patterncommands() if (epmarkchn == epchn) epmarkchn = -1; if ((getPattlen(epnum[epchn])-eppos)*4-4 >= 0) { - std::memmove(&pattern[epnum[epchn]][eppos*4], - &pattern[epnum[epchn]][eppos*4+4], + std::memmove(&song.pattern[epnum[epchn]][eppos*4], + &song.pattern[epnum[epchn]][eppos*4+4], (getPattlen(epnum[epchn])-eppos)*4-4); - pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-4] = REST; - pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-3] = 0x00; - pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-2] = 0x00; - pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-1] = 0x00; + song.pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-4] = REST; + song.pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-3] = 0x00; + song.pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-2] = 0x00; + song.pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-1] = 0x00; } else { @@ -865,10 +860,10 @@ void patterncommands() { if (getPattlen(epnum[epchn]) > 1) { - pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-4] = ENDPATT; - pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-3] = 0x00; - pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-2] = 0x00; - pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-1] = 0x00; + song.pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-4] = ENDPATT; + song.pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-3] = 0x00; + song.pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-2] = 0x00; + song.pattern[epnum[epchn]][getPattlen(epnum[epchn])*4-1] = 0x00; countthispattern(); eppos = getPattlen(epnum[epchn]); } @@ -880,13 +875,13 @@ void patterncommands() if (epmarkchn == epchn) epmarkchn = -1; if ((getPattlen(epnum[epchn])-eppos)*4-4 >= 0) { - std::memmove(&pattern[epnum[epchn]][eppos*4+4], - &pattern[epnum[epchn]][eppos*4], + std::memmove(&song.pattern[epnum[epchn]][eppos*4+4], + &song.pattern[epnum[epchn]][eppos*4], (getPattlen(epnum[epchn])-eppos)*4-4); - pattern[epnum[epchn]][eppos*4] = REST; - pattern[epnum[epchn]][eppos*4+1] = 0x00; - pattern[epnum[epchn]][eppos*4+2] = 0x00; - pattern[epnum[epchn]][eppos*4+3] = 0x00; + song.pattern[epnum[epchn]][eppos*4] = REST; + song.pattern[epnum[epchn]][eppos*4+1] = 0x00; + song.pattern[epnum[epchn]][eppos*4+2] = 0x00; + song.pattern[epnum[epchn]][eppos*4+3] = 0x00; } else { @@ -894,14 +889,14 @@ void patterncommands() { if (getPattlen(epnum[epchn]) < MAX_PATTROWS) { - pattern[epnum[epchn]][eppos*4] = REST; - pattern[epnum[epchn]][eppos*4+1] = 0x00; - pattern[epnum[epchn]][eppos*4+2] = 0x00; - pattern[epnum[epchn]][eppos*4+3] = 0x00; - pattern[epnum[epchn]][eppos*4+4] = ENDPATT; - pattern[epnum[epchn]][eppos*4+5] = 0x00; - pattern[epnum[epchn]][eppos*4+6] = 0x00; - pattern[epnum[epchn]][eppos*4+7] = 0x00; + song.pattern[epnum[epchn]][eppos*4] = REST; + song.pattern[epnum[epchn]][eppos*4+1] = 0x00; + song.pattern[epnum[epchn]][eppos*4+2] = 0x00; + song.pattern[epnum[epchn]][eppos*4+3] = 0x00; + song.pattern[epnum[epchn]][eppos*4+4] = ENDPATT; + song.pattern[epnum[epchn]][eppos*4+5] = 0x00; + song.pattern[epnum[epchn]][eppos*4+6] = 0x00; + song.pattern[epnum[epchn]][eppos*4+7] = 0x00; countthispattern(); eppos = getPattlen(epnum[epchn]); } @@ -920,7 +915,7 @@ void patterncommands() { for (int c = 0; c < maxChns; c++) { - if (eseditpos < songlen[esnum][c]) espos[c] = eseditpos; + if (eseditpos < song.len[esnum][c]) espos[c] = eseditpos; if (esend[c] <= espos[c]) esend[c] = 0; } } @@ -1035,7 +1030,7 @@ void patterncommands() } if ((keypreset == KEY_DMC) && (hexnybble >= 0) && (hexnybble <= 7) && (!epcolumn)) { - int oldbyte = pattern[epnum[epchn]][eppos*4]; + int oldbyte = song.pattern[epnum[epchn]][eppos*4]; epoctave = hexnybble; if ((oldbyte >= FIRSTNOTE) && (oldbyte <= LASTNOTE)) { @@ -1047,7 +1042,7 @@ void patterncommands() newbyte = oldnote+epoctave*12 + FIRSTNOTE; if (newbyte <= LASTNOTE) { - pattern[epnum[epchn]][eppos*4] = newbyte; + song.pattern[epnum[epchn]][eppos*4] = newbyte; } } if (recordmode && (autoadvance < 1)) @@ -1068,35 +1063,35 @@ void patterncommands() switch(epcolumn) { case 1: - pattern[epnum[epchn]][eppos*4+1] &= 0x0f; - pattern[epnum[epchn]][eppos*4+1] |= hexnybble << 4; - pattern[epnum[epchn]][eppos*4+1] &= (MAX_INSTR - 1); + song.pattern[epnum[epchn]][eppos*4+1] &= 0x0f; + song.pattern[epnum[epchn]][eppos*4+1] |= hexnybble << 4; + song.pattern[epnum[epchn]][eppos*4+1] &= (MAX_INSTR - 1); break; case 2: - pattern[epnum[epchn]][eppos*4+1] &= 0xf0; - pattern[epnum[epchn]][eppos*4+1] |= hexnybble; - pattern[epnum[epchn]][eppos*4+1] &= (MAX_INSTR - 1); + song.pattern[epnum[epchn]][eppos*4+1] &= 0xf0; + song.pattern[epnum[epchn]][eppos*4+1] |= hexnybble; + song.pattern[epnum[epchn]][eppos*4+1] &= (MAX_INSTR - 1); break; case 3: - pattern[epnum[epchn]][eppos*4+2] = hexnybble; - if (!pattern[epnum[epchn]][eppos*4+2]) - pattern[epnum[epchn]][eppos*4+3] = 0; + song.pattern[epnum[epchn]][eppos*4+2] = hexnybble; + if (!song.pattern[epnum[epchn]][eppos*4+2]) + song.pattern[epnum[epchn]][eppos*4+3] = 0; break; case 4: - pattern[epnum[epchn]][eppos*4+3] &= 0x0f; - pattern[epnum[epchn]][eppos*4+3] |= hexnybble << 4; - if (!pattern[epnum[epchn]][eppos*4+2]) - pattern[epnum[epchn]][eppos*4+3] = 0; + song.pattern[epnum[epchn]][eppos*4+3] &= 0x0f; + song.pattern[epnum[epchn]][eppos*4+3] |= hexnybble << 4; + if (!song.pattern[epnum[epchn]][eppos*4+2]) + song.pattern[epnum[epchn]][eppos*4+3] = 0; break; case 5: - pattern[epnum[epchn]][eppos*4+3] &= 0xf0; - pattern[epnum[epchn]][eppos*4+3] |= hexnybble; - if (!pattern[epnum[epchn]][eppos*4+2]) - pattern[epnum[epchn]][eppos*4+3] = 0; + song.pattern[epnum[epchn]][eppos*4+3] &= 0xf0; + song.pattern[epnum[epchn]][eppos*4+3] |= hexnybble; + if (!song.pattern[epnum[epchn]][eppos*4+2]) + song.pattern[epnum[epchn]][eppos*4+3] = 0; break; } } @@ -1183,16 +1178,16 @@ void shrinkpattern() for (int d = 0; d < nl; d++) { - pattern[c][d*4] = pattern[c][d*2*4]; - pattern[c][d*4+1] = pattern[c][d*2*4+1]; - pattern[c][d*4+2] = pattern[c][d*2*4+2]; - pattern[c][d*4+3] = pattern[c][d*2*4+3]; + song.pattern[c][d*4] = song.pattern[c][d*2*4]; + song.pattern[c][d*4+1] = song.pattern[c][d*2*4+1]; + song.pattern[c][d*4+2] = song.pattern[c][d*2*4+2]; + song.pattern[c][d*4+3] = song.pattern[c][d*2*4+3]; } - pattern[c][nl*4] = ENDPATT; - pattern[c][nl*4+1] = 0; - pattern[c][nl*4+2] = 0; - pattern[c][nl*4+3] = 0; + song.pattern[c][nl*4] = ENDPATT; + song.pattern[c][nl*4+1] = 0; + song.pattern[c][nl*4+2] = 0; + song.pattern[c][nl*4+3] = 0; eppos /= 2; @@ -1222,14 +1217,14 @@ void expandpattern() } else { - temp[d*4] = pattern[c][d*2]; - temp[d*4+1] = pattern[c][d*2+1]; - temp[d*4+2] = pattern[c][d*2+2]; - temp[d*4+3] = pattern[c][d*2+3]; + temp[d*4] = song.pattern[c][d*2]; + temp[d*4+1] = song.pattern[c][d*2+1]; + temp[d*4+2] = song.pattern[c][d*2+2]; + temp[d*4+3] = song.pattern[c][d*2+3]; } } - std::memcpy(pattern[c], temp, (nl+1)*4); + std::memcpy(song.pattern[c], temp, (nl+1)*4); eppos *= 2; @@ -1254,15 +1249,15 @@ void splitpattern() for (int d = eppos; d <= l; d++) { - pattern[c+1][(d-eppos)*4] = pattern[c][d*4]; - pattern[c+1][(d-eppos)*4+1] = pattern[c][d*4+1]; - pattern[c+1][(d-eppos)*4+2] = pattern[c][d*4+2]; - pattern[c+1][(d-eppos)*4+3] = pattern[c][d*4+3]; + song.pattern[c+1][(d-eppos)*4] = song.pattern[c][d*4]; + song.pattern[c+1][(d-eppos)*4+1] = song.pattern[c][d*4+1]; + song.pattern[c+1][(d-eppos)*4+2] = song.pattern[c][d*4+2]; + song.pattern[c+1][(d-eppos)*4+3] = song.pattern[c][d*4+3]; } - pattern[c][eppos*4] = ENDPATT; - pattern[c][eppos*4+1] = 0; - pattern[c][eppos*4+2] = 0; - pattern[c][eppos*4+3] = 0; + song.pattern[c][eppos*4] = ENDPATT; + song.pattern[c][eppos*4+1] = 0; + song.pattern[c][eppos*4+2] = 0; + song.pattern[c][eppos*4+3] = 0; countpatternlengths(); @@ -1270,11 +1265,11 @@ void splitpattern() { for (eschn = 0; eschn < maxChns; eschn++) { - for (eseditpos = 0; eseditpos < songlen[esnum][eschn]; eseditpos++) + for (eseditpos = 0; eseditpos < song.len[esnum][eschn]; eseditpos++) { - if (songorder[esnum][eschn][eseditpos] == c) + if (song.order[esnum][eschn][eseditpos] == c) { - songorder[esnum][eschn][eseditpos] = c+1; + song.order[esnum][eschn][eseditpos] = c+1; insertorder(c); } } @@ -1292,9 +1287,9 @@ void joinpattern() int maxChns = getMaxChannels(); if (eschn != epchn) return; - if (songorder[esnum][epchn][eseditpos] != c) return; + if (song.order[esnum][epchn][eseditpos] != c) return; - int d = songorder[esnum][epchn][eseditpos + 1]; + int d = song.order[esnum][epchn][eseditpos + 1]; if (d >= MAX_PATT) return; if (getPattlen(c) + getPattlen(d) > MAX_PATTROWS) return; @@ -1310,23 +1305,23 @@ void joinpattern() int e; for (e = 0; e < getPattlen(c); e++) { - pattern[c+1][e*4] = pattern[c][e*4]; - pattern[c+1][e*4+1] = pattern[c][e*4+1]; - pattern[c+1][e*4+2] = pattern[c][e*4+2]; - pattern[c+1][e*4+3] = pattern[c][e*4+3]; + song.pattern[c+1][e*4] = song.pattern[c][e*4]; + song.pattern[c+1][e*4+1] = song.pattern[c][e*4+1]; + song.pattern[c+1][e*4+2] = song.pattern[c][e*4+2]; + song.pattern[c+1][e*4+3] = song.pattern[c][e*4+3]; } for (int f = 0; f < getPattlen(d); f++) { - pattern[c+1][e*4] = pattern[d][f*4]; - pattern[c+1][e*4+1] = pattern[d][f*4+1]; - pattern[c+1][e*4+2] = pattern[d][f*4+2]; - pattern[c+1][e*4+3] = pattern[d][f*4+3]; - e++; + song.pattern[c+1][e*4] = song.pattern[d][f*4]; + song.pattern[c+1][e*4+1] = song.pattern[d][f*4+1]; + song.pattern[c+1][e*4+2] = song.pattern[d][f*4+2]; + song.pattern[c+1][e*4+3] = song.pattern[d][f*4+3]; + e++; } - pattern[c+1][e*4] = ENDPATT; - pattern[c+1][e*4+1] = 0; - pattern[c+1][e*4+2] = 0; - pattern[c+1][e*4+3] = 0; + song.pattern[c+1][e*4] = ENDPATT; + song.pattern[c+1][e*4+1] = 0; + song.pattern[c+1][e*4+2] = 0; + song.pattern[c+1][e*4+3] = 0; countpatternlengths(); @@ -1334,12 +1329,12 @@ void joinpattern() { for (eschn = 0; eschn < maxChns; eschn++) { - for (eseditpos = 0; eseditpos < songlen[esnum][eschn]; eseditpos++) + for (eseditpos = 0; eseditpos < song.len[esnum][eschn]; eseditpos++) { - if ((songorder[esnum][eschn][eseditpos] == c) && (songorder[esnum][eschn][eseditpos+1] == d)) + if ((song.order[esnum][eschn][eseditpos] == c) && (song.order[esnum][eschn][eseditpos+1] == d)) { deleteorder(); - songorder[esnum][eschn][eseditpos] = c+1; + song.order[esnum][eschn][eseditpos] = c+1; } } } diff --git a/src/play.cpp b/src/play.cpp index a6b6e09..638e438 100644 --- a/src/play.cpp +++ b/src/play.cpp @@ -152,10 +152,10 @@ void playtestnote(int note, int ins, int chnnum) return; } - if (!(instr[ins].gatetimer & 0x40)) + if (!(song.instr[ins].gatetimer & 0x40)) { chn[chnnum].gate = 0xfe; // Keyoff - if (!(instr[ins].gatetimer & 0x80)) + if (!(song.instr[ins].gatetimer & 0x80)) { if (chnnum < 3) { @@ -174,8 +174,8 @@ void playtestnote(int note, int ins, int chnnum) chn[chnnum].newnote = note; if (songinit == PLAY_STOPPED) { - chn[chnnum].tick = (instr[ins].gatetimer & 0x3f)+1; - chn[chnnum].gatetimer = instr[ins].gatetimer & 0x3f; + chn[chnnum].tick = (song.instr[ins].gatetimer & 0x3f)+1; + chn[chnnum].gatetimer = song.instr[ins].gatetimer & 0x3f; } } @@ -213,7 +213,7 @@ void playroutine() if ((songinit == PLAY_POS) || (songinit == PLAY_PATTERN)) { - if ((espos[0] >= songlen[psnum][0]) || (espos[1] >= songlen[psnum][1]) || (espos[2] >= songlen[psnum][2])) + if ((espos[0] >= song.len[psnum][0]) || (espos[1] >= song.len[psnum][1]) || (espos[2] >= song.len[psnum][2])) songinit = PLAY_BEGINNING; } @@ -233,7 +233,7 @@ void playroutine() cptr->tick = 6*multiplier-1; else cptr->tick = 6-1; - cptr->gatetimer = instr[1].gatetimer & 0x3f; + cptr->gatetimer = song.instr[1].gatetimer & 0x3f; cptr->pattptr = 0x7fffffff; if (cptr->tempo < 2) cptr->tempo = 0; @@ -252,8 +252,8 @@ void playroutine() funktable[1] = 6-1; cptr->tempo = 6-1; } - if ((instr[MAX_INSTR-1].ad >= 2) && (!(instr[MAX_INSTR-1].ptr[WTBL]))) - cptr->tempo = instr[MAX_INSTR-1].ad - 1; + if ((song.instr[MAX_INSTR-1].ad >= 2) && (!(song.instr[MAX_INSTR-1].ptr[WTBL]))) + cptr->tempo = song.instr[MAX_INSTR-1].ad - 1; cptr->trans = 0; cptr->instr = 1; sequencer(c, cptr); @@ -278,7 +278,7 @@ void playroutine() songinit = PLAY_PLAYING; else songinit = PLAY_STOPPED; - if ((!songlen[psnum][0]) || (!songlen[psnum][1]) || (!songlen[psnum][2])) + if ((!song.len[psnum][0]) || (!song.len[psnum][1]) || (!song.len[psnum][2])) songinit = PLAY_STOPPED; // Zero length song startpattpos = 0; @@ -288,36 +288,36 @@ void playroutine() if (filterptr) { // Filter jump - if (ltable[FTBL][filterptr-1] == 0xff) + if (song.ltable[FTBL][filterptr-1] == 0xff) { - filterptr = rtable[FTBL][filterptr-1]; + filterptr = song.rtable[FTBL][filterptr-1]; if (!filterptr) goto FILTERSTOP; } if (!filtertime) { // Filter set - if (ltable[FTBL][filterptr-1] >= 0x80) + if (song.ltable[FTBL][filterptr-1] >= 0x80) { - filtertype = ltable[FTBL][filterptr-1] & 0x70; - filterctrl = rtable[FTBL][filterptr-1]; + filtertype = song.ltable[FTBL][filterptr-1] & 0x70; + filterctrl = song.rtable[FTBL][filterptr-1]; filterptr++; // Can be combined with cutoff set - if (ltable[FTBL][filterptr-1] == 0x00) + if (song.ltable[FTBL][filterptr-1] == 0x00) { - filtercutoff = rtable[FTBL][filterptr-1]; + filtercutoff = song.rtable[FTBL][filterptr-1]; filterptr++; } } else { // New modulation step - if (ltable[FTBL][filterptr-1]) - filtertime = ltable[FTBL][filterptr-1]; + if (song.ltable[FTBL][filterptr-1]) + filtertime = song.ltable[FTBL][filterptr-1]; else { // Cutoff set - filtercutoff = rtable[FTBL][filterptr-1]; + filtercutoff = song.rtable[FTBL][filterptr-1]; filterptr++; } } @@ -325,7 +325,7 @@ void playroutine() // Filter modulation if (filtertime) { - filtercutoff += rtable[FTBL][filterptr-1]; + filtercutoff += song.rtable[FTBL][filterptr-1]; filtertime--; if (!filtertime) filterptr++; } @@ -338,7 +338,7 @@ void playroutine() for (int c = 0; c < MAX_CHN_MONO; c++) { - iptr = &instr[cptr->instr]; + iptr = &song.instr[cptr->instr]; // Reset tempo in jammode if ((songinit == PLAY_STOPPED) && (cptr->tempo < 2)) @@ -404,7 +404,7 @@ void playroutine() if (cptr->ptr[WTBL]) { // Stop the song in case of jumping into a jump - if (ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) + if (song.ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) stopsong(); } if (iptr->ptr[PTBL]) @@ -414,7 +414,7 @@ void playroutine() if (cptr->ptr[PTBL]) { // Stop the song in case of jumping into a jump - if (ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) + if (song.ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) stopsong(); } } @@ -425,7 +425,7 @@ void playroutine() if (filterptr) { // Stop the song in case of jumping into a jump - if (ltable[FTBL][filterptr-1] == 0xff) + if (song.ltable[FTBL][filterptr-1] == 0xff) stopsong(); } } @@ -474,7 +474,7 @@ void playroutine() if (cptr->ptr[WTBL]) { // Stop the song in case of jumping into a jump - if (ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) + if (song.ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) stopsong(); } break; @@ -485,7 +485,7 @@ void playroutine() if (cptr->ptr[PTBL]) { // Stop the song in case of jumping into a jump - if (ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) + if (song.ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) stopsong(); } break; @@ -496,7 +496,7 @@ void playroutine() if (filterptr) { // Stop the song in case of jumping into a jump - if (ltable[FTBL][filterptr-1] == 0xff) + if (song.ltable[FTBL][filterptr-1] == 0xff) stopsong(); } break; @@ -518,8 +518,8 @@ void playroutine() case CMD_FUNKTEMPO: if (cptr->newcmddata) { - funktable[0] = ltable[STBL][cptr->newcmddata-1]-1; - funktable[1] = rtable[STBL][cptr->newcmddata-1]-1; + funktable[0] = song.ltable[STBL][cptr->newcmddata-1]-1; + funktable[1] = song.rtable[STBL][cptr->newcmddata-1]-1; } chn[0].tempo = 0; chn[1].tempo = 0; @@ -551,8 +551,8 @@ void playroutine() WAVEEXEC: if (cptr->ptr[WTBL]) { - unsigned char wave = ltable[WTBL][cptr->ptr[WTBL]-1]; - unsigned char note = rtable[WTBL][cptr->ptr[WTBL]-1]; + unsigned char wave = song.ltable[WTBL][cptr->ptr[WTBL]-1]; + unsigned char note = song.rtable[WTBL][cptr->ptr[WTBL]-1]; if (wave > WAVELASTDELAY) { @@ -563,7 +563,7 @@ void playroutine() // Command execution from wavetable if ((wave >= WAVECMD) && (wave <= WAVELASTCMD)) { - unsigned char param = rtable[WTBL][cptr->ptr[WTBL]-1]; + unsigned char param = song.rtable[WTBL][cptr->ptr[WTBL]-1]; switch (wave & 0xf) { case CMD_DONOTHING: @@ -577,13 +577,13 @@ void playroutine() unsigned short speed = 0; if (param) { - speed = (ltable[STBL][param-1] << 8) | rtable[STBL][param-1]; + speed = (song.ltable[STBL][param-1] << 8) | song.rtable[STBL][param-1]; } if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][param-1]; + speed >>= song.rtable[STBL][param-1]; } cptr->freq += speed; } @@ -594,13 +594,13 @@ void playroutine() unsigned short speed = 0; if (param) { - speed = (ltable[STBL][param-1] << 8) | rtable[STBL][param-1]; + speed = (song.ltable[STBL][param-1] << 8) | song.rtable[STBL][param-1]; } if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][param-1]; + speed >>= song.rtable[STBL][param-1]; } cptr->freq -= speed; } @@ -619,12 +619,12 @@ void playroutine() } else { - speed = (ltable[STBL][param-1] << 8) | rtable[STBL][param-1]; + speed = (song.ltable[STBL][param-1] << 8) | song.rtable[STBL][param-1]; if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][param-1]; + speed >>= song.rtable[STBL][param-1]; } if (cptr->freq < targetfreq) { @@ -657,15 +657,15 @@ void playroutine() if (param) { - cmpvalue = ltable[STBL][param-1]; - speed = rtable[STBL][param-1]; + cmpvalue = song.ltable[STBL][param-1]; + speed = song.rtable[STBL][param-1]; } if (cmpvalue >= 0x80) { cmpvalue &= 0x7f; speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][param-1]; + speed >>= song.rtable[STBL][param-1]; } if ((cptr->vibtime < 0x80) && (cptr->vibtime > cmpvalue)) @@ -696,7 +696,7 @@ void playroutine() if (cptr->ptr[PTBL]) { // Stop the song in case of jumping into a jump - if (ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) + if (song.ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) stopsong(); } break; @@ -707,7 +707,7 @@ void playroutine() if (filterptr) { // Stop the song in case of jumping into a jump - if (ltable[FTBL][filterptr-1] == 0xff) + if (song.ltable[FTBL][filterptr-1] == 0xff) stopsong(); } break; @@ -741,9 +741,9 @@ void playroutine() cptr->wavetime = 0; cptr->ptr[WTBL]++; // Wavetable jump - if (ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) + if (song.ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) { - cptr->ptr[WTBL] = rtable[WTBL][cptr->ptr[WTBL]-1]; + cptr->ptr[WTBL] = song.rtable[WTBL][cptr->ptr[WTBL]-1]; } if ((wave >= WAVECMD) && (wave <= WAVELASTCMD)) @@ -772,13 +772,13 @@ void playroutine() unsigned short speed = 0; if (cptr->cmddata) { - speed = (ltable[STBL][cptr->cmddata-1] << 8) | rtable[STBL][cptr->cmddata-1]; + speed = (song.ltable[STBL][cptr->cmddata-1] << 8) | song.rtable[STBL][cptr->cmddata-1]; } if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][cptr->cmddata-1]; + speed >>= song.rtable[STBL][cptr->cmddata-1]; } cptr->freq += speed; } @@ -789,13 +789,13 @@ void playroutine() unsigned short speed = 0; if (cptr->cmddata) { - speed = (ltable[STBL][cptr->cmddata-1] << 8) | rtable[STBL][cptr->cmddata-1]; + speed = (song.ltable[STBL][cptr->cmddata-1] << 8) | song.rtable[STBL][cptr->cmddata-1]; } if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][cptr->cmddata-1]; + speed >>= song.rtable[STBL][cptr->cmddata-1]; } cptr->freq -= speed; } @@ -817,15 +817,15 @@ void playroutine() if (cptr->cmddata) { - cmpvalue = ltable[STBL][cptr->cmddata-1]; - speed = rtable[STBL][cptr->cmddata-1]; + cmpvalue = song.ltable[STBL][cptr->cmddata-1]; + speed = song.rtable[STBL][cptr->cmddata-1]; } if (cmpvalue >= 0x80) { cmpvalue &= 0x7f; speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][cptr->cmddata-1]; + speed >>= song.rtable[STBL][cptr->cmddata-1]; } if ((cptr->vibtime < 0x80) && (cptr->vibtime > cmpvalue)) @@ -851,12 +851,12 @@ void playroutine() } else { - speed = (ltable[STBL][cptr->cmddata-1] << 8) | rtable[STBL][cptr->cmddata-1]; + speed = (song.ltable[STBL][cptr->cmddata-1] << 8) | song.rtable[STBL][cptr->cmddata-1]; if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][cptr->cmddata-1]; + speed >>= song.rtable[STBL][cptr->cmddata-1]; } if (cptr->freq < targetfreq) { @@ -899,30 +899,30 @@ void playroutine() } // Pulsetable jump - if (ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) + if (song.ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) { - cptr->ptr[PTBL] = rtable[PTBL][cptr->ptr[PTBL]-1]; + cptr->ptr[PTBL] = song.rtable[PTBL][cptr->ptr[PTBL]-1]; if (!cptr->ptr[PTBL]) goto PULSEEXEC; } if (!cptr->pulsetime) { // Set pulse - if (ltable[PTBL][cptr->ptr[PTBL]-1] >= 0x80) + if (song.ltable[PTBL][cptr->ptr[PTBL]-1] >= 0x80) { - cptr->pulse = (ltable[PTBL][cptr->ptr[PTBL]-1] & 0xf) << 8; - cptr->pulse |= rtable[PTBL][cptr->ptr[PTBL]-1]; + cptr->pulse = (song.ltable[PTBL][cptr->ptr[PTBL]-1] & 0xf) << 8; + cptr->pulse |= song.rtable[PTBL][cptr->ptr[PTBL]-1]; cptr->ptr[PTBL]++; } else { - cptr->pulsetime = ltable[PTBL][cptr->ptr[PTBL]-1]; + cptr->pulsetime = song.ltable[PTBL][cptr->ptr[PTBL]-1]; } } // Pulse modulation if (cptr->pulsetime) { - unsigned char speed = rtable[PTBL][cptr->ptr[PTBL]-1]; + unsigned char speed = song.rtable[PTBL][cptr->ptr[PTBL]-1]; if (speed < 0x80) { cptr->pulse += speed; @@ -945,13 +945,13 @@ void playroutine() { unsigned char newnote; - newnote = pattern[cptr->pattnum][cptr->pattptr]; - if (pattern[cptr->pattnum][cptr->pattptr+1]) - cptr->instr = pattern[cptr->pattnum][cptr->pattptr+1]; - cptr->newcommand = pattern[cptr->pattnum][cptr->pattptr+2]; - cptr->newcmddata = pattern[cptr->pattnum][cptr->pattptr+3]; + newnote = song.pattern[cptr->pattnum][cptr->pattptr]; + if (song.pattern[cptr->pattnum][cptr->pattptr+1]) + cptr->instr = song.pattern[cptr->pattnum][cptr->pattptr+1]; + cptr->newcommand = song.pattern[cptr->pattnum][cptr->pattptr+2]; + cptr->newcmddata = song.pattern[cptr->pattnum][cptr->pattptr+3]; cptr->pattptr += 4; - if (pattern[cptr->pattnum][cptr->pattptr] == ENDPATT) + if (song.pattern[cptr->pattnum][cptr->pattptr] == ENDPATT) cptr->pattptr = 0x7fffffff; if (newnote == KEYOFF) @@ -963,10 +963,10 @@ void playroutine() cptr->newnote = newnote+cptr->trans; if ((cptr->newcommand) != CMD_TONEPORTA) { - if (!(instr[cptr->instr].gatetimer & 0x40)) + if (!(song.instr[cptr->instr].gatetimer & 0x40)) { cptr->gate = 0xfe; - if (!(instr[cptr->instr].gatetimer & 0x80)) + if (!(song.instr[cptr->instr].gatetimer & 0x80)) { sidreg[0x5+7*c] = adparam>>8; sidreg[0x6+7*c] = adparam&0xff; @@ -999,10 +999,10 @@ void sequencer(int c, CHN *cptr) cptr->pattptr = startpattpos * 4; if (!cptr->advance) goto SEQDONE; // Song loop - if (songorder[psnum][c][cptr->songptr] == LOOPSONG) + if (song.order[psnum][c][cptr->songptr] == LOOPSONG) { - cptr->songptr = songorder[psnum][c][cptr->songptr+1]; - if (cptr->songptr >= songlen[psnum][c]) + cptr->songptr = song.order[psnum][c][cptr->songptr+1]; + if (cptr->songptr >= song.len[psnum][c]) { stopsong(); cptr->songptr = 0; @@ -1010,19 +1010,19 @@ void sequencer(int c, CHN *cptr) } } // Transpose - if ((songorder[psnum][c][cptr->songptr] >= TRANSDOWN) && (songorder[psnum][c][cptr->songptr] < LOOPSONG)) + if ((song.order[psnum][c][cptr->songptr] >= TRANSDOWN) && (song.order[psnum][c][cptr->songptr] < LOOPSONG)) { - cptr->trans = songorder[psnum][c][cptr->songptr]-TRANSUP; + cptr->trans = song.order[psnum][c][cptr->songptr]-TRANSUP; cptr->songptr++; } // Repeat - if ((songorder[psnum][c][cptr->songptr] >= REPEAT) && (songorder[psnum][c][cptr->songptr] < TRANSDOWN)) + if ((song.order[psnum][c][cptr->songptr] >= REPEAT) && (song.order[psnum][c][cptr->songptr] < TRANSDOWN)) { - cptr->repeat = songorder[psnum][c][cptr->songptr]-REPEAT; + cptr->repeat = song.order[psnum][c][cptr->songptr]-REPEAT; cptr->songptr++; } // Pattern number - cptr->pattnum = songorder[psnum][c][cptr->songptr]; + cptr->pattnum = song.order[psnum][c][cptr->songptr]; if (cptr->repeat) cptr->repeat--; else @@ -1038,7 +1038,7 @@ void sequencer(int c, CHN *cptr) cptr->pattptr = 0; // Check for playback endpos - if ((lastsonginit != PLAY_BEGINNING) && (esend[c] > 0) && (esend[c] > espos[c]) && (cptr->songptr > esend[c]) && (espos[c] < songlen[psnum][c])) + if ((lastsonginit != PLAY_BEGINNING) && (esend[c] > 0) && (esend[c] > espos[c]) && (cptr->songptr > esend[c]) && (espos[c] < song.len[psnum][c])) cptr->songptr = espos[c]; } SEQDONE: {} @@ -1069,7 +1069,7 @@ void playroutine_stereo() { for (int c = 0; c < MAX_CHN; c++) { - if (espos[c] >= songlen[psnum][c]) + if (espos[c] >= song.len[psnum][c]) songinit = PLAY_BEGINNING; } } @@ -1090,7 +1090,7 @@ void playroutine_stereo() cptr->tick = 6*multiplier-1; else cptr->tick = 6-1; - cptr->gatetimer = instr[1].gatetimer & 0x3f; + cptr->gatetimer = song.instr[1].gatetimer & 0x3f; cptr->pattptr = 0x7fffffff; if (cptr->tempo < 2) cptr->tempo = 0; @@ -1109,8 +1109,8 @@ void playroutine_stereo() funktable[1] = 6-1; cptr->tempo = 6-1; } - if ((instr[MAX_INSTR-1].ad >= 2) && (!(instr[MAX_INSTR-1].ptr[WTBL]))) - cptr->tempo = instr[MAX_INSTR-1].ad - 1; + if ((song.instr[MAX_INSTR-1].ad >= 2) && (!(song.instr[MAX_INSTR-1].ptr[WTBL]))) + cptr->tempo = song.instr[MAX_INSTR-1].ad - 1; cptr->trans = 0; cptr->instr = 1; sequencer_stereo(c, cptr); @@ -1135,8 +1135,8 @@ void playroutine_stereo() songinit = PLAY_PLAYING; else songinit = PLAY_STOPPED; - if ((!songlen[psnum][0]) || (!songlen[psnum][1]) || (!songlen[psnum][2]) || - (!songlen[psnum][3]) || (!songlen[psnum][4]) || (!songlen[psnum][5])) + if ((!song.len[psnum][0]) || (!song.len[psnum][1]) || (!song.len[psnum][2]) || + (!song.len[psnum][3]) || (!song.len[psnum][4]) || (!song.len[psnum][5])) songinit = PLAY_STOPPED; // Zero length song startpattpos = 0; @@ -1146,36 +1146,36 @@ void playroutine_stereo() if (filterptr) { // Filter jump - if (ltable[FTBL][filterptr-1] == 0xff) + if (song.ltable[FTBL][filterptr-1] == 0xff) { - filterptr = rtable[FTBL][filterptr-1]; + filterptr = song.rtable[FTBL][filterptr-1]; if (!filterptr) goto FILTERSTOP_S; } if (!filtertime) { // Filter set - if (ltable[FTBL][filterptr-1] >= 0x80) + if (song.ltable[FTBL][filterptr-1] >= 0x80) { - filtertype = ltable[FTBL][filterptr-1] & 0x70; - filterctrl = rtable[FTBL][filterptr-1]; + filtertype = song.ltable[FTBL][filterptr-1] & 0x70; + filterctrl = song.rtable[FTBL][filterptr-1]; filterptr++; // Can be combined with cutoff set - if (ltable[FTBL][filterptr-1] == 0x00) + if (song.ltable[FTBL][filterptr-1] == 0x00) { - filtercutoff = rtable[FTBL][filterptr-1]; + filtercutoff = song.rtable[FTBL][filterptr-1]; filterptr++; } } else { // New modulation step - if (ltable[FTBL][filterptr-1]) - filtertime = ltable[FTBL][filterptr-1]; + if (song.ltable[FTBL][filterptr-1]) + filtertime = song.ltable[FTBL][filterptr-1]; else { // Cutoff set - filtercutoff = rtable[FTBL][filterptr-1]; + filtercutoff = song.rtable[FTBL][filterptr-1]; filterptr++; } } @@ -1183,7 +1183,7 @@ void playroutine_stereo() // Filter modulation if (filtertime) { - filtercutoff += rtable[FTBL][filterptr-1]; + filtercutoff += song.rtable[FTBL][filterptr-1]; filtertime--; if (!filtertime) filterptr++; } @@ -1197,36 +1197,36 @@ void playroutine_stereo() if (filter2ptr) { // Filter jump - if (ltable[FTBL][filter2ptr-1] == 0xff) + if (song.ltable[FTBL][filter2ptr-1] == 0xff) { - filter2ptr = rtable[FTBL][filter2ptr-1]; + filter2ptr = song.rtable[FTBL][filter2ptr-1]; if (!filter2ptr) goto FILTER2STOP_S; } if (!filter2time) { // Filter set - if (ltable[FTBL][filter2ptr-1] >= 0x80) + if (song.ltable[FTBL][filter2ptr-1] >= 0x80) { - filter2type = ltable[FTBL][filter2ptr-1] & 0x70; - filter2ctrl = rtable[FTBL][filter2ptr-1]; + filter2type = song.ltable[FTBL][filter2ptr-1] & 0x70; + filter2ctrl = song.rtable[FTBL][filter2ptr-1]; filter2ptr++; // Can be combined with cutoff set - if (ltable[FTBL][filter2ptr-1] == 0x00) + if (song.ltable[FTBL][filter2ptr-1] == 0x00) { - filter2cutoff = rtable[FTBL][filter2ptr-1]; + filter2cutoff = song.rtable[FTBL][filter2ptr-1]; filter2ptr++; } } else { // New modulation step - if (ltable[FTBL][filter2ptr-1]) - filter2time = ltable[FTBL][filter2ptr-1]; + if (song.ltable[FTBL][filter2ptr-1]) + filter2time = song.ltable[FTBL][filter2ptr-1]; else { // Cutoff set - filter2cutoff = rtable[FTBL][filter2ptr-1]; + filter2cutoff = song.rtable[FTBL][filter2ptr-1]; filter2ptr++; } } @@ -1234,7 +1234,7 @@ void playroutine_stereo() // Filter modulation if (filter2time) { - filter2cutoff += rtable[FTBL][filter2ptr-1]; + filter2cutoff += song.rtable[FTBL][filter2ptr-1]; filter2time--; if (!filter2time) filter2ptr++; } @@ -1248,7 +1248,7 @@ void playroutine_stereo() for (int c = 0; c < MAX_CHN; c++) { - iptr = &instr[cptr->instr]; + iptr = &song.instr[cptr->instr]; // Reset tempo in jammode if ((songinit == PLAY_STOPPED) && (cptr->tempo < 2)) @@ -1314,7 +1314,7 @@ void playroutine_stereo() if (cptr->ptr[WTBL]) { // Stop the song in case of jumping into a jump - if (ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) + if (song.ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) stopsong(); } if (iptr->ptr[PTBL]) @@ -1324,7 +1324,7 @@ void playroutine_stereo() if (cptr->ptr[PTBL]) { // Stop the song in case of jumping into a jump - if (ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) + if (song.ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) stopsong(); } } @@ -1337,7 +1337,7 @@ void playroutine_stereo() if (filterptr) { // Stop the song in case of jumping into a jump - if (ltable[FTBL][filterptr-1] == 0xff) + if (song.ltable[FTBL][filterptr-1] == 0xff) stopsong(); } } @@ -1348,7 +1348,7 @@ void playroutine_stereo() if (filter2ptr) { // Stop the song in case of jumping into a jump - if (ltable[FTBL][filter2ptr-1] == 0xff) + if (song.ltable[FTBL][filter2ptr-1] == 0xff) stopsong(); } } @@ -1412,7 +1412,7 @@ void playroutine_stereo() if (cptr->ptr[WTBL]) { // Stop the song in case of jumping into a jump - if (ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) + if (song.ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) stopsong(); } break; @@ -1423,7 +1423,7 @@ void playroutine_stereo() if (cptr->ptr[PTBL]) { // Stop the song in case of jumping into a jump - if (ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) + if (song.ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) stopsong(); } break; @@ -1436,7 +1436,7 @@ void playroutine_stereo() if (filterptr) { // Stop the song in case of jumping into a jump - if (ltable[FTBL][filterptr-1] == 0xff) + if (song.ltable[FTBL][filterptr-1] == 0xff) stopsong(); } } @@ -1447,7 +1447,7 @@ void playroutine_stereo() if (filter2ptr) { // Stop the song in case of jumping into a jump - if (ltable[FTBL][filter2ptr-1] == 0xff) + if (song.ltable[FTBL][filter2ptr-1] == 0xff) stopsong(); } } @@ -1481,8 +1481,8 @@ void playroutine_stereo() case CMD_FUNKTEMPO: if (cptr->newcmddata) { - funktable[0] = ltable[STBL][cptr->newcmddata-1]-1; - funktable[1] = rtable[STBL][cptr->newcmddata-1]-1; + funktable[0] = song.ltable[STBL][cptr->newcmddata-1]-1; + funktable[1] = song.rtable[STBL][cptr->newcmddata-1]-1; } { int d; @@ -1516,8 +1516,8 @@ void playroutine_stereo() WAVEEXEC_S: if (cptr->ptr[WTBL]) { - unsigned char wave = ltable[WTBL][cptr->ptr[WTBL]-1]; - unsigned char note = rtable[WTBL][cptr->ptr[WTBL]-1]; + unsigned char wave = song.ltable[WTBL][cptr->ptr[WTBL]-1]; + unsigned char note = song.rtable[WTBL][cptr->ptr[WTBL]-1]; if (wave > WAVELASTDELAY) { @@ -1528,7 +1528,7 @@ void playroutine_stereo() // Command execution from wavetable if ((wave >= WAVECMD) && (wave <= WAVELASTCMD)) { - unsigned char param = rtable[WTBL][cptr->ptr[WTBL]-1]; + unsigned char param = song.rtable[WTBL][cptr->ptr[WTBL]-1]; switch (wave & 0xf) { case CMD_DONOTHING: @@ -1542,13 +1542,13 @@ void playroutine_stereo() unsigned short speed = 0; if (param) { - speed = (ltable[STBL][param-1] << 8) | rtable[STBL][param-1]; + speed = (song.ltable[STBL][param-1] << 8) | song.rtable[STBL][param-1]; } if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][param-1]; + speed >>= song.rtable[STBL][param-1]; } cptr->freq += speed; } @@ -1559,13 +1559,13 @@ void playroutine_stereo() unsigned short speed = 0; if (param) { - speed = (ltable[STBL][param-1] << 8) | rtable[STBL][param-1]; + speed = (song.ltable[STBL][param-1] << 8) | song.rtable[STBL][param-1]; } if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][param-1]; + speed >>= song.rtable[STBL][param-1]; } cptr->freq -= speed; } @@ -1583,12 +1583,12 @@ void playroutine_stereo() } else { - speed = (ltable[STBL][param-1] << 8) | rtable[STBL][param-1]; + speed = (song.ltable[STBL][param-1] << 8) | song.rtable[STBL][param-1]; if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][param-1]; + speed >>= song.rtable[STBL][param-1]; } if (cptr->freq < targetfreq) { @@ -1619,15 +1619,15 @@ void playroutine_stereo() if (param) { - cmpvalue = ltable[STBL][param-1]; - speed = rtable[STBL][param-1]; + cmpvalue = song.ltable[STBL][param-1]; + speed = song.rtable[STBL][param-1]; } if (cmpvalue >= 0x80) { cmpvalue &= 0x7f; speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][param-1]; + speed >>= song.rtable[STBL][param-1]; } if ((cptr->vibtime < 0x80) && (cptr->vibtime > cmpvalue)) @@ -1664,7 +1664,7 @@ void playroutine_stereo() if (cptr->ptr[PTBL]) { // Stop the song in case of jumping into a jump - if (ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) + if (song.ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) stopsong(); } break; @@ -1677,7 +1677,7 @@ void playroutine_stereo() if (filterptr) { // Stop the song in case of jumping into a jump - if (ltable[FTBL][filterptr-1] == 0xff) + if (song.ltable[FTBL][filterptr-1] == 0xff) stopsong(); } } @@ -1688,7 +1688,7 @@ void playroutine_stereo() if (filter2ptr) { // Stop the song in case of jumping into a jump - if (ltable[FTBL][filter2ptr-1] == 0xff) + if (song.ltable[FTBL][filter2ptr-1] == 0xff) stopsong(); } } @@ -1734,9 +1734,9 @@ void playroutine_stereo() cptr->wavetime = 0; cptr->ptr[WTBL]++; // Wavetable jump - if (ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) + if (song.ltable[WTBL][cptr->ptr[WTBL]-1] == 0xff) { - cptr->ptr[WTBL] = rtable[WTBL][cptr->ptr[WTBL]-1]; + cptr->ptr[WTBL] = song.rtable[WTBL][cptr->ptr[WTBL]-1]; } if ((wave >= WAVECMD) && (wave <= WAVELASTCMD)) @@ -1765,13 +1765,13 @@ void playroutine_stereo() unsigned short speed = 0; if (cptr->cmddata) { - speed = (ltable[STBL][cptr->cmddata-1] << 8) | rtable[STBL][cptr->cmddata-1]; + speed = (song.ltable[STBL][cptr->cmddata-1] << 8) | song.rtable[STBL][cptr->cmddata-1]; } if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][cptr->cmddata-1]; + speed >>= song.rtable[STBL][cptr->cmddata-1]; } cptr->freq += speed; } @@ -1782,13 +1782,13 @@ void playroutine_stereo() unsigned short speed = 0; if (cptr->cmddata) { - speed = (ltable[STBL][cptr->cmddata-1] << 8) | rtable[STBL][cptr->cmddata-1]; + speed = (song.ltable[STBL][cptr->cmddata-1] << 8) | song.rtable[STBL][cptr->cmddata-1]; } if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][cptr->cmddata-1]; + speed >>= song.rtable[STBL][cptr->cmddata-1]; } cptr->freq -= speed; } @@ -1810,15 +1810,15 @@ void playroutine_stereo() if (cptr->cmddata) { - cmpvalue = ltable[STBL][cptr->cmddata-1]; - speed = rtable[STBL][cptr->cmddata-1]; + cmpvalue = song.ltable[STBL][cptr->cmddata-1]; + speed = song.rtable[STBL][cptr->cmddata-1]; } if (cmpvalue >= 0x80) { cmpvalue &= 0x7f; speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][cptr->cmddata-1]; + speed >>= song.rtable[STBL][cptr->cmddata-1]; } if ((cptr->vibtime < 0x80) && (cptr->vibtime > cmpvalue)) @@ -1843,12 +1843,12 @@ void playroutine_stereo() } else { - speed = (ltable[STBL][cptr->cmddata-1] << 8) | rtable[STBL][cptr->cmddata-1]; + speed = (song.ltable[STBL][cptr->cmddata-1] << 8) | song.rtable[STBL][cptr->cmddata-1]; if (speed >= 0x8000) { speed = freqtbllo[cptr->lastnote + 1] | (freqtblhi[cptr->lastnote + 1] << 8); speed -= freqtbllo[cptr->lastnote] | (freqtblhi[cptr->lastnote] << 8); - speed >>= rtable[STBL][cptr->cmddata-1]; + speed >>= song.rtable[STBL][cptr->cmddata-1]; } if (cptr->freq < targetfreq) { @@ -1889,30 +1889,30 @@ void playroutine_stereo() } // Pulsetable jump - if (ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) + if (song.ltable[PTBL][cptr->ptr[PTBL]-1] == 0xff) { - cptr->ptr[PTBL] = rtable[PTBL][cptr->ptr[PTBL]-1]; + cptr->ptr[PTBL] = song.rtable[PTBL][cptr->ptr[PTBL]-1]; if (!cptr->ptr[PTBL]) goto PULSEEXEC_S; } if (!cptr->pulsetime) { // Set pulse - if (ltable[PTBL][cptr->ptr[PTBL]-1] >= 0x80) + if (song.ltable[PTBL][cptr->ptr[PTBL]-1] >= 0x80) { - cptr->pulse = (ltable[PTBL][cptr->ptr[PTBL]-1] & 0xf) << 8; - cptr->pulse |= rtable[PTBL][cptr->ptr[PTBL]-1]; + cptr->pulse = (song.ltable[PTBL][cptr->ptr[PTBL]-1] & 0xf) << 8; + cptr->pulse |= song.rtable[PTBL][cptr->ptr[PTBL]-1]; cptr->ptr[PTBL]++; } else { - cptr->pulsetime = ltable[PTBL][cptr->ptr[PTBL]-1]; + cptr->pulsetime = song.ltable[PTBL][cptr->ptr[PTBL]-1]; } } // Pulse modulation if (cptr->pulsetime) { - unsigned char speed = rtable[PTBL][cptr->ptr[PTBL]-1]; + unsigned char speed = song.rtable[PTBL][cptr->ptr[PTBL]-1]; if (speed < 0x80) { cptr->pulse += speed; @@ -1935,13 +1935,13 @@ void playroutine_stereo() { unsigned char newnote; - newnote = pattern[cptr->pattnum][cptr->pattptr]; - if (pattern[cptr->pattnum][cptr->pattptr+1]) - cptr->instr = pattern[cptr->pattnum][cptr->pattptr+1]; - cptr->newcommand = pattern[cptr->pattnum][cptr->pattptr+2]; - cptr->newcmddata = pattern[cptr->pattnum][cptr->pattptr+3]; + newnote = song.pattern[cptr->pattnum][cptr->pattptr]; + if (song.pattern[cptr->pattnum][cptr->pattptr+1]) + cptr->instr = song.pattern[cptr->pattnum][cptr->pattptr+1]; + cptr->newcommand = song.pattern[cptr->pattnum][cptr->pattptr+2]; + cptr->newcmddata = song.pattern[cptr->pattnum][cptr->pattptr+3]; cptr->pattptr += 4; - if (pattern[cptr->pattnum][cptr->pattptr] == ENDPATT) + if (song.pattern[cptr->pattnum][cptr->pattptr] == ENDPATT) cptr->pattptr = 0x7fffffff; if (newnote == KEYOFF) @@ -1953,10 +1953,10 @@ void playroutine_stereo() cptr->newnote = newnote+cptr->trans; if ((cptr->newcommand) != CMD_TONEPORTA) { - if (!(instr[cptr->instr].gatetimer & 0x40)) + if (!(song.instr[cptr->instr].gatetimer & 0x40)) { cptr->gate = 0xfe; - if (!(instr[cptr->instr].gatetimer & 0x80)) + if (!(song.instr[cptr->instr].gatetimer & 0x80)) { if (c < 3) { @@ -2013,10 +2013,10 @@ void sequencer_stereo(int c, CHN *cptr) cptr->pattptr = startpattpos * 4; if (!cptr->advance) goto SEQDONE_S; // Song loop - if (songorder[psnum][c][cptr->songptr] == LOOPSONG) + if (song.order[psnum][c][cptr->songptr] == LOOPSONG) { - cptr->songptr = songorder[psnum][c][cptr->songptr+1]; - if (cptr->songptr >= songlen[psnum][c]) + cptr->songptr = song.order[psnum][c][cptr->songptr+1]; + if (cptr->songptr >= song.len[psnum][c]) { stopsong(); cptr->songptr = 0; @@ -2024,19 +2024,19 @@ void sequencer_stereo(int c, CHN *cptr) } } // Transpose - if ((songorder[psnum][c][cptr->songptr] >= TRANSDOWN) && (songorder[psnum][c][cptr->songptr] < LOOPSONG)) + if ((song.order[psnum][c][cptr->songptr] >= TRANSDOWN) && (song.order[psnum][c][cptr->songptr] < LOOPSONG)) { - cptr->trans = songorder[psnum][c][cptr->songptr]-TRANSUP; + cptr->trans = song.order[psnum][c][cptr->songptr]-TRANSUP; cptr->songptr++; } // Repeat - if ((songorder[psnum][c][cptr->songptr] >= REPEAT) && (songorder[psnum][c][cptr->songptr] < TRANSDOWN)) + if ((song.order[psnum][c][cptr->songptr] >= REPEAT) && (song.order[psnum][c][cptr->songptr] < TRANSDOWN)) { - cptr->repeat = songorder[psnum][c][cptr->songptr]-REPEAT; + cptr->repeat = song.order[psnum][c][cptr->songptr]-REPEAT; cptr->songptr++; } // Pattern number - cptr->pattnum = songorder[psnum][c][cptr->songptr]; + cptr->pattnum = song.order[psnum][c][cptr->songptr]; if (cptr->repeat) cptr->repeat--; else @@ -2052,7 +2052,7 @@ void sequencer_stereo(int c, CHN *cptr) cptr->pattptr = 0; // Check for playback endpos - if ((lastsonginit != PLAY_BEGINNING) && (esend[c] > 0) && (esend[c] > espos[c]) && (cptr->songptr > esend[c]) && (espos[c] < songlen[psnum][c])) + if ((lastsonginit != PLAY_BEGINNING) && (esend[c] > 0) && (esend[c] > espos[c]) && (cptr->songptr > esend[c]) && (espos[c] < song.len[psnum][c])) cptr->songptr = espos[c]; } SEQDONE_S: diff --git a/src/reloc.cpp b/src/reloc.cpp index 194978d..1a62ea9 100644 --- a/src/reloc.cpp +++ b/src/reloc.cpp @@ -270,47 +270,47 @@ void relocator() // Calculate amount of songs with nonzero length for (int c = 0; c < MAX_SONGS; c++) { - if ((songlen[c][0]) && - (songlen[c][1]) && - (songlen[c][2])) + if ((song.len[c][0]) && + (song.len[c][1]) && + (song.len[c][2])) { // See which patterns are used in this song for (int d = 0; d < maxChns; d++) { - songdatasize += songlen[c][d]+2; - for (int e = 0; e < songlen[c][d]; e++) + songdatasize += song.len[c][d]+2; + for (int e = 0; e < song.len[c][d]; e++) { - if (songorder[c][d][e] < REPEAT) + if (song.order[c][d][e] < REPEAT) { - int num = songorder[c][d][e]; + int num = song.order[c][d][e]; pattused[num] = 1; for (int f = 0; f < getPattlen(num); f++) { - if ((pattern[num][f*4] != REST) || (pattern[num][f*4+1]) || (pattern[num][f*4+2])) + if ((song.pattern[num][f*4] != REST) || (song.pattern[num][f*4+1]) || (song.pattern[num][f*4+2])) chnused[d] = 1; } } else { - if (songorder[c][d][e] >= TRANSDOWN) + if (song.order[c][d][e] >= TRANSDOWN) { notrans = 0; - if (songorder[c][d][e] < TRANSUP) + if (song.order[c][d][e] < TRANSUP) { - int newtransdownrange = -(songorder[c][d][e] - TRANSUP); + int newtransdownrange = -(song.order[c][d][e] - TRANSUP); if (newtransdownrange > transdownrange) transdownrange = newtransdownrange; } else { - int newtransuprange = songorder[c][d][e] - TRANSUP; + int newtransuprange = song.order[c][d][e] - TRANSUP; if (newtransuprange > transuprange) transuprange = newtransuprange; } } else norepeat = 0; } } - if (songorder[c][d][songlen[c][d]+1] >= songlen[c][d]) + if (song.order[c][d][song.len[c][d]+1] >= song.len[c][d]) { sprintf(textbuffer, "ILLEGAL SONG RESTART POSITION! (SUBTUNE %02X, CHANNEL %d)", c, d+1); clearscreen(); @@ -354,33 +354,33 @@ void relocator() { tableerror = 0; - if ((pattern[c][d*4] == KEYOFF) || (pattern[c][d*4] == KEYON)) + if ((song.pattern[c][d*4] == KEYOFF) || (song.pattern[c][d*4] == KEYON)) nogate = 0; - if (pattern[c][d*4+1]) - instrused[pattern[c][d*4+1]] = 1; - if (pattern[c][d*4+2]) + if (song.pattern[c][d*4+1]) + instrused[song.pattern[c][d*4+1]] = 1; + if (song.pattern[c][d*4+2]) noeffects = 0; - if ((pattern[c][d*4+2] >= CMD_SETWAVEPTR) && (pattern[c][d*4+2] <= CMD_SETFILTERPTR)) - exectable(pattern[c][d*4+2] - CMD_SETWAVEPTR, pattern[c][d*4+3]); - if ((pattern[c][d*4+2] >= CMD_PORTAUP) && (pattern[c][d*4+2] <= CMD_VIBRATO)) + if ((song.pattern[c][d*4+2] >= CMD_SETWAVEPTR) && (song.pattern[c][d*4+2] <= CMD_SETFILTERPTR)) + exectable(song.pattern[c][d*4+2] - CMD_SETWAVEPTR, song.pattern[c][d*4+3]); + if ((song.pattern[c][d*4+2] >= CMD_PORTAUP) && (song.pattern[c][d*4+2] <= CMD_VIBRATO)) { - exectable(STBL, pattern[c][d*4+3]); - calcspeedtest(pattern[c][d*4+3]); + exectable(STBL, song.pattern[c][d*4+3]); + calcspeedtest(song.pattern[c][d*4+3]); } - if (pattern[c][d*4+2] == CMD_FUNKTEMPO) - exectable(STBL, pattern[c][d*4+3]); - if (pattern[c][d*4+2] == CMD_FUNKTEMPO) + if (song.pattern[c][d*4+2] == CMD_FUNKTEMPO) + exectable(STBL, song.pattern[c][d*4+3]); + if (song.pattern[c][d*4+2] == CMD_FUNKTEMPO) { nofunktempo = 0; noglobaltempo = 0; } - if ((pattern[c][d*4+2] == CMD_SETTEMPO) && ((pattern[c][d*4+3] & 0x7f) < 3)) nofunktempo = 0; + if ((song.pattern[c][d*4+2] == CMD_SETTEMPO) && ((song.pattern[c][d*4+3] & 0x7f) < 3)) nofunktempo = 0; // See, which are the highest/lowest notes used - if ((pattern[c][d*4] >= FIRSTNOTE) && (pattern[c][d*4] <= LASTNOTE)) + if ((song.pattern[c][d*4] >= FIRSTNOTE) && (song.pattern[c][d*4] <= LASTNOTE)) { - int newfirstnote = pattern[c][d*4] - FIRSTNOTE - transdownrange; - int newlastnote = pattern[c][d*4] - FIRSTNOTE + transuprange; + int newfirstnote = song.pattern[c][d*4] - FIRSTNOTE - transdownrange; + int newlastnote = song.pattern[c][d*4] - FIRSTNOTE + transuprange; if (newfirstnote < 0) newfirstnote = 0; if (newlastnote > MAX_NOTES-1) newlastnote = MAX_NOTES-1; @@ -413,13 +413,13 @@ void relocator() { if (instrused[c]) { - if (instr[c].gatetimer & 0x40) numlegato++; + if (song.instr[c].gatetimer & 0x40) numlegato++; else { - if (instr[c].gatetimer & 0x80) numnohr++; + if (song.instr[c].gatetimer & 0x80) numnohr++; else numnormal++; } - if ((!instr[c].firstwave) || (instr[c].firstwave >= 0xfe)) + if ((!song.instr[c].firstwave) || (song.instr[c].firstwave >= 0xfe)) nofirstwavecmd = 0; } } @@ -432,18 +432,18 @@ void relocator() { if (instrused[c]) { - if (instr[c].gatetimer & 0x40) instrmap[c] = freelegato++; + if (song.instr[c].gatetimer & 0x40) instrmap[c] = freelegato++; else { - if (instr[c].gatetimer & 0x80) instrmap[c] = freenohr++; + if (song.instr[c].gatetimer & 0x80) instrmap[c] = freenohr++; else instrmap[c] = freenormal++; } instruments++; for (d = 0; d < MAX_TABLES; d++) { tableerror = 0; - exectable(d, instr[c].ptr[d]); - if (d == STBL) calcspeedtest(instr[c].ptr[d]); + exectable(d, song.instr[c].ptr[d]); + if (d == STBL) calcspeedtest(song.instr[c].ptr[d]); if ((tableerror) && (!tableerrortype)) { tableerrortype = tableerror; @@ -460,19 +460,19 @@ void relocator() { if (tableused[WTBL][c+1]) { - if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) + if ((song.ltable[WTBL][c] >= WAVECMD) && (song.ltable[WTBL][c] <= WAVELASTCMD)) { int d = -1; tableerror = 0; - switch(ltable[WTBL][c] - WAVECMD) + switch(song.ltable[WTBL][c] - WAVECMD) { case CMD_PORTAUP: case CMD_PORTADOWN: case CMD_TONEPORTA: case CMD_VIBRATO: d = STBL; - calcspeedtest(rtable[WTBL][c]); + calcspeedtest(song.rtable[WTBL][c]); break; case CMD_SETPULSEPTR: @@ -488,7 +488,7 @@ void relocator() case CMD_DONOTHING: case CMD_SETWAVEPTR: case CMD_FUNKTEMPO: - sprintf(textbuffer, "ILLEGAL WAVETABLE COMMAND (ROW %02X, COMMAND %X)", c+1, ltable[WTBL][c] - WAVECMD); + sprintf(textbuffer, "ILLEGAL WAVETABLE COMMAND (ROW %02X, COMMAND %X)", c+1, song.ltable[WTBL][c] - WAVECMD); clearscreen(); printtextc(MAX_ROWS/2, colors.CTITLE, textbuffer); fliptoscreen(); @@ -496,7 +496,7 @@ void relocator() goto PRCLEANUP; } - if (d != -1) exectable(d, rtable[WTBL][c]); + if (d != -1) exectable(d, song.rtable[WTBL][c]); if ((tableerror) && (!tableerrortype)) { @@ -727,54 +727,54 @@ void relocator() goto PRCLEANUP; } - // Generate songorderlists & songtable + // Generate song.orderlists & songtable songdatasize = 0; for (int c = 0; c < songs; c++) { - if ((songlen[c][0]) && - (songlen[c][1]) && - (songlen[c][2])) + if ((song.len[c][0]) && + (song.len[c][1]) && + (song.len[c][2])) { for (int d = 0; d < maxChns; d++) { songoffset[c][d] = songdatasize; - songsize[c][d] = songlen[c][d] + 2; + songsize[c][d] = song.len[c][d] + 2; int e; - for (e = 0; e < songlen[c][d]; e++) + for (e = 0; e < song.len[c][d]; e++) { // Pattern - if (songorder[c][d][e] < REPEAT) - songwork[songdatasize++] = pattmap[songorder[c][d][e]]; + if (song.order[c][d][e] < REPEAT) + songwork[songdatasize++] = pattmap[song.order[c][d][e]]; else { // Transpose - if (songorder[c][d][e] >= TRANSDOWN) + if (song.order[c][d][e] >= TRANSDOWN) { - songwork[songdatasize++] = songorder[c][d][e]; + songwork[songdatasize++] = song.order[c][d][e]; } // Repeat sequence: must be swapped else { // See that repeat amount is more than 1 - if (songorder[c][d][e] > REPEAT) + if (song.order[c][d][e] > REPEAT) { // Insanity check that a pattern indeed follows - if (songorder[c][d][e+1] < REPEAT) + if (song.order[c][d][e+1] < REPEAT) { - songwork[songdatasize++] = pattmap[songorder[c][d][e+1]]; - songwork[songdatasize++] = songorder[c][d][e]; + songwork[songdatasize++] = pattmap[song.order[c][d][e+1]]; + songwork[songdatasize++] = song.order[c][d][e]; e++; } else - songwork[songdatasize++] = songorder[c][d][e]; + songwork[songdatasize++] = song.order[c][d][e]; } } } } // Endmark & repeat position - songwork[songdatasize++] = songorder[c][d][e++]; - songwork[songdatasize++] = songorder[c][d][e++]; + songwork[songdatasize++] = song.order[c][d][e++]; + songwork[songdatasize++] = song.order[c][d][e++]; } } else @@ -792,7 +792,7 @@ void relocator() { if (pattused[c]) { - int result = packpattern(patttemp, pattern[c], getPattlen(c)); + int result = packpattern(patttemp, song.pattern[c], getPattlen(c)); if (result < 0) { @@ -826,7 +826,7 @@ void relocator() if (pattused[c]) { pattoffset[d] = pattdatasize; - pattsize[d] = packpattern(&pattwork[pattdatasize], pattern[c], getPattlen(c)); + pattsize[d] = packpattern(&pattwork[pattdatasize], song.pattern[c], getPattlen(c)); pattdatasize += pattsize[d]; d++; } @@ -849,40 +849,40 @@ void relocator() if (instrused[c]) { d = instrmap[c] - 1; - instrwork[d] = instr[c].ad; - instrwork[d+instruments] = instr[c].sr; - instrwork[d+instruments*2] = tablemap[WTBL][instr[c].ptr[WTBL]]; - instrwork[d+instruments*3] = tablemap[PTBL][instr[c].ptr[PTBL]]; - instrwork[d+instruments*4] = tablemap[FTBL][instr[c].ptr[FTBL]]; - if (instr[c].vibdelay) + instrwork[d] = song.instr[c].ad; + instrwork[d+instruments] = song.instr[c].sr; + instrwork[d+instruments*2] = tablemap[WTBL][song.instr[c].ptr[WTBL]]; + instrwork[d+instruments*3] = tablemap[PTBL][song.instr[c].ptr[PTBL]]; + instrwork[d+instruments*4] = tablemap[FTBL][song.instr[c].ptr[FTBL]]; + if (song.instr[c].vibdelay) { - instrwork[d+instruments*5] = tablemap[STBL][instr[c].ptr[STBL]]; - instrwork[d+instruments*6] = instr[c].vibdelay - 1; + instrwork[d+instruments*5] = tablemap[STBL][song.instr[c].ptr[STBL]]; + instrwork[d+instruments*6] = song.instr[c].vibdelay - 1; } else { instrwork[d+instruments*5] = 0; instrwork[d+instruments*6] = 0; } - instrwork[d+instruments*7] = instr[c].gatetimer & 0x3f; - instrwork[d+instruments*8] = instr[c].firstwave; + instrwork[d+instruments*7] = song.instr[c].gatetimer & 0x3f; + instrwork[d+instruments*8] = song.instr[c].firstwave; - if (instr[c].ptr[STBL]) + if (song.instr[c].ptr[STBL]) { novib = 0; noinsvib = 0; } - if (instr[c].ptr[PTBL]) + if (song.instr[c].ptr[PTBL]) nopulse = 0; - if (instr[c].ptr[FTBL]) + if (song.instr[c].ptr[FTBL]) nofilter = 0; // See if all instruments use same gatetimer & firstwave parameters - if ((instr[c].gatetimer != instr[1].gatetimer) || - (instr[c].firstwave != instr[1].firstwave)) + if ((song.instr[c].gatetimer != song.instr[1].gatetimer) || + (song.instr[c].firstwave != song.instr[1].firstwave)) fixedparams = 0; // or if special firstwave commands are in use - if ((!instr[c].firstwave) || (instr[c].firstwave >= 0xfe)) + if ((!song.instr[c].firstwave) || (song.instr[c].firstwave >= 0xfe)) fixedparams = 0; } } @@ -906,12 +906,12 @@ void relocator() if (tableused[WTBL][c+1]) { wavetblsize += 2; - if ((ltable[WTBL][c] >= WAVEDELAY) && (ltable[WTBL][c] <= WAVELASTDELAY)) nowavedelay = 0; - if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) + if ((song.ltable[WTBL][c] >= WAVEDELAY) && (song.ltable[WTBL][c] <= WAVELASTDELAY)) nowavedelay = 0; + if ((song.ltable[WTBL][c] >= WAVECMD) && (song.ltable[WTBL][c] <= WAVELASTCMD)) { nowavecmd = 0; noeffects = 0; - switch (ltable[WTBL][c] - WAVECMD) + switch (song.ltable[WTBL][c] - WAVECMD) { case CMD_PORTAUP: case CMD_PORTADOWN: @@ -959,19 +959,19 @@ void relocator() break; } } - if (ltable[WTBL][c] < WAVECMD) + if (song.ltable[WTBL][c] < WAVECMD) { - if (rtable[WTBL][c] <= 0x80) + if (song.rtable[WTBL][c] <= 0x80) { - int newlastnote = rtable[WTBL][c] + patternlastnote; + int newlastnote = song.rtable[WTBL][c] + patternlastnote; if (newlastnote > MAX_NOTES - 1) newlastnote = MAX_NOTES - 1; - if (rtable[WTBL][c] >= 0x20) firstnote = 0; + if (song.rtable[WTBL][c] >= 0x20) firstnote = 0; if (newlastnote > lastnote) lastnote = newlastnote; } else { - int newfirstnote = rtable[WTBL][c] & 0x7f; - int newlastnote = rtable[WTBL][c] & 0x7f; + int newfirstnote = song.rtable[WTBL][c] & 0x7f; + int newlastnote = song.rtable[WTBL][c] & 0x7f; if (newlastnote > MAX_NOTES - 1) newlastnote = MAX_NOTES - 1; if (newfirstnote < firstnote) firstnote = newfirstnote; if (newlastnote > lastnote) lastnote = newlastnote; @@ -984,14 +984,14 @@ void relocator() if (tableused[PTBL][c+1]) { pulsetblsize += 2; - if ((ltable[PTBL][c] >= 0x80) && (ltable[PTBL][c] != 0xff)) + if ((song.ltable[PTBL][c] >= 0x80) && (song.ltable[PTBL][c] != 0xff)) { - if (rtable[PTBL][c] & 0xf) simplepulse = 0; + if (song.rtable[PTBL][c] & 0xf) simplepulse = 0; } - if (ltable[PTBL][c] < 0x80) + if (song.ltable[PTBL][c] < 0x80) { nopulsemod = 0; - if (rtable[PTBL][c] & 0xf) simplepulse = 0; + if (song.rtable[PTBL][c] & 0xf) simplepulse = 0; } } } @@ -1000,7 +1000,7 @@ void relocator() if (tableused[FTBL][c+1]) { filttblsize += 2; - if (ltable[FTBL][c] < 0x80) nofiltermod = 0; + if (song.ltable[FTBL][c] < 0x80) nofiltermod = 0; } } for (int c = 0; c < MAX_TABLELEN; c++) @@ -1214,16 +1214,16 @@ void relocator() insertdefine("SRPARAM", adparam & 0xff); insertdefine("CIAVALLO", ciaval & 0xff); insertdefine("CIAVALHI", ciaval >> 8); - if ((instr[MAX_INSTR-1].ad >= 2) && (!(instr[MAX_INSTR-1].ptr[WTBL]))) - insertdefine("DEFAULTTEMPO", instr[MAX_INSTR-1].ad - 1); + if ((song.instr[MAX_INSTR-1].ad >= 2) && (!(song.instr[MAX_INSTR-1].ptr[WTBL]))) + insertdefine("DEFAULTTEMPO", song.instr[MAX_INSTR-1].ad - 1); else insertdefine("DEFAULTTEMPO", multiplier ? (multiplier*6-1) : 5); // Fixed firstwave & gatetimer if (fixedparams) { - insertdefine("FIRSTWAVEPARAM", instr[1].firstwave); - insertdefine("GATETIMERPARAM", instr[1].gatetimer & 0x3f); + insertdefine("FIRSTWAVEPARAM", song.instr[1].firstwave); + insertdefine("GATETIMERPARAM", song.instr[1].gatetimer & 0x3f); } // Insert source code of player @@ -1342,30 +1342,30 @@ void relocator() // In wavetable, convert waveform values for the playroutine case WTBL: { - unsigned char wave = ltable[c][d]; - if ((ltable[c][d] >= WAVESILENT) && (ltable[c][d] <= WAVELASTSILENT)) wave &= 0xf; - if ((ltable[c][d] > WAVELASTDELAY) && (ltable[c][d] <= WAVELASTSILENT) && (!nowavedelay)) wave += 0x10; + 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; insertbyte(wave); } break; case PTBL: - if ((simplepulse) && (ltable[c][d] != 0xff) && (ltable[c][d] > 0x80)) + if ((simplepulse) && (song.ltable[c][d] != 0xff) && (song.ltable[c][d] > 0x80)) insertbyte(0x80); else - insertbyte(ltable[c][d]); + insertbyte(song.ltable[c][d]); break; - // In filtertable, modify passband bits + // In filtesong.rtable, modify passband bits case FTBL: - if ((ltable[c][d] != 0xff) && (ltable[c][d] > 0x80)) - insertbyte(((ltable[c][d] & 0x70) >> 1) | 0x80); + if ((song.ltable[c][d] != 0xff) && (song.ltable[c][d] > 0x80)) + insertbyte(((song.ltable[c][d] & 0x70) >> 1) | 0x80); else - insertbyte(ltable[c][d]); + insertbyte(song.ltable[c][d]); break; default: - insertbyte(ltable[c][d]); + insertbyte(song.ltable[c][d]); break; } } @@ -1381,52 +1381,52 @@ void relocator() { if (tableused[c][d+1]) { - if ((ltable[c][d] != 0xff) || (c == STBL)) + if ((song.ltable[c][d] != 0xff) || (c == STBL)) { switch(c) { case WTBL: - if ((ltable[c][d] >= WAVECMD) && (ltable[c][d] <= WAVELASTCMD)) + if ((song.ltable[c][d] >= WAVECMD) && (song.ltable[c][d] <= WAVELASTCMD)) { // Remap table-referencing commands - switch (ltable[c][d] - WAVECMD) + switch (song.ltable[c][d] - WAVECMD) { case CMD_PORTAUP: case CMD_PORTADOWN: case CMD_TONEPORTA: case CMD_VIBRATO: - insertbyte(tablemap[STBL][rtable[c][d]]); + insertbyte(tablemap[STBL][song.rtable[c][d]]); break; case CMD_SETPULSEPTR: - insertbyte(tablemap[PTBL][rtable[c][d]]); + insertbyte(tablemap[PTBL][song.rtable[c][d]]); break; case CMD_SETFILTERPTR: - insertbyte(tablemap[FTBL][rtable[c][d]]); + insertbyte(tablemap[FTBL][song.rtable[c][d]]); break; default: - insertbyte(rtable[c][d]); + insertbyte(song.rtable[c][d]); break; } } else { // For normal notes, reverse all right side high bits - insertbyte(rtable[c][d] ^ 0x80); + insertbyte(song.rtable[c][d] ^ 0x80); } break; case PTBL: if (simplepulse) { - if (ltable[c][d] >= 0x80) - insertbyte((ltable[c][d] & 0x0f) | (rtable[c][d] & 0xf0)); + if (song.ltable[c][d] >= 0x80) + insertbyte((song.ltable[c][d] & 0x0f) | (song.rtable[c][d] & 0xf0)); else { - int pulsespeed = rtable[c][d] >> 4; - if (rtable[c][d] & 0x80) + int pulsespeed = song.rtable[c][d] >> 4; + if (song.rtable[c][d] & 0x80) { pulsespeed |= 0xf0; pulsespeed--; @@ -1436,16 +1436,16 @@ void relocator() } } else - insertbyte(rtable[c][d]); + insertbyte(song.rtable[c][d]); break; default: - insertbyte(rtable[c][d]); + insertbyte(song.rtable[c][d]); break; } } else - insertbyte(tablemap[c][rtable[c][d]]); + insertbyte(tablemap[c][song.rtable[c][d]]); } } @@ -1489,7 +1489,7 @@ void relocator() { for (int c = 0; c < 32; c++) { - packeddata[32+c] = authorname[c]; + packeddata[32+c] = song.author[c]; // Convert 0 to space if (packeddata[32+c] == 0) packeddata[32+c] = 0x20; } @@ -1715,9 +1715,9 @@ void relocator() fwrite8(songhandle, byte); // Songname etc. - std::fwrite(songname, sizeof songname, 1, songhandle); - std::fwrite(authorname, sizeof authorname, 1, songhandle); - std::fwrite(copyrightname, sizeof copyrightname, 1, songhandle); + std::fwrite(song.title, sizeof song.title, 1, songhandle); + std::fwrite(song.author, sizeof song.author, 1, songhandle); + std::fwrite(song.released, sizeof song.released, 1, songhandle); // Flags byte = 0x00; @@ -2130,7 +2130,7 @@ void findtableduplicates(int num) { if (tableused[num][d]) { - if ((ltable[num][d-1] == ltable[num][c-1]) && (rtable[num][d-1] == rtable[num][c-1])) + if ((song.ltable[num][d-1] == song.ltable[num][c-1]) && (song.rtable[num][d-1] == song.rtable[num][c-1])) { // Duplicate found, remove and map to the original tableused[num][d] = 0; @@ -2160,24 +2160,24 @@ void findtableduplicates(int num) if (e < len-1) { // Is table data the same? - if ((ltable[num][d+e-1] != ltable[num][c+e-1]) || (rtable[num][d+e-1] != rtable[num][c+e-1])) + 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])) break; } else { // Do both parts have a jump in the end? - if (ltable[num][d+e-1] != ltable[num][c+e-1]) + if (song.ltable[num][d+e-1] != song.ltable[num][c+e-1]) break; // Do both parts end? - if (rtable[num][d+e-1] == 0) + if (song.rtable[num][d+e-1] == 0) { - if (rtable[num][c+e-1] != 0) + if (song.rtable[num][c+e-1] != 0) break; } else { // Do both parts loop in the same way? - if ((rtable[num][d+e-1] - d) != (rtable[num][c+e-1] - c)) + if ((song.rtable[num][d+e-1] - d) != (song.rtable[num][c+e-1] - c)) break; } } @@ -2214,15 +2214,15 @@ int isusedandselfcontained(int num, int start) if (tableused[num][c] == 0) return 0; } // Check for jump to outside - if (rtable[num][end-1] != 0) + if (song.rtable[num][end-1] != 0) { - if ((rtable[num][end-1] < start) || (rtable[num][end-1] > end)) return 0; + if ((song.rtable[num][end-1] < start) || (song.rtable[num][end-1] > end)) return 0; } // Check for jump from outside for (int c = 1; c < start; c++) - if ((tableused[num][c]) && (ltable[num][c-1] == 0xff) && (rtable[num][c-1] >= start) && (rtable[num][c-1] <= end)) return 0; + if ((tableused[num][c]) && (song.ltable[num][c-1] == 0xff) && (song.rtable[num][c-1] >= start) && (song.rtable[num][c-1] <= end)) return 0; for (int c = end+1; c <= MAX_TABLELEN; c++) - if ((tableused[num][c]) && (ltable[num][c-1] == 0xff) && (rtable[num][c-1] >= start) && (rtable[num][c-1] <= end)) return 0; + if ((tableused[num][c]) && (song.ltable[num][c-1] == 0xff) && (song.rtable[num][c-1] >= start) && (song.rtable[num][c-1] <= end)) return 0; // OK! return 1; @@ -2236,7 +2236,7 @@ void calcspeedtest(unsigned char pos) return; } - if (ltable[STBL][pos-1] >= 0x80) nocalculatedspeed = 0; + if (song.ltable[STBL][pos-1] >= 0x80) nocalculatedspeed = 0; else nonormalspeed = 0; } @@ -2338,47 +2338,47 @@ void relocator_stereo() // Calculate amount of songs with nonzero length for (int c = 0; c < MAX_SONGS; c++) { - if ((songlen[c][0]) && - (songlen[c][1]) && - (songlen[c][2])) + if ((song.len[c][0]) && + (song.len[c][1]) && + (song.len[c][2])) { // See which patterns are used in this song for (int d = 0; d < MAX_CHN; d++) { - songdatasize += songlen[c][d]+2; - for (int e = 0; e < songlen[c][d]; e++) + songdatasize += song.len[c][d]+2; + for (int e = 0; e < song.len[c][d]; e++) { - if (songorder[c][d][e] < REPEAT) + if (song.order[c][d][e] < REPEAT) { - int num = songorder[c][d][e]; + int num = song.order[c][d][e]; pattused[num] = 1; for (int f = 0; f < getPattlen(num); f++) { - if ((pattern[num][f*4] != REST) || (pattern[num][f*4+1]) || (pattern[num][f*4+2])) + if ((song.pattern[num][f*4] != REST) || (song.pattern[num][f*4+1]) || (song.pattern[num][f*4+2])) chnused_stereo[d] = 1; } } else { - if (songorder[c][d][e] >= TRANSDOWN) + if (song.order[c][d][e] >= TRANSDOWN) { notrans = 0; - if (songorder[c][d][e] < TRANSUP) + if (song.order[c][d][e] < TRANSUP) { - int newtransdownrange = -(songorder[c][d][e] - TRANSUP); + int newtransdownrange = -(song.order[c][d][e] - TRANSUP); if (newtransdownrange > transdownrange) transdownrange = newtransdownrange; } else { - int newtransuprange = songorder[c][d][e] - TRANSUP; + int newtransuprange = song.order[c][d][e] - TRANSUP; if (newtransuprange > transuprange) transuprange = newtransuprange; } } else norepeat = 0; } } - if (songorder[c][d][songlen[c][d]+1] >= songlen[c][d]) + if (song.order[c][d][song.len[c][d]+1] >= song.len[c][d]) { sprintf(textbuffer, "ILLEGAL SONG RESTART POSITION! (SUBTUNE %02X, CHANNEL %d)", c, d+1); clearscreen(); @@ -2416,33 +2416,33 @@ void relocator_stereo() { tableerror = 0; - if ((pattern[c][d*4] == KEYOFF) || (pattern[c][d*4] == KEYON)) + if ((song.pattern[c][d*4] == KEYOFF) || (song.pattern[c][d*4] == KEYON)) nogate = 0; - if (pattern[c][d*4+1]) - instrused[pattern[c][d*4+1]] = 1; - if (pattern[c][d*4+2]) + if (song.pattern[c][d*4+1]) + instrused[song.pattern[c][d*4+1]] = 1; + if (song.pattern[c][d*4+2]) noeffects = 0; - if ((pattern[c][d*4+2] >= CMD_SETWAVEPTR) && (pattern[c][d*4+2] <= CMD_SETFILTERPTR)) - exectable(pattern[c][d*4+2] - CMD_SETWAVEPTR, pattern[c][d*4+3]); - if ((pattern[c][d*4+2] >= CMD_PORTAUP) && (pattern[c][d*4+2] <= CMD_VIBRATO)) + if ((song.pattern[c][d*4+2] >= CMD_SETWAVEPTR) && (song.pattern[c][d*4+2] <= CMD_SETFILTERPTR)) + exectable(song.pattern[c][d*4+2] - CMD_SETWAVEPTR, song.pattern[c][d*4+3]); + if ((song.pattern[c][d*4+2] >= CMD_PORTAUP) && (song.pattern[c][d*4+2] <= CMD_VIBRATO)) { - exectable(STBL, pattern[c][d*4+3]); - calcspeedtest(pattern[c][d*4+3]); + exectable(STBL, song.pattern[c][d*4+3]); + calcspeedtest(song.pattern[c][d*4+3]); } - if (pattern[c][d*4+2] == CMD_FUNKTEMPO) - exectable(STBL, pattern[c][d*4+3]); - if (pattern[c][d*4+2] == CMD_FUNKTEMPO) + if (song.pattern[c][d*4+2] == CMD_FUNKTEMPO) + exectable(STBL, song.pattern[c][d*4+3]); + if (song.pattern[c][d*4+2] == CMD_FUNKTEMPO) { nofunktempo = 0; noglobaltempo = 0; } - if ((pattern[c][d*4+2] == CMD_SETTEMPO) && ((pattern[c][d*4+3] & 0x7f) < 3)) nofunktempo = 0; + if ((song.pattern[c][d*4+2] == CMD_SETTEMPO) && ((song.pattern[c][d*4+3] & 0x7f) < 3)) nofunktempo = 0; // See, which are the highest/lowest notes used - if ((pattern[c][d*4] >= FIRSTNOTE) && (pattern[c][d*4] <= LASTNOTE)) + if ((song.pattern[c][d*4] >= FIRSTNOTE) && (song.pattern[c][d*4] <= LASTNOTE)) { - int newfirstnote = pattern[c][d*4] - FIRSTNOTE - transdownrange; - int newlastnote = pattern[c][d*4] - FIRSTNOTE + transuprange; + int newfirstnote = song.pattern[c][d*4] - FIRSTNOTE - transdownrange; + int newlastnote = song.pattern[c][d*4] - FIRSTNOTE + transuprange; if (newfirstnote < 0) newfirstnote = 0; if (newlastnote > MAX_NOTES-1) newlastnote = MAX_NOTES-1; @@ -2475,13 +2475,13 @@ void relocator_stereo() { if (instrused[c]) { - if (instr[c].gatetimer & 0x40) numlegato++; + if (song.instr[c].gatetimer & 0x40) numlegato++; else { - if (instr[c].gatetimer & 0x80) numnohr++; + if (song.instr[c].gatetimer & 0x80) numnohr++; else numnormal++; } - if ((!instr[c].firstwave) || (instr[c].firstwave >= 0xfe)) + if ((!song.instr[c].firstwave) || (song.instr[c].firstwave >= 0xfe)) nofirstwavecmd = 0; } } @@ -2494,18 +2494,18 @@ void relocator_stereo() { if (instrused[c]) { - if (instr[c].gatetimer & 0x40) instrmap[c] = freelegato++; + if (song.instr[c].gatetimer & 0x40) instrmap[c] = freelegato++; else { - if (instr[c].gatetimer & 0x80) instrmap[c] = freenohr++; + if (song.instr[c].gatetimer & 0x80) instrmap[c] = freenohr++; else instrmap[c] = freenormal++; } instruments++; for (d = 0; d < MAX_TABLES; d++) { tableerror = 0; - exectable(d, instr[c].ptr[d]); - if (d == STBL) calcspeedtest(instr[c].ptr[d]); + exectable(d, song.instr[c].ptr[d]); + if (d == STBL) calcspeedtest(song.instr[c].ptr[d]); if ((tableerror) && (!tableerrortype)) { tableerrortype = tableerror; @@ -2522,19 +2522,19 @@ void relocator_stereo() { if (tableused[WTBL][c+1]) { - if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) + if ((song.ltable[WTBL][c] >= WAVECMD) && (song.ltable[WTBL][c] <= WAVELASTCMD)) { int d = -1; tableerror = 0; - switch(ltable[WTBL][c] - WAVECMD) + switch(song.ltable[WTBL][c] - WAVECMD) { case CMD_PORTAUP: case CMD_PORTADOWN: case CMD_TONEPORTA: case CMD_VIBRATO: d = STBL; - calcspeedtest(rtable[WTBL][c]); + calcspeedtest(song.rtable[WTBL][c]); break; case CMD_SETPULSEPTR: @@ -2550,7 +2550,7 @@ void relocator_stereo() case CMD_DONOTHING: case CMD_SETWAVEPTR: case CMD_FUNKTEMPO: - sprintf(textbuffer, "ILLEGAL WAVETABLE COMMAND (ROW %02X, COMMAND %X)", c+1, ltable[WTBL][c] - WAVECMD); + sprintf(textbuffer, "ILLEGAL WAVETABLE COMMAND (ROW %02X, COMMAND %X)", c+1, song.ltable[WTBL][c] - WAVECMD); clearscreen(); printtextc(MAX_ROWS/2, colors.CTITLE, textbuffer); fliptoscreen(); @@ -2558,7 +2558,7 @@ void relocator_stereo() goto PRCLEANUP_S; } - if (d != -1) exectable(d, rtable[WTBL][c]); + if (d != -1) exectable(d, song.rtable[WTBL][c]); if ((tableerror) && (!tableerrortype)) { @@ -2779,54 +2779,54 @@ void relocator_stereo() goto PRCLEANUP_S; } - // Generate songorderlists & songtable + // Generate song.orderlists & songtable songdatasize = 0; for (int c = 0; c < songs; c++) { - if ((songlen[c][0]) && - (songlen[c][1]) && - (songlen[c][2])) + if ((song.len[c][0]) && + (song.len[c][1]) && + (song.len[c][2])) { for (d = 0; d < MAX_CHN; d++) { songoffset[c][d] = songdatasize; - songsize[c][d] = songlen[c][d] + 2; + songsize[c][d] = song.len[c][d] + 2; int e; - for (e = 0; e < songlen[c][d]; e++) + for (e = 0; e < song.len[c][d]; e++) { // Pattern - if (songorder[c][d][e] < REPEAT) - songwork[songdatasize++] = pattmap[songorder[c][d][e]]; + if (song.order[c][d][e] < REPEAT) + songwork[songdatasize++] = pattmap[song.order[c][d][e]]; else { // Transpose - if (songorder[c][d][e] >= TRANSDOWN) + if (song.order[c][d][e] >= TRANSDOWN) { - songwork[songdatasize++] = songorder[c][d][e]; + songwork[songdatasize++] = song.order[c][d][e]; } // Repeat sequence: must be swapped else { // See that repeat amount is more than 1 - if (songorder[c][d][e] > REPEAT) + if (song.order[c][d][e] > REPEAT) { // Insanity check that a pattern indeed follows - if (songorder[c][d][e+1] < REPEAT) + if (song.order[c][d][e+1] < REPEAT) { - songwork[songdatasize++] = pattmap[songorder[c][d][e+1]]; - songwork[songdatasize++] = songorder[c][d][e]; + songwork[songdatasize++] = pattmap[song.order[c][d][e+1]]; + songwork[songdatasize++] = song.order[c][d][e]; e++; } else - songwork[songdatasize++] = songorder[c][d][e]; + songwork[songdatasize++] = song.order[c][d][e]; } } } } // Endmark & repeat position - songwork[songdatasize++] = songorder[c][d][e++]; - songwork[songdatasize++] = songorder[c][d][e++]; + songwork[songdatasize++] = song.order[c][d][e++]; + songwork[songdatasize++] = song.order[c][d][e++]; } } else @@ -2844,7 +2844,7 @@ void relocator_stereo() { if (pattused[c]) { - int result = packpattern(patttemp, pattern[c], getPattlen(c)); + int result = packpattern(patttemp, song.pattern[c], getPattlen(c)); if (result < 0) { @@ -2878,7 +2878,7 @@ void relocator_stereo() if (pattused[c]) { pattoffset[d] = pattdatasize; - pattsize[d] = packpattern(&pattwork[pattdatasize], pattern[c], getPattlen(c)); + pattsize[d] = packpattern(&pattwork[pattdatasize], song.pattern[c], getPattlen(c)); pattdatasize += pattsize[d]; d++; } @@ -2901,40 +2901,40 @@ void relocator_stereo() if (instrused[c]) { d = instrmap[c] - 1; - instrwork[d] = instr[c].ad; - instrwork[d+instruments] = instr[c].sr; - instrwork[d+instruments*2] = tablemap[WTBL][instr[c].ptr[WTBL]]; - instrwork[d+instruments*3] = tablemap[PTBL][instr[c].ptr[PTBL]]; - instrwork[d+instruments*4] = tablemap[FTBL][instr[c].ptr[FTBL]]; - if (instr[c].vibdelay) + instrwork[d] = song.instr[c].ad; + instrwork[d+instruments] = song.instr[c].sr; + instrwork[d+instruments*2] = tablemap[WTBL][song.instr[c].ptr[WTBL]]; + instrwork[d+instruments*3] = tablemap[PTBL][song.instr[c].ptr[PTBL]]; + instrwork[d+instruments*4] = tablemap[FTBL][song.instr[c].ptr[FTBL]]; + if (song.instr[c].vibdelay) { - instrwork[d+instruments*5] = tablemap[STBL][instr[c].ptr[STBL]]; - instrwork[d+instruments*6] = instr[c].vibdelay - 1; + instrwork[d+instruments*5] = tablemap[STBL][song.instr[c].ptr[STBL]]; + instrwork[d+instruments*6] = song.instr[c].vibdelay - 1; } else { instrwork[d+instruments*5] = 0; instrwork[d+instruments*6] = 0; } - instrwork[d+instruments*7] = instr[c].gatetimer & 0x3f; - instrwork[d+instruments*8] = instr[c].firstwave; + instrwork[d+instruments*7] = song.instr[c].gatetimer & 0x3f; + instrwork[d+instruments*8] = song.instr[c].firstwave; - if (instr[c].ptr[STBL]) + if (song.instr[c].ptr[STBL]) { novib = 0; noinsvib = 0; } - if (instr[c].ptr[PTBL]) + if (song.instr[c].ptr[PTBL]) nopulse = 0; - if (instr[c].ptr[FTBL]) + if (song.instr[c].ptr[FTBL]) nofilter = 0; // See if all instruments use same gatetimer & firstwave parameters - if ((instr[c].gatetimer != instr[1].gatetimer) || - (instr[c].firstwave != instr[1].firstwave)) + if ((song.instr[c].gatetimer != song.instr[1].gatetimer) || + (song.instr[c].firstwave != song.instr[1].firstwave)) fixedparams = 0; // or if special firstwave commands are in use - if ((!instr[c].firstwave) || (instr[c].firstwave >= 0xfe)) + if ((!song.instr[c].firstwave) || (song.instr[c].firstwave >= 0xfe)) fixedparams = 0; } } @@ -2958,12 +2958,12 @@ void relocator_stereo() if (tableused[WTBL][c+1]) { wavetblsize += 2; - if ((ltable[WTBL][c] >= WAVEDELAY) && (ltable[WTBL][c] <= WAVELASTDELAY)) nowavedelay = 0; - if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) + if ((song.ltable[WTBL][c] >= WAVEDELAY) && (song.ltable[WTBL][c] <= WAVELASTDELAY)) nowavedelay = 0; + if ((song.ltable[WTBL][c] >= WAVECMD) && (song.ltable[WTBL][c] <= WAVELASTCMD)) { nowavecmd = 0; noeffects = 0; - switch (ltable[WTBL][c] - WAVECMD) + switch (song.ltable[WTBL][c] - WAVECMD) { case CMD_PORTAUP: case CMD_PORTADOWN: @@ -3011,19 +3011,19 @@ void relocator_stereo() break; } } - if (ltable[WTBL][c] < WAVECMD) + if (song.ltable[WTBL][c] < WAVECMD) { - if (rtable[WTBL][c] <= 0x80) + if (song.rtable[WTBL][c] <= 0x80) { - int newlastnote = rtable[WTBL][c] + patternlastnote; + int newlastnote = song.rtable[WTBL][c] + patternlastnote; if (newlastnote > MAX_NOTES - 1) newlastnote = MAX_NOTES - 1; - if (rtable[WTBL][c] >= 0x20) firstnote = 0; + if (song.rtable[WTBL][c] >= 0x20) firstnote = 0; if (newlastnote > lastnote) lastnote = newlastnote; } else { - int newfirstnote = rtable[WTBL][c] & 0x7f; - int newlastnote = rtable[WTBL][c] & 0x7f; + int newfirstnote = song.rtable[WTBL][c] & 0x7f; + int newlastnote = song.rtable[WTBL][c] & 0x7f; if (newlastnote > MAX_NOTES - 1) newlastnote = MAX_NOTES - 1; if (newfirstnote < firstnote) firstnote = newfirstnote; if (newlastnote > lastnote) lastnote = newlastnote; @@ -3036,14 +3036,14 @@ void relocator_stereo() if (tableused[PTBL][c+1]) { pulsetblsize += 2; - if ((ltable[PTBL][c] >= 0x80) && (ltable[PTBL][c] != 0xff)) + if ((song.ltable[PTBL][c] >= 0x80) && (song.ltable[PTBL][c] != 0xff)) { - if (rtable[PTBL][c] & 0xf) simplepulse = 0; + if (song.rtable[PTBL][c] & 0xf) simplepulse = 0; } - if (ltable[PTBL][c] < 0x80) + if (song.ltable[PTBL][c] < 0x80) { nopulsemod = 0; - if (rtable[PTBL][c] & 0xf) simplepulse = 0; + if (song.rtable[PTBL][c] & 0xf) simplepulse = 0; } } } @@ -3052,7 +3052,7 @@ void relocator_stereo() if (tableused[FTBL][c+1]) { filttblsize += 2; - if (ltable[FTBL][c] < 0x80) nofiltermod = 0; + if (song.ltable[FTBL][c] < 0x80) nofiltermod = 0; } } for (int c = 0; c < MAX_TABLELEN; c++) @@ -3266,16 +3266,16 @@ void relocator_stereo() insertdefine("SRPARAM", adparam & 0xff); insertdefine("CIAVALLO", ciaval & 0xff); insertdefine("CIAVALHI", ciaval >> 8); - if ((instr[MAX_INSTR-1].ad >= 2) && (!(instr[MAX_INSTR-1].ptr[WTBL]))) - insertdefine("DEFAULTTEMPO", instr[MAX_INSTR-1].ad - 1); + if ((song.instr[MAX_INSTR-1].ad >= 2) && (!(song.instr[MAX_INSTR-1].ptr[WTBL]))) + insertdefine("DEFAULTTEMPO", song.instr[MAX_INSTR-1].ad - 1); else insertdefine("DEFAULTTEMPO", multiplier ? (multiplier*6-1) : 5); // Fixed firstwave & gatetimer if (fixedparams) { - insertdefine("FIRSTWAVEPARAM", instr[1].firstwave); - insertdefine("GATETIMERPARAM", instr[1].gatetimer & 0x3f); + insertdefine("FIRSTWAVEPARAM", song.instr[1].firstwave); + insertdefine("GATETIMERPARAM", song.instr[1].gatetimer & 0x3f); } // Insert source code of player @@ -3379,30 +3379,30 @@ void relocator_stereo() // In wavetable, convert waveform values for the playroutine case WTBL: { - unsigned char wave = ltable[c][d]; - if ((ltable[c][d] >= WAVESILENT) && (ltable[c][d] <= WAVELASTSILENT)) wave &= 0xf; - if ((ltable[c][d] > WAVELASTDELAY) && (ltable[c][d] <= WAVELASTSILENT) && (!nowavedelay)) wave += 0x10; + 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; insertbyte(wave); } break; case PTBL: - if ((simplepulse) && (ltable[c][d] != 0xff) && (ltable[c][d] > 0x80)) + if ((simplepulse) && (song.ltable[c][d] != 0xff) && (song.ltable[c][d] > 0x80)) insertbyte(0x80); else - insertbyte(ltable[c][d]); + insertbyte(song.ltable[c][d]); break; - // In filtertable, modify passband bits + // In filtesong.rtable, modify passband bits case FTBL: - if ((ltable[c][d] != 0xff) && (ltable[c][d] > 0x80)) - insertbyte(((ltable[c][d] & 0x70) >> 1) | 0x80); + if ((song.ltable[c][d] != 0xff) && (song.ltable[c][d] > 0x80)) + insertbyte(((song.ltable[c][d] & 0x70) >> 1) | 0x80); else - insertbyte(ltable[c][d]); + insertbyte(song.ltable[c][d]); break; default: - insertbyte(ltable[c][d]); + insertbyte(song.ltable[c][d]); break; } } @@ -3418,52 +3418,52 @@ void relocator_stereo() { if (tableused[c][d+1]) { - if ((ltable[c][d] != 0xff) || (c == STBL)) + if ((song.ltable[c][d] != 0xff) || (c == STBL)) { switch(c) { case WTBL: - if ((ltable[c][d] >= WAVECMD) && (ltable[c][d] <= WAVELASTCMD)) + if ((song.ltable[c][d] >= WAVECMD) && (song.ltable[c][d] <= WAVELASTCMD)) { // Remap table-referencing commands - switch (ltable[c][d] - WAVECMD) + switch (song.ltable[c][d] - WAVECMD) { case CMD_PORTAUP: case CMD_PORTADOWN: case CMD_TONEPORTA: case CMD_VIBRATO: - insertbyte(tablemap[STBL][rtable[c][d]]); + insertbyte(tablemap[STBL][song.rtable[c][d]]); break; case CMD_SETPULSEPTR: - insertbyte(tablemap[PTBL][rtable[c][d]]); + insertbyte(tablemap[PTBL][song.rtable[c][d]]); break; case CMD_SETFILTERPTR: - insertbyte(tablemap[FTBL][rtable[c][d]]); + insertbyte(tablemap[FTBL][song.rtable[c][d]]); break; default: - insertbyte(rtable[c][d]); + insertbyte(song.rtable[c][d]); break; } } else { // For normal notes, reverse all right side high bits - insertbyte(rtable[c][d] ^ 0x80); + insertbyte(song.rtable[c][d] ^ 0x80); } break; case PTBL: if (simplepulse) { - if (ltable[c][d] >= 0x80) - insertbyte((ltable[c][d] & 0x0f) | (rtable[c][d] & 0xf0)); + if (song.ltable[c][d] >= 0x80) + insertbyte((song.ltable[c][d] & 0x0f) | (song.rtable[c][d] & 0xf0)); else { - int pulsespeed = rtable[c][d] >> 4; - if (rtable[c][d] & 0x80) + int pulsespeed = song.rtable[c][d] >> 4; + if (song.rtable[c][d] & 0x80) { pulsespeed |= 0xf0; pulsespeed--; @@ -3473,16 +3473,16 @@ void relocator_stereo() } } else - insertbyte(rtable[c][d]); + insertbyte(song.rtable[c][d]); break; default: - insertbyte(rtable[c][d]); + insertbyte(song.rtable[c][d]); break; } } else - insertbyte(tablemap[c][rtable[c][d]]); + insertbyte(tablemap[c][song.rtable[c][d]]); } } @@ -3527,7 +3527,7 @@ void relocator_stereo() { for (int c = 0; c < 32; c++) { - packeddata[32+c] = authorname[c]; + packeddata[32+c] = song.author[c]; // Convert 0 to space if (packeddata[32+c] == 0) packeddata[32+c] = 0x20; } @@ -3753,9 +3753,9 @@ void relocator_stereo() fwrite8(songhandle, byte); // Songname etc. - std::fwrite(songname, sizeof songname, 1, songhandle); - std::fwrite(authorname, sizeof authorname, 1, songhandle); - std::fwrite(copyrightname, sizeof copyrightname, 1, songhandle); + std::fwrite(song.title, sizeof song.title, 1, songhandle); + std::fwrite(song.author, sizeof song.author, 1, songhandle); + std::fwrite(song.released, sizeof song.released, 1, songhandle); // Flags byte = 0x00; diff --git a/src/song.cpp b/src/song.cpp index 24dabe4..a1f78e4 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -39,16 +39,12 @@ #include #include -INSTR instr[MAX_INSTR]; -unsigned char ltable[MAX_TABLES][MAX_TABLELEN]; -unsigned char rtable[MAX_TABLES][MAX_TABLELEN]; -unsigned char songorder[MAX_SONGS][MAX_CHN][MAX_SONGLEN+2]; -unsigned char pattern[MAX_PATT][MAX_PATTROWS*4+4]; +Song song; + char songname[MAX_STR]; char authorname[MAX_STR]; char copyrightname[MAX_STR]; int pattlen[MAX_PATT]; -int songlen[MAX_SONGS][MAX_CHN]; int highestusedpattern; int highestusedinstr; @@ -78,8 +74,8 @@ bool savesong() countpatternlengths(); for (int c = 1; c < MAX_INSTR; c++) { - if ((instr[c].ad) || (instr[c].sr) || (instr[c].ptr[0]) || (instr[c].ptr[1]) || - (instr[c].ptr[2]) || (instr[c].vibdelay) || (instr[c].ptr[3])) + if ((song.instr[c].ad) || (song.instr[c].sr) || (song.instr[c].ptr[0]) || (song.instr[c].ptr[1]) || + (song.instr[c].ptr[2]) || (song.instr[c].vibdelay) || (song.instr[c].ptr[3])) { if (c > highestusedinstr) highestusedinstr = c; } @@ -94,25 +90,25 @@ bool savesong() int c = MAX_SONGS - 1; for (;;) { - if ((songlen[c][0]) && - (songlen[c][1]) && - (songlen[c][2])) break; + if ((song.len[c][0]) && + (song.len[c][1]) && + (song.len[c][2])) break; if (c == 0) break; c--; } int amount = c + 1; fwrite8(handle, amount); - // Write songorderlists + // Write song.orderlists for (int d = 0; d < amount; d++) { for (int c = 0; c < maxChns; c++) { - int length = songlen[d][c]+1; + int length = song.len[d][c]+1; fwrite8(handle, length); int writebytes = length; writebytes++; - std::fwrite(songorder[d][c], writebytes, 1, handle); + std::fwrite(song.order[d][c], writebytes, 1, handle); } } // Write amount of instruments @@ -120,24 +116,24 @@ bool savesong() // Write instruments for (int c = 1; c <= highestusedinstr; c++) { - fwrite8(handle, instr[c].ad); - fwrite8(handle, instr[c].sr); - fwrite8(handle, instr[c].ptr[WTBL]); - fwrite8(handle, instr[c].ptr[PTBL]); - fwrite8(handle, instr[c].ptr[FTBL]); - fwrite8(handle, instr[c].ptr[STBL]); - fwrite8(handle, instr[c].vibdelay); - fwrite8(handle, instr[c].gatetimer); - fwrite8(handle, instr[c].firstwave); - std::fwrite(&instr[c].name, MAX_INSTRNAMELEN, 1, handle); + fwrite8(handle, song.instr[c].ad); + fwrite8(handle, song.instr[c].sr); + fwrite8(handle, song.instr[c].ptr[WTBL]); + fwrite8(handle, song.instr[c].ptr[PTBL]); + fwrite8(handle, song.instr[c].ptr[FTBL]); + fwrite8(handle, song.instr[c].ptr[STBL]); + fwrite8(handle, song.instr[c].vibdelay); + fwrite8(handle, song.instr[c].gatetimer); + fwrite8(handle, song.instr[c].firstwave); + std::fwrite(&song.instr[c].name, MAX_INSTRNAMELEN, 1, handle); } // Write tables for (int c = 0; c < MAX_TABLES; c++) { int writebytes = gettablelen(c); fwrite8(handle, writebytes); - std::fwrite(ltable[c], writebytes, 1, handle); - std::fwrite(rtable[c], writebytes, 1, handle); + std::fwrite(song.ltable[c], writebytes, 1, handle); + std::fwrite(song.rtable[c], writebytes, 1, handle); } // Write patterns amount = highestusedpattern + 1; @@ -146,7 +142,7 @@ bool savesong() { int length = pattlen[c]+1; fwrite8(handle, length); - fwrite(pattern[c], length * 4, 1, handle); + fwrite(song.pattern[c], length * 4, 1, handle); } std::fclose(handle); std::strcpy(loadedsongfilename, songfilename); @@ -175,25 +171,25 @@ bool saveinstrument() std::fwrite(ident, 4, 1, handle); // Write instrument - fwrite8(handle, instr[einum].ad); - fwrite8(handle, instr[einum].sr); - fwrite8(handle, instr[einum].ptr[WTBL]); - fwrite8(handle, instr[einum].ptr[PTBL]); - fwrite8(handle, instr[einum].ptr[FTBL]); - fwrite8(handle, instr[einum].ptr[STBL]); - fwrite8(handle, instr[einum].vibdelay); - fwrite8(handle, instr[einum].gatetimer); - fwrite8(handle, instr[einum].firstwave); - fwrite(&instr[einum].name, MAX_INSTRNAMELEN, 1, handle); + fwrite8(handle, song.instr[einum].ad); + fwrite8(handle, song.instr[einum].sr); + fwrite8(handle, song.instr[einum].ptr[WTBL]); + fwrite8(handle, song.instr[einum].ptr[PTBL]); + fwrite8(handle, song.instr[einum].ptr[FTBL]); + fwrite8(handle, song.instr[einum].ptr[STBL]); + fwrite8(handle, song.instr[einum].vibdelay); + fwrite8(handle, song.instr[einum].gatetimer); + fwrite8(handle, song.instr[einum].firstwave); + fwrite(&song.instr[einum].name, MAX_INSTRNAMELEN, 1, handle); for (int c = 0; c < MAX_TABLES; c++) { - if (instr[einum].ptr[c]) + if (song.instr[einum].ptr[c]) { - int pos = instr[einum].ptr[c] - 1; + int pos = song.instr[einum].ptr[c] - 1; int len = gettablepartlen(c, pos); fwrite8(handle, len); - std::fwrite(<able[c][pos], len, 1, handle); - std::fwrite(&rtable[c][pos], len, 1, handle); + std::fwrite(&song.ltable[c][pos], len, 1, handle); + std::fwrite(&song.rtable[c][pos], len, 1, handle); } else fwrite8(handle, 0); } @@ -229,7 +225,7 @@ void loadsong() std::fread(authorname, sizeof authorname, 1, handle); std::fread(copyrightname, sizeof copyrightname, 1, handle); - // Read songorderlists + // Read song.orderlists channelstoload = determinechannels(handle); amount = fread8(handle); for (int d = 0; d < amount; d++) @@ -239,37 +235,37 @@ void loadsong() length = fread8(handle); loadsize = length; loadsize++; - std::fread(songorder[d][c], loadsize, 1, handle); + std::fread(song.order[d][c], loadsize, 1, handle); } } // Read instruments amount = fread8(handle); for (int c = 1; c <= amount; c++) { - instr[c].ad = fread8(handle); - instr[c].sr = fread8(handle); - instr[c].ptr[WTBL] = fread8(handle); - instr[c].ptr[PTBL] = fread8(handle); - instr[c].ptr[FTBL] = fread8(handle); - instr[c].ptr[STBL] = fread8(handle); - instr[c].vibdelay = fread8(handle); - instr[c].gatetimer = fread8(handle); - instr[c].firstwave = fread8(handle); - std::fread(&instr[c].name, MAX_INSTRNAMELEN, 1, handle); + song.instr[c].ad = fread8(handle); + song.instr[c].sr = fread8(handle); + song.instr[c].ptr[WTBL] = fread8(handle); + song.instr[c].ptr[PTBL] = fread8(handle); + song.instr[c].ptr[FTBL] = fread8(handle); + song.instr[c].ptr[STBL] = fread8(handle); + song.instr[c].vibdelay = fread8(handle); + song.instr[c].gatetimer = fread8(handle); + song.instr[c].firstwave = fread8(handle); + std::fread(&song.instr[c].name, MAX_INSTRNAMELEN, 1, handle); } // Read tables for (int c = 0; c < MAX_TABLES; c++) { loadsize = fread8(handle); - std::fread(ltable[c], loadsize, 1, handle); - std::fread(rtable[c], loadsize, 1, handle); + std::fread(song.ltable[c], loadsize, 1, handle); + std::fread(song.rtable[c], loadsize, 1, handle); } // Read patterns amount = fread8(handle); for (int c = 0; c < amount; c++) { length = fread8(handle) * 4; - std::fread(pattern[c], length, 1, handle); + std::fread(song.pattern[c], length, 1, handle); } countpatternlengths(); songchange(); @@ -289,7 +285,7 @@ void loadsong() std::fread(authorname, sizeof authorname, 1, handle); std::fread(copyrightname, sizeof copyrightname, 1, handle); - // Read songorderlists + // Read song.orderlists channelstoload = determinechannels(handle); amount = fread8(handle); for (int d = 0; d < amount; d++) @@ -299,55 +295,55 @@ void loadsong() length = fread8(handle); loadsize = length; loadsize++; - std::fread(songorder[d][c], loadsize, 1, handle); + std::fread(song.order[d][c], loadsize, 1, handle); } } // Read instruments amount = fread8(handle); for (int c = 1; c <= amount; c++) { - instr[c].ad = fread8(handle); - instr[c].sr = fread8(handle); - instr[c].ptr[WTBL] = fread8(handle); - instr[c].ptr[PTBL] = fread8(handle); - instr[c].ptr[FTBL] = fread8(handle); - instr[c].vibdelay = fread8(handle); - instr[c].ptr[STBL] = makespeedtable(fread8(handle), finevibrato, false) + 1; - instr[c].gatetimer = fread8(handle); - instr[c].firstwave = fread8(handle); - std::fread(&instr[c].name, MAX_INSTRNAMELEN, 1, handle); + song.instr[c].ad = fread8(handle); + song.instr[c].sr = fread8(handle); + song.instr[c].ptr[WTBL] = fread8(handle); + song.instr[c].ptr[PTBL] = fread8(handle); + song.instr[c].ptr[FTBL] = fread8(handle); + song.instr[c].vibdelay = fread8(handle); + song.instr[c].ptr[STBL] = makespeedtable(fread8(handle), finevibrato, false) + 1; + song.instr[c].gatetimer = fread8(handle); + song.instr[c].firstwave = fread8(handle); + std::fread(&song.instr[c].name, MAX_INSTRNAMELEN, 1, handle); } // Read tables for (int c = 0; c < MAX_TABLES-1; c++) { loadsize = fread8(handle); - std::fread(ltable[c], loadsize, 1, handle); - std::fread(rtable[c], loadsize, 1, handle); + std::fread(song.ltable[c], loadsize, 1, handle); + std::fread(song.rtable[c], loadsize, 1, handle); } // Read patterns amount = fread8(handle); for (int c = 0; c < amount; c++) { length = fread8(handle) * 4; - std::fread(pattern[c], length, 1, handle); + std::fread(song.pattern[c], length, 1, handle); // Convert speedtable-requiring commands for (int d = 0; d < length; d++) { - switch (pattern[c][d*4+2]) + switch (song.pattern[c][d*4+2]) { case CMD_FUNKTEMPO: - pattern[c][d*4+3] = makespeedtable(pattern[c][d*4+3], MST_FUNKTEMPO, false) + 1; + song.pattern[c][d*4+3] = makespeedtable(song.pattern[c][d*4+3], MST_FUNKTEMPO, false) + 1; break; case CMD_PORTAUP: case CMD_PORTADOWN: case CMD_TONEPORTA: - pattern[c][d*4+3] = makespeedtable(pattern[c][d*4+3], MST_PORTAMENTO, false) + 1; + song.pattern[c][d*4+3] = makespeedtable(song.pattern[c][d*4+3], MST_PORTAMENTO, false) + 1; break; case CMD_VIBRATO: - pattern[c][d*4+3] = makespeedtable(pattern[c][d*4+3], finevibrato, false) + 1; + song.pattern[c][d*4+3] = makespeedtable(song.pattern[c][d*4+3], finevibrato, false) + 1; break; } } @@ -380,7 +376,7 @@ void loadsong() std::fread(authorname, sizeof authorname, 1, handle); std::fread(copyrightname, sizeof copyrightname, 1, handle); - // Read songorderlists + // Read song.orderlists channelstoload = determinechannels(handle); amount = fread8(handle); for (int d = 0; d < amount; d++) @@ -390,7 +386,7 @@ void loadsong() length = fread8(handle); loadsize = length; loadsize++; - std::fread(songorder[d][c], loadsize, 1, handle); + std::fread(song.order[d][c], loadsize, 1, handle); } } @@ -399,31 +395,31 @@ void loadsong() { unsigned char wavelen; - instr[c].ad = fread8(handle); - instr[c].sr = fread8(handle); + song.instr[c].ad = fread8(handle); + song.instr[c].sr = fread8(handle); pulse[c] = fread8(handle); pulseadd[c] = fread8(handle); pulselimitlow[c] = fread8(handle); pulselimithigh[c] = fread8(handle); - instr[c].ptr[FTBL] = fread8(handle); // Will be converted later - if (instr[c].ptr[FTBL] > numfilter) numfilter = instr[c].ptr[FTBL]; - if (pulse[c] & 1) instr[c].gatetimer |= 0x80; // "No hardrestart" flag + song.instr[c].ptr[FTBL] = fread8(handle); // Will be converted later + if (song.instr[c].ptr[FTBL] > numfilter) numfilter = song.instr[c].ptr[FTBL]; + if (pulse[c] & 1) song.instr[c].gatetimer |= 0x80; // "No hardrestart" flag pulse[c] &= 0xfe; wavelen = fread8(handle)/2; - std::fread(&instr[c].name, MAX_INSTRNAMELEN, 1, handle); - instr[c].ptr[WTBL] = fw+1; + std::fread(&song.instr[c].name, MAX_INSTRNAMELEN, 1, handle); + song.instr[c].ptr[WTBL] = fw+1; // Convert wavetable for (int d = 0; d < wavelen; d++) { if (fw < MAX_TABLELEN) { - ltable[WTBL][fw] = fread8(handle); - rtable[WTBL][fw] = fread8(handle); - if (ltable[WTBL][fw] == 0xff) - if (rtable[WTBL][fw]) rtable[WTBL][fw] += instr[c].ptr[WTBL]-1; - if ((ltable[WTBL][fw] >= 0x8) && (ltable[WTBL][fw] <= 0xf)) - ltable[WTBL][fw] |= 0xe0; + 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[c].ptr[WTBL]-1; + if ((song.ltable[WTBL][fw] >= 0x8) && (song.ltable[WTBL][fw] <= 0xf)) + song.ltable[WTBL][fw] |= 0xe0; fw++; } else @@ -434,14 +430,14 @@ void loadsong() } // Remove empty wavetable afterwards - if ((wavelen == 2) && (!ltable[WTBL][fw-2]) && (!rtable[WTBL][fw-2])) + if ((wavelen == 2) && (!song.ltable[WTBL][fw-2]) && (!song.rtable[WTBL][fw-2])) { - instr[c].ptr[WTBL] = 0; + song.instr[c].ptr[WTBL] = 0; fw -= 2; - ltable[WTBL][fw] = 0; - rtable[WTBL][fw] = 0; - ltable[WTBL][fw+1] = 0; - rtable[WTBL][fw+1] = 0; + song.ltable[WTBL][fw] = 0; + song.rtable[WTBL][fw] = 0; + song.ltable[WTBL][fw+1] = 0; + song.rtable[WTBL][fw+1] = 0; } // Convert pulsetable @@ -455,16 +451,16 @@ void loadsong() if ((pulse[d] == pulse[c]) && (pulseadd[d] == pulseadd[c]) && (pulselimitlow[d] == pulselimitlow[c]) && (pulselimithigh[d] == pulselimithigh[c])) { - instr[c].ptr[PTBL] = instr[d].ptr[PTBL]; + song.instr[c].ptr[PTBL] = song.instr[d].ptr[PTBL]; goto PULSEDONE; } } // Initial pulse setting if (fp >= MAX_TABLELEN) goto PULSEDONE; - instr[c].ptr[PTBL] = fp+1; - ltable[PTBL][fp] = 0x80 | (pulse[c] >> 4); - rtable[PTBL][fp] = pulse[c] << 4; + song.instr[c].ptr[PTBL] = fp+1; + song.ltable[PTBL][fp] = 0x80 | (pulse[c] >> 4); + song.rtable[PTBL][fp] = pulse[c] << 4; fp++; // Pulse modulation @@ -483,8 +479,8 @@ void loadsong() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = acttime; - rtable[PTBL][fp] = pulseadd[c] / 2; + song.ltable[PTBL][fp] = acttime; + song.rtable[PTBL][fp] = pulseadd[c] / 2; fp++; pulsetime -= acttime; } @@ -502,8 +498,8 @@ void loadsong() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = acttime; - rtable[PTBL][fp] = -(pulseadd[c] / 2); + song.ltable[PTBL][fp] = acttime; + song.rtable[PTBL][fp] = -(pulseadd[c] / 2); fp++; pulsetime -= acttime; } @@ -521,16 +517,16 @@ void loadsong() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = acttime; - rtable[PTBL][fp] = pulseadd[c] / 2; + song.ltable[PTBL][fp] = acttime; + song.rtable[PTBL][fp] = pulseadd[c] / 2; fp++; pulsetime -= acttime; } } // Pulse jump back to beginning if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = 0xff; - rtable[PTBL][fp] = instr[c].ptr[PTBL] + 1; + song.ltable[PTBL][fp] = 0xff; + song.rtable[PTBL][fp] = song.instr[c].ptr[PTBL] + 1; fp++; } else @@ -544,16 +540,16 @@ void loadsong() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = acttime; - rtable[PTBL][fp] = pulseadd[c] / 2; + song.ltable[PTBL][fp] = acttime; + song.rtable[PTBL][fp] = pulseadd[c] / 2; fp++; pulsetime -= acttime; } } // Pulse jump back to beginning if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = 0xff; - rtable[PTBL][fp] = hlpos + 1; + song.ltable[PTBL][fp] = 0xff; + song.rtable[PTBL][fp] = hlpos + 1; fp++; } } @@ -561,8 +557,8 @@ void loadsong() { // Pulse stopped if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = 0xff; - rtable[PTBL][fp] = 0; + song.ltable[PTBL][fp] = 0xff; + song.rtable[PTBL][fp] = 0; fp++; } PULSEDONE: {} @@ -617,10 +613,10 @@ void loadsong() } break; } - pattern[c][d*4] = note; - pattern[c][d*4+1] = instr; - pattern[c][d*4+2] = cmd; - pattern[c][d*4+3] = data; + song.pattern[c][d*4] = note; + song.pattern[c][d*4+1] = instr; + song.pattern[c][d*4+2] = cmd; + song.pattern[c][d*4+3] = data; } } countpatternlengths(); @@ -649,13 +645,13 @@ void loadsong() // Filter set if (filtertable[c*4]) { - ltable[FTBL][ff] = 0x80 + (filtertable[c*4+1] & 0x70); - rtable[FTBL][ff] = filtertable[c*4]; + song.ltable[FTBL][ff] = 0x80 + (filtertable[c*4+1] & 0x70); + song.rtable[FTBL][ff] = filtertable[c*4]; ff++; if (filtertable[c*4+2]) { - ltable[FTBL][ff] = 0x00; - rtable[FTBL][ff] = filtertable[c*4+2]; + song.ltable[FTBL][ff] = 0x00; + song.rtable[FTBL][ff] = filtertable[c*4+2]; ff++; } } @@ -668,8 +664,8 @@ void loadsong() { int acttime = time; if (acttime > 127) acttime = 127; - ltable[FTBL][ff] = acttime; - rtable[FTBL][ff] = filtertable[c*4+2]; + song.ltable[FTBL][ff] = acttime; + song.rtable[FTBL][ff] = filtertable[c*4+2]; ff++; time -= acttime; } @@ -679,8 +675,8 @@ void loadsong() if (filtertable[c*4+3] != c+1) { filterjumppos[c] = ff; - ltable[FTBL][ff] = 0xff; - rtable[FTBL][ff] = filtertable[c*4+3]; // Fix the jump later + song.ltable[FTBL][ff] = 0xff; + song.rtable[FTBL][ff] = filtertable[c*4+3]; // Fix the jump later ff++; } } @@ -690,12 +686,12 @@ void loadsong() for (int c = 1; c <= numfilter; c++) { if (filterjumppos[c] != -1) - rtable[FTBL][filterjumppos[c]] = filtermap[rtable[FTBL][filterjumppos[c]]]; + song.rtable[FTBL][filterjumppos[c]] = filtermap[song.rtable[FTBL][filterjumppos[c]]]; } // Fix filterpointers in instruments for (int c = 1; c < 32; c++) - instr[c].ptr[FTBL] = filtermap[instr[c].ptr[FTBL]]; + song.instr[c].ptr[FTBL] = filtermap[song.instr[c].ptr[FTBL]]; // Now fix pattern commands std::memset(arpmap, 0, sizeof arpmap); @@ -704,35 +700,35 @@ void loadsong() unsigned char i = 0; for (int d = 0; d <= MAX_PATTROWS; d++) { - if (pattern[c][d*4+1]) i = pattern[c][d*4+1]; + if (song.pattern[c][d*4+1]) i = song.pattern[c][d*4+1]; // Convert portamento & vibrato - if (pattern[c][d*4+2] == CMD_PORTAUP) - pattern[c][d*4+3] = makespeedtable(pattern[c][d*4+3], MST_PORTAMENTO, false) + 1; - if (pattern[c][d*4+2] == CMD_PORTADOWN) - pattern[c][d*4+3] = makespeedtable(pattern[c][d*4+3], MST_PORTAMENTO, false) + 1; - if (pattern[c][d*4+2] == CMD_TONEPORTA) - pattern[c][d*4+3] = makespeedtable(pattern[c][d*4+3], MST_PORTAMENTO, false) + 1; - if (pattern[c][d*4+2] == CMD_VIBRATO) - pattern[c][d*4+3] = makespeedtable(pattern[c][d*4+3], MST_NOFINEVIB, false) + 1; + if (song.pattern[c][d*4+2] == CMD_PORTAUP) + song.pattern[c][d*4+3] = makespeedtable(song.pattern[c][d*4+3], MST_PORTAMENTO, false) + 1; + if (song.pattern[c][d*4+2] == CMD_PORTADOWN) + song.pattern[c][d*4+3] = makespeedtable(song.pattern[c][d*4+3], MST_PORTAMENTO, false) + 1; + if (song.pattern[c][d*4+2] == CMD_TONEPORTA) + song.pattern[c][d*4+3] = makespeedtable(song.pattern[c][d*4+3], MST_PORTAMENTO, false) + 1; + if (song.pattern[c][d*4+2] == CMD_VIBRATO) + song.pattern[c][d*4+3] = makespeedtable(song.pattern[c][d*4+3], MST_NOFINEVIB, false) + 1; // Convert filterjump - if (pattern[c][d*4+2] == CMD_SETFILTERPTR) - pattern[c][d*4+3] = filtermap[pattern[c][d*4+3]]; + if (song.pattern[c][d*4+2] == CMD_SETFILTERPTR) + song.pattern[c][d*4+3] = filtermap[song.pattern[c][d*4+3]]; // Convert funktempo - if ((pattern[c][d*4+2] == CMD_SETTEMPO) && (!pattern[c][d*4+3])) + if ((song.pattern[c][d*4+2] == CMD_SETTEMPO) && (!song.pattern[c][d*4+3])) { - pattern[c][d*4+2] = CMD_FUNKTEMPO; - pattern[c][d*4+3] = makespeedtable((filtertable[2] << 4) | (filtertable[3] & 0x0f), MST_FUNKTEMPO, false) + 1; + song.pattern[c][d*4+2] = CMD_FUNKTEMPO; + song.pattern[c][d*4+3] = makespeedtable((filtertable[2] << 4) | (filtertable[3] & 0x0f), MST_FUNKTEMPO, false) + 1; } // Convert arpeggio - if ((pattern[c][d*4+2] == CMD_DONOTHING) && (pattern[c][d*4+3])) + if ((song.pattern[c][d*4+2] == CMD_DONOTHING) && (song.pattern[c][d*4+3])) { // Must be in conjunction with a note - if ((pattern[c][d*4] >= FIRSTNOTE) && (pattern[c][d*4] <= LASTNOTE)) + if ((song.pattern[c][d*4] >= FIRSTNOTE) && (song.pattern[c][d*4] <= LASTNOTE)) { - unsigned char param = pattern[c][d*4+3]; + unsigned char param = song.pattern[c][d*4+3]; if (i) { // Old arpeggio @@ -741,13 +737,13 @@ void loadsong() // As command, or as instrument? if (arpmap[i][param] < 256) { - pattern[c][d*4+2] = CMD_SETWAVEPTR; - pattern[c][d*4+3] = arpmap[i][param]; + song.pattern[c][d*4+2] = CMD_SETWAVEPTR; + song.pattern[c][d*4+3] = arpmap[i][param]; } else { - pattern[c][d*4+1] = arpmap[i][param] - 256; - pattern[c][d*4+3] = 0; + song.pattern[c][d*4+1] = arpmap[i][param] - 256; + song.pattern[c][d*4+3] = 0; } } else @@ -759,14 +755,14 @@ void loadsong() // New arpeggio // Copy first the instrument's wavetable up to loop/end point arpstart = fw + 1; - if (instr[i].ptr[WTBL]) + if (song.instr[i].ptr[WTBL]) { - for (e = instr[i].ptr[WTBL]-1;; e++) + for (e = song.instr[i].ptr[WTBL]-1;; e++) { - if (ltable[WTBL][e] == 0xff) break; + if (song.ltable[WTBL][e] == 0xff) break; if (fw < MAX_TABLELEN) { - ltable[WTBL][fw] = ltable[WTBL][e]; + song.ltable[WTBL][fw] = song.ltable[WTBL][e]; fw++; } } @@ -775,31 +771,31 @@ void loadsong() arploop = fw + 1; if (fw < MAX_TABLELEN-3) { - ltable[WTBL][fw] = (param & 0x80) >> 7; - rtable[WTBL][fw] = (param & 0x70) >> 4; + song.ltable[WTBL][fw] = (param & 0x80) >> 7; + song.rtable[WTBL][fw] = (param & 0x70) >> 4; fw++; - ltable[WTBL][fw] = (param & 0x80) >> 7; - rtable[WTBL][fw] = (param & 0xf); + song.ltable[WTBL][fw] = (param & 0x80) >> 7; + song.rtable[WTBL][fw] = (param & 0xf); fw++; - ltable[WTBL][fw] = (param & 0x80) >> 7; - rtable[WTBL][fw] = 0; + song.ltable[WTBL][fw] = (param & 0x80) >> 7; + song.rtable[WTBL][fw] = 0; fw++; - ltable[WTBL][fw] = 0xff; - rtable[WTBL][fw] = arploop; + song.ltable[WTBL][fw] = 0xff; + song.rtable[WTBL][fw] = arploop; fw++; // Create new instrument if possible if (fi < MAX_INSTR) { arpmap[i][param] = fi + 256; - instr[fi] = instr[i]; - instr[fi].ptr[WTBL] = arpstart; + song.instr[fi] = song.instr[i]; + song.instr[fi].ptr[WTBL] = arpstart; // Add arpeggio parameter to new instrument name - if (strlen(instr[fi].name) < MAX_INSTRNAMELEN-3) + if (strlen(song.instr[fi].name) < MAX_INSTRNAMELEN-3) { char arpname[8]; sprintf(arpname, "0%02X", param&0x7f); - strcat(instr[fi].name, arpname); + strcat(song.instr[fi].name, arpname); } fi++; } @@ -814,21 +810,21 @@ void loadsong() // As command, or as instrument? if (arpmap[i][param] < 256) { - pattern[c][d*4+2] = CMD_SETWAVEPTR; - pattern[c][d*4+3] = arpmap[i][param]; + song.pattern[c][d*4+2] = CMD_SETWAVEPTR; + song.pattern[c][d*4+3] = arpmap[i][param]; } else { - pattern[c][d*4+1] = arpmap[i][param] - 256; - pattern[c][d*4+3] = 0; + song.pattern[c][d*4+1] = arpmap[i][param] - 256; + song.pattern[c][d*4+3] = 0; } } } } } // If arpeggio could not be converted, databyte zero - if (!pattern[c][d*4+2]) - pattern[c][d*4+3] = 0; + if (!song.pattern[c][d*4+2]) + song.pattern[c][d*4+3] = 0; } } } @@ -847,13 +843,13 @@ void loadsong() { for (int c = 0; c < MAX_TABLELEN; c++) { - if ((ltable[PTBL][c] < 0x80) && (rtable[PTBL][c])) + if ((song.ltable[PTBL][c] < 0x80) && (song.rtable[PTBL][c])) { - int speed = ((signed char)rtable[PTBL][c]); + int speed = ((signed char)song.rtable[PTBL][c]); speed <<= 1; if (speed > 127) speed = 127; if (speed < -128) speed = -128; - rtable[PTBL][c] = speed; + song.rtable[PTBL][c] = speed; } } } @@ -863,12 +859,12 @@ void loadsong() { for (int c = 1; c < MAX_INSTR; c++) { - if (instr[c].firstwave >= 0x80) + if (song.instr[c].firstwave >= 0x80) { - instr[c].gatetimer |= 0x80; - instr[c].firstwave &= 0x7f; + song.instr[c].gatetimer |= 0x80; + song.instr[c].firstwave &= 0x7f; } - if (!instr[c].firstwave) instr[c].gatetimer |= 0x40; + if (!song.instr[c].firstwave) song.instr[c].gatetimer |= 0x40; } } @@ -886,8 +882,8 @@ void loadsong() int ok = 1; for (d = 0; d < pattlen[c]; d++) { - if ((pattern[c][d*4] != REST) || (pattern[c][d*4+1] != 0x00) || - (pattern[c][d*4+2] != 0x00) || (pattern[c][d*4+3] != 0x00)) + if ((song.pattern[c][d*4] != REST) || (song.pattern[c][d*4+1] != 0x00) || + (song.pattern[c][d*4+2] != 0x00) || (song.pattern[c][d*4+3] != 0x00)) ok = 0; } @@ -901,14 +897,14 @@ void loadsong() for (int c = 0; c < MAX_SONGS; c++) { - if (songlen[c][0]) + if (song.len[c][0]) { for (int d = channelstoload; d < MAX_CHN; d++) { - songorder[c][d][0] = emptypatt; - songorder[c][d][1] = 0xff; - songorder[c][d][2] = 0x00; - songlen[c][d] = 1; + song.order[c][d][0] = emptypatt; + song.order[c][d][1] = 0xff; + song.order[c][d][2] = 0x00; + song.len[c][d] = 1; } } } @@ -933,16 +929,16 @@ void loadinstrument() { unsigned char optr[4]; - instr[einum].ad = fread8(handle); - instr[einum].sr = fread8(handle); + song.instr[einum].ad = fread8(handle); + song.instr[einum].sr = fread8(handle); optr[0] = fread8(handle); optr[1] = fread8(handle); optr[2] = fread8(handle); optr[3] = fread8(handle); - instr[einum].vibdelay = fread8(handle); - instr[einum].gatetimer = fread8(handle); - instr[einum].firstwave = fread8(handle); - std::fread(&instr[einum].name, MAX_INSTRNAMELEN, 1, handle); + song.instr[einum].vibdelay = fread8(handle); + song.instr[einum].gatetimer = fread8(handle); + song.instr[einum].firstwave = fread8(handle); + std::fread(&song.instr[einum].name, MAX_INSTRNAMELEN, 1, handle); // Erase old tabledata deleteinstrtable(einum); @@ -957,14 +953,14 @@ void loadinstrument() { int d; for (d = start; (d < start+len) && (d < MAX_TABLELEN); d++) - ltable[c][d] = fread8(handle); + song.ltable[c][d] = fread8(handle); while (d < start+len) { fread8(handle); d++; } for (d = start; (d < start+len) && (d < MAX_TABLELEN); d++) - rtable[c][d] = fread8(handle); + song.rtable[c][d] = fread8(handle); while (d < start+len) { fread8(handle); @@ -974,10 +970,10 @@ void loadinstrument() { for (int d = start; (d < start+len) && (d < MAX_TABLELEN); d++) { - if (ltable[c][d] == 0xff) + if (song.ltable[c][d] == 0xff) { - if (rtable[c][d]) - rtable[c][d] = rtable[c][d] - optr[c] + start + 1; + if (song.rtable[c][d]) + song.rtable[c][d] = song.rtable[c][d] - optr[c] + start + 1; } } } @@ -986,9 +982,9 @@ void loadinstrument() pulsestart = start; pulseend = start + len; } - instr[einum].ptr[c] = start + 1; + song.instr[einum].ptr[c] = start + 1; } - else instr[einum].ptr[c] = 0; + else song.instr[einum].ptr[c] = 0; } } @@ -997,16 +993,16 @@ void loadinstrument() { unsigned char optr[3]; - instr[einum].ad = fread8(handle); - instr[einum].sr = fread8(handle); + song.instr[einum].ad = fread8(handle); + song.instr[einum].sr = fread8(handle); optr[0] = fread8(handle); optr[1] = fread8(handle); optr[2] = fread8(handle); - instr[einum].vibdelay = fread8(handle); - instr[einum].ptr[STBL] = makespeedtable(fread8(handle), finevibrato, false) + 1; - instr[einum].gatetimer = fread8(handle); - instr[einum].firstwave = fread8(handle); - std::fread(&instr[einum].name, MAX_INSTRNAMELEN, 1, handle); + song.instr[einum].vibdelay = fread8(handle); + song.instr[einum].ptr[STBL] = makespeedtable(fread8(handle), finevibrato, false) + 1; + song.instr[einum].gatetimer = fread8(handle); + song.instr[einum].firstwave = fread8(handle); + std::fread(&song.instr[einum].name, MAX_INSTRNAMELEN, 1, handle); // Erase old tabledata deleteinstrtable(einum); @@ -1021,14 +1017,14 @@ void loadinstrument() { int d; for (d = start; (d < start+len) && (d < MAX_TABLELEN); d++) - ltable[c][d] = fread8(handle); + song.ltable[c][d] = fread8(handle); while (d < start+len) { fread8(handle); d++; } for (d = start; (d < start+len) && (d < MAX_TABLELEN); d++) - rtable[c][d] = fread8(handle); + song.rtable[c][d] = fread8(handle); while (d < start+len) { fread8(handle); @@ -1036,10 +1032,10 @@ void loadinstrument() } for (int d = start; (d < start+len) && (d < MAX_TABLELEN); d++) { - if (ltable[c][d] == 0xff) + if (song.ltable[c][d] == 0xff) { - if (rtable[c][d]) - rtable[c][d] = rtable[c][d] - optr[c] + start + 1; + if (song.rtable[c][d]) + song.rtable[c][d] = song.rtable[c][d] - optr[c] + start + 1; } } if (c == PTBL) @@ -1047,9 +1043,9 @@ void loadinstrument() pulsestart = start; pulseend = start + len; } - instr[einum].ptr[c] = start + 1; + song.instr[einum].ptr[c] = start + 1; } - else instr[einum].ptr[c] = 0; + else song.instr[einum].ptr[c] = 0; } } // Goattracker 1.xx import @@ -1067,32 +1063,32 @@ void loadinstrument() fp = gettablelen(PTBL); ff = gettablelen(FTBL); - instr[einum].ad = fread8(handle); - instr[einum].sr = fread8(handle); + song.instr[einum].ad = fread8(handle); + song.instr[einum].sr = fread8(handle); if (multiplier) - instr[einum].gatetimer = 2 * multiplier; + song.instr[einum].gatetimer = 2 * multiplier; else - instr[einum].gatetimer = 1; - instr[einum].firstwave = 0x9; + song.instr[einum].gatetimer = 1; + song.instr[einum].firstwave = 0x9; pulse = fread8(handle); pulseadd = fread8(handle); pulselimitlow = fread8(handle); pulselimithigh = fread8(handle); - instr[einum].ptr[FTBL] = fread8(handle) ? ff+1 : 0; - if (pulse & 1) instr[einum].gatetimer |= 0x80; // "No hardrestart" flag + song.instr[einum].ptr[FTBL] = fread8(handle) ? ff+1 : 0; + if (pulse & 1) song.instr[einum].gatetimer |= 0x80; // "No hardrestart" flag wavelen = fread8(handle)/2; - std::fread(&instr[einum].name, MAX_INSTRNAMELEN, 1, handle); - instr[einum].ptr[WTBL] = fw+1; + std::fread(&song.instr[einum].name, MAX_INSTRNAMELEN, 1, handle); + song.instr[einum].ptr[WTBL] = fw+1; // Convert wavetable for (int d = 0; d < wavelen; d++) { if (fw < MAX_TABLELEN) { - ltable[WTBL][fw] = fread8(handle); - rtable[WTBL][fw] = fread8(handle); - if (ltable[WTBL][fw] == 0xff) - if (rtable[WTBL][fw]) rtable[WTBL][fw] += instr[einum].ptr[WTBL]-1; + 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; fw++; } else @@ -1103,14 +1099,14 @@ void loadinstrument() } // Remove empty wavetable afterwards - if ((wavelen == 2) && (!ltable[WTBL][fw-2]) && (!rtable[WTBL][fw-2])) + if ((wavelen == 2) && (!song.ltable[WTBL][fw-2]) && (!song.rtable[WTBL][fw-2])) { - instr[einum].ptr[WTBL] = 0; + song.instr[einum].ptr[WTBL] = 0; fw -= 2; - ltable[WTBL][fw] = 0; - rtable[WTBL][fw] = 0; - ltable[WTBL][fw+1] = 0; - rtable[WTBL][fw+1] = 0; + song.ltable[WTBL][fw] = 0; + song.rtable[WTBL][fw] = 0; + song.ltable[WTBL][fw+1] = 0; + song.rtable[WTBL][fw+1] = 0; } // Convert pulsetable @@ -1122,9 +1118,9 @@ void loadinstrument() // Initial pulse setting if (fp >= MAX_TABLELEN) goto PULSEDONE; pulsestart = fp; - instr[einum].ptr[PTBL] = fp+1; - ltable[PTBL][fp] = 0x80 | (pulse >> 4); - rtable[PTBL][fp] = pulse << 4; + song.instr[einum].ptr[PTBL] = fp+1; + song.ltable[PTBL][fp] = 0x80 | (pulse >> 4); + song.rtable[PTBL][fp] = pulse << 4; fp++; // Pulse modulation @@ -1143,8 +1139,8 @@ void loadinstrument() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = acttime; - rtable[PTBL][fp] = pulseadd / 2; + song.ltable[PTBL][fp] = acttime; + song.rtable[PTBL][fp] = pulseadd / 2; fp++; pulsetime -= acttime; } @@ -1162,8 +1158,8 @@ void loadinstrument() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = acttime; - rtable[PTBL][fp] = -(pulseadd / 2); + song.ltable[PTBL][fp] = acttime; + song.rtable[PTBL][fp] = -(pulseadd / 2); fp++; pulsetime -= acttime; } @@ -1181,16 +1177,16 @@ void loadinstrument() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = acttime; - rtable[PTBL][fp] = pulseadd / 2; + song.ltable[PTBL][fp] = acttime; + song.rtable[PTBL][fp] = pulseadd / 2; fp++; pulsetime -= acttime; } } // Pulse jump back to beginning if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = 0xff; - rtable[PTBL][fp] = instr[einum].ptr[PTBL] + 1; + song.ltable[PTBL][fp] = 0xff; + song.rtable[PTBL][fp] = song.instr[einum].ptr[PTBL] + 1; fp++; } else @@ -1204,16 +1200,16 @@ void loadinstrument() int acttime = pulsetime; if (acttime > 127) acttime = 127; if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = acttime; - rtable[PTBL][fp] = pulseadd / 2; + song.ltable[PTBL][fp] = acttime; + song.rtable[PTBL][fp] = pulseadd / 2; fp++; pulsetime -= acttime; } } // Pulse jump back to beginning if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = 0xff; - rtable[PTBL][fp] = hlpos + 1; + song.ltable[PTBL][fp] = 0xff; + song.rtable[PTBL][fp] = hlpos + 1; fp++; } } @@ -1221,8 +1217,8 @@ void loadinstrument() { // Pulse stopped if (fp >= MAX_TABLELEN) goto PULSEDONE; - ltable[PTBL][fp] = 0xff; - rtable[PTBL][fp] = 0; + song.ltable[PTBL][fp] = 0xff; + song.rtable[PTBL][fp] = 0; fp++; } PULSEDONE: @@ -1230,19 +1226,19 @@ void loadinstrument() } // Convert filter (if any) - if ((instr[einum].ptr[FTBL]) && (ff < MAX_TABLELEN-2)) + if ((song.instr[einum].ptr[FTBL]) && (ff < MAX_TABLELEN-2)) { std::fread(filtertemp, sizeof filtertemp, 1, handle); // Filter set if (filtertemp[0]) { - ltable[FTBL][ff] = 0x80 + (filtertemp[1] & 0x70); - rtable[FTBL][ff] = filtertemp[0]; + song.ltable[FTBL][ff] = 0x80 + (filtertemp[1] & 0x70); + song.rtable[FTBL][ff] = filtertemp[0]; ff++; if (filtertemp[2]) { - ltable[FTBL][ff] = 0x00; - rtable[FTBL][ff] = filtertemp[2]; + song.ltable[FTBL][ff] = 0x00; + song.rtable[FTBL][ff] = filtertemp[2]; ff++; } } @@ -1255,16 +1251,16 @@ void loadinstrument() { int acttime = time; if (acttime > 127) acttime = 127; - ltable[FTBL][ff] = acttime; - rtable[FTBL][ff] = filtertemp[2]; + song.ltable[FTBL][ff] = acttime; + song.rtable[FTBL][ff] = filtertemp[2]; ff++; time -= acttime; } } // Jump to next step: always end the filter - ltable[FTBL][ff] = 0xff; - rtable[FTBL][ff] = 0; + song.ltable[FTBL][ff] = 0xff; + song.rtable[FTBL][ff] = 0; ff++; } } @@ -1276,25 +1272,25 @@ void loadinstrument() { for (int c = pulsestart; (c < pulseend) && (c < MAX_TABLELEN); c++) { - if ((ltable[PTBL][c] < 0x80) && (rtable[PTBL][c])) + if ((song.ltable[PTBL][c] < 0x80) && (song.rtable[PTBL][c])) { - int speed = ((signed char)rtable[PTBL][c]); + int speed = ((signed char)song.rtable[PTBL][c]); speed <<= 1; if (speed > 127) speed = 127; if (speed < -128) speed = -128; - rtable[PTBL][c] = speed; + song.rtable[PTBL][c] = speed; } } } // Convert old legato/nohr parameters if (ident[3] < '5') { - if (instr[einum].firstwave >= 0x80) + if (song.instr[einum].firstwave >= 0x80) { - instr[einum].firstwave &= 0x7f; - instr[einum].gatetimer |= 0x80; + song.instr[einum].firstwave &= 0x7f; + song.instr[einum].gatetimer |= 0x80; } - if (!instr[einum].firstwave) instr[einum].gatetimer |= 0x40; + if (!song.instr[einum].firstwave) song.instr[einum].gatetimer |= 0x40; } } } @@ -1326,18 +1322,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(&songorder[d][c][0], 0, MAX_SONGLEN+2); + std::memset(&song.order[d][c][0], 0, MAX_SONGLEN+2); if (!d) { - songorder[d][c][0] = c; - songorder[d][c][1] = LOOPSONG; + song.order[d][c][0] = c; + song.order[d][c][1] = LOOPSONG; } else { - songorder[d][c][0] = LOOPSONG; + song.order[d][c][0] = LOOPSONG; } } - epnum[c] = songorder[0][c][0]; + epnum[c] = song.order[0][c][0]; espos[c] = 0; esend[c] = 0; } @@ -1376,8 +1372,8 @@ void clearsong(bool cs, bool cp, bool ci, bool ct, bool cn) { for (int c = MAX_TABLES-1; c >= 0; c--) { - std::memset(ltable[c], 0, MAX_TABLELEN); - std::memset(rtable[c], 0, MAX_TABLELEN); + std::memset(song.ltable[c], 0, MAX_TABLELEN); + std::memset(song.rtable[c], 0, MAX_TABLELEN); tables.settableview(c, 0); } } @@ -1395,10 +1391,10 @@ void countpatternlengths() int d; for (d = 0; d <= MAX_PATTROWS; d++) { - if (pattern[c][d*4] == ENDPATT) break; - if ((pattern[c][d*4] != REST) || (pattern[c][d*4+1]) || (pattern[c][d*4+2]) || (pattern[c][d*4+3])) + if (song.pattern[c][d*4] == ENDPATT) break; + if ((song.pattern[c][d*4] != REST) || (song.pattern[c][d*4+1]) || (song.pattern[c][d*4+2]) || (song.pattern[c][d*4+3])) highestusedpattern = c; - if (pattern[c][d*4+1] > highestusedinstr) highestusedinstr = pattern[c][d*4+1]; + if (song.pattern[c][d*4+1] > highestusedinstr) highestusedinstr = song.pattern[c][d*4+1]; } pattlen[c] = d; } @@ -1410,14 +1406,14 @@ void countpatternlengths() int d; for (d = 0; d < MAX_SONGLEN; d++) { - if (songorder[e][c][d] >= LOOPSONG) break; - if ((songorder[e][c][d] < REPEAT) && - (songorder[e][c][d] > highestusedpattern)) + if (song.order[e][c][d] >= LOOPSONG) break; + if ((song.order[e][c][d] < REPEAT) && + (song.order[e][c][d] > highestusedpattern)) { - highestusedpattern = songorder[e][c][d]; + highestusedpattern = song.order[e][c][d]; } } - songlen[e][c] = d; + song.len[e][c] = d; } } } @@ -1428,7 +1424,7 @@ void countthispattern() int d; for (d = 0; d <= MAX_PATTROWS; d++) { - if (pattern[c][d*4] == ENDPATT) break; + if (song.pattern[c][d*4] == ENDPATT) break; } pattlen[c] = d; @@ -1436,13 +1432,13 @@ void countthispattern() c = eschn; for (d = 0; d < MAX_SONGLEN; d++) { - if (songorder[e][c][d] >= LOOPSONG) break; - if (songorder[e][c][d] > highestusedpattern) + if (song.order[e][c][d] >= LOOPSONG) break; + if (song.order[e][c][d] > highestusedpattern) { - highestusedpattern = songorder[e][c][d]; + highestusedpattern = song.order[e][c][d]; } } - songlen[e][c] = d; + song.len[e][c] = d; } int insertpattern(int p) @@ -1452,23 +1448,23 @@ int insertpattern(int p) findusedpatterns(); if (p >= MAX_PATT-2) return 0; if (pattused[MAX_PATT-1]) return 0; - std::memmove(pattern[p+2], pattern[p+1], (MAX_PATT-p-2)*(MAX_PATTROWS*4+4)); + std::memmove(song.pattern[p+2], song.pattern[p+1], (MAX_PATT-p-2)*(MAX_PATTROWS*4+4)); countpatternlengths(); for (int c = 0; c < MAX_SONGS; c++) { - if ((songlen[c][0]) && (songlen[c][1]) && (songlen[c][2])) + if ((song.len[c][0]) && (song.len[c][1]) && (song.len[c][2])) { for (int d = 0; d < maxChns; d++) { - int tmp = songlen[c][d]; + int tmp = song.len[c][d]; for (int e = 0; e < tmp; e++) { - if ((songorder[c][d][e] < REPEAT) && - (songorder[c][d][e] > p) && - (songorder[c][d][e] != MAX_PATT-1)) + if ((song.order[c][d][e] < REPEAT) && + (song.order[c][d][e] > p) && + (song.order[c][d][e] != MAX_PATT-1)) { - songorder[c][d][e]++; + song.order[c][d][e]++; } } } @@ -1489,23 +1485,23 @@ void deletepattern(int p) if (p == MAX_PATT-1) return; - std::memmove(pattern[p], pattern[p+1], (MAX_PATT-p-1)*(MAX_PATTROWS*4+4)); + std::memmove(song.pattern[p], song.pattern[p+1], (MAX_PATT-p-1)*(MAX_PATTROWS*4+4)); clearpattern(MAX_PATT-1); countpatternlengths(); for (int c = 0; c < MAX_SONGS; c++) { - if ((songlen[c][0]) && (songlen[c][1]) && (songlen[c][2])) + if ((song.len[c][0]) && (song.len[c][1]) && (song.len[c][2])) { for (int d = 0; d < maxChns; d++) { - int tmp = songlen[c][d]; + int tmp = song.len[c][d]; for (int e = 0; e < tmp; e++) { - if ((songorder[c][d][e] < REPEAT) && - (songorder[c][d][e] > p)) + if ((song.order[c][d][e] < REPEAT) && + (song.order[c][d][e] > p)) { - songorder[c][d][e]--; + song.order[c][d][e]--; } } } @@ -1520,9 +1516,9 @@ void deletepattern(int p) void clearpattern(int p) { - std::memset(pattern[p], 0, MAX_PATTROWS*4); - for (int c = 0; c < defaultpatternlength; c++) pattern[p][c*4] = REST; - for (int c = defaultpatternlength; c <= MAX_PATTROWS; c++) pattern[p][c*4] = ENDPATT; + std::memset(song.pattern[p], 0, MAX_PATTROWS*4); + for (int c = 0; c < defaultpatternlength; c++) song.pattern[p][c*4] = REST; + for (int c = defaultpatternlength; c <= MAX_PATTROWS; c++) song.pattern[p][c*4] = ENDPATT; } void findusedpatterns() @@ -1533,16 +1529,16 @@ void findusedpatterns() std::memset(pattused, 0, sizeof pattused); for (int c = 0; c < MAX_SONGS; c++) { - if ((songlen[c][0]) && (songlen[c][1]) && (songlen[c][2])) + if ((song.len[c][0]) && (song.len[c][1]) && (song.len[c][2])) { for (int d = 0; d < maxChns; d++) { - int tmp = songlen[c][d]; + int tmp = song.len[c][d]; for (int e = 0; e < tmp; e++) { - if (songorder[c][d][e] < REPEAT) + if (song.order[c][d][e] < REPEAT) { - pattused[songorder[c][d][e]] = 1; + pattused[song.order[c][d][e]] = 1; } } } @@ -1557,8 +1553,8 @@ void mergesong() highestusedinstr = 0; for (int c = 1; c < MAX_INSTR; c++) { - if ((instr[c].ad) || (instr[c].sr) || (instr[c].ptr[0]) || (instr[c].ptr[1]) || - (instr[c].ptr[2]) || (instr[c].vibdelay) || (instr[c].ptr[3])) + if ((song.instr[c].ad) || (song.instr[c].sr) || (song.instr[c].ptr[0]) || (song.instr[c].ptr[1]) || + (song.instr[c].ptr[2]) || (song.instr[c].vibdelay) || (song.instr[c].ptr[3])) { if (c > highestusedinstr) highestusedinstr = c; } @@ -1568,9 +1564,9 @@ void mergesong() int c = MAX_SONGS - 1; for (;;) { - if ((songlen[c][0]) && - (songlen[c][1]) && - (songlen[c][2])) break; + if ((song.len[c][0]) && + (song.len[c][1]) && + (song.len[c][2])) break; if (c == 0) break; c--; } @@ -1601,7 +1597,7 @@ void mergesong() // Skip infotexts std::fseek(handle, sizeof songname + sizeof authorname + sizeof copyrightname, SEEK_CUR); - // Read songorderlists + // Read song.orderlists int channelstoload = determinechannels(handle); int amount = fread8(handle); if (amount + songbase > MAX_SONGS) @@ -1613,12 +1609,12 @@ void mergesong() length = fread8(handle); loadsize = length; loadsize++; - std::fread(songorder[songbase + d][c], loadsize, 1, handle); + std::fread(song.order[songbase + d][c], loadsize, 1, handle); // Remap patterns for (int e = 0; e < loadsize - 1; e++) { - if (songorder[songbase + d][c][e] < REPEAT) - songorder[songbase + d][c][e] += pattbase; + if (song.order[songbase + d][c][e] < REPEAT) + song.order[songbase + d][c][e] += pattbase; } } } @@ -1628,24 +1624,24 @@ void mergesong() goto ABORT; for (int c = 1; c <= amount; c++) { - instr[c + instrbase].ad = fread8(handle); - instr[c + instrbase].sr = fread8(handle); - instr[c + instrbase].ptr[WTBL] = fread8(handle); - instr[c + instrbase].ptr[PTBL] = fread8(handle); - instr[c + instrbase].ptr[FTBL] = fread8(handle); - instr[c + instrbase].ptr[STBL] = fread8(handle); - if (instr[c + instrbase].ptr[WTBL] > 0) - instr[c + instrbase].ptr[WTBL] += tablebase[WTBL]; - if (instr[c + instrbase].ptr[PTBL] > 0) - instr[c + instrbase].ptr[PTBL] += tablebase[PTBL]; - if (instr[c + instrbase].ptr[FTBL] > 0) - instr[c + instrbase].ptr[FTBL] += tablebase[FTBL]; - if (instr[c + instrbase].ptr[STBL] > 0) - instr[c + instrbase].ptr[STBL] += tablebase[STBL]; - instr[c + instrbase].vibdelay = fread8(handle); - instr[c + instrbase].gatetimer = fread8(handle); - instr[c + instrbase].firstwave = fread8(handle); - std::fread(&instr[c + instrbase].name, MAX_INSTRNAMELEN, 1, handle); + song.instr[c + instrbase].ad = fread8(handle); + song.instr[c + instrbase].sr = fread8(handle); + song.instr[c + instrbase].ptr[WTBL] = fread8(handle); + song.instr[c + instrbase].ptr[PTBL] = fread8(handle); + song.instr[c + instrbase].ptr[FTBL] = fread8(handle); + song.instr[c + instrbase].ptr[STBL] = fread8(handle); + if (song.instr[c + instrbase].ptr[WTBL] > 0) + song.instr[c + instrbase].ptr[WTBL] += tablebase[WTBL]; + if (song.instr[c + instrbase].ptr[PTBL] > 0) + song.instr[c + instrbase].ptr[PTBL] += tablebase[PTBL]; + if (song.instr[c + instrbase].ptr[FTBL] > 0) + song.instr[c + instrbase].ptr[FTBL] += tablebase[FTBL]; + if (song.instr[c + instrbase].ptr[STBL] > 0) + song.instr[c + instrbase].ptr[STBL] += tablebase[STBL]; + song.instr[c + instrbase].vibdelay = fread8(handle); + song.instr[c + instrbase].gatetimer = fread8(handle); + song.instr[c + instrbase].firstwave = fread8(handle); + std::fread(&song.instr[c + instrbase].name, MAX_INSTRNAMELEN, 1, handle); } // Read tables for (int c = 0; c < MAX_TABLES; c++) @@ -1653,24 +1649,24 @@ void mergesong() loadsize = fread8(handle); if (loadsize + tablebase[c] > MAX_TABLELEN) goto ABORT; - std::fread(<able[c][tablebase[c]], loadsize, 1, handle); - std::fread(&rtable[c][tablebase[c]], loadsize, 1, handle); + std::fread(&song.ltable[c][tablebase[c]], loadsize, 1, handle); + std::fread(&song.rtable[c][tablebase[c]], loadsize, 1, handle); // Remap jumps and tablecommands for (int d = tablebase[c]; d < tablebase[c] + loadsize; d++) { - if (ltable[c][d] == 0xff && rtable[c][d] > 0) - rtable[c][d] += tablebase[c]; - if (c == 0 && (ltable[c][d] >= WAVECMD && ltable[c][d] <= WAVELASTCMD)) + 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)) { - int cmd = ltable[c][d] & 0xf; - if (cmd == CMD_SETWAVEPTR && rtable[c][d] > 0) - rtable[c][d] += tablebase[WTBL]; - if (cmd == CMD_SETPULSEPTR && rtable[c][d] > 0) - rtable[c][d] += tablebase[PTBL]; - if (cmd == CMD_SETFILTERPTR && rtable[c][d] > 0) - rtable[c][d] += tablebase[FTBL]; - if (((cmd >= CMD_PORTAUP && cmd <= CMD_VIBRATO) || cmd == CMD_FUNKTEMPO) && rtable[c][d] > 0) - rtable[c][d] += tablebase[STBL]; + 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]; } } } @@ -1682,21 +1678,21 @@ void mergesong() for (int c = 0; c < amount; c++) { length = fread8(handle) * 4; - std::fread(pattern[c + pattbase], length, 1, handle); - // Remap pattern instruments and commands + std::fread(song.pattern[c + pattbase], length, 1, handle); + // Remap song.pattern instruments and commands for (int d = 0; d < length; d += 4) { - if (pattern[c + pattbase][d + 1] > 0) - pattern[c + pattbase][d + 1] += instrbase; - if (pattern[c + pattbase][d + 2] == CMD_SETWAVEPTR && pattern[c + pattbase][d + 3] > 0) - pattern[c + pattbase][d + 3] += tablebase[WTBL]; - if (pattern[c + pattbase][d + 2] == CMD_SETPULSEPTR && pattern[c + pattbase][d + 3] > 0) - pattern[c + pattbase][d + 3] += tablebase[PTBL]; - if (pattern[c + pattbase][d + 2] == CMD_SETFILTERPTR && pattern[c + pattbase][d + 3] > 0) - pattern[c + pattbase][d + 3] += tablebase[FTBL]; - if (((pattern[c + pattbase][d + 2] >= CMD_PORTAUP && pattern[c + pattbase][d + 2] <= CMD_VIBRATO) || - pattern[c + pattbase][d + 2] == CMD_FUNKTEMPO) && pattern[c + pattbase][d + 3] > 0) - pattern[c + pattbase][d + 3] += tablebase[STBL]; + if (song.pattern[c + pattbase][d + 1] > 0) + song.pattern[c + pattbase][d + 1] += instrbase; + if (song.pattern[c + pattbase][d + 2] == CMD_SETWAVEPTR && song.pattern[c + pattbase][d + 3] > 0) + song.pattern[c + pattbase][d + 3] += tablebase[WTBL]; + if (song.pattern[c + pattbase][d + 2] == CMD_SETPULSEPTR && song.pattern[c + pattbase][d + 3] > 0) + song.pattern[c + pattbase][d + 3] += tablebase[PTBL]; + if (song.pattern[c + pattbase][d + 2] == CMD_SETFILTERPTR && song.pattern[c + pattbase][d + 3] > 0) + song.pattern[c + pattbase][d + 3] += tablebase[FTBL]; + if (((song.pattern[c + pattbase][d + 2] >= CMD_PORTAUP && song.pattern[c + pattbase][d + 2] <= CMD_VIBRATO) || + song.pattern[c + pattbase][d + 2] == CMD_FUNKTEMPO) && song.pattern[c + pattbase][d + 3] > 0) + song.pattern[c + pattbase][d + 3] += tablebase[STBL]; } } } diff --git a/src/song.h b/src/song.h index 574c8ee..4b35329 100644 --- a/src/song.h +++ b/src/song.h @@ -19,16 +19,25 @@ #ifndef SONG_H #define SONG_H +#include "common.h" + +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]; + unsigned char pattern[MAX_PATT][MAX_PATTROWS*4+4]; + + char title[MAX_STR]; + char author[MAX_STR]; + char released[MAX_STR]; +}; + + #ifndef SONG_C -extern INSTR instr[MAX_INSTR]; -extern unsigned char ltable[MAX_TABLES][MAX_TABLELEN]; -extern unsigned char rtable[MAX_TABLES][MAX_TABLELEN]; -extern unsigned char songorder[MAX_SONGS][MAX_CHN][MAX_SONGLEN+2]; -extern int songlen[MAX_SONGS][MAX_CHN]; -extern unsigned char pattern[MAX_PATT][MAX_PATTROWS*4+4]; -extern char songname[MAX_STR]; -extern char authorname[MAX_STR]; -extern char copyrightname[MAX_STR]; +extern Song song; #endif void loadsong(); diff --git a/src/table.cpp b/src/table.cpp index cfb354f..680fc39 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -55,64 +55,64 @@ void tablecommands() case KEY_Q: if ((shiftpressed) && (tables.num() == STBL)) { - int speed = (ltable[tables.num()][tables.pos()] << 8) | rtable[tables.num()][tables.pos()]; + int speed = (song.ltable[tables.num()][tables.pos()] << 8) | song.rtable[tables.num()][tables.pos()]; speed *= 34716; speed /= 32768; if (speed > 65535) speed = 65535; - ltable[tables.num()][tables.pos()] = speed >> 8; - rtable[tables.num()][tables.pos()] = speed & 0xff; + song.ltable[tables.num()][tables.pos()] = speed >> 8; + song.rtable[tables.num()][tables.pos()] = speed & 0xff; } break; case KEY_A: if ((shiftpressed) && (tables.num() == STBL)) { - int speed = (ltable[tables.num()][tables.pos()] << 8) | rtable[tables.num()][tables.pos()]; + int speed = (song.ltable[tables.num()][tables.pos()] << 8) | song.rtable[tables.num()][tables.pos()]; speed *= 30929; speed /= 32768; - ltable[tables.num()][tables.pos()] = speed >> 8; - rtable[tables.num()][tables.pos()] = speed & 0xff; + song.ltable[tables.num()][tables.pos()] = speed >> 8; + song.rtable[tables.num()][tables.pos()] = speed & 0xff; } break; case KEY_W: if ((shiftpressed) && (tables.num() == STBL)) { - int speed = (ltable[tables.num()][tables.pos()] << 8) | rtable[tables.num()][tables.pos()]; + int speed = (song.ltable[tables.num()][tables.pos()] << 8) | song.rtable[tables.num()][tables.pos()]; speed *= 2; if (speed > 65535) speed = 65535; - ltable[tables.num()][tables.pos()] = speed >> 8; - rtable[tables.num()][tables.pos()] = speed & 0xff; + song.ltable[tables.num()][tables.pos()] = speed >> 8; + song.rtable[tables.num()][tables.pos()] = speed & 0xff; } - if ((shiftpressed) && ((tables.num() == PTBL) || (tables.num() == FTBL)) && (ltable[tables.num()][tables.pos()] < 0x80)) + if ((shiftpressed) && ((tables.num() == PTBL) || (tables.num() == FTBL)) && (song.ltable[tables.num()][tables.pos()] < 0x80)) { - int speed = (signed char)(rtable[tables.num()][tables.pos()]); + int speed = (signed char)(song.rtable[tables.num()][tables.pos()]); speed *= 2; if (speed > 127) speed = 127; if (speed < -128) speed = -128; - rtable[tables.num()][tables.pos()] = speed; + song.rtable[tables.num()][tables.pos()] = speed; } break; case KEY_S: if ((shiftpressed) && (tables.num() == STBL)) { - int speed = (ltable[tables.num()][tables.pos()] << 8) | rtable[tables.num()][tables.pos()]; + int speed = (song.ltable[tables.num()][tables.pos()] << 8) | song.rtable[tables.num()][tables.pos()]; speed /= 2; - ltable[tables.num()][tables.pos()] = speed >> 8; - rtable[tables.num()][tables.pos()] = speed & 0xff; + song.ltable[tables.num()][tables.pos()] = speed >> 8; + song.rtable[tables.num()][tables.pos()] = speed & 0xff; } - if ((shiftpressed) && ((tables.num() == PTBL) || (tables.num() == FTBL)) && (ltable[tables.num()][tables.pos()] < 0x80)) + if ((shiftpressed) && ((tables.num() == PTBL) || (tables.num() == FTBL)) && (song.ltable[tables.num()][tables.pos()] < 0x80)) { - int speed = (signed char)(rtable[tables.num()][tables.pos()]); + int speed = (signed char)(song.rtable[tables.num()][tables.pos()]); speed /= 2; - rtable[tables.num()][tables.pos()] = speed; + song.rtable[tables.num()][tables.pos()] = speed; } break; @@ -188,12 +188,12 @@ void tablecommands() int d = 0; for (int c = markstart; c <= markend; c++) { - ltablecopybuffer[d] = ltable[tables.marknum()][c]; - rtablecopybuffer[d] = rtable[tables.marknum()][c]; + ltablecopybuffer[d] = song.ltable[tables.marknum()][c]; + rtablecopybuffer[d] = song.rtable[tables.marknum()][c]; if (rawkey == KEY_X) { - ltable[tables.marknum()][c] = 0; - rtable[tables.marknum()][c] = 0; + song.ltable[tables.marknum()][c] = 0; + song.rtable[tables.marknum()][c] = 0; } d++; } @@ -210,8 +210,8 @@ void tablecommands() { for (int c = 0; c < tablecopyrows; c++) { - ltable[tables.num()][tables.pos()] = ltablecopybuffer[c]; - rtable[tables.num()][tables.pos()] = rtablecopybuffer[c]; + song.ltable[tables.num()][tables.pos()] = ltablecopybuffer[c]; + song.rtable[tables.num()][tables.pos()] = rtablecopybuffer[c]; tables.m_pos++; if (tables.pos() >= MAX_TABLELEN) tables.m_pos = MAX_TABLELEN-1; } @@ -234,11 +234,11 @@ void tablecommands() case KEY_R: if (tables.num() == WTBL) { - if (ltable[tables.num()][tables.pos()] != 0xff) + if (song.ltable[tables.num()][tables.pos()] != 0xff) { // Convert absolute pitch to relative pitch or vice versa int basenote = epoctave * 12; - int note = rtable[tables.num()][tables.pos()]; + int note = song.rtable[tables.num()][tables.pos()]; if (note >= 0x80) { @@ -251,7 +251,7 @@ void tablecommands() note |= 0x80; } - rtable[tables.num()][tables.pos()] = note; + song.rtable[tables.num()][tables.pos()] = note; } } /* fall through */ @@ -259,8 +259,8 @@ void tablecommands() if (tables.num() == PTBL) { int currentpulse = -1; - int targetpulse = ltable[tables.num()][tables.pos()] << 4; - int speed = rtable[tables.num()][tables.pos()]; + int targetpulse = song.ltable[tables.num()][tables.pos()] << 4; + int speed = song.rtable[tables.num()][tables.pos()]; if (!speed) break; @@ -268,10 +268,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 (ltable[tables.num()][c] == 0xff) break; - if (ltable[tables.num()][c] >= 0x80) + if (song.ltable[tables.num()][c] == 0xff) break; + if (song.ltable[tables.num()][c] >= 0x80) { - currentpulse = (ltable[tables.num()][c] << 8) | rtable[tables.num()][c]; + currentpulse = (song.ltable[tables.num()][c] << 8) | song.rtable[tables.num()][c]; currentpulse &= 0xfff; break; } @@ -281,10 +281,10 @@ void tablecommands() // Then follow the chain of modulation steps for (; c < tables.pos(); c++) { - if (ltable[tables.num()][c] < 0x80) + if (song.ltable[tables.num()][c] < 0x80) { - currentpulse += ltable[tables.num()][c] * (rtable[tables.num()][c] & 0xff); - if (rtable[tables.num()][c] >= 0x80) currentpulse -= 256 * ltable[tables.num()][c]; + 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 &= 0xfff; } } @@ -303,16 +303,16 @@ void tablecommands() { if (std::abs(speed) < 128) { - ltable[tables.num()][tables.pos()] = (time < 127) ? time : 127; - rtable[tables.num()][tables.pos()] = speed; - time -= ltable[tables.num()][tables.pos()]; + song.ltable[tables.num()][tables.pos()] = (time < 127) ? time : 127; + song.rtable[tables.num()][tables.pos()] = speed; + time -= song.ltable[tables.num()][tables.pos()]; tables.m_pos++; } else { currentpulse += speed; - ltable[tables.num()][tables.pos()] = 0x80 | ((currentpulse >> 8) & 0xf); - rtable[tables.num()][tables.pos()] = currentpulse & 0xff; + song.ltable[tables.num()][tables.pos()] = 0x80 | ((currentpulse >> 8) & 0xf); + song.rtable[tables.num()][tables.pos()] = currentpulse & 0xff; time--; tables.m_pos++; } @@ -321,8 +321,8 @@ void tablecommands() if (tables.num() == FTBL) { int currentfilter = -1; - int targetfilter = ltable[tables.num()][tables.pos()]; - int speed = rtable[tables.num()][tables.pos()] & 0x7f; + int targetfilter = song.ltable[tables.num()][tables.pos()]; + int speed = song.rtable[tables.num()][tables.pos()] & 0x7f; if (!speed) break; @@ -330,10 +330,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 (ltable[tables.num()][c] == 0xff) break; - if (ltable[tables.num()][c] == 0x00) + if (song.ltable[tables.num()][c] == 0xff) break; + if (song.ltable[tables.num()][c] == 0x00) { - currentfilter = rtable[tables.num()][c]; + currentfilter = song.rtable[tables.num()][c]; break; } } @@ -342,9 +342,9 @@ void tablecommands() // Then follow the chain of modulation steps for (; c < tables.pos(); c++) { - if (ltable[tables.num()][c] < 0x80) + if (song.ltable[tables.num()][c] < 0x80) { - currentfilter += ltable[tables.num()][c] * rtable[tables.num()][c]; + currentfilter += song.ltable[tables.num()][c] * song.rtable[tables.num()][c]; currentfilter &= 0xff; } } @@ -360,9 +360,9 @@ void tablecommands() while (time) { - ltable[tables.num()][tables.pos()] = (time < 127) ? time : 127; - rtable[tables.num()][tables.pos()] = speed; - time -= ltable[tables.num()][tables.pos()]; + song.ltable[tables.num()][tables.pos()] = (time < 127) ? time : 127; + song.rtable[tables.num()][tables.pos()] = speed; + time -= song.ltable[tables.num()][tables.pos()]; tables.m_pos++; } } @@ -375,17 +375,17 @@ void tablecommands() { // Negate pulse or filter speed case FTBL: - if (!ltable[tables.num()][tables.pos()]) break; + if (!song.ltable[tables.num()][tables.pos()]) break; /* fall through */ case PTBL: - if (ltable[tables.num()][tables.pos()] < 0x80) - rtable[tables.num()][tables.pos()] = (rtable[tables.num()][tables.pos()] ^ 0xff) + 1; + if (song.ltable[tables.num()][tables.pos()] < 0x80) + song.rtable[tables.num()][tables.pos()] = (song.rtable[tables.num()][tables.pos()] ^ 0xff) + 1; break; // Negate relative note case WTBL: - 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; + 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; break; } } @@ -405,7 +405,7 @@ void tablecommands() int table = -1; int mstmode = MST_PORTAMENTO; - switch (ltable[tables.num()][tables.pos()]) + switch (song.ltable[tables.num()][tables.pos()]) { case WAVECMD + CMD_PORTAUP: case WAVECMD + CMD_PORTADOWN: @@ -439,22 +439,22 @@ void tablecommands() return; case STBL: - if (rtable[tables.num()][tables.pos()]) + if (song.rtable[tables.num()][tables.pos()]) { if (!shiftpressed) { - gototable(STBL, rtable[tables.num()][tables.pos()] - 1); + gototable(STBL, song.rtable[tables.num()][tables.pos()] - 1); return; } else { int oldeditpos = tables.pos(); int oldeditcolumn = tables.m_column; - int pos = makespeedtable(rtable[tables.num()][tables.pos()], mstmode, true); + int pos = makespeedtable(song.rtable[tables.num()][tables.pos()], mstmode, true); gototable(WTBL, oldeditpos); tables.m_column = oldeditcolumn; - rtable[tables.num()][tables.pos()] = pos + 1; + song.rtable[tables.num()][tables.pos()] = pos + 1; return; } } @@ -463,7 +463,7 @@ void tablecommands() int pos = findfreespeedtable(); if (pos >= 0) { - rtable[tables.num()][tables.pos()] = pos + 1; + song.rtable[tables.num()][tables.pos()] = pos + 1; gototable(STBL, pos); return; } @@ -472,9 +472,9 @@ void tablecommands() case PTBL: case FTBL: - if (rtable[tables.num()][tables.pos()]) + if (song.rtable[tables.num()][tables.pos()]) { - gototable(table, rtable[tables.num()][tables.pos()] - 1); + gototable(table, song.rtable[tables.num()][tables.pos()] - 1); return; } else @@ -483,7 +483,7 @@ void tablecommands() { int pos = gettablelen(table); if (pos >= MAX_TABLELEN-1) pos = MAX_TABLELEN - 1; - rtable[tables.num()][tables.pos()] = pos + 1; + song.rtable[tables.num()][tables.pos()] = pos + 1; gototable(table, pos); return; } @@ -520,20 +520,20 @@ void tablecommands() switch(tables.m_column) { case 0: - ltable[tables.num()][tables.pos()] &= 0x0f; - ltable[tables.num()][tables.pos()] |= hexnybble << 4; + song.ltable[tables.num()][tables.pos()] &= 0x0f; + song.ltable[tables.num()][tables.pos()] |= hexnybble << 4; break; case 1: - ltable[tables.num()][tables.pos()] &= 0xf0; - ltable[tables.num()][tables.pos()] |= hexnybble; + song.ltable[tables.num()][tables.pos()] &= 0xf0; + song.ltable[tables.num()][tables.pos()] |= hexnybble; break; case 2: - rtable[tables.num()][tables.pos()] &= 0x0f; - rtable[tables.num()][tables.pos()] |= hexnybble << 4; + song.rtable[tables.num()][tables.pos()] &= 0x0f; + song.rtable[tables.num()][tables.pos()] |= hexnybble << 4; break; case 3: - rtable[tables.num()][tables.pos()] &= 0xf0; - rtable[tables.num()][tables.pos()] |= hexnybble; + song.rtable[tables.num()][tables.pos()] &= 0xf0; + song.rtable[tables.num()][tables.pos()] |= hexnybble; break; } tables.m_column++; @@ -553,28 +553,28 @@ void deletetable(int num, int pos) // Shift tablepointers in instruments for (int c = 1; c < MAX_INSTR; c++) { - if ((instr[c].ptr[num]-1) > pos) instr[c].ptr[num]--; + if ((song.instr[c].ptr[num]-1) > pos) song.instr[c].ptr[num]--; } // Shift tablepointers in wavetable commands for (int c = 0; c < MAX_TABLELEN; c++) { - if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) + if ((song.ltable[WTBL][c] >= WAVECMD) && (song.ltable[WTBL][c] <= WAVELASTCMD)) { - int cmd = ltable[WTBL][c] & 0xf; + int cmd = song.ltable[WTBL][c] & 0xf; if (num < STBL) { if (cmd == CMD_SETWAVEPTR+num) { - if ((rtable[WTBL][c]-1) > pos) rtable[WTBL][c]--; + if ((song.rtable[WTBL][c]-1) > pos) song.rtable[WTBL][c]--; } } else { if ((cmd == CMD_FUNKTEMPO) || ((cmd >= CMD_PORTAUP) && (cmd <= CMD_VIBRATO))) { - if ((rtable[WTBL][c]-1) > pos) rtable[WTBL][c]--; + if ((song.rtable[WTBL][c]-1) > pos) song.rtable[WTBL][c]--; } } } @@ -587,17 +587,17 @@ void deletetable(int num, int pos) { if (num < STBL) { - if (pattern[c][d*4+2] == CMD_SETWAVEPTR+num) + if (song.pattern[c][d*4+2] == CMD_SETWAVEPTR+num) { - if ((pattern[c][d*4+3]-1) > pos) pattern[c][d*4+3]--; + if ((song.pattern[c][d*4+3]-1) > pos) song.pattern[c][d*4+3]--; } } else { - if ((pattern[c][d*4+2] == CMD_FUNKTEMPO) || - ((pattern[c][d*4+2] >= CMD_PORTAUP) && (pattern[c][d*4+2] <= CMD_VIBRATO))) + if ((song.pattern[c][d*4+2] == CMD_FUNKTEMPO) || + ((song.pattern[c][d*4+2] >= CMD_PORTAUP) && (song.pattern[c][d*4+2] <= CMD_VIBRATO))) { - if ((pattern[c][d*4+3]-1) > pos) pattern[c][d*4+3]--; + if ((song.pattern[c][d*4+3]-1) > pos) song.pattern[c][d*4+3]--; } } } @@ -608,8 +608,8 @@ void deletetable(int num, int pos) { if (num != STBL) { - if (ltable[num][c] == 0xff) - if ((rtable[num][c]-1) > pos) rtable[num][c]--; + if (song.ltable[num][c] == 0xff) + if ((song.rtable[num][c]-1) > pos) song.rtable[num][c]--; } } @@ -617,13 +617,13 @@ void deletetable(int num, int pos) { if (c+1 < MAX_TABLELEN) { - ltable[num][c] = ltable[num][c+1]; - rtable[num][c] = rtable[num][c+1]; + song.ltable[num][c] = song.ltable[num][c+1]; + song.rtable[num][c] = song.rtable[num][c+1]; } else { - ltable[num][c] = 0; - rtable[num][c] = 0; + song.ltable[num][c] = 0; + song.rtable[num][c] = 0; } } } @@ -635,20 +635,20 @@ void inserttable(int num, int pos, int mode) { if (!mode) { - if ((instr[c].ptr[num]-1) >= pos) instr[c].ptr[num]++; + if ((song.instr[c].ptr[num]-1) >= pos) song.instr[c].ptr[num]++; } else { - if ((instr[c].ptr[num]-1) > pos) instr[c].ptr[num]++; + if ((song.instr[c].ptr[num]-1) > pos) song.instr[c].ptr[num]++; } } // Shift tablepointers in wavetable commands for (int c = 0; c < MAX_TABLELEN; c++) { - if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) + if ((song.ltable[WTBL][c] >= WAVECMD) && (song.ltable[WTBL][c] <= WAVELASTCMD)) { - int cmd = ltable[WTBL][c] & 0xf; + int cmd = song.ltable[WTBL][c] & 0xf; if (num < STBL) { @@ -656,11 +656,11 @@ void inserttable(int num, int pos, int mode) { if (!mode) { - if ((rtable[WTBL][c]-1) >= pos) rtable[WTBL][c]++; + if ((song.rtable[WTBL][c]-1) >= pos) song.rtable[WTBL][c]++; } else { - if ((rtable[WTBL][c]-1) > pos) rtable[WTBL][c]++; + if ((song.rtable[WTBL][c]-1) > pos) song.rtable[WTBL][c]++; } } } @@ -670,11 +670,11 @@ void inserttable(int num, int pos, int mode) { if (!mode) { - if ((rtable[WTBL][c]-1) >= pos) rtable[WTBL][c]++; + if ((song.rtable[WTBL][c]-1) >= pos) song.rtable[WTBL][c]++; } else { - if ((rtable[WTBL][c]-1) > pos) rtable[WTBL][c]++; + if ((song.rtable[WTBL][c]-1) > pos) song.rtable[WTBL][c]++; } } } @@ -689,30 +689,30 @@ void inserttable(int num, int pos, int mode) { if (num < STBL) { - if (pattern[c][d*4+2] == CMD_SETWAVEPTR+num) + if (song.pattern[c][d*4+2] == CMD_SETWAVEPTR+num) { if (!mode) { - if ((pattern[c][d*4+3]-1) >= pos) pattern[c][d*4+3]++; + if ((song.pattern[c][d*4+3]-1) >= pos) song.pattern[c][d*4+3]++; } else { - if ((pattern[c][d*4+3]-1) > pos) pattern[c][d*4+3]++; + if ((song.pattern[c][d*4+3]-1) > pos) song.pattern[c][d*4+3]++; } } } else { - if ((pattern[c][d*4+2] == CMD_FUNKTEMPO) || - ((pattern[c][d*4+2] >= CMD_PORTAUP) && (pattern[c][d*4+2] <= CMD_VIBRATO))) + if ((song.pattern[c][d*4+2] == CMD_FUNKTEMPO) || + ((song.pattern[c][d*4+2] >= CMD_PORTAUP) && (song.pattern[c][d*4+2] <= CMD_VIBRATO))) { if (!mode) { - if ((pattern[c][d*4+3]-1) >= pos) pattern[c][d*4+3]++; + if ((song.pattern[c][d*4+3]-1) >= pos) song.pattern[c][d*4+3]++; } else { - if ((pattern[c][d*4+3]-1) > pos) pattern[c][d*4+3]++; + if ((song.pattern[c][d*4+3]-1) > pos) song.pattern[c][d*4+3]++; } } } @@ -724,15 +724,15 @@ void inserttable(int num, int pos, int mode) { for (int c = 0; c < MAX_TABLELEN; c++) { - if (ltable[num][c] == 0xff) + if (song.ltable[num][c] == 0xff) { if (!mode) { - if ((rtable[num][c]-1) >= pos) rtable[num][c]++; + if ((song.rtable[num][c]-1) >= pos) song.rtable[num][c]++; } else { - if ((rtable[num][c]-1) > pos) rtable[num][c]++; + if ((song.rtable[num][c]-1) > pos) song.rtable[num][c]++; } } } @@ -742,20 +742,20 @@ void inserttable(int num, int pos, int mode) { if (c > pos) { - ltable[num][c] = ltable[num][c-1]; - rtable[num][c] = rtable[num][c-1]; + song.ltable[num][c] = song.ltable[num][c-1]; + song.rtable[num][c] = song.rtable[num][c-1]; } else { if ((num == WTBL) && (mode == 1)) { - ltable[num][c] = 0xe9; - rtable[num][c] = 0; + song.ltable[num][c] = 0xe9; + song.rtable[num][c] = 0; } else { - ltable[num][c] = 0; - rtable[num][c] = 0; + song.ltable[num][c] = 0; + song.rtable[num][c] = 0; } } } @@ -766,7 +766,7 @@ int gettablelen(int num) int c; for (c = MAX_TABLELEN-1; c >= 0; c--) { - if (ltable[num][c] | rtable[num][c]) break; + if (song.ltable[num][c] | song.rtable[num][c]) break; } return c+1; } @@ -779,7 +779,7 @@ int gettablepartlen(int num, int pos) int c; for (c = pos; c < MAX_TABLELEN; c++) { - if (ltable[num][c] == 0xff) + if (song.ltable[num][c] == 0xff) { c++; break; @@ -796,12 +796,12 @@ void optimizetable(int num) { for (int d = 0; d < getPattlen(c); d++) { - if ((pattern[c][d*4+2] >= CMD_SETWAVEPTR) && (pattern[c][d*4+2] <= CMD_SETFILTERPTR)) - exectable(pattern[c][d*4+2] - CMD_SETWAVEPTR, pattern[c][d*4+3]); - if ((pattern[c][d*4+2] >= CMD_PORTAUP) && (pattern[c][d*4+2] <= CMD_VIBRATO)) - exectable(STBL, pattern[c][d*4+3]); - if (pattern[c][d*4+2] == CMD_FUNKTEMPO) - exectable(STBL, pattern[c][d*4+3]); + if ((song.pattern[c][d*4+2] >= CMD_SETWAVEPTR) && (song.pattern[c][d*4+2] <= CMD_SETFILTERPTR)) + exectable(song.pattern[c][d*4+2] - CMD_SETWAVEPTR, song.pattern[c][d*4+3]); + if ((song.pattern[c][d*4+2] >= CMD_PORTAUP) && (song.pattern[c][d*4+2] <= CMD_VIBRATO)) + exectable(STBL, song.pattern[c][d*4+3]); + if (song.pattern[c][d*4+2] == CMD_FUNKTEMPO) + exectable(STBL, song.pattern[c][d*4+3]); } } @@ -809,7 +809,7 @@ void optimizetable(int num) { for (int d = 0; d < MAX_TABLES; d++) { - exectable(d, instr[c].ptr[d]); + exectable(d, song.instr[c].ptr[d]); } } @@ -817,11 +817,11 @@ void optimizetable(int num) { if (tableused[WTBL][c+1]) { - if ((ltable[WTBL][c] >= WAVECMD) && (ltable[WTBL][c] <= WAVELASTCMD)) + if ((song.ltable[WTBL][c] >= WAVECMD) && (song.ltable[WTBL][c] <= WAVELASTCMD)) { int d = -1; - switch(ltable[WTBL][c] - WAVECMD) + switch(song.ltable[WTBL][c] - WAVECMD) { case CMD_PORTAUP: case CMD_PORTADOWN: @@ -839,7 +839,7 @@ void optimizetable(int num) break; } - if (d != -1) exectable(d, rtable[WTBL][c]); + if (d != -1) exectable(d, song.rtable[WTBL][c]); } } } @@ -847,7 +847,7 @@ void optimizetable(int num) int c; for (c = MAX_TABLELEN-1; c >= 0; c--) { - if ((ltable[num][c]) || (rtable[num][c])) break; + if ((song.ltable[num][c]) || (song.rtable[num][c])) break; } for (; c >= 0; c--) { @@ -893,17 +893,17 @@ int makespeedtable(unsigned data, int mode, bool makenew) { for (int c = 0; c < MAX_TABLELEN; c++) { - if ((ltable[STBL][c] == l) && (rtable[STBL][c] == r)) + if ((song.ltable[STBL][c] == l) && (song.rtable[STBL][c] == r)) return c; } } for (int c = 0; c < MAX_TABLELEN; c++) { - if ((!ltable[STBL][c]) && (!rtable[STBL][c])) + if ((!song.ltable[STBL][c]) && (!song.rtable[STBL][c])) { - ltable[STBL][c] = l; - rtable[STBL][c] = r; + song.ltable[STBL][c] = l; + song.rtable[STBL][c] = r; tables.settableview(STBL, c); return c; @@ -918,17 +918,17 @@ void deleteinstrtable(int i) for (int c = 0; c < MAX_TABLES; c++) { - if (instr[i].ptr[c]) + if (song.instr[i].ptr[c]) { - int pos = instr[i].ptr[c]-1; + int pos = song.instr[i].ptr[c]-1; int len = gettablepartlen(c, pos); // Check that this table area isn't used by another instrument for (int d = 1; d < MAX_INSTR; d++) { - if ((d != i) && (instr[d].ptr[c])) + if ((d != i) && (song.instr[d].ptr[c])) { - int cmppos = instr[d].ptr[c]-1; + int cmppos = song.instr[d].ptr[c]-1; if ((cmppos >= pos) && (cmppos < pos+len)) eraseok = false; } } @@ -943,7 +943,7 @@ void exectable(int num, int ptr) // Jump error check if ((num != STBL) && (ptr) && (ptr <= MAX_TABLELEN)) { - if (ltable[num][ptr-1] == 0xff) + if (song.ltable[num][ptr-1] == 0xff) { tableerror = TYPE_JUMP; return; @@ -967,9 +967,9 @@ void exectable(int num, int ptr) // Go to next ptr. if (num != STBL) { - if (ltable[num][ptr-1] == 0xff) + if (song.ltable[num][ptr-1] == 0xff) { - ptr = rtable[num][ptr-1]; + ptr = song.rtable[num][ptr-1]; } else ptr++; } @@ -981,7 +981,7 @@ int findfreespeedtable() { for (int c = 0; c < MAX_TABLELEN; c++) { - if ((!ltable[STBL][c]) && (!rtable[STBL][c])) + if ((!song.ltable[STBL][c]) && (!song.rtable[STBL][c])) { return c; }