From 3b688774fe36bfa9c3beedd89d54b5e5a45373c3 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 24 May 2023 03:33:51 -0500 Subject: [PATCH] move loop when deleting in sample editor --- src/engine/sample.cpp | 29 ++++++++++++++++++++++++++++- src/gui/sampleEdit.cpp | 2 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/engine/sample.cpp b/src/engine/sample.cpp index 346f9a12..b178c6e8 100644 --- a/src/engine/sample.cpp +++ b/src/engine/sample.cpp @@ -584,7 +584,34 @@ bool DivSample::strip(unsigned int begin, unsigned int end) { if (begin>samples) begin=samples; if (end>samples) end=samples; int count=samples-(end-begin); - if (count<=0) return resize(0); + if (count<=0) { + loopStart=-1; + loopEnd=-1; + loop=false; + return resize(0); + } + if (loopStart>(int)begin && loopEnd<(int)end) { + loopStart=-1; + loopEnd=-1; + loop=false; + } else { + if (loopStart<(int)end && loopStart>(int)begin) { + loopStart=end; + } + if (loopStart>(int)begin && loopEnd>(int)begin) { + loopStart-=end-begin; + loopEnd-=end-begin; + if (loopEnd<0) loopEnd=0; + if (loopStart<0) loopStart=0; + } else if (loopEnd>(int)begin) { + loopEnd=begin; + } + } + if (loopStart>loopEnd) { + loopStart=-1; + loopEnd=-1; + loop=false; + } if (depth==DIV_SAMPLE_DEPTH_8BIT) { if (data8!=NULL) { signed char* oldData8=data8; diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index e0f079ba..9d0fcc19 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -215,7 +215,7 @@ void FurnaceGUI::drawSampleEdit() { } popToggleColors(); ImGui::TableNextColumn(); - bool doLoop=(sample->isLoopable()); + bool doLoop=(sample->loop); if (ImGui::Checkbox("Loop",&doLoop)) { MARK_MODIFIED if (doLoop) { sample->loop=true;