Skip to content

Commit

Permalink
Modulation Index Support
Browse files Browse the repository at this point in the history
Addresses surge-synthesizer#4868

1. Add a source index to modrouting and stream it
2. Use that modrouting to lookup values in processing (but not in all the 'is' or 'get' apis)
3. Const up a bunch of stuff along the way (workign on surge-synthesizer#3808)
  • Loading branch information
baconpaul committed Aug 18, 2021
1 parent 49f99b4 commit 46b69c1
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/common/ModulationSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ struct ModulationRouting
int destination_id;
float depth;
bool muted = false;
int source_index{0};
};

class ModulationSource
Expand Down
7 changes: 7 additions & 0 deletions src/common/SurgePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,12 @@ void SurgePatch::load_xml(const void *data, int datasize, bool is_preset)
else
t.muted = false;

int source_index = 0;
if (mr->QueryIntAttribute("source_index", &source_index) == TIXML_SUCCESS)
t.source_index = source_index;
else
t.source_index = 0;

if (sceneId != 0)
t.destination_id = paramIdInScene;
else
Expand Down Expand Up @@ -2219,6 +2225,7 @@ unsigned int SurgePatch::save_xml(void **data) // allocates mem, must be freed b
mr.SetAttribute("source", r->at(b).source_id);
mr.SetAttribute("depth", float_to_str(r->at(b).depth, tempstr));
mr.SetAttribute("muted", r->at(b).muted);
mr.SetAttribute("source_index", r->at(b).source_index);
p.InsertEndChild(mr);
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/common/SurgeStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ void SurgeStorage::initializePatchDb()
}
}

SurgePatch &SurgeStorage::getPatch() { return *_patch.get(); }
SurgePatch &SurgeStorage::getPatch() const { return *_patch.get(); }

