From 4ee7e91c77a5801cc64e95159d788c9e30ef7fc8 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 10 Sep 2021 18:19:11 -0400 Subject: [PATCH] Fix a bug with Async Prompts (#5049) the Async Prompt stuff earlier htis week to get MODAL_LOOPS on broke the non-modal Storage OkCancel. Defacto this meant that you could never replace a patch because the OK Cancel asked you but had already canceled. Closes #5045, where we had thought this was a global volume saving problem, but it was really an anything saving problem --- src/common/SurgeStorage.h | 12 ++--- src/common/SurgeSynthesizerIO.cpp | 90 +++++++++++++++++-------------- src/gui/SurgeGUIEditor.cpp | 13 ++--- 3 files changed, 62 insertions(+), 53 deletions(-) diff --git a/src/common/SurgeStorage.h b/src/common/SurgeStorage.h index 712cbcaf2f7..23451f57fe4 100644 --- a/src/common/SurgeStorage.h +++ b/src/common/SurgeStorage.h @@ -928,14 +928,14 @@ class alignas(16) SurgeStorage CANCEL }; - std::function - okCancelProvider = - [](const std::string &, const std::string &, OkCancel def) { return def; }; + std::function)> + okCancelProvider = [](const std::string &, const std::string &, OkCancel def, + std::function callback) { callback(def); }; void clearOkCancelProvider() { - okCancelProvider = [](const std::string &, const std::string &, OkCancel def) { - return def; - }; + okCancelProvider = [](const std::string &, const std::string &, OkCancel def, + std::function callback) { callback(def); }; } std::string initPatchName{"Init Saw"}, initPatchCategory{"Templates"}; diff --git a/src/common/SurgeSynthesizerIO.cpp b/src/common/SurgeSynthesizerIO.cpp index 0f05ec78036..cc3f85c3cc9 100644 --- a/src/common/SurgeSynthesizerIO.cpp +++ b/src/common/SurgeSynthesizerIO.cpp @@ -306,47 +306,48 @@ bool SurgeSynthesizer::loadPatchByPath(const char *fxpPath, int categoryId, cons } else { - auto okc = storage.okCancelProvider( + storage.okCancelProvider( std::string("Loaded patch contains a custom tuning, but there is ") + "already a user-selected tuning in place. Do you want to replace the currently " "loaded tuning " + "with the tuning stored in the patch? (The rest of the patch will load " "normally.)", - "Replace Tuning", SurgeStorage::CANCEL); - if (okc == SurgeStorage::OK) - { - try - { - if (storage.getPatch().patchTuning.scaleContents.size() > 1) - { - storage.retuneToScale( - Tunings::parseSCLData(storage.getPatch().patchTuning.scaleContents)); - } - else - { - storage.retuneTo12TETScale(); - } - if (storage.getPatch().patchTuning.mappingContents.size() > 1) - { - auto kb = - Tunings::parseKBMData(storage.getPatch().patchTuning.mappingContents); - if (storage.getPatch().patchTuning.mappingName.size() > 1) - kb.name = storage.getPatch().patchTuning.mappingName; - else - kb.name = storage.guessAtKBMName(kb); - storage.remapToKeyboard(kb); - } - else + "Replace Tuning", SurgeStorage::CANCEL, [this](SurgeStorage::OkCancel okc) { + if (okc == SurgeStorage::OK) { - storage.remapToConcertCKeyboard(); + try + { + if (storage.getPatch().patchTuning.scaleContents.size() > 1) + { + storage.retuneToScale(Tunings::parseSCLData( + storage.getPatch().patchTuning.scaleContents)); + } + else + { + storage.retuneTo12TETScale(); + } + if (storage.getPatch().patchTuning.mappingContents.size() > 1) + { + auto kb = Tunings::parseKBMData( + storage.getPatch().patchTuning.mappingContents); + if (storage.getPatch().patchTuning.mappingName.size() > 1) + kb.name = storage.getPatch().patchTuning.mappingName; + else + kb.name = storage.guessAtKBMName(kb); + storage.remapToKeyboard(kb); + } + else + { + storage.remapToConcertCKeyboard(); + } + } + catch (Tunings::TuningError &e) + { + storage.reportError(e.what(), "Error Restoring Tuning"); + storage.retuneTo12TETScaleC261Mapping(); + } } - } - catch (Tunings::TuningError &e) - { - storage.reportError(e.what(), "Error Restoring Tuning"); - storage.retuneTo12TETScaleC261Mapping(); - } - } + }); } } @@ -528,14 +529,21 @@ void SurgeSynthesizer::savePatch() if (fs::exists(filename)) { - if (storage.okCancelProvider( - std::string("The patch '" + storage.getPatch().name + "' already exists in '" + - storage.getPatch().category + - "'. Are you sure you want to overwrite it?"), - std::string("Overwrite patch"), SurgeStorage::OK) == SurgeStorage::CANCEL) - return; + storage.okCancelProvider(std::string("The patch '" + storage.getPatch().name + + "' already exists in '" + storage.getPatch().category + + "'. Are you sure you want to overwrite it?"), + std::string("Overwrite patch"), SurgeStorage::OK, + [filename, this](SurgeStorage::OkCancel okc) { + if (okc == SurgeStorage::OK) + { + savePatchToPath(filename); + } + }); + } + else + { + savePatchToPath(filename); } - savePatchToPath(filename); } void SurgeSynthesizer::savePatchToPath(fs::path filename) diff --git a/src/gui/SurgeGUIEditor.cpp b/src/gui/SurgeGUIEditor.cpp index ee511e66858..0140e282d3d 100644 --- a/src/gui/SurgeGUIEditor.cpp +++ b/src/gui/SurgeGUIEditor.cpp @@ -93,14 +93,15 @@ SurgeGUIEditor::SurgeGUIEditor(SurgeSynthEditor *jEd, SurgeSynthesizer *synth) assert(n_paramslots >= n_total_params); synth->storage.addErrorListener(this); synth->storage.okCancelProvider = [](const std::string &msg, const std::string &title, - SurgeStorage::OkCancel def) { + SurgeStorage::OkCancel def, + std::function callback) { // think about threading one day probably + auto cb = juce::ModalCallbackFunction::create([callback](int isOk) { + auto r = isOk ? SurgeStorage::OK : SurgeStorage::CANCEL; + callback(r); + }); auto res = juce::AlertWindow::showOkCancelBox(juce::AlertWindow::InfoIcon, title, msg, "OK", - "Cancel", nullptr, nullptr); - - if (res) - return SurgeStorage::OK; - return SurgeStorage::CANCEL; + "Cancel", nullptr, cb); }; #ifdef INSTRUMENT_UI Surge::Debug::record("SurgeGUIEditor::SurgeGUIEditor");