From 7ba6b3680a9c61b06ff7cefaf963b6f6440dedbe Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 15 Oct 2025 21:05:13 -0500 Subject: [PATCH] pattern data refactor, part 5 the engine is done still does not compile --- src/engine/engine.cpp | 50 ++++-------------- src/engine/playback.cpp | 110 ++++++++++++++++++++-------------------- src/engine/song.cpp | 16 +++--- 3 files changed, 72 insertions(+), 104 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 66de17439..1d3bd75a3 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -947,8 +947,8 @@ void DivEngine::delUnusedIns() { for (int k=0; kpat[i].data[k]==NULL) continue; for (int l=0; lpatLen; l++) { - if (song.subsong[j]->pat[i].data[k]->data[l][2]>=0 && song.subsong[j]->pat[i].data[k]->data[l][2]<256) { - isUsed[song.subsong[j]->pat[i].data[k]->data[l][2]]=true; + if (song.subsong[j]->pat[i].data[k]->newData[l][DIV_PAT_INS]>=0 && song.subsong[j]->pat[i].data[k]->newData[l][DIV_PAT_INS]<256) { + isUsed[song.subsong[j]->pat[i].data[k]->newData[l][DIV_PAT_INS]]=true; } } } @@ -1033,38 +1033,6 @@ void DivEngine::delUnusedSamples() { } } - // scan in pattern (legacy sample mode) - // disabled because it is unreliable - /* - for (DivSubSong* i: song.subsong) { - for (int j=0; jordersLen; k++) { - DivPattern* p=i->pat[j].getPattern(i->orders.ord[j][k],false); - for (int l=0; lpatLen; l++) { - for (int m=0; mpat[j].effectCols; m++) { - if (p->data[l][4+(m<<1)]==0x17) { - is17On=(p->data[l][5+(m<<1)]>0); - } - if (p->data[l][4+(m<<1)]==0xeb) { - bank=p->data[l][5+(m<<1)]; - if (bank==-1) bank=0; - } - } - if (is17On) { - if (p->data[l][1]!=0 || p->data[l][0]!=0) { - if (p->data[l][0]<=12) { - int note=(12*bank)+(p->data[l][0]%12); - if (note<256) isUsed[note]=true; - } - } - } - } - } - } - }*/ - // delete for (int i=0; ipat[i].data[k]==NULL) continue; for (int l=0; lpatLen; l++) { - if (song.subsong[j]->pat[i].data[k]->data[l][2]>index) { - song.subsong[j]->pat[i].data[k]->data[l][2]--; + if (song.subsong[j]->pat[i].data[k]->newData[l][DIV_PAT_INS]>index) { + song.subsong[j]->pat[i].data[k]->newData[l][DIV_PAT_INS]--; } } } @@ -3168,7 +3136,7 @@ void DivEngine::deepCloneOrder(int pos, bool where) { order[i]=j; DivPattern* oldPat=curPat[i].getPattern(origOrd,false); DivPattern* pat=curPat[i].getPattern(j,true); - memcpy(pat->data,oldPat->data,DIV_MAX_ROWS*DIV_MAX_COLS*sizeof(short)); + memcpy(pat->newData,oldPat->newData,DIV_MAX_ROWS*DIV_MAX_COLS*sizeof(short)); logD("found at %d",j); didNotFind=false; break; @@ -3274,10 +3242,10 @@ void DivEngine::exchangeIns(int one, int two) { for (int k=0; kpat[i].data[k]==NULL) continue; for (int l=0; lpatLen; l++) { - if (song.subsong[j]->pat[i].data[k]->data[l][2]==one) { - song.subsong[j]->pat[i].data[k]->data[l][2]=two; - } else if (song.subsong[j]->pat[i].data[k]->data[l][2]==two) { - song.subsong[j]->pat[i].data[k]->data[l][2]=one; + if (song.subsong[j]->pat[i].data[k]->newData[l][DIV_PAT_INS]==one) { + song.subsong[j]->pat[i].data[k]->newData[l][DIV_PAT_INS]=two; + } else if (song.subsong[j]->pat[i].data[k]->newData[l][DIV_PAT_INS]==two) { + song.subsong[j]->pat[i].data[k]->newData[l][DIV_PAT_INS]=one; } } } diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 183b0a7b6..eb8f9a4f3 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -320,18 +320,18 @@ const char* cmdName[]={ static_assert((sizeof(cmdName)/sizeof(void*))==DIV_CMD_MAX,"update cmdName!"); -const char* formatNote(unsigned char note, unsigned char octave) { +const char* formatNote(short note) { static char ret[4]; - if (note==100) { + if (note==DIV_NOTE_OFF) { return "OFF"; - } else if (note==101) { + } else if (note==DIV_NOTE_REL) { return "==="; - } else if (note==102) { + } else if (note==DIV_MACRO_REL) { return "REL"; - } else if (octave==0 && note==0) { + } else if (note<0) { return "---"; } - snprintf(ret,4,"%s%d",notes[note%12],octave+note/12); + snprintf(ret,4,"%s%d",notes[note%12],(note-60)/12); return ret; } @@ -509,8 +509,8 @@ void DivEngine::processRowPre(int i) { int whatRow=curRow; DivPattern* pat=curPat[i].getPattern(curOrders->ord[i][whatOrder],false); for (int j=0; jdata[whatRow][4+(j<<1)]; - short effectVal=pat->data[whatRow][5+(j<<1)]; + short effect=pat->newData[whatRow][DIV_PAT_FX(j)]; + short effectVal=pat->newData[whatRow][DIV_PAT_FXVAL(j)]; if (effectVal==-1) effectVal=0; effectVal&=255; @@ -526,8 +526,8 @@ void DivEngine::processRow(int i, bool afterDelay) { if (!afterDelay) { bool returnAfterPre=false; for (int j=0; jdata[whatRow][4+(j<<1)]; - short effectVal=pat->data[whatRow][5+(j<<1)]; + short effect=pat->newData[whatRow][DIV_PAT_FX(j)]; + short effectVal=pat->newData[whatRow][DIV_PAT_FXVAL(j)]; if (effectVal==-1) effectVal=0; effectVal&=255; @@ -615,10 +615,10 @@ void DivEngine::processRow(int i, bool afterDelay) { // instrument bool insChanged=false; - if (pat->data[whatRow][2]!=-1) { - if (chan[i].lastIns!=pat->data[whatRow][2]) { - dispatchCmd(DivCommand(DIV_CMD_INSTRUMENT,i,pat->data[whatRow][2])); - chan[i].lastIns=pat->data[whatRow][2]; + if (pat->newData[whatRow][DIV_PAT_INS]!=-1) { + if (chan[i].lastIns!=pat->newData[whatRow][DIV_PAT_INS]) { + dispatchCmd(DivCommand(DIV_CMD_INSTRUMENT,i,pat->newData[whatRow][DIV_PAT_INS])); + chan[i].lastIns=pat->newData[whatRow][DIV_PAT_INS]; insChanged=true; if (song.legacyVolumeSlides && chan[i].volume==chan[i].volMax+1) { logV("forcing volume"); @@ -629,7 +629,7 @@ void DivEngine::processRow(int i, bool afterDelay) { } } // note - if (pat->data[whatRow][0]==100) { // note off + if (pat->newData[whatRow][DIV_PAT_NOTE]==DIV_NOTE_OFF) { // note off //chan[i].note=-1; chan[i].keyOn=false; chan[i].keyOff=true; @@ -652,7 +652,7 @@ void DivEngine::processRow(int i, bool afterDelay) { chan[i].scheduledSlideReset=true; } dispatchCmd(DivCommand(DIV_CMD_NOTE_OFF,i)); - } else if (pat->data[whatRow][0]==101) { // note off + env release + } else if (pat->newData[whatRow][DIV_PAT_NOTE]==DIV_NOTE_REL) { // note off + env release //chan[i].note=-1; chan[i].keyOn=false; chan[i].keyOff=true; @@ -676,12 +676,12 @@ void DivEngine::processRow(int i, bool afterDelay) { } dispatchCmd(DivCommand(DIV_CMD_NOTE_OFF_ENV,i)); chan[i].releasing=true; - } else if (pat->data[whatRow][0]==102) { // env release + } else if (pat->newData[whatRow][DIV_PAT_NOTE]==DIV_MACRO_REL) { // env release dispatchCmd(DivCommand(DIV_CMD_ENV_RELEASE,i)); chan[i].releasing=true; - } else if (!(pat->data[whatRow][0]==0 && pat->data[whatRow][1]==0)) { + } else if (pat->newData[whatRow][DIV_PAT_NOTE]!=-1) { chan[i].oldNote=chan[i].note; - chan[i].note=pat->data[whatRow][0]+((signed char)pat->data[whatRow][1])*12; + chan[i].note=pat->newData[whatRow][DIV_PAT_NOTE]-60; if (!chan[i].keyOn) { if (disCont[dispatchOfChan[i]].dispatch->keyOffAffectsArp(dispatchChanOfChan[i])) { chan[i].arp=0; @@ -698,11 +698,11 @@ void DivEngine::processRow(int i, bool afterDelay) { int volPortaTarget=-1; bool noApplyVolume=false; for (int j=0; jdata[whatRow][4+(j<<1)]; + short effect=pat->newData[whatRow][DIV_PAT_FX(j)]; if (effect==0xd3 || effect==0xd4) { // vol porta - volPortaTarget=pat->data[whatRow][3]<<8; // can be -256 + volPortaTarget=pat->newData[whatRow][DIV_PAT_VOL]<<8; // can be -256 - short effectVal=pat->data[whatRow][5+(j<<1)]; + short effectVal=pat->newData[whatRow][DIV_PAT_FXVAL(j)]; if (effectVal==-1) effectVal=0; effectVal&=255; @@ -711,12 +711,12 @@ void DivEngine::processRow(int i, bool afterDelay) { } } - if (pat->data[whatRow][3]!=-1 && !noApplyVolume) { - if (!song.oldAlwaysSetVolume || disCont[dispatchOfChan[i]].dispatch->getLegacyAlwaysSetVolume() || (MIN(chan[i].volMax,chan[i].volume)>>8)!=pat->data[whatRow][3]) { - if (pat->data[whatRow][0]==0 && pat->data[whatRow][1]==0) { + if (pat->newData[whatRow][DIV_PAT_VOL]!=-1 && !noApplyVolume) { + if (!song.oldAlwaysSetVolume || disCont[dispatchOfChan[i]].dispatch->getLegacyAlwaysSetVolume() || (MIN(chan[i].volMax,chan[i].volume)>>8)!=pat->newData[whatRow][DIV_PAT_VOL]) { + if (pat->newData[whatRow][DIV_PAT_NOTE]==-1) { chan[i].midiAftertouch=true; } - chan[i].volume=pat->data[whatRow][3]<<8; + chan[i].volume=pat->newData[whatRow][DIV_PAT_VOL]<<8; dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8)); dispatchCmd(DivCommand(DIV_CMD_HINT_VOLUME,i,chan[i].volume>>8)); } @@ -732,8 +732,8 @@ void DivEngine::processRow(int i, bool afterDelay) { // effects for (int j=0; jdata[whatRow][4+(j<<1)]; - short effectVal=pat->data[whatRow][5+(j<<1)]; + short effect=pat->newData[whatRow][DIV_PAT_FX(j)]; + short effectVal=pat->newData[whatRow][DIV_PAT_FXVAL(j)]; if (effectVal==-1) effectVal=0; effectVal&=255; @@ -1306,8 +1306,8 @@ void DivEngine::processRow(int i, bool afterDelay) { // post effects for (int j=0; jdata[whatRow][4+(j<<1)]; - short effectVal=pat->data[whatRow][5+(j<<1)]; + short effect=pat->newData[whatRow][DIV_PAT_FX(j)]; + short effectVal=pat->newData[whatRow][DIV_PAT_FXVAL(j)]; if (effectVal==-1) effectVal=0; effectVal&=255; @@ -1352,31 +1352,31 @@ void DivEngine::nextRow() { DivPattern* pat=curPat[i].getPattern(curOrders->ord[i][curOrder],false); snprintf(pb2,4095,"\x1b[37m %s", - formatNote(pat->data[curRow][0],pat->data[curRow][1])); + formatNote(pat->newData[curRow][DIV_PAT_NOTE])); strcat(pb3,pb2); - if (pat->data[curRow][3]==-1) { + if (pat->newData[curRow][DIV_PAT_VOL]==-1) { strcat(pb3,"\x1b[m--"); } else { - snprintf(pb2,4095,"\x1b[1;32m%.2x",pat->data[curRow][3]); + snprintf(pb2,4095,"\x1b[1;32m%.2x",pat->newData[curRow][DIV_PAT_VOL]); strcat(pb3,pb2); } - if (pat->data[curRow][2]==-1) { + if (pat->newData[curRow][DIV_PAT_INS]==-1) { strcat(pb3,"\x1b[m--"); } else { - snprintf(pb2,4095,"\x1b[0;36m%.2x",pat->data[curRow][2]); + snprintf(pb2,4095,"\x1b[0;36m%.2x",pat->newData[curRow][DIV_PAT_INS]); strcat(pb3,pb2); } for (int j=0; jdata[curRow][4+(j<<1)]==-1) { + if (pat->newData[curRow][DIV_PAT_FX(j)]==-1) { strcat(pb3,"\x1b[m--"); } else { - snprintf(pb2,4095,"\x1b[1;31m%.2x",pat->data[curRow][4+(j<<1)]); + snprintf(pb2,4095,"\x1b[1;31m%.2x",pat->newData[curRow][DIV_PAT_FX(j)]); strcat(pb3,pb2); } - if (pat->data[curRow][5+(j<<1)]==-1) { + if (pat->newData[curRow][DIV_PAT_FXVAL(j)]==-1) { strcat(pb3,"\x1b[m--"); } else { - snprintf(pb2,4095,"\x1b[1;37m%.2x",pat->data[curRow][5+(j<<1)]); + snprintf(pb2,4095,"\x1b[1;37m%.2x",pat->newData[curRow][DIV_PAT_FXVAL(j)]); strcat(pb3,pb2); } } @@ -1481,8 +1481,8 @@ void DivEngine::nextRow() { // post row details for (int i=0; iord[i][curOrder],false); - if (!(pat->data[curRow][0]==0 && pat->data[curRow][1]==0)) { - if (pat->data[curRow][0]!=100 && pat->data[curRow][0]!=101 && pat->data[curRow][0]!=102) { + if (pat->newData[curRow][DIV_PAT_NOTE]!=-1) { + if (pat->newData[curRow][DIV_PAT_NOTE]!=DIV_NOTE_OFF && pat->newData[curRow][DIV_PAT_NOTE]!=DIV_NOTE_REL && pat->newData[curRow][DIV_PAT_NOTE]!=DIV_MACRO_REL) { if (!chan[i].legato) { bool wantPreNote=false; if (disCont[dispatchOfChan[i]].dispatch!=NULL) { @@ -1493,24 +1493,24 @@ void DivEngine::nextRow() { for (int j=0; jdata[curRow][4+(j<<1)]==0x03 && pat->data[curRow][5+(j<<1)]!=0 && pat->data[curRow][5+(j<<1)]!=-1) { + if (pat->newData[curRow][DIV_PAT_FX(j)]==0x03 && pat->newData[curRow][DIV_PAT_FXVAL(j)]!=0 && pat->newData[curRow][DIV_PAT_FXVAL(j)]!=-1) { doPreparePreNote=false; break; } - if (pat->data[curRow][4+(j<<1)]==0x06 && pat->data[curRow][5+(j<<1)]!=0 && pat->data[curRow][5+(j<<1)]!=-1) { + if (pat->newData[curRow][DIV_PAT_FX(j)]==0x06 && pat->newData[curRow][DIV_PAT_FXVAL(j)]!=0 && pat->newData[curRow][DIV_PAT_FXVAL(j)]!=-1) { doPreparePreNote=false; break; } - if (pat->data[curRow][4+(j<<1)]==0xea) { - if (pat->data[curRow][5+(j<<1)]>0) { + if (pat->newData[curRow][DIV_PAT_FX(j)]==0xea) { + if (pat->newData[curRow][DIV_PAT_FXVAL(j)]>0) { doPreparePreNote=false; break; } } } - if (pat->data[curRow][4+(j<<1)]==0xed) { - if (pat->data[curRow][5+(j<<1)]>0) { - addition=pat->data[curRow][5+(j<<1)]&255; + if (pat->newData[curRow][DIV_PAT_FX(j)]==0xed) { + if (pat->newData[curRow][DIV_PAT_FXVAL(j)]>0) { + addition=pat->newData[curRow][DIV_PAT_FXVAL(j)]&255; break; } } @@ -1524,23 +1524,23 @@ void DivEngine::nextRow() { int addition=0; for (int j=0; jdata[curRow][4+(j<<1)]==0x03 && pat->data[curRow][5+(j<<1)]!=0 && pat->data[curRow][5+(j<<1)]!=-1) { + if (pat->newData[curRow][DIV_PAT_FX(j)]==0x03 && pat->newData[curRow][DIV_PAT_FXVAL(j)]!=0 && pat->newData[curRow][DIV_PAT_FXVAL(j)]!=-1) { doPrepareCut=false; break; } - if (pat->data[curRow][4+(j<<1)]==0x06 && pat->data[curRow][5+(j<<1)]!=0 && pat->data[curRow][5+(j<<1)]!=-1) { + if (pat->newData[curRow][DIV_PAT_FX(j)]==0x06 && pat->newData[curRow][DIV_PAT_FXVAL(j)]!=0 && pat->newData[curRow][DIV_PAT_FXVAL(j)]!=-1) { doPrepareCut=false; break; } - if (pat->data[curRow][4+(j<<1)]==0xea) { - if (pat->data[curRow][5+(j<<1)]>0) { + if (pat->newData[curRow][DIV_PAT_FX(j)]==0xea) { + if (pat->newData[curRow][DIV_PAT_FXVAL(j)]>0) { doPrepareCut=false; break; } } - if (pat->data[curRow][4+(j<<1)]==0xed) { - if (pat->data[curRow][5+(j<<1)]>0) { - addition=pat->data[curRow][5+(j<<1)]&255; + if (pat->newData[curRow][DIV_PAT_FX(j)]==0xed) { + if (pat->newData[curRow][DIV_PAT_FXVAL(j)]>0) { + addition=pat->newData[curRow][DIV_PAT_FXVAL(j)]&255; break; } } diff --git a/src/engine/song.cpp b/src/engine/song.cpp index e457478e4..05d402055 100644 --- a/src/engine/song.cpp +++ b/src/engine/song.cpp @@ -54,9 +54,9 @@ bool DivSubSong::walk(int& loopOrder, int& loopRow, int& loopEnd, int chans, int } for (int k=0; kdata[j][5+(l<<1)]; + effectVal=subPat[k]->newData[j][DIV_PAT_FXVAL(l)]; if (effectVal<0) effectVal=0; - if (subPat[k]->data[j][4+(l<<1)]==0x0d) { + if (subPat[k]->newData[j][DIV_PAT_FX(l)]==0x0d) { if (jumpTreatment==2) { if ((idata[j][4+(l<<1)]==0x0b) { + } else if (subPat[k]->newData[j][DIV_PAT_FX(l)]==0x0b) { if (nextOrder==-1 || jumpTreatment==0) { nextOrder=effectVal; if (jumpTreatment==1 || jumpTreatment==2 || !jumpingOrder) { @@ -160,10 +160,10 @@ void DivSubSong::findLength(int loopOrder, int loopRow, double fadeoutLen, int& } for (int k=0; kdata[j][5+(l<<1)]; + effectVal=subPat[k]->newData[j][DIV_PAT_FXVAL(l)]; if (effectVal<0) effectVal=0; - if (subPat[k]->data[j][4+(l<<1)]==0xff) { + if (subPat[k]->newData[j][DIV_PAT_FX(l)]==0xff) { hasFFxx=true; // FFxx makes YOU SHALL NOT PASS!!! move @@ -173,7 +173,7 @@ void DivSubSong::findLength(int loopOrder, int loopRow, double fadeoutLen, int& return; } - switch (subPat[k]->data[j][4+(l<<1)]) { + switch (subPat[k]->newData[j][DIV_PAT_FX(l)]) { case 0x09: { // select groove pattern/speed 1 if (grooves.empty()) { if (effectVal>0) curSpeeds.val[0]=effectVal; @@ -208,7 +208,7 @@ void DivSubSong::findLength(int loopOrder, int loopRow, double fadeoutLen, int& } } - if (subPat[k]->data[j][4+(l<<1)]==0x0d) { + if (subPat[k]->newData[j][DIV_PAT_FX(l)]==0x0d) { if (jumpTreatment==2) { if ((idata[j][4+(l<<1)]==0x0b) { + } else if (subPat[k]->newData[j][DIV_PAT_FX(l)]==0x0b) { if (nextOrder==-1 || jumpTreatment==0) { nextOrder=effectVal; if (jumpTreatment==1 || jumpTreatment==2 || !jumpingOrder) {