Skip to content

Commit

Permalink
Greatly shrink the Synthesizer::ID code (#4867)
Browse files Browse the repository at this point in the history
Synthesizer::ID was a bunch of plubming to allow indices,
ids, and param ids to all co-exist, but iwth JUCE we really
only need param ids.

I could have removed this class altogether but decided to keep
the indirection until a rainy day, so the ID is now a simple wrapper
on an int which is the param index.

Closes #4866
  • Loading branch information
baconpaul authored Aug 18, 2021
1 parent bb1b247 commit 49f99b4
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 472 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ set(SURGE_SHARED_SOURCES

set(SURGE_SYNTH_SOURCES
src/common/SurgeSynthesizer.cpp
src/common/SurgeSynthesizerIDManagement.cpp
src/common/SurgeSynthesizerIO.cpp
)

Expand Down
34 changes: 19 additions & 15 deletions src/common/SurgeSynthesizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,26 @@ class alignas(16) SurgeSynthesizer

public:
/*
* For more on this IFDEF see the comment in SurgeSynthesizerIDManagement.cpp
* So when surge was pre-juce we contemplated writing our own ID remapping between
* internal indices and DAW IDs so put an indirectin and class in place. JUCE obviates
* the need for that by using hash of stremaing name as an ID consistently throuhg its
* param mechanism. I could, in theory, have gone right back to int as my accessor class
* but there's something compelilng about keeping that indirection I plumbed in just in case
* i need it in the future. So the ID class is now just a simple wrapper on an int which is
* entirely inline.
*/
struct ID
{
int getDawSideIndex() const { return dawindex; }
int getDawSideId() const { return dawid; }
int getSynthSideId() const { return synthid; }

std::string toString() const
{
std::ostringstream oss;
oss << "ID[ dawidx=" << dawindex << ", dawid=" << dawid << " synthid=" << synthid
<< " ]";
oss << "ID[" << synthid << "]";
return oss.str();
}

bool operator==(const ID &other) const
{
return dawindex == other.dawindex && dawid == other.dawid && synthid == other.synthid;
}
bool operator==(const ID &other) const { return synthid == other.synthid; }
bool operator!=(const ID &other) const { return !(*this == other); }

friend std::ostream &operator<<(std::ostream &os, const ID &id)
Expand All @@ -170,16 +170,20 @@ class alignas(16) SurgeSynthesizer
}

private:
int dawindex = -1, dawid = -1, synthid = -1;
int synthid = -1;
friend SurgeSynthesizer;
};

bool fromDAWSideId(int i, ID &q);
bool fromDAWSideIndex(int i, ID &q);
bool fromSynthSideId(int i, ID &q);
bool fromSynthSideIdWithGuiOffset(int i, int start_paramtags, int start_metacontrol_tag, ID &q);
bool fromSynthSideId(int i, ID &q) const
{
if (i < 0 || i >= n_total_params)
return false;

q.synthid = i;
return true;
}

const ID idForParameter(const Parameter *p)
ID idForParameter(const Parameter *p) const
{
// We know this will always work
ID i;
Expand Down
183 changes: 0 additions & 183 deletions src/common/SurgeSynthesizerIDManagement.cpp

This file was deleted.

6 changes: 0 additions & 6 deletions src/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ using namespace Surge::ParamConfig;

int SurgeGUIEditor::start_paramtag_value = start_paramtags;

bool SurgeGUIEditor::fromSynthGUITag(SurgeSynthesizer *synth, int tag, SurgeSynthesizer::ID &q)
{
// This is wrong for macros and params but is close
return synth->fromSynthSideIdWithGuiOffset(tag, start_paramtags, tag_mod_source0 + ms_ctrl1, q);
}

SurgeGUIEditor::SurgeGUIEditor(SurgeSynthEditor *jEd, SurgeSynthesizer *synth)
{
assert(n_paramslots >= n_total_params);
Expand Down
1 change: 0 additions & 1 deletion src/gui/SurgeGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener,
void showSettingsMenu(const juce::Point<int> &where,
Surge::GUI::IComponentTagValue *launchFrom);

static bool fromSynthGUITag(SurgeSynthesizer *synth, int tag, SurgeSynthesizer::ID &q);
// If n_scenes > 2, then this initialization and the modsource_editor one below will need to
// adjust
int current_scene = 0, current_osc[n_scenes] = {0, 0}, current_fx = 0;
Expand Down
61 changes: 0 additions & 61 deletions src/headless/UnitTestsID.cpp

This file was deleted.

2 changes: 0 additions & 2 deletions src/python_bindings/surgepy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,6 @@ PYBIND11_MODULE(surgepy, m)
"getVersion", []() { return Surge::Build::FullVersionStr; }, "Get the version of Surge");
py::class_<SurgeSynthesizer::ID>(m, "SurgeSynthesizer_ID")
.def(py::init<>())
.def("getDawSideIndex", &SurgeSynthesizer::ID::getDawSideIndex)
.def("getDawSideId", &SurgeSynthesizer::ID::getDawSideId)
.def("getSynthSideId", &SurgeSynthesizer::ID::getSynthSideId)
.def("__repr__", &SurgeSynthesizer::ID::toString);

Expand Down
Loading

0 comments on commit 49f99b4

Please sign in to comment.