From 2c7b92b60fa0b23a820cb02a62d68abc088619cb Mon Sep 17 00:00:00 2001 From: Phil Stone Date: Mon, 23 Oct 2023 05:33:54 -0700 Subject: [PATCH] Modulator name api refactor (#7265) Move the modulator name functions and mpe status to better parts of the code base (free functions and storage, respectively) --------- Co-authored-by: Phil Stone Co-authored-by: Paul Walker --- src/common/CMakeLists.txt | 1 + src/common/ModulationSource.cpp | 262 ++++++++++++++++++ src/common/ModulationSource.h | 14 + src/common/SurgeStorage.h | 2 + src/common/SurgeSynthesizer.cpp | 2 +- src/common/SurgeSynthesizer.h | 2 +- src/surge-python/surgepy.cpp | 7 +- src/surge-xt/gui/SurgeGUIEditor.cpp | 249 ++--------------- src/surge-xt/gui/SurgeGUIEditor.h | 5 - .../gui/SurgeGUIEditorHtmlGenerators.cpp | 16 +- src/surge-xt/gui/SurgeGUIEditorInfowindow.cpp | 3 +- .../gui/SurgeGUIEditorValueCallbacks.cpp | 24 +- src/surge-xt/gui/UndoManager.cpp | 7 +- .../gui/overlays/ModulationEditor.cpp | 22 +- .../gui/widgets/ModulationSourceButton.cpp | 8 +- 15 files changed, 362 insertions(+), 262 deletions(-) create mode 100644 src/common/ModulationSource.cpp diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index b1479b2e297..397ba5e50e1 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -105,6 +105,7 @@ add_library(${PROJECT_NAME} FxPresetAndClipboardManager.h LuaSupport.cpp LuaSupport.h + ModulationSource.cpp ModulationSource.h ModulatorPresetManager.cpp ModulatorPresetManager.h diff --git a/src/common/ModulationSource.cpp b/src/common/ModulationSource.cpp new file mode 100644 index 00000000000..6b146a1753e --- /dev/null +++ b/src/common/ModulationSource.cpp @@ -0,0 +1,262 @@ +/* + * Surge XT - a free and open source hybrid synthesizer, + * built by Surge Synth Team + * + * Learn more at https://surge-synthesizer.github.io/ + * + * Copyright 2018-2023, various authors, as described in the GitHub + * transaction log. + * + * Surge XT is released under the GNU General Public Licence v3 + * or later (GPL-3.0-or-later). The license is found in the "LICENSE" + * file in the root of this repository, or at + * https://www.gnu.org/licenses/gpl-3.0.en.html + * + * Surge was a commercial product from 2004-2018, copyright and ownership + * held by Claes Johanson at Vember Audio during that period. + * Claes made Surge open source in September 2018. + * + * All source for Surge XT is available at + * https://github.com/surge-synthesizer/surge + */ + +#include "ModulationSource.h" +#include "SurgeStorage.h" + +class SurgeStorage; + +namespace ModulatorName +{ + +std::string modulatorName(const SurgeStorage *s, int i, bool button, int current_scene, + int forScene) +{ + if ((i >= ms_lfo1 && i <= ms_slfo6)) + { + int idx = i - ms_lfo1; + bool isS = idx >= 6; + int fnum = idx % 6; + auto useScene = forScene >= 0 ? forScene : current_scene; + auto *lfodata = &(s->getPatch().scene[useScene].lfo[i - ms_lfo1]); + + std::string sceneL = "Scene", shortsceneL = "S-"; + + if (forScene >= 0) + { + sceneL = fmt::format("Scene {:c}", 'A' + forScene); + shortsceneL = fmt::format("{:c} S-", 'A' + forScene); + } + + std::string txt; + + if (lfodata->shape.val.i == lt_envelope) + { + if (button) + txt = fmt::format("{:s}ENV {:d}", (isS ? shortsceneL : ""), fnum + 1); + else + txt = fmt::format("{:s} Envelope {:d}", (isS ? sceneL : "Voice"), fnum + 1); + } + else if (lfodata->shape.val.i == lt_stepseq) + { + if (button) + txt = fmt::format("{:s}SEQ {:d}", (isS ? shortsceneL : ""), fnum + 1); + else + txt = fmt::format("{:s} Step Sequencer {:d}", (isS ? sceneL : "Voice"), fnum + 1); + } + else if (lfodata->shape.val.i == lt_mseg) + { + if (button) + txt = fmt::format("{:s}MSEG {:d}", (isS ? shortsceneL : ""), fnum + 1); + else + txt = fmt::format("{:s} MSEG {:d}", (isS ? sceneL : "Voice"), fnum + 1); + } + else if (lfodata->shape.val.i == lt_formula) + { + if (button) + txt = fmt::format("{:s}FORM {:d}", (isS ? shortsceneL : ""), fnum + 1); + else + txt = fmt::format("{:s} Formula {:d}", (isS ? sceneL : "Voice"), fnum + 1); + } + else + { + if (button) + txt = fmt::format("{:s}LFO {:d}", (isS ? shortsceneL : ""), fnum + 1); + else + txt = fmt::format("{:s} LFO {:d}", (isS ? sceneL : "Voice"), fnum + 1); + } + + return txt; + } + + if (i >= ms_ctrl1 && i <= ms_ctrl8) + { + if (button) + { + std::string ccl = std::string(s->getPatch().CustomControllerLabel[i - ms_ctrl1]); + + if (ccl == "-") + { + return std::string(modsource_names[i]); + } + else + { + return ccl; + } + } + else + { + std::string ccl = std::string(s->getPatch().CustomControllerLabel[i - ms_ctrl1]); + + if (ccl == "-") + { + return std::string(modsource_names[i]); + } + else + { + return ccl + " (" + modsource_names[i] + ")"; + } + } + } + + if (i == ms_aftertouch && s->mpeEnabled) + { + return "MPE Pressure"; + } + + if (i == ms_timbre && s->mpeEnabled) + { + return "MPE Timbre"; + } + + if (button) + { + return std::string(modsource_names_button[i]); + } + else + { + return std::string(modsource_names[i]); + } +} + +std::string modulatorIndexExtension(const SurgeStorage *s, int scene, int ms, int index, + bool shortV) +{ + if (ModulatorName::supportsIndexedModulator(scene, (modsources)ms)) + { + if (ms == ms_random_bipolar) + { + if (index == 0) + return shortV ? "" : " (Uniform)"; + if (index == 1) + return shortV ? " N" : " (Normal)"; + } + if (ms == ms_random_unipolar) + { + if (index == 0) + return shortV ? "" : " (Uniform)"; + if (index == 1) + return shortV ? " HN" : " (Half Normal)"; + } + if (ms == ms_lowest_key || ms == ms_latest_key || ms == ms_highest_key) + { + return (index == 0 ? " Key" : " Voice"); + } + + if (ms >= ms_lfo1 && ms <= ms_slfo6) + { + auto lf = &(s->getPatch().scene[scene].lfo[ms - ms_lfo1]); + if (lf->shape.val.i != lt_formula) + { + if (index == 0) + return ""; + if (index == 1) + { + if (shortV) + return " Raw"; + return " (" + Surge::GUI::toOSCase("Raw Waveform") + ")"; + } + if (index == 2) + { + if (shortV) + return " EG"; + return Surge::GUI::toOSCase(" (EG Only)"); + } + } + } + + if (shortV) + return "." + std::to_string(index + 1); + else + return std::string(" Out ") + std::to_string(index + 1); + } + return ""; +} + +std::string modulatorNameWithIndex(const SurgeStorage *s, int scene, int ms, int index, + bool forButton, bool useScene, bool baseNameOnly) +{ + int lfo_id = ms - ms_lfo1; + bool hasOverride = isLFO((modsources)ms) && index >= 0 && + s->getPatch().LFOBankLabel[scene][lfo_id][index][0] != 0; + + if (baseNameOnly) + { + auto base = modulatorName(s, ms, scene, true, useScene ? scene : -1); + + if (ModulatorName::supportsIndexedModulator(scene, (modsources)ms)) + { + base += ModulatorName::modulatorIndexExtension(s, scene, ms, index, true); + } + + return base; + } + + if (!hasOverride) + { + auto base = modulatorName(s, ms, forButton, useScene ? scene : -1); + + if (index >= 0 && ModulatorName::supportsIndexedModulator(scene, (modsources)ms)) + { + base += ModulatorName::modulatorIndexExtension(s, scene, ms, index, forButton); + } + + return base; + } + else + { + if (forButton) + { + return s->getPatch().LFOBankLabel[scene][ms - ms_lfo1][index]; + } + + // Long name is alias (button name) + auto base = modulatorName(s, ms, true, useScene ? scene : -1, scene); + + if (ModulatorName::supportsIndexedModulator(scene, (modsources)ms)) + { + base += ModulatorName::modulatorIndexExtension(s, scene, ms, index, true); + } + + std::string res = s->getPatch().LFOBankLabel[scene][ms - ms_lfo1][index]; + res = res + " (" + base + ")"; + return res; + } +} + +// This is a copy of a trivial function from SurgeSynthesizer +bool supportsIndexedModulator(int scene, modsources modsource) +{ + if (modsource >= ms_lfo1 && modsource <= ms_slfo6) + { + return true; + // auto lf = &(storage.getPatch().scene[scene].lfo[modsource - ms_lfo1]); + // return lf->shape.val.i == lt_formula; + } + + if (modsource == ms_random_bipolar || modsource == ms_random_unipolar) + { + return true; + } + return false; +} +} // namespace ModulatorName \ No newline at end of file diff --git a/src/common/ModulationSource.h b/src/common/ModulationSource.h index a3c4959b659..cfb58e8232b 100644 --- a/src/common/ModulationSource.h +++ b/src/common/ModulationSource.h @@ -236,6 +236,20 @@ inline bool canModulateVoiceModulators(modsources ms) return (ms <= ms_ctrl8) || ms == ms_timbre; } +class SurgeStorage; + +namespace ModulatorName +{ +std::string modulatorName(const SurgeStorage *s, int ms, bool forButton, int current_scene, + int forScene = -1); +std::string modulatorIndexExtension(const SurgeStorage *s, int scene, int ms, int index, + bool shortV = false); +std::string modulatorNameWithIndex(const SurgeStorage *s, int scene, int ms, int index, + bool forButton, bool useScene, bool baseNameOnly = false); +bool supportsIndexedModulator(int scene, modsources modsource); + +} // namespace ModulatorName + struct ModulationRouting { int source_id; diff --git a/src/common/SurgeStorage.h b/src/common/SurgeStorage.h index bcdaede176f..62be1b92e70 100644 --- a/src/common/SurgeStorage.h +++ b/src/common/SurgeStorage.h @@ -1451,6 +1451,8 @@ class alignas(16) SurgeStorage std::atomic mapChannelToOctave; // When other midi modes come along, clean this up. + bool mpeEnabled{false}; + static constexpr double MIDI_0_FREQ = Tunings::MIDI_0_FREQ; // this value needs to be passed along to FilterCoefficientMaker diff --git a/src/common/SurgeSynthesizer.cpp b/src/common/SurgeSynthesizer.cpp index 43197b23fd1..7bcfb0c16bf 100644 --- a/src/common/SurgeSynthesizer.cpp +++ b/src/common/SurgeSynthesizer.cpp @@ -55,7 +55,7 @@ using CMSKey = ControllerModulationSourceVector<1>; // sigh see #4286 for failed SurgeSynthesizer::SurgeSynthesizer(PluginLayer *parent, const std::string &suppliedDataPath) : storage(suppliedDataPath), hpA{cutl::make_array(&storage)}, hpB{cutl::make_array(&storage)}, _parent(parent), halfbandA(6, true), - halfbandB(6, true), halfbandIN(6, true) + halfbandB(6, true), halfbandIN(6, true), mpeEnabled(storage.mpeEnabled) { switch_toggled_queued = false; audio_processing_active = false; diff --git a/src/common/SurgeSynthesizer.h b/src/common/SurgeSynthesizer.h index 831128a38e3..00d2495ef77 100644 --- a/src/common/SurgeSynthesizer.h +++ b/src/common/SurgeSynthesizer.h @@ -467,7 +467,7 @@ class alignas(16) SurgeSynthesizer std::unique_ptr fx[n_fx_slots]; std::atomic halt_engine; MidiChannelState channelState[16]; - bool mpeEnabled = false; + bool &mpeEnabled; int mpeVoices = 0; int mpeGlobalPitchBendRange = 0; diff --git a/src/surge-python/surgepy.cpp b/src/surge-python/surgepy.cpp index b217e79fb33..feaac0eb714 100644 --- a/src/surge-python/surgepy.cpp +++ b/src/surge-python/surgepy.cpp @@ -893,6 +893,10 @@ class SurgeSynthesizerWithPythonExtensions : public SurgeSynthesizer { return storage.tuningApplicationMode; } + + void setMPEEnabled(bool m) { storage.mpeEnabled = m; } + + bool getMPEEnabled() const { return storage.mpeEnabled; } }; SurgeSynthesizer *createSurge(float sr) @@ -1042,7 +1046,8 @@ PYBIND11_MODULE(surgepy, m) .def("remapToStandardKeyboard", &SurgeSynthesizerWithPythonExtensions::remapToStandardKeyboard, "Return to standard C-centered keyboard mapping") - .def_readwrite("mpeEnabled", &SurgeSynthesizerWithPythonExtensions::mpeEnabled) + .def_property("mpeEnabled", &SurgeSynthesizerWithPythonExtensions::getMPEEnabled, + &SurgeSynthesizerWithPythonExtensions::setMPEEnabled) .def_property("tuningApplicationMode", &SurgeSynthesizerWithPythonExtensions::getTuningApplicationMode, &SurgeSynthesizerWithPythonExtensions::setTuningApplicationMode); diff --git a/src/surge-xt/gui/SurgeGUIEditor.cpp b/src/surge-xt/gui/SurgeGUIEditor.cpp index a43f0a02c66..1e94e81a10d 100644 --- a/src/surge-xt/gui/SurgeGUIEditor.cpp +++ b/src/surge-xt/gui/SurgeGUIEditor.cpp @@ -1369,7 +1369,8 @@ void SurgeGUIEditor::refresh_mod() state |= 4; // update the LFO title label - std::string modname = modulatorName(modsource_editor[current_scene], true); + std::string modname = ModulatorName::modulatorName( + &synth->storage, modsource_editor[current_scene], true, current_scene); lfoNameLabel->setText(modname.c_str()); } @@ -5276,7 +5277,9 @@ void SurgeGUIEditor::promptForUserValueEntry(Parameter *p, juce::Component *c, i char pname[1024]; p->create_fullname(p->get_name(), pname, p->ctrlgroup, p->ctrlgroup_entry, - modulatorName(p->ctrlgroup_entry, true).c_str()); + ModulatorName::modulatorName(&synth->storage, p->ctrlgroup_entry, + true, current_scene) + .c_str()); lab = pname; } else @@ -5286,7 +5289,7 @@ void SurgeGUIEditor::promptForUserValueEntry(Parameter *p, juce::Component *c, i } else { - lab = modulatorName(ms, false); + lab = ModulatorName::modulatorName(&synth->storage, ms, false, current_scene); } typeinParamEditor->setMainLabel(lab); @@ -5331,8 +5334,9 @@ void SurgeGUIEditor::promptForUserValueEntry(Parameter *p, juce::Component *c, i if (ismod) { - std::string mls = - std::string("by ") + modulatorNameWithIndex(current_scene, ms, modidx, true, false); + std::string mls = std::string("by ") + + ModulatorName::modulatorNameWithIndex(&synth->storage, current_scene, ms, + modidx, true, false); typeinParamEditor->setModByLabel(mls); } @@ -5360,117 +5364,6 @@ void SurgeGUIEditor::promptForUserValueEntry(Parameter *p, juce::Component *c, i typeinParamEditor->grabFocus(); } -std::string SurgeGUIEditor::modulatorName(int i, bool button, int forScene) -{ - if ((i >= ms_lfo1 && i <= ms_slfo6)) - { - int idx = i - ms_lfo1; - bool isS = idx >= 6; - int fnum = idx % 6; - auto useScene = forScene >= 0 ? forScene : current_scene; - auto *lfodata = &(synth->storage.getPatch().scene[useScene].lfo[i - ms_lfo1]); - - std::string sceneL = "Scene", shortsceneL = "S-"; - - if (forScene >= 0) - { - sceneL = fmt::format("Scene {:c}", 'A' + forScene); - shortsceneL = fmt::format("{:c} S-", 'A' + forScene); - } - - std::string txt; - - if (lfodata->shape.val.i == lt_envelope) - { - if (button) - txt = fmt::format("{:s}ENV {:d}", (isS ? shortsceneL : ""), fnum + 1); - else - txt = fmt::format("{:s} Envelope {:d}", (isS ? sceneL : "Voice"), fnum + 1); - } - else if (lfodata->shape.val.i == lt_stepseq) - { - if (button) - txt = fmt::format("{:s}SEQ {:d}", (isS ? shortsceneL : ""), fnum + 1); - else - txt = fmt::format("{:s} Step Sequencer {:d}", (isS ? sceneL : "Voice"), fnum + 1); - } - else if (lfodata->shape.val.i == lt_mseg) - { - if (button) - txt = fmt::format("{:s}MSEG {:d}", (isS ? shortsceneL : ""), fnum + 1); - else - txt = fmt::format("{:s} MSEG {:d}", (isS ? sceneL : "Voice"), fnum + 1); - } - else if (lfodata->shape.val.i == lt_formula) - { - if (button) - txt = fmt::format("{:s}FORM {:d}", (isS ? shortsceneL : ""), fnum + 1); - else - txt = fmt::format("{:s} Formula {:d}", (isS ? sceneL : "Voice"), fnum + 1); - } - else - { - if (button) - txt = fmt::format("{:s}LFO {:d}", (isS ? shortsceneL : ""), fnum + 1); - else - txt = fmt::format("{:s} LFO {:d}", (isS ? sceneL : "Voice"), fnum + 1); - } - - return txt; - } - - if (i >= ms_ctrl1 && i <= ms_ctrl8) - { - if (button) - { - std::string ccl = - std::string(synth->storage.getPatch().CustomControllerLabel[i - ms_ctrl1]); - - if (ccl == "-") - { - return std::string(modsource_names[i]); - } - else - { - return ccl; - } - } - else - { - std::string ccl = - std::string(synth->storage.getPatch().CustomControllerLabel[i - ms_ctrl1]); - - if (ccl == "-") - { - return std::string(modsource_names[i]); - } - else - { - return ccl + " (" + modsource_names[i] + ")"; - } - } - } - - if (i == ms_aftertouch && synth->mpeEnabled) - { - return "MPE Pressure"; - } - - if (i == ms_timbre && synth->mpeEnabled) - { - return "MPE Timbre"; - } - - if (button) - { - return std::string(modsource_names_button[i]); - } - else - { - return std::string(modsource_names[i]); - } -} - std::string SurgeGUIEditor::helpURLFor(Parameter *p) { auto storage = &(synth->storage); @@ -6014,7 +5907,8 @@ void SurgeGUIEditor::openLFORenameDialog(const int lfo_id, const juce::Pointstorage.getPatch().LFOBankLabel[current_scene][lfo_id][msi], fmt::format("Enter a new name for {:s}:", - modulatorNameWithIndex(current_scene, modsource, msi, false, false, true)), + ModulatorName::modulatorNameWithIndex(&synth->storage, current_scene, modsource, + msi, false, false, true)), "Rename Modulator", juce::Point(10, 10), callback, c); } @@ -7168,7 +7062,8 @@ void SurgeGUIEditor::lfoShapeChanged(int prior, int curr) } // update the LFO title label - std::string modname = modulatorName(modsource_editor[current_scene], true); + std::string modname = ModulatorName::modulatorName( + &synth->storage, modsource_editor[current_scene], true, current_scene); lfoNameLabel->setText(modname.c_str()); lfoNameLabel->repaint(); @@ -7299,110 +7194,6 @@ void SurgeGUIEditor::setAccessibilityInformationByTitleAndAction(juce::Component } } -std::string SurgeGUIEditor::modulatorIndexExtension(int scene, int ms, int index, bool shortV) -{ - if (synth->supportsIndexedModulator(scene, (modsources)ms)) - { - if (ms == ms_random_bipolar) - { - if (index == 0) - return shortV ? "" : " (Uniform)"; - if (index == 1) - return shortV ? " N" : " (Normal)"; - } - if (ms == ms_random_unipolar) - { - if (index == 0) - return shortV ? "" : " (Uniform)"; - if (index == 1) - return shortV ? " HN" : " (Half Normal)"; - } - if (ms == ms_lowest_key || ms == ms_latest_key || ms == ms_highest_key) - { - return (index == 0 ? " Key" : " Voice"); - } - - if (ms >= ms_lfo1 && ms <= ms_slfo6) - { - auto lf = &(synth->storage.getPatch().scene[scene].lfo[ms - ms_lfo1]); - if (lf->shape.val.i != lt_formula) - { - if (index == 0) - return ""; - if (index == 1) - { - if (shortV) - return " Raw"; - return " (" + Surge::GUI::toOSCase("Raw Waveform") + ")"; - } - if (index == 2) - { - if (shortV) - return " EG"; - return Surge::GUI::toOSCase(" (EG Only)"); - } - } - } - - if (shortV) - return "." + std::to_string(index + 1); - else - return std::string(" Out ") + std::to_string(index + 1); - } - return ""; -} - -std::string SurgeGUIEditor::modulatorNameWithIndex(int scene, int ms, int index, bool forButton, - bool useScene, bool baseNameOnly) -{ - int lfo_id = ms - ms_lfo1; - bool hasOverride = isLFO((modsources)ms) && index >= 0 && - synth->storage.getPatch().LFOBankLabel[scene][lfo_id][index][0] != 0; - - if (baseNameOnly) - { - auto base = modulatorName(ms, true, useScene ? scene : -1); - - if (synth->supportsIndexedModulator(scene, (modsources)ms)) - { - base += modulatorIndexExtension(scene, ms, index, true); - } - - return base; - } - - if (!hasOverride) - { - auto base = modulatorName(ms, forButton, useScene ? scene : -1); - - if (index >= 0 && synth->supportsIndexedModulator(scene, (modsources)ms)) - { - base += modulatorIndexExtension(scene, ms, index, forButton); - } - - return base; - } - else - { - if (forButton) - { - return synth->storage.getPatch().LFOBankLabel[scene][ms - ms_lfo1][index]; - } - - // Long name is alias (button name) - auto base = modulatorName(ms, true, useScene ? scene : -1); - - if (synth->supportsIndexedModulator(scene, (modsources)ms)) - { - base += modulatorIndexExtension(scene, ms, index, true); - } - - std::string res = synth->storage.getPatch().LFOBankLabel[scene][ms - ms_lfo1][index]; - res = res + " (" + base + ")"; - return res; - } -} - void SurgeGUIEditor::setupAlternates(modsources ms) { jassert(gui_modsrc[ms]); @@ -7423,8 +7214,10 @@ void SurgeGUIEditor::setupAlternates(modsources ms) idxc = synth->getMaxModulationIndex(current_scene, a); for (int q = 0; q < idxc; ++q) { - auto tl = modulatorNameWithIndex(current_scene, a, q, true, false); - auto ll = modulatorNameWithIndex(current_scene, a, q, false, false); + auto tl = ModulatorName::modulatorNameWithIndex(&synth->storage, current_scene, a, q, + true, false); + auto ll = ModulatorName::modulatorNameWithIndex(&synth->storage, current_scene, a, q, + false, false); indexedAlternates.emplace_back(a, q, tl, ll); } } @@ -8113,9 +7906,11 @@ void SurgeGUIEditor::announceGuiState() oss << "Patch '" << s->getPatch().name << "'. Scene " << (current_scene == 0 ? "A" : "B") << ". " << " Oscillator " << (current_osc[current_scene] + 1) << " " << osc_type_names[ot] << "." - << " Modulator " << modulatorName(modsource_editor[current_scene], false) << " " - << lt_names[ms] << ". " << fxslot_names[current_fx] << " " << fx_type_names[ft] << "." - << std::endl; + << " Modulator " + << ModulatorName::modulatorName(&synth->storage, modsource_editor[current_scene], false, + current_scene) + << " " << lt_names[ms] << ". " << fxslot_names[current_fx] << " " << fx_type_names[ft] + << "." << std::endl; enqueueAccessibleAnnouncement(oss.str()); } diff --git a/src/surge-xt/gui/SurgeGUIEditor.h b/src/surge-xt/gui/SurgeGUIEditor.h index 1553f31b4a8..6d2da84e934 100644 --- a/src/surge-xt/gui/SurgeGUIEditor.h +++ b/src/surge-xt/gui/SurgeGUIEditor.h @@ -755,11 +755,6 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener, std::unique_ptr fxPresetLabel; public: - std::string modulatorName(int ms, bool forButton, int forScene = -1); - std::string modulatorIndexExtension(int scene, int ms, int index, bool shortV = false); - std::string modulatorNameWithIndex(int scene, int ms, int index, bool forButton, bool useScene, - bool baseNameOnly = false); - private: Parameter *typeinEditTarget = nullptr; int typeinModSource = -1; diff --git a/src/surge-xt/gui/SurgeGUIEditorHtmlGenerators.cpp b/src/surge-xt/gui/SurgeGUIEditorHtmlGenerators.cpp index 7ee8be16ff9..53cf5afa774 100644 --- a/src/surge-xt/gui/SurgeGUIEditorHtmlGenerators.cpp +++ b/src/surge-xt/gui/SurgeGUIEditorHtmlGenerators.cpp @@ -1374,8 +1374,10 @@ std::string SurgeGUIEditor::patchToHtml(bool includeDefaults) depth, synth->getModDepth(ptag, thisms, mr.source_scene, mr.source_index), synth->isBipolarModulation(thisms), Parameter::Menu); - globmods << tab4 << "" << modulatorName(mr.source_id, false) << " -> " - << p->get_full_name() << ": " << depth << "
\n"; + globmods << tab4 << "" + << ModulatorName::modulatorName(&synth->storage, mr.source_id, false, + current_scene) + << " -> " << p->get_full_name() << ": " << depth << "
\n"; modsourceSceneActive.emplace(mr.source_id, mr.source_scene); } @@ -1409,8 +1411,10 @@ std::string SurgeGUIEditor::patchToHtml(bool includeDefaults) depth, synth->getModDepth(ptag, thisms, scn, mr.source_index), synth->isBipolarModulation(thisms), Parameter::Menu); - curscenemods << tab4 << "" << modulatorName(thisms, false) << " -> " - << p->get_full_name() << ": " << depth << "
\n"; + curscenemods << tab4 << "" + << ModulatorName::modulatorName(&synth->storage, thisms, false, + current_scene) + << " -> " << p->get_full_name() << ": " << depth << "
\n"; modsourceSceneActive.emplace(thisms, mr.source_scene); } @@ -1639,7 +1643,9 @@ std::string SurgeGUIEditor::patchToHtml(bool includeDefaults) if (modsourceSceneActive.find({ms, scn}) != modsourceSceneActive.end()) { htmls << std::endl - << tab3 << "

" << modulatorName(ms, false) << "

" << std::endl + << tab3 << "

" + << ModulatorName::modulatorName(&synth->storage, ms, false, current_scene) + << "

" << std::endl << tab3 << "

" << std::endl; const auto *p = &(lf.rate); diff --git a/src/surge-xt/gui/SurgeGUIEditorInfowindow.cpp b/src/surge-xt/gui/SurgeGUIEditorInfowindow.cpp index d7625d6bb14..93e8298a4f7 100644 --- a/src/surge-xt/gui/SurgeGUIEditorInfowindow.cpp +++ b/src/surge-xt/gui/SurgeGUIEditorInfowindow.cpp @@ -112,7 +112,8 @@ void SurgeGUIEditor::updateInfowindowContents(int ptag, bool isModulated) { SurgeSynthesizer::ID ptagid; char pdisp[TXT_SIZE], txt[TXT_SIZE]; - auto mn = modulatorNameWithIndex(current_scene, modsource, modsource_index, true, false); + auto mn = ModulatorName::modulatorNameWithIndex(&synth->storage, current_scene, modsource, + modsource_index, true, false); if (synth->fromSynthSideId(pid, ptagid)) { diff --git a/src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp b/src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp index c17618310fa..bdfd3808849 100644 --- a/src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp +++ b/src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp @@ -905,7 +905,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c if (lurl != "") lurl = fullyResolvedHelpURL(lurl); auto hmen = std::make_unique( - modulatorNameWithIndex(current_scene, modsource, modsource_index, false, false), + ModulatorName::modulatorNameWithIndex(&synth->storage, current_scene, modsource, + modsource_index, false, false), lurl); hmen->setSkin(currentSkin, bitmapStore); auto hment = hmen->getTitle(); @@ -984,7 +985,10 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c parameter->create_fullname( parameter->get_name(), pname, parameter->ctrlgroup, parameter->ctrlgroup_entry, - modulatorName(parameter->ctrlgroup_entry, true).c_str()); + ModulatorName::modulatorName(&synth->storage, + parameter->ctrlgroup_entry, true, + current_scene) + .c_str()); targetName = pname; } else @@ -2699,8 +2703,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c modtxt, synth->getModDepth(ptag, ms, sc, modidx), synth->isBipolarModulation(ms), Parameter::Menu); - std::string srctxt = - modulatorNameWithIndex(sc, ms, modidx, true, showScene); + std::string srctxt = ModulatorName::modulatorNameWithIndex( + &synth->storage, sc, ms, modidx, true, showScene); auto comp = std::make_unique( @@ -2841,7 +2845,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c if ((!synth->isAnyActiveModulation(ptag, ms, current_scene) || isIndexed) && synth->isValidModulation(ptag, ms)) { - auto modName = modulatorName(ms, false); + auto modName = ModulatorName::modulatorName(&synth->storage, ms, false, + current_scene); auto *popMenu = &addMIDISub; int modIdx = -1; @@ -2877,8 +2882,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c for (int i = 0; i < maxidx; ++i) { - auto subn = - modulatorNameWithIndex(current_scene, ms, i, false, false); + auto subn = ModulatorName::modulatorNameWithIndex( + &synth->storage, current_scene, ms, i, false, false); subm.addItem(subn, [this, p, bvf, ms, modIdx, i]() { this->promptForUserValueEntry(p, bvf, ms, current_scene, i); @@ -3796,7 +3801,10 @@ void SurgeGUIEditor::valueChanged(Surge::GUI::IComponentTagValue *control) synth->getParameterName(ptagid, txt); } - snprintf(pname, TXT_SIZE - 1, "%s -> %s", modulatorName(thisms, true).c_str(), txt); + snprintf(pname, TXT_SIZE - 1, "%s -> %s", + ModulatorName::modulatorName(&synth->storage, thisms, true, current_scene) + .c_str(), + txt); ModulationDisplayInfoWindowStrings mss; diff --git a/src/surge-xt/gui/UndoManager.cpp b/src/surge-xt/gui/UndoManager.cpp index 9425de28f3f..af04c174fba 100644 --- a/src/surge-xt/gui/UndoManager.cpp +++ b/src/surge-xt/gui/UndoManager.cpp @@ -288,9 +288,10 @@ struct UndoManagerImpl } if (auto pa = std::get_if(&a)) { - return fmt::format("Modulation[id={},source={},scene={},idx={},val={},muted={}]", - pa->paramId, editor->modulatorName(pa->ms, false, pa->scene), - pa->scene, pa->index, pa->val, pa->muted); + return fmt::format( + "Modulation[id={},source={},scene={},idx={},val={},muted={}]", pa->paramId, + ModulatorName::modulatorName(&synth->storage, pa->ms, false, pa->scene), pa->scene, + pa->index, pa->val, pa->muted); } if (auto pa = std::get_if(&a)) { diff --git a/src/surge-xt/gui/overlays/ModulationEditor.cpp b/src/surge-xt/gui/overlays/ModulationEditor.cpp index 031a92aa134..d8397cc7d4a 100644 --- a/src/surge-xt/gui/overlays/ModulationEditor.cpp +++ b/src/surge-xt/gui/overlays/ModulationEditor.cpp @@ -894,7 +894,9 @@ struct ModulationListContents : public juce::Component, public Surge::GUI::SkinC { std::string pfx = p->scene == 1 ? "A " : "B "; p->create_fullname(p->get_name(), nm, p->ctrlgroup, p->ctrlgroup_entry, - (pfx + editor->ed->modulatorName(p->ctrlgroup_entry, true)).c_str()); + (pfx + ModulatorName::modulatorName( + &synth->storage, p->ctrlgroup_entry, true, p->scene)) + .c_str()); } else { @@ -904,8 +906,8 @@ struct ModulationListContents : public juce::Component, public Surge::GUI::SkinC d.pscene = p->scene; d.pControlGroup = p->ctrlgroup; - std::string sname = editor->ed->modulatorNameWithIndex( - d.source_scene, d.source_id, d.source_index, false, d.inScene < 0); + std::string sname = ModulatorName::modulatorNameWithIndex( + &synth->storage, d.source_scene, d.source_id, d.source_index, false, d.inScene < 0); d.sname = sname + sceneMod; d.pname = nm; @@ -1391,7 +1393,8 @@ void ModulationSideControls::showAddSourceMenu() for (int i = 0; i < maxidx; ++i) { - auto subn = sge->modulatorNameWithIndex(sc, ms, i, false, false); + auto subn = ModulatorName::modulatorNameWithIndex(&synth->storage, sc, ms, + i, false, false); subm.addItem(subn, [this, ms, i, sc, subn]() { add_ms = ms; @@ -1405,12 +1408,14 @@ void ModulationSideControls::showAddSourceMenu() }); } - popMenu->addSubMenu( - sge->modulatorNameWithIndex(sc, ms, -1, false, false, false), subm); + popMenu->addSubMenu(ModulatorName::modulatorNameWithIndex( + &synth->storage, sc, ms, -1, false, false, false), + subm); } else { - auto sn = sge->modulatorNameWithIndex(sc, ms, 0, false, false); + auto sn = ModulatorName::modulatorNameWithIndex(&synth->storage, sc, ms, 0, + false, false); popMenu->addItem(sn, [this, sn, sc, ms]() { add_ms = ms; @@ -1557,7 +1562,8 @@ void ModulationSideControls::showAddTargetMenu() break; case 1000: case 1001: - return editor->ed->modulatorName(cge, false); + return ModulatorName::modulatorName(editor->ed->getStorage(), cge, false, + editor->ed->current_scene); break; default: return std::string("CGE=") + std::to_string(cge); diff --git a/src/surge-xt/gui/widgets/ModulationSourceButton.cpp b/src/surge-xt/gui/widgets/ModulationSourceButton.cpp index 7a37333a779..78993a9f9a6 100644 --- a/src/surge-xt/gui/widgets/ModulationSourceButton.cpp +++ b/src/surge-xt/gui/widgets/ModulationSourceButton.cpp @@ -383,11 +383,15 @@ void ModulationSourceButton::buildHamburgerMenu(juce::PopupMenu &menu, if (hu != "") { auto lurl = sge->fullyResolvedHelpURL(hu); - sge->addHelpHeaderTo(sge->modulatorName(modsource, false), lurl, menu); + sge->addHelpHeaderTo( + ModulatorName::modulatorName(storage, modsource, false, sge->current_scene), lurl, + menu); } else { - menu.addItem(sge->modulatorName(modsource, false), []() {}); + menu.addItem( + ModulatorName::modulatorName(storage, modsource, false, sge->current_scene), + []() {}); } menu.addSeparator();