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;