diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 5d70ea816..a27fe8a69 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -999,7 +999,8 @@ bool DivEngine::changeSystem(int index, DivSystem which, bool preserveOrder) { lastError=_("invalid index"); return false; } - if (song.chans-getChannelCount(song.system[index])+getChannelCount(which)>DIV_MAX_CHANS) { + unsigned short newChanCount=getChannelCount(which); + if (song.chans-song.systemChans[index]+newChanCount>DIV_MAX_CHANS) { lastError=fmt::sprintf(_("max number of total channels is %d"),DIV_MAX_CHANS); return false; } @@ -1011,9 +1012,9 @@ bool DivEngine::changeSystem(int index, DivSystem which, bool preserveOrder) { if (!preserveOrder) { int firstChan=0; - int chanMovement=getChannelCount(which)-getChannelCount(song.system[index]); + int chanMovement=newChanCount-song.systemChans[index]; while (song.dispatchOfChan[firstChan]!=index) firstChan++; - int lastChan=firstChan+getChannelCount(song.system[index]); + int lastChan=firstChan+song.systemChans[index]; if (chanMovement!=0) { if (chanMovement>0) { // add channels @@ -1036,7 +1037,7 @@ bool DivEngine::changeSystem(int index, DivSystem which, bool preserveOrder) { } song.system[index]=which; - song.systemChans[index]=getChannelCount(which); + song.systemChans[index]=newChanCount; song.systemFlags[index].clear(); song.recalcChans(); saveLock.unlock(); @@ -1110,7 +1111,7 @@ bool DivEngine::duplicateSystem(int index, bool pat, bool end) { lastError=fmt::sprintf(_("max number of systems is %d"),DIV_MAX_CHIPS); return false; } - if (song.chans+getChannelCount(song.system[index])>DIV_MAX_CHANS) { + if (song.chans+song.systemChans[index]>DIV_MAX_CHANS) { lastError=fmt::sprintf(_("max number of total channels is %d"),DIV_MAX_CHANS); return false; } @@ -1155,13 +1156,13 @@ bool DivEngine::duplicateSystem(int index, bool pat, bool end) { int srcChan=0; int destChan=0; for (int i=0; ipat[destChan+j].effectCols=i->pat[srcChan+j].effectCols; i->chanShow[destChan+j]=i->chanShow[srcChan+j]; i->chanShowChanOsc[destChan+j]=i->chanShowChanOsc[srcChan+j]; @@ -1224,11 +1225,11 @@ bool DivEngine::removeSystem(int index, bool preserveOrder) { if (!preserveOrder) { int firstChan=0; while (song.dispatchOfChan[firstChan]!=index) firstChan++; - for (int i=0; i0) swapList.reserve(song.systemLen); for (int i=0; i0) chanList.reserve(channelCount); for (int j=0; j