From 5ca66800cc813938d947cb6ce3c2ddc1274aeb66 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Wed, 2 Jun 2021 21:12:48 -0400 Subject: [PATCH] Restore patchid on initial load The initial load would ignore the patchid-from-name guess since we had already found Init Saw. Make it so we beleive the name with various checks to make sure that is reasonable. Closes #4625. Also puts the inti patch name and template as a member of storage and uses that consistently, which is part of the way to #4502. --- src/common/SurgeStorage.h | 2 ++ src/common/SurgeSynthesizer.cpp | 3 +- src/common/SurgeSynthesizerIO.cpp | 56 +++++++++++++++++++++---------- src/gui/widgets/PatchSelector.cpp | 3 +- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/common/SurgeStorage.h b/src/common/SurgeStorage.h index 3c837bc9b15..887c36c799f 100644 --- a/src/common/SurgeStorage.h +++ b/src/common/SurgeStorage.h @@ -936,6 +936,8 @@ class alignas(16) SurgeStorage }; } + std::string initPatchName{"Init Saw"}, initPatchCategory{"Templates"}; + static constexpr int tuning_table_size = 512; float table_pitch alignas(16)[tuning_table_size]; float table_pitch_inv alignas(16)[tuning_table_size]; diff --git a/src/common/SurgeSynthesizer.cpp b/src/common/SurgeSynthesizer.cpp index 391a2027799..6bf8dbcf724 100644 --- a/src/common/SurgeSynthesizer.cpp +++ b/src/common/SurgeSynthesizer.cpp @@ -229,7 +229,8 @@ SurgeSynthesizer::SurgeSynthesizer(PluginLayer *parent, std::string suppliedData int pid = 0; for (auto p : storage.patch_list) { - if (p.name == "Init Saw" && storage.patch_category[p.category].name == "Templates") + if (p.name == storage.initPatchName && + storage.patch_category[p.category].name == storage.initPatchCategory) { patchid_queue = pid; break; diff --git a/src/common/SurgeSynthesizerIO.cpp b/src/common/SurgeSynthesizerIO.cpp index d9f80c52968..2f4d49296aa 100644 --- a/src/common/SurgeSynthesizerIO.cpp +++ b/src/common/SurgeSynthesizerIO.cpp @@ -421,25 +421,47 @@ void SurgeSynthesizer::loadRaw(const void *data, int size, bool preset) patch_loaded = true; refresh_editor = true; - if (patchid < 0) + /* + ** new patch just loaded so I look up and set the current category and patch. + ** This is used to draw checkmarks in the menu. If for some reason we don't + ** find one, nothing will break + */ + int inferredPatchId = -1; + int cnt = storage.patch_list.size(); + string name = storage.getPatch().name; + string cat = storage.getPatch().category; + for (int p = 0; p < cnt; ++p) { - /* - ** new patch just loaded so I look up and set the current category and patch. - ** This is used to draw checkmarks in the menu. If for some reason we don't - ** find one, nothing will break - */ - int cnt = storage.patch_list.size(); - string name = storage.getPatch().name; - string cat = storage.getPatch().category; - for (int p = 0; p < cnt; ++p) + if (storage.patch_list[p].name == name && + storage.patch_category[storage.patch_list[p].category].name == cat) { - if (storage.patch_list[p].name == name && - storage.patch_category[storage.patch_list[p].category].name == cat) - { - current_category_id = storage.patch_list[p].category; - patchid = p; - break; - } + current_category_id = storage.patch_list[p].category; + inferredPatchId = p; + break; + } + } + + if (inferredPatchId >= 0 && inferredPatchId != patchid) + { + // If the patchid is out of range or if it is the default overrule + if (patchid < 0 && patchid >= storage.patch_list.size()) + { + patchid = inferredPatchId; + } + else if (storage.patch_list[patchid].name == storage.initPatchName && + storage.patch_category[storage.patch_list[patchid].category].name == + storage.initPatchCategory) + { + patchid = inferredPatchId; + } + else + { + /* + * I don't see how this could ever happen. Punt. + */ + storage.reportError("Loading patch couldn't infer patch name. Please tell devs.", + "Software Error"); + patchid = inferredPatchId; } } } diff --git a/src/gui/widgets/PatchSelector.cpp b/src/gui/widgets/PatchSelector.cpp index f51efbc2431..950fde3360c 100644 --- a/src/gui/widgets/PatchSelector.cpp +++ b/src/gui/widgets/PatchSelector.cpp @@ -193,7 +193,8 @@ void PatchSelector::mouseDown(const juce::MouseEvent &e) for (auto p : storage->patch_list) { - if (p.name == "Init Saw" && storage->patch_category[p.category].name == "Templates") + if (p.name == storage->initPatchName && + storage->patch_category[p.category].name == storage->initPatchCategory) { loadPatch(i); break;