diff --git a/src/common/ModulationSource.h b/src/common/ModulationSource.h index 6e37f094447..1b312e10cc6 100644 --- a/src/common/ModulationSource.h +++ b/src/common/ModulationSource.h @@ -262,6 +262,7 @@ struct ModulationRouting int destination_id; float depth; bool muted = false; + int source_index{0}; }; class ModulationSource diff --git a/src/common/SurgePatch.cpp b/src/common/SurgePatch.cpp index c93a6a1b706..6393811a7b6 100644 --- a/src/common/SurgePatch.cpp +++ b/src/common/SurgePatch.cpp @@ -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 @@ -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); } } diff --git a/src/common/SurgeStorage.cpp b/src/common/SurgeStorage.cpp index 106b55375d1..bb1af0d04a4 100644 --- a/src/common/SurgeStorage.cpp +++ b/src/common/SurgeStorage.cpp @@ -727,7 +727,7 @@ void SurgeStorage::initializePatchDb() } } -SurgePatch &SurgeStorage::getPatch() { return *_patch.get(); } +SurgePatch &SurgeStorage::getPatch() const { return *_patch.get(); } struct PEComparer { @@ -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; @@ -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; @@ -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; @@ -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; @@ -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); @@ -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); diff --git a/src/common/SurgeStorage.h b/src/common/SurgeStorage.h index 37165af1f8a..7cb5cb85054 100644 --- a/src/common/SurgeStorage.h +++ b/src/common/SurgeStorage.h @@ -949,7 +949,8 @@ class alignas(16) SurgeStorage std::unique_ptr _patch; - SurgePatch &getPatch(); + // SurgePatch &getPatch(); + SurgePatch &getPatch() const; float pitch_bend; diff --git a/src/common/SurgeSynthesizer.cpp b/src/common/SurgeSynthesizer.cpp index db3a7fb2cca..089beb3481c 100644 --- a/src/common/SurgeSynthesizer.cpp +++ b/src/common/SurgeSynthesizer.cpp @@ -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; @@ -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; @@ -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; @@ -2483,7 +2483,7 @@ 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)) @@ -2491,7 +2491,7 @@ bool SurgeSynthesizer::isActiveModulation(long ptag, modsources modsource) return false; } -bool SurgeSynthesizer::isBipolarModulation(modsources tms) +bool SurgeSynthesizer::isBipolarModulation(modsources tms) const { int scene_ms = storage.getPatch().scene_active.val.i; @@ -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; @@ -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 *modlist; + const vector *modlist{nullptr}; switch (j) { @@ -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; @@ -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); } } diff --git a/src/common/SurgeSynthesizer.h b/src/common/SurgeSynthesizer.h index 1a1db1e7f93..534301c93c5 100644 --- a/src/common/SurgeSynthesizer.h +++ b/src/common/SurgeSynthesizer.h @@ -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 diff --git a/src/common/dsp/SurgeVoice.cpp b/src/common/dsp/SurgeVoice.cpp index b216e6b5923..06bb0fdc484 100644 --- a/src/common/dsp/SurgeVoice.cpp +++ b/src/common/dsp/SurgeVoice.cpp @@ -583,7 +583,8 @@ template 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++; }