From 5c861ca36eb04e38eca359038e94da25fe7a2f1f Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 26 Jul 2023 17:58:57 -0500 Subject: [PATCH] compensate for sample movement/deletion --- src/engine/engine.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/engine/engine.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 1b9f427c..d27b6a57 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -3851,6 +3851,23 @@ void DivEngine::delSample(int index) { song.sampleLen=song.sample.size(); removeAsset(song.sampleDir,index); checkAssetDir(song.sampleDir,song.sample.size()); + + // compensate + for (DivInstrument* i: song.ins) { + if (i->amiga.initSample==index) { + i->amiga.initSample=-1; + } else if (i->amiga.initSample>index) { + i->amiga.initSample--; + } + for (int j=0; j<120; j++) { + if (i->amiga.noteMap[j].map==index) { + i->amiga.noteMap[j].map=-1; + } else if (i->amiga.noteMap[j].map>index) { + i->amiga.noteMap[j].map--; + } + } + } + renderSamples(); } saveLock.unlock(); @@ -4042,6 +4059,27 @@ void DivEngine::exchangeIns(int one, int two) { } } +void DivEngine::exchangeWave(int one, int two) { + // TODO +} + +void DivEngine::exchangeSample(int one, int two) { + for (DivInstrument* i: song.ins) { + if (i->amiga.initSample==one) { + i->amiga.initSample=two; + } else if (i->amiga.initSample==two) { + i->amiga.initSample=one; + } + for (int j=0; j<120; j++) { + if (i->amiga.noteMap[j].map==one) { + i->amiga.noteMap[j].map=two; + } else if (i->amiga.noteMap[j].map==two) { + i->amiga.noteMap[j].map=one; + } + } + } +} + bool DivEngine::moveInsUp(int which) { if (which<1 || which>=(int)song.ins.size()) return false; BUSY_BEGIN; @@ -4064,6 +4102,7 @@ bool DivEngine::moveWaveUp(int which) { song.wave[which]=song.wave[which-1]; song.wave[which-1]=prev; moveAsset(song.waveDir,which,which-1); + exchangeWave(which,which-1); saveLock.unlock(); BUSY_END; return true; @@ -4080,6 +4119,7 @@ bool DivEngine::moveSampleUp(int which) { song.sample[which]=song.sample[which-1]; song.sample[which-1]=prev; moveAsset(song.sampleDir,which,which-1); + exchangeSample(which,which-1); saveLock.unlock(); renderSamples(); BUSY_END; @@ -4107,6 +4147,7 @@ bool DivEngine::moveWaveDown(int which) { saveLock.lock(); song.wave[which]=song.wave[which+1]; song.wave[which+1]=prev; + exchangeWave(which,which+1); moveAsset(song.waveDir,which,which+1); saveLock.unlock(); BUSY_END; @@ -4123,6 +4164,7 @@ bool DivEngine::moveSampleDown(int which) { saveLock.lock(); song.sample[which]=song.sample[which+1]; song.sample[which+1]=prev; + exchangeSample(which,which+1); moveAsset(song.sampleDir,which,which+1); saveLock.unlock(); renderSamples(); diff --git a/src/engine/engine.h b/src/engine/engine.h index 87ff7116..0f13659b 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -531,6 +531,9 @@ class DivEngine { void initSongWithDesc(const char* description, bool inBase64=true, bool oldVol=false); void exchangeIns(int one, int two); + void exchangeWave(int one, int two); + void exchangeSample(int one, int two); + void swapChannels(int src, int dest); void stompChannel(int ch);