From 4bd0dc2c637d42976cb6d3550c3f8a7e3d00b335 Mon Sep 17 00:00:00 2001 From: LeviathaninWaves Date: Fri, 1 Dec 2023 15:06:42 -0600 Subject: [PATCH 1/9] Add loop point crossfading in the sample editor. --- src/engine/sample.h | 1 + src/gui/doAction.cpp | 4 +++ src/gui/gui.cpp | 3 +++ src/gui/gui.h | 4 ++- src/gui/guiConst.cpp | 1 + src/gui/sampleEdit.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/engine/sample.h b/src/engine/sample.h index 253fe347c2..118fe77763 100644 --- a/src/engine/sample.h +++ b/src/engine/sample.h @@ -287,6 +287,7 @@ struct DivSample { */ void convert(DivSampleDepth newDepth); + /** * initialize the rest of sample formats for this sample. */ diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index 0d1bcf623a..afd6de9574 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -1336,6 +1336,10 @@ void FurnaceGUI::doAction(int what) { MARK_MODIFIED; break; } + case GUI_ACTION_SAMPLE_XFADE_LOOP: + if (curSample<0 || curSample>=(int)e->song.sample.size()) break; + openSampleXFadeOpt=true; + break; case GUI_ACTION_SAMPLE_FILTER: if (curSample<0 || curSample>=(int)e->song.sample.size()) break; openSampleFilterOpt=true; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 3f585047e4..50808e689a 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -7529,6 +7529,8 @@ FurnaceGUI::FurnaceGUI(): sampleFilterRes(0.25f), sampleFilterCutStart(16000.0f), sampleFilterCutEnd(100.0f), + sampleXFadeLoopLength(0), + sampleXFadeLoopLaw(50000), sampleFilterPower(1), sampleClipboard(NULL), sampleClipboardLen(0), @@ -7537,6 +7539,7 @@ FurnaceGUI::FurnaceGUI(): openSampleAmplifyOpt(false), openSampleSilenceOpt(false), openSampleFilterOpt(false), + openSampleXFadeOpt(false), selectedPortSet(0x1fff), selectedSubPort(-1), hoveredPortSet(0x1fff), diff --git a/src/gui/gui.h b/src/gui/gui.h index 67b83484c8..686f9b9667 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -722,6 +722,7 @@ enum FurnaceGUIActions { GUI_ACTION_SAMPLE_INVERT, GUI_ACTION_SAMPLE_SIGN, GUI_ACTION_SAMPLE_FILTER, + GUI_ACTION_SAMPLE_XFADE_LOOP, GUI_ACTION_SAMPLE_PREVIEW, GUI_ACTION_SAMPLE_STOP_PREVIEW, GUI_ACTION_SAMPLE_ZOOM_IN, @@ -2103,10 +2104,11 @@ class FurnaceGUI { ImVec2 sampleDragAreaSize; unsigned int sampleDragLen; float sampleFilterL, sampleFilterB, sampleFilterH, sampleFilterRes, sampleFilterCutStart, sampleFilterCutEnd; + int sampleXFadeLoopLength, sampleXFadeLoopLaw; unsigned char sampleFilterPower; short* sampleClipboard; size_t sampleClipboardLen; - bool openSampleResizeOpt, openSampleResampleOpt, openSampleAmplifyOpt, openSampleSilenceOpt, openSampleFilterOpt; + bool openSampleResizeOpt, openSampleResampleOpt, openSampleAmplifyOpt, openSampleSilenceOpt, openSampleFilterOpt, openSampleXFadeOpt; // mixer // 0xxx: output diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index 0411d8a3cf..561dcffe34 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -743,6 +743,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={ D("SAMPLE_INVERT", "Invert", FURKMOD_CMD|FURKMOD_SHIFT|SDLK_t), D("SAMPLE_SIGN", "Signed/unsigned exchange", FURKMOD_CMD|SDLK_u), D("SAMPLE_FILTER", "Apply filter", FURKMOD_CMD|SDLK_f), + D("SAMPLE_XFADE_LOOP", "Crossfade loop points", NOT_AN_ACTION), D("SAMPLE_PREVIEW", "Preview sample", 0), D("SAMPLE_STOP_PREVIEW", "Stop sample preview", 0), D("SAMPLE_ZOOM_IN", "Zoom in", FURKMOD_CMD|SDLK_EQUALS), diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 5a57483ddf..373521e052 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -1226,6 +1226,63 @@ void FurnaceGUI::drawSampleEdit() { ImGui::SameLine(); ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); sameLineMaybe(); + ImGui::Button("Crossfade"); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Crossfade loop points."); + } + if (openSampleXFadeOpt) { + openSampleXFadeOpt=false; + ImGui::OpenPopup("SXFadeOpt"); + } + if (ImGui::BeginPopupContextItem("SXFadeÓpt",ImGuiPopupFlags_MouseButtonLeft)) { + if (ImGui::SliderInt("Number of samples", &sampleXFadeLoopLength, 0, 100000)) { + if (sampleXFadeLoopLength<0) sampleXFadeLoopLength=0; + if (sampleXFadeLoopLength>sample->loopStart) sampleXFadeLoopLength=sample->loopStart; + if (sampleXFadeLoopLength>100000) sampleXFadeLoopLength=100000; + } + if (ImGui::SliderInt("Linear <-> Equal power", &sampleXFadeLoopLaw, 0, 100000)) { + if (sampleXFadeLoopLaw<0) sampleXFadeLoopLaw=0; + if (sampleXFadeLoopLaw>100000) sampleXFadeLoopLaw=100000; + } + if (ImGui::Button("Apply")) { + sample->prepareUndo(true); + e->lockEngine([this,sample]{ + SAMPLE_OP_BEGIN; + double l=1.0/(double)sampleXFadeLoopLength; + double evar=1.0-sampleXFadeLoopLaw/200000.0; + if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) { + unsigned int xfadeInput=sample->loopStart-sampleXFadeLoopLength; + unsigned int xfadeOutput=sample->loopEnd-sampleXFadeLoopLength; + for (int i=0;idata8[xfadeInput])*f1+((double)sample->data8[xfadeOutput])*f2); + sample->data8[xfadeOutput]=out; + xfadeInput++; + xfadeOutput++; + } + } else if (sample->depth==DIV_SAMPLE_DEPTH_16BIT) { + unsigned int xfadeInput=sample->loopStart-sampleXFadeLoopLength; + unsigned int xfadeOutput=sample->loopEnd-sampleXFadeLoopLength; + for (int i=0;idata16[xfadeInput])*f1+((double)sample->data16[xfadeOutput])*f2); + sample->data16[xfadeOutput]=out; + xfadeInput++; + xfadeOutput++; + } + } + updateSampleTex=true; + + e->renderSamples(curSample); + }); + MARK_MODIFIED; + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } + ImGui::SameLine(); if (ImGui::Button(ICON_FA_PLAY "##PreviewSample")) { e->previewSample(curSample); } From c634f20d05b34d8199177e5126c33853c846aa64 Mon Sep 17 00:00:00 2001 From: LeviathaninWaves Date: Fri, 1 Dec 2023 19:13:44 -0600 Subject: [PATCH 2/9] Out of bounds checking and crash fix --- src/gui/sampleEdit.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 373521e052..53ff39c3e7 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -1235,9 +1235,12 @@ void FurnaceGUI::drawSampleEdit() { ImGui::OpenPopup("SXFadeOpt"); } if (ImGui::BeginPopupContextItem("SXFadeÓpt",ImGuiPopupFlags_MouseButtonLeft)) { + if (sampleXFadeLoopLength>sample->loopStart) sampleXFadeLoopLength=sample->loopStart; + if (sampleXFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleXFadeLoopLength=sample->loopEnd-sample->loopStart; if (ImGui::SliderInt("Number of samples", &sampleXFadeLoopLength, 0, 100000)) { if (sampleXFadeLoopLength<0) sampleXFadeLoopLength=0; if (sampleXFadeLoopLength>sample->loopStart) sampleXFadeLoopLength=sample->loopStart; + if (sampleXFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleXFadeLoopLength=sample->loopEnd-sample->loopStart; if (sampleXFadeLoopLength>100000) sampleXFadeLoopLength=100000; } if (ImGui::SliderInt("Linear <-> Equal power", &sampleXFadeLoopLaw, 0, 100000)) { @@ -1245,6 +1248,14 @@ void FurnaceGUI::drawSampleEdit() { if (sampleXFadeLoopLaw>100000) sampleXFadeLoopLaw=100000; } if (ImGui::Button("Apply")) { + if (sampleXFadeLoopLength>sample->loopStart){ + SAMPLE_WARN(warnLoop,"Crossfade: length would go out of bounds. Aborted..."); + goto done; + } + if (sampleXFadeLoopLength>(sample->loopEnd-sample->loopStart)) { + SAMPLE_WARN(warnLoop,"Crossfade: length would overflow loopStart. Try a smaller random value."); + goto done; + } sample->prepareUndo(true); e->lockEngine([this,sample]{ SAMPLE_OP_BEGIN; @@ -1278,6 +1289,7 @@ void FurnaceGUI::drawSampleEdit() { e->renderSamples(curSample); }); MARK_MODIFIED; + done: ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); From 249ce8366213861ce9de9b6109a6ab8ba3a955e5 Mon Sep 17 00:00:00 2001 From: LeviathaninWaves Date: Sat, 2 Dec 2023 07:42:43 -0600 Subject: [PATCH 3/9] Cleanup --- src/engine/sample.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/engine/sample.h b/src/engine/sample.h index 118fe77763..253fe347c2 100644 --- a/src/engine/sample.h +++ b/src/engine/sample.h @@ -287,7 +287,6 @@ struct DivSample { */ void convert(DivSampleDepth newDepth); - /** * initialize the rest of sample formats for this sample. */ From d59dfa30f066092ab6d8faf487e4d9ebd3c8a83f Mon Sep 17 00:00:00 2001 From: LeviathaninWaves Date: Sat, 2 Dec 2023 19:02:43 -0600 Subject: [PATCH 4/9] Adjustments to crossfade algo/slider and renaming --- src/gui/doAction.cpp | 2 +- src/gui/gui.cpp | 6 ++-- src/gui/gui.h | 4 +-- src/gui/sampleEdit.cpp | 72 +++++++++++++++++++++--------------------- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index afd6de9574..7e998af917 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -1338,7 +1338,7 @@ void FurnaceGUI::doAction(int what) { } case GUI_ACTION_SAMPLE_XFADE_LOOP: if (curSample<0 || curSample>=(int)e->song.sample.size()) break; - openSampleXFadeOpt=true; + openSampleCrossFadeOpt=true; break; case GUI_ACTION_SAMPLE_FILTER: if (curSample<0 || curSample>=(int)e->song.sample.size()) break; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 50808e689a..d032cc805c 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -7529,8 +7529,8 @@ FurnaceGUI::FurnaceGUI(): sampleFilterRes(0.25f), sampleFilterCutStart(16000.0f), sampleFilterCutEnd(100.0f), - sampleXFadeLoopLength(0), - sampleXFadeLoopLaw(50000), + sampleCrossFadeLoopLength(0), + sampleCrossFadeLoopLaw(50), sampleFilterPower(1), sampleClipboard(NULL), sampleClipboardLen(0), @@ -7539,7 +7539,7 @@ FurnaceGUI::FurnaceGUI(): openSampleAmplifyOpt(false), openSampleSilenceOpt(false), openSampleFilterOpt(false), - openSampleXFadeOpt(false), + openSampleCrossFadeOpt(false), selectedPortSet(0x1fff), selectedSubPort(-1), hoveredPortSet(0x1fff), diff --git a/src/gui/gui.h b/src/gui/gui.h index 686f9b9667..704e3475be 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -2104,11 +2104,11 @@ class FurnaceGUI { ImVec2 sampleDragAreaSize; unsigned int sampleDragLen; float sampleFilterL, sampleFilterB, sampleFilterH, sampleFilterRes, sampleFilterCutStart, sampleFilterCutEnd; - int sampleXFadeLoopLength, sampleXFadeLoopLaw; + int sampleCrossFadeLoopLength, sampleCrossFadeLoopLaw; unsigned char sampleFilterPower; short* sampleClipboard; size_t sampleClipboardLen; - bool openSampleResizeOpt, openSampleResampleOpt, openSampleAmplifyOpt, openSampleSilenceOpt, openSampleFilterOpt, openSampleXFadeOpt; + bool openSampleResizeOpt, openSampleResampleOpt, openSampleAmplifyOpt, openSampleSilenceOpt, openSampleFilterOpt, openSampleCrossFadeOpt; // mixer // 0xxx: output diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 53ff39c3e7..78a8aa9e5c 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -1230,58 +1230,58 @@ void FurnaceGUI::drawSampleEdit() { if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Crossfade loop points."); } - if (openSampleXFadeOpt) { - openSampleXFadeOpt=false; - ImGui::OpenPopup("SXFadeOpt"); - } - if (ImGui::BeginPopupContextItem("SXFadeÓpt",ImGuiPopupFlags_MouseButtonLeft)) { - if (sampleXFadeLoopLength>sample->loopStart) sampleXFadeLoopLength=sample->loopStart; - if (sampleXFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleXFadeLoopLength=sample->loopEnd-sample->loopStart; - if (ImGui::SliderInt("Number of samples", &sampleXFadeLoopLength, 0, 100000)) { - if (sampleXFadeLoopLength<0) sampleXFadeLoopLength=0; - if (sampleXFadeLoopLength>sample->loopStart) sampleXFadeLoopLength=sample->loopStart; - if (sampleXFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleXFadeLoopLength=sample->loopEnd-sample->loopStart; - if (sampleXFadeLoopLength>100000) sampleXFadeLoopLength=100000; - } - if (ImGui::SliderInt("Linear <-> Equal power", &sampleXFadeLoopLaw, 0, 100000)) { - if (sampleXFadeLoopLaw<0) sampleXFadeLoopLaw=0; - if (sampleXFadeLoopLaw>100000) sampleXFadeLoopLaw=100000; + if (openSampleCrossFadeOpt) { + openSampleCrossFadeOpt=false; + ImGui::OpenPopup("SCrossFadeOpt"); + } + if (ImGui::BeginPopupContextItem("SCrossFadeÓpt",ImGuiPopupFlags_MouseButtonLeft)) { + if (sampleCrossFadeLoopLength>sample->loopStart) sampleCrossFadeLoopLength=sample->loopStart; + if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleCrossFadeLoopLength=sample->loopEnd-sample->loopStart; + if (ImGui::SliderInt("Number of samples", &sampleCrossFadeLoopLength, 0, 100000)) { + if (sampleCrossFadeLoopLength<0) sampleCrossFadeLoopLength=0; + if (sampleCrossFadeLoopLength>sample->loopStart) sampleCrossFadeLoopLength=sample->loopStart; + if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleCrossFadeLoopLength=sample->loopEnd-sample->loopStart; + if (sampleCrossFadeLoopLength>100000) sampleCrossFadeLoopLength=100000; + } + if (ImGui::SliderInt("Linear <-> Equal power", &sampleCrossFadeLoopLaw, 0, 100)) { + if (sampleCrossFadeLoopLaw<0) sampleCrossFadeLoopLaw=0; + if (sampleCrossFadeLoopLaw>100) sampleCrossFadeLoopLaw=100; } if (ImGui::Button("Apply")) { - if (sampleXFadeLoopLength>sample->loopStart){ + if (sampleCrossFadeLoopLength>sample->loopStart){ SAMPLE_WARN(warnLoop,"Crossfade: length would go out of bounds. Aborted..."); goto done; } - if (sampleXFadeLoopLength>(sample->loopEnd-sample->loopStart)) { + if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) { SAMPLE_WARN(warnLoop,"Crossfade: length would overflow loopStart. Try a smaller random value."); goto done; } sample->prepareUndo(true); e->lockEngine([this,sample]{ SAMPLE_OP_BEGIN; - double l=1.0/(double)sampleXFadeLoopLength; - double evar=1.0-sampleXFadeLoopLaw/200000.0; + double l=1.0/(double)sampleCrossFadeLoopLength; + double evar=1.0-sampleCrossFadeLoopLaw/200.0; if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) { - unsigned int xfadeInput=sample->loopStart-sampleXFadeLoopLength; - unsigned int xfadeOutput=sample->loopEnd-sampleXFadeLoopLength; - for (int i=0;iloopStart-sampleCrossFadeLoopLength; + unsigned int crossFadeOutput=sample->loopEnd-sampleCrossFadeLoopLength; + for (int i=0;idata8[xfadeInput])*f1+((double)sample->data8[xfadeOutput])*f2); - sample->data8[xfadeOutput]=out; - xfadeInput++; - xfadeOutput++; + double f2=std::pow((sampleCrossFadeLoopLength-i)*l, evar); + signed char out=(signed char)(((double)sample->data8[crossFadeInput])*f1+((double)sample->data8[crossFadeOutput])*f2); + sample->data8[crossFadeOutput]=out; + crossFadeInput++; + crossFadeOutput++; } } else if (sample->depth==DIV_SAMPLE_DEPTH_16BIT) { - unsigned int xfadeInput=sample->loopStart-sampleXFadeLoopLength; - unsigned int xfadeOutput=sample->loopEnd-sampleXFadeLoopLength; - for (int i=0;iloopStart-sampleCrossFadeLoopLength; + unsigned int crossFadeOutput=sample->loopEnd-sampleCrossFadeLoopLength; + for (int i=0;idata16[xfadeInput])*f1+((double)sample->data16[xfadeOutput])*f2); - sample->data16[xfadeOutput]=out; - xfadeInput++; - xfadeOutput++; + double f2=std::pow((sampleCrossFadeLoopLength-i)*l,evar); + short out = (short)(((double)sample->data16[crossFadeInput])*f1+((double)sample->data16[crossFadeOutput])*f2); + sample->data16[crossFadeOutput]=out; + crossFadeInput++; + crossFadeOutput++; } } updateSampleTex=true; From 6c379d24df9a2ba064a026d9477de37eb15394c8 Mon Sep 17 00:00:00 2001 From: LeviathaninWaves Date: Sat, 2 Dec 2023 19:07:04 -0600 Subject: [PATCH 5/9] More renaming --- src/gui/doAction.cpp | 2 +- src/gui/gui.h | 2 +- src/gui/guiConst.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index 7e998af917..4db68d93b0 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -1336,7 +1336,7 @@ void FurnaceGUI::doAction(int what) { MARK_MODIFIED; break; } - case GUI_ACTION_SAMPLE_XFADE_LOOP: + case GUI_ACTION_SAMPLE_CROSSFADE_LOOP: if (curSample<0 || curSample>=(int)e->song.sample.size()) break; openSampleCrossFadeOpt=true; break; diff --git a/src/gui/gui.h b/src/gui/gui.h index 704e3475be..857a6081a0 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -722,7 +722,7 @@ enum FurnaceGUIActions { GUI_ACTION_SAMPLE_INVERT, GUI_ACTION_SAMPLE_SIGN, GUI_ACTION_SAMPLE_FILTER, - GUI_ACTION_SAMPLE_XFADE_LOOP, + GUI_ACTION_SAMPLE_CROSSFADE_LOOP, GUI_ACTION_SAMPLE_PREVIEW, GUI_ACTION_SAMPLE_STOP_PREVIEW, GUI_ACTION_SAMPLE_ZOOM_IN, diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index 561dcffe34..75decd374e 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -743,7 +743,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={ D("SAMPLE_INVERT", "Invert", FURKMOD_CMD|FURKMOD_SHIFT|SDLK_t), D("SAMPLE_SIGN", "Signed/unsigned exchange", FURKMOD_CMD|SDLK_u), D("SAMPLE_FILTER", "Apply filter", FURKMOD_CMD|SDLK_f), - D("SAMPLE_XFADE_LOOP", "Crossfade loop points", NOT_AN_ACTION), + D("SAMPLE_CROSSFADE_LOOP", "Crossfade loop points", NOT_AN_ACTION), D("SAMPLE_PREVIEW", "Preview sample", 0), D("SAMPLE_STOP_PREVIEW", "Stop sample preview", 0), D("SAMPLE_ZOOM_IN", "Zoom in", FURKMOD_CMD|SDLK_EQUALS), From 041739c5cea1b55999a7580043eed3149d57b281 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 5 Dec 2023 16:57:00 -0500 Subject: [PATCH 6/9] =?UTF-8?q?GUI:=20f=C3=ADx=20acc=C3=A9nt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/sampleEdit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 78a8aa9e5c..8b4a70ca22 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -1234,7 +1234,7 @@ void FurnaceGUI::drawSampleEdit() { openSampleCrossFadeOpt=false; ImGui::OpenPopup("SCrossFadeOpt"); } - if (ImGui::BeginPopupContextItem("SCrossFadeÓpt",ImGuiPopupFlags_MouseButtonLeft)) { + if (ImGui::BeginPopupContextItem("SCrossFadeOpt",ImGuiPopupFlags_MouseButtonLeft)) { if (sampleCrossFadeLoopLength>sample->loopStart) sampleCrossFadeLoopLength=sample->loopStart; if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleCrossFadeLoopLength=sample->loopEnd-sample->loopStart; if (ImGui::SliderInt("Number of samples", &sampleCrossFadeLoopLength, 0, 100000)) { From 673a2d0f118695fc61b6db511b88774f9065f30d Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 5 Dec 2023 16:59:16 -0500 Subject: [PATCH 7/9] more work --- src/gui/sampleEdit.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 8b4a70ca22..7ce7d2f347 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -1226,9 +1226,9 @@ void FurnaceGUI::drawSampleEdit() { ImGui::SameLine(); ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); sameLineMaybe(); - ImGui::Button("Crossfade"); + ImGui::Button(ICON_FUR_CROSSFADE "##Crossfade"); if (ImGui::IsItemHovered()) { - ImGui::SetTooltip("Crossfade loop points."); + ImGui::SetTooltip("Crossfade loop points"); } if (openSampleCrossFadeOpt) { openSampleCrossFadeOpt=false; @@ -1248,13 +1248,13 @@ void FurnaceGUI::drawSampleEdit() { if (sampleCrossFadeLoopLaw>100) sampleCrossFadeLoopLaw=100; } if (ImGui::Button("Apply")) { - if (sampleCrossFadeLoopLength>sample->loopStart){ + if (sampleCrossFadeLoopLength>sample->loopStart) { SAMPLE_WARN(warnLoop,"Crossfade: length would go out of bounds. Aborted..."); - goto done; + ImGui::CloseCurrentPopup(); } if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) { SAMPLE_WARN(warnLoop,"Crossfade: length would overflow loopStart. Try a smaller random value."); - goto done; + ImGui::CloseCurrentPopup(); } sample->prepareUndo(true); e->lockEngine([this,sample]{ @@ -1289,7 +1289,6 @@ void FurnaceGUI::drawSampleEdit() { e->renderSamples(curSample); }); MARK_MODIFIED; - done: ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); From bf212779a7c39b8f8a5e5a481e3fe44029c8282d Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 5 Dec 2023 17:00:26 -0500 Subject: [PATCH 8/9] prepare for cross-fade icon --- src/icon/furIcons.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/icon/furIcons.h b/src/icon/furIcons.h index 718e6822be..5d5cec4cbf 100644 --- a/src/icon/furIcons.h +++ b/src/icon/furIcons.h @@ -1,7 +1,7 @@ // not auto-generated. update every time you change icons.ttf! #define ICON_MIN_FUR 0xe0f0 -#define ICON_MAX_FUR 0xe158 +#define ICON_MAX_FUR 0xe159 // test #define ICON_FUR_TEST0 u8"\ue0f0" @@ -105,4 +105,5 @@ #define ICON_FUR_INC_LINEAR u8"\ue14b" #define ICON_FUR_INC_BENT u8"\ue14c" #define ICON_FUR_VOL_DIRECT u8"\ue14d" -#define ICON_FUR_ADSR u8"\ue14e" \ No newline at end of file +#define ICON_FUR_ADSR u8"\ue14e" +#define ICON_FUR_CROSSFADE u8"\ue159" From 02bc89f8cb127eb1402b2f5a7a29993033f0f8f3 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 5 Dec 2023 17:06:46 -0500 Subject: [PATCH 9/9] more work --- src/gui/sampleEdit.cpp | 80 +++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 7ce7d2f347..5c070eebc0 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -1226,7 +1226,7 @@ void FurnaceGUI::drawSampleEdit() { ImGui::SameLine(); ImGui::Dummy(ImVec2(4.0*dpiScale,dpiScale)); sameLineMaybe(); - ImGui::Button(ICON_FUR_CROSSFADE "##Crossfade"); + ImGui::Button(ICON_FUR_CROSSFADE "##CrossFade"); if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Crossfade loop points"); } @@ -1237,59 +1237,59 @@ void FurnaceGUI::drawSampleEdit() { if (ImGui::BeginPopupContextItem("SCrossFadeOpt",ImGuiPopupFlags_MouseButtonLeft)) { if (sampleCrossFadeLoopLength>sample->loopStart) sampleCrossFadeLoopLength=sample->loopStart; if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleCrossFadeLoopLength=sample->loopEnd-sample->loopStart; - if (ImGui::SliderInt("Number of samples", &sampleCrossFadeLoopLength, 0, 100000)) { + if (ImGui::SliderInt("Number of samples",&sampleCrossFadeLoopLength,0,100000)) { if (sampleCrossFadeLoopLength<0) sampleCrossFadeLoopLength=0; if (sampleCrossFadeLoopLength>sample->loopStart) sampleCrossFadeLoopLength=sample->loopStart; if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleCrossFadeLoopLength=sample->loopEnd-sample->loopStart; if (sampleCrossFadeLoopLength>100000) sampleCrossFadeLoopLength=100000; } - if (ImGui::SliderInt("Linear <-> Equal power", &sampleCrossFadeLoopLaw, 0, 100)) { + if (ImGui::SliderInt("Linear <-> Equal power",&sampleCrossFadeLoopLaw,0,100)) { if (sampleCrossFadeLoopLaw<0) sampleCrossFadeLoopLaw=0; if (sampleCrossFadeLoopLaw>100) sampleCrossFadeLoopLaw=100; } if (ImGui::Button("Apply")) { if (sampleCrossFadeLoopLength>sample->loopStart) { - SAMPLE_WARN(warnLoop,"Crossfade: length would go out of bounds. Aborted..."); + showError("Crossfade: length would go out of bounds. Aborted..."); ImGui::CloseCurrentPopup(); - } - if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) { - SAMPLE_WARN(warnLoop,"Crossfade: length would overflow loopStart. Try a smaller random value."); + } else if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) { + showError("Crossfade: length would overflow loopStart. Try a smaller random value."); ImGui::CloseCurrentPopup(); - } - sample->prepareUndo(true); - e->lockEngine([this,sample]{ - SAMPLE_OP_BEGIN; - double l=1.0/(double)sampleCrossFadeLoopLength; - double evar=1.0-sampleCrossFadeLoopLaw/200.0; - if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) { - unsigned int crossFadeInput=sample->loopStart-sampleCrossFadeLoopLength; - unsigned int crossFadeOutput=sample->loopEnd-sampleCrossFadeLoopLength; - for (int i=0;idata8[crossFadeInput])*f1+((double)sample->data8[crossFadeOutput])*f2); - sample->data8[crossFadeOutput]=out; - crossFadeInput++; - crossFadeOutput++; - } - } else if (sample->depth==DIV_SAMPLE_DEPTH_16BIT) { - unsigned int crossFadeInput=sample->loopStart-sampleCrossFadeLoopLength; - unsigned int crossFadeOutput=sample->loopEnd-sampleCrossFadeLoopLength; - for (int i=0;idata16[crossFadeInput])*f1+((double)sample->data16[crossFadeOutput])*f2); - sample->data16[crossFadeOutput]=out; - crossFadeInput++; - crossFadeOutput++; + } else { + sample->prepareUndo(true); + e->lockEngine([this,sample] { + SAMPLE_OP_BEGIN; + double l=1.0/(double)sampleCrossFadeLoopLength; + double evar=1.0-sampleCrossFadeLoopLaw/200.0; + if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) { + unsigned int crossFadeInput=sample->loopStart-sampleCrossFadeLoopLength; + unsigned int crossFadeOutput=sample->loopEnd-sampleCrossFadeLoopLength; + for (int i=0; idata8[crossFadeInput])*f1+((double)sample->data8[crossFadeOutput])*f2); + sample->data8[crossFadeOutput]=out; + crossFadeInput++; + crossFadeOutput++; + } + } else if (sample->depth==DIV_SAMPLE_DEPTH_16BIT) { + unsigned int crossFadeInput=sample->loopStart-sampleCrossFadeLoopLength; + unsigned int crossFadeOutput=sample->loopEnd-sampleCrossFadeLoopLength; + for (int i=0; idata16[crossFadeInput])*f1+((double)sample->data16[crossFadeOutput])*f2); + sample->data16[crossFadeOutput]=out; + crossFadeInput++; + crossFadeOutput++; + } } - } - updateSampleTex=true; + updateSampleTex=true; - e->renderSamples(curSample); - }); - MARK_MODIFIED; - ImGui::CloseCurrentPopup(); + e->renderSamples(curSample); + }); + MARK_MODIFIED; + ImGui::CloseCurrentPopup(); + } } ImGui::EndPopup(); }