struct PEComparer
{
Expand Down Expand Up @@ -1384,6 +1384,7 @@ void SurgeStorage::clipboard_copy(int type, int scene, int entry)
{
ModulationRouting m;
m.source_id = getPatch().scene[scene].modulation_voice[i].source_id;
m.source_index = getPatch().scene[scene].modulation_voice[i].source_index;
m.depth = getPatch().scene[scene].modulation_voice[i].depth;
m.destination_id =
getPatch().scene[scene].modulation_voice[i].destination_id + idoffset;
Expand All @@ -1395,6 +1396,7 @@ void SurgeStorage::clipboard_copy(int type, int scene, int entry)
{
ModulationRouting m;
m.source_id = getPatch().scene[scene].modulation_scene[i].source_id;
m.source_index = getPatch().scene[scene].modulation_scene[i].source_index;
m.depth = getPatch().scene[scene].modulation_scene[i].depth;
m.destination_id =
getPatch().scene[scene].modulation_scene[i].destination_id + idoffset;
Expand Down Expand Up @@ -1502,6 +1504,7 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry)
{
ModulationRouting m;
m.source_id = clipboard_modulation_voice[i].source_id;
m.source_index = clipboard_modulation_voice[i].source_index;
m.depth = clipboard_modulation_voice[i].depth;
m.destination_id =
clipboard_modulation_voice[i].destination_id + id - n_global_params;
Expand All @@ -1512,6 +1515,7 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry)
{
ModulationRouting m;
m.source_id = clipboard_modulation_scene[i].source_id;
m.source_index = clipboard_modulation_scene[i].source_index;
m.depth = clipboard_modulation_scene[i].depth;
m.destination_id =
clipboard_modulation_scene[i].destination_id + id - n_global_params;
Expand Down Expand Up @@ -1540,6 +1544,7 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry)
{
ModulationRouting m;
m.source_id = clipboard_modulation_voice[i].source_id;
m.source_index = clipboard_modulation_voice[i].source_index;
m.depth = clipboard_modulation_voice[i].depth;
m.destination_id = clipboard_modulation_voice[i].destination_id;
getPatch().scene[scene].modulation_voice.push_back(m);
Expand All @@ -1549,6 +1554,7 @@ void SurgeStorage::clipboard_paste(int type, int scene, int entry)
{
ModulationRouting m;
m.source_id = clipboard_modulation_scene[i].source_id;
m.source_index = clipboard_modulation_scene[i].source_index;
m.depth = clipboard_modulation_scene[i].depth;
m.destination_id = clipboard_modulation_scene[i].destination_id;
getPatch().scene[scene].modulation_scene.push_back(m);
Expand Down
3 changes: 2 additions & 1 deletion src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,8 @@ class alignas(16) SurgeStorage

std::unique_ptr<SurgePatch> _patch;

SurgePatch &getPatch();
// SurgePatch &getPatch();
SurgePatch &getPatch() const;

float pitch_bend;

Expand Down
28 changes: 15 additions & 13 deletions src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2405,7 +2405,7 @@ bool SurgeSynthesizer::loadOscalgos()
return true;
}

bool SurgeSynthesizer::isValidModulation(long ptag, modsources modsource)
bool SurgeSynthesizer::isValidModulation(long ptag, modsources modsource) const
{
if (!modsource)
return false;
Expand Down Expand Up @@ -2435,7 +2435,7 @@ bool SurgeSynthesizer::isValidModulation(long ptag, modsources modsource)
return true;
}

ModulationRouting *SurgeSynthesizer::getModRouting(long ptag, modsources modsource)
ModulationRouting *SurgeSynthesizer::getModRouting(long ptag, modsources modsource) const
{
if (!isValidModulation(ptag, modsource))
return nullptr;
Expand Down Expand Up @@ -2471,9 +2471,9 @@ ModulationRouting *SurgeSynthesizer::getModRouting(long ptag, modsources modsour
return nullptr;
}

float SurgeSynthesizer::getModDepth(long ptag, modsources modsource)
float SurgeSynthesizer::getModDepth(long ptag, modsources modsource) const
{
ModulationRouting *r = getModRouting(ptag, modsource);
auto *r = getModRouting(ptag, modsource);
float d = 0.f;
if (r)
d = r->depth;
Expand All @@ -2483,15 +2483,15 @@ float SurgeSynthesizer::getModDepth(long ptag, modsources modsource)
return d;
}

bool SurgeSynthesizer::isActiveModulation(long ptag, modsources modsource)
bool SurgeSynthesizer::isActiveModulation(long ptag, modsources modsource) const
{
// if(!isValidModulation(ptag,modsource)) return false;
if (getModRouting(ptag, modsource))
return true;
return false;
}

bool SurgeSynthesizer::isBipolarModulation(modsources tms)
bool SurgeSynthesizer::isBipolarModulation(modsources tms) const
{
int scene_ms = storage.getPatch().scene_active.val.i;

Expand Down Expand Up @@ -2523,7 +2523,7 @@ bool SurgeSynthesizer::isBipolarModulation(modsources tms)
return false;
}

bool SurgeSynthesizer::isModDestUsed(long ptag)
bool SurgeSynthesizer::isModDestUsed(long ptag) const
{
int scene_ms = storage.getPatch().scene_active.val.i;
int scene_p = storage.getPatch().param_ptr[ptag]->scene;
Expand All @@ -2537,7 +2537,7 @@ bool SurgeSynthesizer::isModDestUsed(long ptag)
// if((scene && (j>0))||(!scene && (j==0)))
if ((scene_p && (j > 0)) || (!scene_p && (j == 0)))
{
vector<ModulationRouting> *modlist;
const vector<ModulationRouting> *modlist{nullptr};

switch (j)
{
Expand Down Expand Up @@ -2654,24 +2654,24 @@ bool SurgeSynthesizer::isModsourceUsed(modsources modsource)
return modsourceused[modsource];
}

float SurgeSynthesizer::getModulation(long ptag, modsources modsource)
float SurgeSynthesizer::getModulation(long ptag, modsources modsource) const
{
if (!isValidModulation(ptag, modsource))
return 0.0f;

ModulationRouting *r = getModRouting(ptag, modsource);
auto *r = getModRouting(ptag, modsource);
if (r)
return storage.getPatch().param_ptr[ptag]->get_modulation_f01(r->depth);

return storage.getPatch().param_ptr[ptag]->get_modulation_f01(0);
}

bool SurgeSynthesizer::isModulationMuted(long ptag, modsources modsource)
bool SurgeSynthesizer::isModulationMuted(long ptag, modsources modsource) const
{
if (!isValidModulation(ptag, modsource))
return false;

ModulationRouting *r = getModRouting(ptag, modsource);
auto *r = getModRouting(ptag, modsource);
if (r)
return r->muted;

Expand Down Expand Up @@ -3226,12 +3226,14 @@ void SurgeSynthesizer::processControl()
for (int i = 0; i < n; i++)
{
int src_id = storage.getPatch().scene[s].modulation_scene[i].source_id;
int src_index = storage.getPatch().scene[s].modulation_scene[i].source_index;
if (storage.getPatch().scene[s].modsources[src_id])
{
int dst_id = storage.getPatch().scene[s].modulation_scene[i].destination_id;
float depth = storage.getPatch().scene[s].modulation_scene[i].depth;
storage.getPatch().scenedata[s][dst_id].f +=
depth * storage.getPatch().scene[s].modsources[src_id]->get_output(0) *
depth *
storage.getPatch().scene[s].modsources[src_id]->get_output(src_index) *
(1.0 - storage.getPatch().scene[s].modulation_scene[i].muted);
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/common/SurgeSynthesizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,17 @@ class alignas(16) SurgeSynthesizer

public:
void updateDisplay();
bool isValidModulation(long ptag, modsources modsource);
bool isActiveModulation(long ptag, modsources modsource);
bool isBipolarModulation(modsources modsources);
bool isModsourceUsed(modsources modsource);
bool isModDestUsed(long moddest);
ModulationRouting *getModRouting(long ptag, modsources modsource);
bool isValidModulation(long ptag, modsources modsource) const;
bool isActiveModulation(long ptag, modsources modsource) const;
bool isBipolarModulation(modsources modsources) const;
bool isModsourceUsed(modsources modsource); // FIXME - this should be const
bool isModDestUsed(long moddest) const;
ModulationRouting *getModRouting(long ptag, modsources modsource) const;
bool setModulation(long ptag, modsources modsource, float value);
float getModulation(long ptag, modsources modsource);
float getModulation(long ptag, modsources modsource) const;
void muteModulation(long ptag, modsources modsource, bool mute);
bool isModulationMuted(long ptag, modsources modsource);
float getModDepth(long ptag, modsources modsource);
bool isModulationMuted(long ptag, modsources modsource) const;
float getModDepth(long ptag, modsources modsource) const;
void clearModulation(long ptag, modsources modsource, bool clearEvenIfInvalid = false);
void clear_osc_modulation(
int scene, int entry); // clear the modulation routings on the algorithm-specific sliders
Expand Down
3 changes: 2 additions & 1 deletion src/common/dsp/SurgeVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,8 @@ template <bool first> void SurgeVoice::calc_ctrldata(QuadFilterChainState *Q, in

if (modsources[src_id])
{
localcopy[dst_id].f += depth * modsources[src_id]->get_output(0) * (1.0 - iter->muted);
localcopy[dst_id].f +=
depth * modsources[src_id]->get_output(iter->source_index) * (1.0 - iter->muted);
}
iter++;
}
Expand Down

0 comments on commit 46b69c1

Please sign in to comment.