Skip to content

Commit

Permalink
Restore patchid on initial load
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
baconpaul committed Jun 3, 2021
1 parent 74ebdba commit 5ca6680
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
56 changes: 39 additions & 17 deletions src/common/SurgeSynthesizerIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/widgets/PatchSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5ca6680

Please sign in to comment.