total extinction of legacy sample mode, part 8
fix conversion memory leak add reverse conversion for .dmf export
This commit is contained in:
parent
69ae4f56bd
commit
9e41e509a0
2 changed files with 136 additions and 1 deletions
|
|
@ -1646,8 +1646,139 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) {
|
|||
short note, octave;
|
||||
w->writeC(curPat[i].effectCols);
|
||||
|
||||
bool convertSampleUsage=false;
|
||||
int convIns=-1;
|
||||
bool isConverting=false;
|
||||
bool alwaysConvert=false;
|
||||
|
||||
switch (sys) {
|
||||
case DIV_SYSTEM_GENESIS:
|
||||
if (i==5) convertSampleUsage=true;
|
||||
break;
|
||||
case DIV_SYSTEM_GENESIS_EXT:
|
||||
if (i==8) convertSampleUsage=true;
|
||||
break;
|
||||
case DIV_SYSTEM_PCE:
|
||||
convertSampleUsage=true;
|
||||
break;
|
||||
case DIV_SYSTEM_NES:
|
||||
if (i==4) {
|
||||
convertSampleUsage=true;
|
||||
alwaysConvert=true;
|
||||
}
|
||||
break;
|
||||
case DIV_SYSTEM_ARCADE:
|
||||
if (i>=8) {
|
||||
convertSampleUsage=true;
|
||||
alwaysConvert=true;
|
||||
}
|
||||
break;
|
||||
case DIV_SYSTEM_YM2610:
|
||||
if (i>=7) {
|
||||
convertSampleUsage=true;
|
||||
alwaysConvert=true;
|
||||
}
|
||||
break;
|
||||
case DIV_SYSTEM_YM2610_EXT:
|
||||
if (i>=10) {
|
||||
convertSampleUsage=true;
|
||||
alwaysConvert=true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (int j=0; j<curSubSong->ordersLen; j++) {
|
||||
DivPattern* pat=curPat[i].getPattern(curOrders->ord[i][j],false);
|
||||
// we make a copy in order to convertFurnace sample mode to Defle one
|
||||
DivPattern* origPat=curPat[i].getPattern(curOrders->ord[i][j],false);
|
||||
DivPattern* pat=new DivPattern;
|
||||
origPat->copyOn(pat);
|
||||
|
||||
if (convertSampleUsage) {
|
||||
for (int k=0; k<curSubSong->patLen; k++) {
|
||||
int insert17xx=-1;
|
||||
int insertEBxx=-1;
|
||||
|
||||
if (pat->newData[k][DIV_PAT_INS]!=-1) {
|
||||
if (pat->newData[k][DIV_PAT_INS]>=0 && pat->newData[k][DIV_PAT_INS]<song.insLen) {
|
||||
convIns=pat->newData[k][DIV_PAT_INS];
|
||||
} else {
|
||||
convIns=-1;
|
||||
}
|
||||
|
||||
bool willBeConverting=false;
|
||||
if (convIns>=0 && convIns<song.insLen) {
|
||||
DivInstrument* convInsInst=song.ins[convIns];
|
||||
if (convInsInst->type==DIV_INS_AMIGA ||
|
||||
convInsInst->type==DIV_INS_ADPCMA ||
|
||||
convInsInst->type==DIV_INS_SEGAPCM ||
|
||||
(convInsInst->type==DIV_INS_PCE && convInsInst->amiga.useSample)) {
|
||||
willBeConverting=true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isConverting!=willBeConverting) {
|
||||
if (!alwaysConvert) {
|
||||
if (willBeConverting) {
|
||||
insert17xx=1;
|
||||
} else {
|
||||
insert17xx=0;
|
||||
}
|
||||
}
|
||||
isConverting=willBeConverting;
|
||||
}
|
||||
|
||||
if (isConverting || alwaysConvert) {
|
||||
pat->newData[k][DIV_PAT_INS]=-1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pat->newData[k][DIV_PAT_NOTE]!=-1 && pat->newData[k][DIV_PAT_NOTE]!=DIV_NOTE_OFF && pat->newData[k][DIV_PAT_NOTE]!=DIV_NOTE_REL && pat->newData[k][DIV_PAT_NOTE]!=DIV_MACRO_REL) {
|
||||
if (isConverting || alwaysConvert) {
|
||||
if (convIns>=0 && convIns<song.insLen) {
|
||||
DivInstrument* convInsInst=song.ins[convIns];
|
||||
if (convInsInst->amiga.useNoteMap) {
|
||||
int mapTarget=pat->newData[k][DIV_PAT_NOTE]-60;
|
||||
if (mapTarget<0) mapTarget=0;
|
||||
if (mapTarget>119) mapTarget=119;
|
||||
insertEBxx=convInsInst->amiga.noteMap[mapTarget].map/12;
|
||||
pat->newData[k][DIV_PAT_NOTE]=(12*(pat->newData[k][DIV_PAT_NOTE]/12))+(convInsInst->amiga.noteMap[mapTarget].map%12);
|
||||
} else {
|
||||
insertEBxx=convInsInst->amiga.initSample/12;
|
||||
pat->newData[k][DIV_PAT_NOTE]=(12*(pat->newData[k][DIV_PAT_NOTE]/12))+(convInsInst->amiga.initSample%12);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (insert17xx!=-1) {
|
||||
int freeSlot=0;
|
||||
for (int l=0; l<curPat[i].effectCols; l++) {
|
||||
if (pat->newData[k][DIV_PAT_FX(l)]==-1) {
|
||||
freeSlot=l;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pat->newData[k][DIV_PAT_FX(freeSlot)]=0x17;
|
||||
pat->newData[k][DIV_PAT_FXVAL(freeSlot)]=insert17xx;
|
||||
}
|
||||
if (insertEBxx!=-1) {
|
||||
int freeSlot=1;
|
||||
for (int l=0; l<curPat[i].effectCols; l++) {
|
||||
if (pat->newData[k][DIV_PAT_FX(l)]==-1) {
|
||||
freeSlot=l;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pat->newData[k][DIV_PAT_FX(freeSlot)]=0xeb;
|
||||
pat->newData[k][DIV_PAT_FXVAL(freeSlot)]=insertEBxx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int k=0; k<curSubSong->patLen; k++) {
|
||||
if (pat->newData[k][DIV_PAT_NOTE]==DIV_NOTE_REL || pat->newData[k][DIV_PAT_NOTE]==DIV_MACRO_REL) {
|
||||
w->writeS(100);
|
||||
|
|
@ -1671,6 +1802,8 @@ SafeWriter* DivEngine::saveDMF(unsigned char version) {
|
|||
#endif
|
||||
w->writeS(pat->newData[k][DIV_PAT_INS]); // instrument
|
||||
}
|
||||
|
||||
delete pat;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -366,5 +366,7 @@ bool DivEngine::convertLegacySampleMode() {
|
|||
}
|
||||
}
|
||||
|
||||
delete[] isUsedByIns;
|
||||
|
||||
return (legacyInsInit!=-1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue