Skip to content

Commit

Permalink
Fix a bug with Async Prompts (#5049)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
baconpaul authored Sep 10, 2021
1 parent 437ec85 commit 4ee7e91
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 53 deletions.
12 changes: 6 additions & 6 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -928,14 +928,14 @@ class alignas(16) SurgeStorage
CANCEL
};

std::function<OkCancel(const std::string &msg, const std::string &title, OkCancel def)>
okCancelProvider =
[](const std::string &, const std::string &, OkCancel def) { return def; };
std::function<void(const std::string &msg, const std::string &title, OkCancel def,
std::function<void(OkCancel)>)>
okCancelProvider = [](const std::string &, const std::string &, OkCancel def,
std::function<void(OkCancel)> 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<void(OkCancel)> callback) { callback(def); };
}

std::string initPatchName{"Init Saw"}, initPatchCategory{"Templates"};
Expand Down
90 changes: 49 additions & 41 deletions src/common/SurgeSynthesizerIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
});
}
}

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions src/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(SurgeStorage::OkCancel)> 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");
Expand Down

0 comments on commit 4ee7e91

Please sign in to comment.