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 surge-synthesizer#4625.

Also puts the inti patch name and template as a member of
storage and uses that consistently, and allows a user default
for the patch to use there.  Closes surge-synthesizer#4502.
  • Loading branch information
baconpaul committed Jun 3, 2021
1 parent 74ebdba commit 42af31d
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 19 deletions.
5 changes: 5 additions & 0 deletions src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,11 @@ SurgeStorage::SurgeStorage(std::string suppliedDataPath) : otherscene_clients(0)
oddsound_mts_client = nullptr;
oddsound_mts_active = false;
}

initPatchName =
Surge::Storage::getUserDefaultValue(this, Surge::Storage::InitialPatchName, "Init Saw");
initPatchCategory = Surge::Storage::getUserDefaultValue(
this, Surge::Storage::InitialPatchCategory, "Templates");
}

void SurgeStorage::initializePatchDb()
Expand Down
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
7 changes: 7 additions & 0 deletions src/common/UserDefaults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ void initMaps()
break;
case ShowVirtualKeyboard_Standalone:
r = "showVirtualKeyboardStandalone";
break;
case InitialPatchName:
r = "initialPatchName";
break;
case InitialPatchCategory:
r = "initialPatchCategory";
break;
case nKeys:
break;
}
Expand Down
3 changes: 3 additions & 0 deletions src/common/UserDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ enum DefaultKey // streamed as strings so feel free to change the order to whate
ShowVirtualKeyboard_Plugin,
ShowVirtualKeyboard_Standalone,

InitialPatchName,
InitialPatchCategory,

nKeys
};
/**
Expand Down
12 changes: 11 additions & 1 deletion src/gui/widgets/PatchSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "SurgeGUIUtils.h"
#include "SurgeGUIEditor.h"
#include "RuntimeFont.h"
#include "UserDefaults.h"

namespace Surge
{
Expand Down Expand Up @@ -193,7 +194,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 All @@ -205,6 +207,14 @@ void PatchSelector::mouseDown(const juce::MouseEvent &e)

contextMenu.addItem(Surge::GUI::toOSCaseForMenu("Initialize Patch"), initAction);

contextMenu.addItem(Surge::GUI::toOSCaseForMenu("Set This Patch As Initial Patch"), [this]() {
Surge::Storage::updateUserDefaultValue(storage, Surge::Storage::InitialPatchName,
storage->patch_list[current_patch].name);

Surge::Storage::updateUserDefaultValue(storage, Surge::Storage::InitialPatchCategory,
storage->patch_category[current_category].name);
});

contextMenu.addSeparator();

contextMenu.addItem(Surge::GUI::toOSCaseForMenu("Open Patch Database..."), [this]() {
Expand Down

0 comments on commit 42af31d

Please sign in to comment.