From 09d226a9aa642bda19a2953b9db41c54315e5d9f Mon Sep 17 00:00:00 2001 From: tildearrow Date: Mon, 17 Jul 2023 16:31:55 -0500 Subject: [PATCH] GUI: fix replace raw --- src/gui/gui.cpp | 24 +++++++++++++++++++++--- src/gui/gui.h | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index d6e689116..332c636d7 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -4848,6 +4848,7 @@ bool FurnaceGUI::loop() { case GUI_FILE_SAMPLE_OPEN_RAW: case GUI_FILE_SAMPLE_OPEN_REPLACE_RAW: pendingRawSample=copyOfName; + pendingRawSampleReplace=(curFileDialog==GUI_FILE_SAMPLE_OPEN_REPLACE_RAW); displayPendingRawSample=true; break; case GUI_FILE_SAMPLE_SAVE: @@ -5715,10 +5716,26 @@ bool FurnaceGUI::loop() { if (s==NULL) { showError(e->getLastError()); } else { - if (e->addSamplePtr(s)==-1) { - showError(e->getLastError()); + if (pendingRawSampleReplace) { + if (curSample>=0 && curSample<(int)e->song.sample.size()) { + e->lockEngine([this,s]() { + // if it crashes here please tell me... + DivSample* oldSample=e->song.sample[curSample]; + e->song.sample[curSample]=s; + delete oldSample; + e->renderSamples(); + MARK_MODIFIED; + }); + } else { + showError("...but you haven't selected a sample!"); + delete s; + } } else { - MARK_MODIFIED; + if (e->addSamplePtr(s)==-1) { + showError(e->getLastError()); + } else { + MARK_MODIFIED; + } } } ImGui::CloseCurrentPopup(); @@ -6756,6 +6773,7 @@ FurnaceGUI::FurnaceGUI(): pendingRawSampleUnsigned(false), pendingRawSampleBigEndian(false), pendingRawSampleSwapNibbles(false), + pendingRawSampleReplace(false), globalWinFlags(0), curFileDialog(GUI_FILE_OPEN), warnAction(GUI_WARN_OPEN), diff --git a/src/gui/gui.h b/src/gui/gui.h index dc7a4aded..8b3460fa1 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1335,7 +1335,7 @@ class FurnaceGUI { String pendingRawSample; int pendingRawSampleDepth, pendingRawSampleChannels; - bool pendingRawSampleUnsigned, pendingRawSampleBigEndian, pendingRawSampleSwapNibbles; + bool pendingRawSampleUnsigned, pendingRawSampleBigEndian, pendingRawSampleSwapNibbles, pendingRawSampleReplace; ImGuiWindowFlags globalWinFlags;