Skip to content

Commit

Permalink
Modulator Menu and Name Changes
Browse files Browse the repository at this point in the history
1. For indexed modulators, the RMB menu shows
   jst the paths for that modulator.
2. LFO-class modulators can be renamed by index
   and then have short name of "N" and long name
   of "N (FORM 1.2)" or waht not. Closes surge-synthesizer#5391
3. Add a single api to get the name rather than
   having to add index extensions everywhere.
  • Loading branch information
baconpaul committed Nov 14, 2021
1 parent 4009309 commit a543a08
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 43 deletions.
44 changes: 44 additions & 0 deletions src/common/SurgePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,13 @@ void SurgePatch::init_default_values()
{
strxcpy(CustomControllerLabel[i], "-", CUSTOM_CONTROLLER_LABEL_SIZE);
}
for (int i = 0; i < n_lfos; ++i)
{
for (int d = 0; d < max_lfo_indices; ++d)
{
LFOBankLabel[i][d][0] = 0;
}
}
}

SurgePatch::~SurgePatch() { free(patchptr); }
Expand Down Expand Up @@ -2015,6 +2022,28 @@ void SurgePatch::load_xml(const void *data, int datasize, bool is_preset)
p = TINYXML_SAFE_TO_ELEMENT(p->NextSibling("entry"));
}

for (int i = 0; i < n_lfos; ++i)
{
for (int d = 0; d < max_lfo_indices; ++d)
{
LFOBankLabel[i][d][0] = 0;
}
}

TiXmlElement *lflb = TINYXML_SAFE_TO_ELEMENT(patch->FirstChild("lfobanklabels"));
if (lflb)
{
auto lb = TINYXML_SAFE_TO_ELEMENT(lflb->FirstChild("label"));
while (lb)
{
int lfo, idx;
if (lb->QueryIntAttribute("lfo", &lfo) == TIXML_SUCCESS &&
lb->QueryIntAttribute("idx", &idx) == TIXML_SUCCESS)
strxcpy(LFOBankLabel[lfo][idx], lb->Attribute("v"), CUSTOM_CONTROLLER_LABEL_SIZE);
lb = TINYXML_SAFE_TO_ELEMENT(lb->NextSibling("label"));
}
}

patchTuning.tuningStoredInPatch = false;
patchTuning.scaleContents = "";
patchTuning.mappingContents = "";
Expand Down Expand Up @@ -2564,6 +2593,21 @@ unsigned int SurgePatch::save_xml(void **data) // allocates mem, must be freed b
}
patch.InsertEndChild(cc);

TiXmlElement lfobank("lfobanklabels");
for (int i = 0; i < n_lfos; ++i)
for (int d = 0; d < max_lfo_indices; ++d)
{
if (LFOBankLabel[i][d][0] != 0)
{
TiXmlElement L("label");
L.SetAttribute("lfo", i);
L.SetAttribute("idx", d);
L.SetAttribute("v", LFOBankLabel[i][d]);
lfobank.InsertEndChild(L);
}
}
patch.InsertEndChild(lfobank);

{
char txt[TXT_SIZE];
TiXmlElement mw("modwheel");
Expand Down
3 changes: 3 additions & 0 deletions src/common/SurgeStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const int n_oscs = 3;
const int n_lfos_voice = 6;
const int n_lfos_scene = 6;
const int n_lfos = n_lfos_voice + n_lfos_scene;
const int max_lfo_indices = 8;
const int n_osc_params = 7;
const int n_egs = 2;
const int n_fx_params = 12;
Expand Down Expand Up @@ -848,6 +849,8 @@ class SurgePatch
#define CUSTOM_CONTROLLER_LABEL_SIZE 20
char CustomControllerLabel[n_customcontrollers][CUSTOM_CONTROLLER_LABEL_SIZE];

char LFOBankLabel[n_lfos][max_lfo_indices][CUSTOM_CONTROLLER_LABEL_SIZE];

int streamingRevision;
int currentSynthStreamingRevision;

Expand Down
2 changes: 1 addition & 1 deletion src/common/dsp/modulators/FormulaModulationHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Surge
{
namespace Formula
{
static constexpr int max_formula_outputs{8};
static constexpr int max_formula_outputs{max_lfo_indices};

struct EvaluatorState
{
Expand Down
41 changes: 29 additions & 12 deletions src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3872,8 +3872,8 @@ void SurgeGUIEditor::promptForUserValueEntry(Parameter *p, juce::Component *c, i

if (ismod)
{
std::string mls = std::string("by ") + modulatorName(ms, true) +
modulatorIndexExtension(current_scene, ms, modidx);
std::string mls =
std::string("by ") + modulatorNameWithIndex(current_scene, ms, modidx, true, false);
typeinParamEditor->setModByLabel(mls);
}

Expand Down Expand Up @@ -5503,6 +5503,31 @@ std::string SurgeGUIEditor::modulatorIndexExtension(int scene, int ms, int index
return "";
}

std::string SurgeGUIEditor::modulatorNameWithIndex(int scene, int ms, int index, bool forButton,
bool useScene)
{
if (synth->storage.getPatch().LFOBankLabel[ms - ms_lfo1][index][0] == 0)
{
auto base = modulatorName(ms, forButton, useScene ? scene : -1);
if (synth->supportsIndexedModulator(scene, (modsources)ms))
base += modulatorIndexExtension(scene, ms, index, forButton);
return base;
}
else
{
if (forButton)
return synth->storage.getPatch().LFOBankLabel[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[ms - ms_lfo1][index];
res = res + " (" + base + ")";
return res;
}
}

void SurgeGUIEditor::setupAlternates(modsources ms)
{
jassert(gui_modsrc[ms]);
Expand All @@ -5518,21 +5543,13 @@ void SurgeGUIEditor::setupAlternates(modsources ms)

for (auto a : traverse)
{
auto baseLabel = modulatorName(a, true);
auto baseLongName = modulatorName(a, false);

int idxc = 1;
if (synth->supportsIndexedModulator(current_scene, a))
idxc = synth->getMaxModulationIndex(current_scene, a);
for (int q = 0; q < idxc; ++q)
{
auto tl = baseLabel;
auto ll = baseLongName;
if (idxc > 1)
{
tl += modulatorIndexExtension(current_scene, a, q, true);
ll += modulatorIndexExtension(current_scene, a, q, false);
}
auto tl = modulatorNameWithIndex(current_scene, a, q, true, false);
auto ll = modulatorNameWithIndex(current_scene, a, q, false, false);
indexedAlternates.emplace_back(a, q, tl, ll);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/surge-xt/gui/SurgeGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ class SurgeGUIEditor : public Surge::GUI::IComponentTagValue::Listener,
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);

private:
Parameter *typeinEditTarget = nullptr;
Expand Down
4 changes: 1 addition & 3 deletions src/surge-xt/gui/SurgeGUIEditorInfowindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ void SurgeGUIEditor::updateInfowindowContents(int ptag, bool isModulated)
SurgeSynthesizer::ID ptagid;
if (synth->fromSynthSideId(pid, ptagid))
synth->getParameterName(ptagid, txt);
auto mn = modulatorName(modsource, true);
if (synth->supportsIndexedModulator(current_scene, modsource))
mn += modulatorIndexExtension(current_scene, modsource, modsource_index, true);
auto mn = modulatorNameWithIndex(current_scene, modsource, modsource_index, true, false);

sprintf(pname, "%s -> %s", mn.c_str(), txt);
ModulationDisplayInfoWindowStrings mss;
Expand Down
43 changes: 21 additions & 22 deletions src/surge-xt/gui/SurgeGUIEditorValueCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c
if (lurl != "")
lurl = fullyResolvedHelpURL(lurl);
auto hmen = std::make_unique<Surge::Widgets::MenuTitleHelpComponent>(
modulatorName(modsource, false), lurl);
modulatorNameWithIndex(current_scene, modsource, modsource_index, false, false),
lurl);
hmen->setSkin(currentSkin, bitmapStore);
contextMenu.addCustomItem(-1, std::move(hmen));

Expand Down Expand Up @@ -622,6 +623,9 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c

for (auto modidx : indices)
{
if (hasIdx && modidx != modsource_index)
continue;

if (first_destination)
{
contextMenu.addSeparator();
Expand Down Expand Up @@ -846,13 +850,6 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c
}
int sc = limit_range(synth->storage.getPatch().scene_active.val.i, 0, n_scenes - 1);

contextMenu.addSeparator();

contextMenu.addItem(Surge::GUI::toOSCaseForMenu("Modulation List..."), [this]() {
if (!isAnyOverlayPresent(MODULATION_EDITOR))
showOverlay(MODULATION_EDITOR);
});

// for macros only
if (within_range(ms_ctrl1, modsource, ms_ctrl1 + n_customcontrollers - 1))
{
Expand Down Expand Up @@ -936,6 +933,18 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c

if (lfo_id >= 0)
{
auto msi = modsource_index;
contextMenu.addItem(
Surge::GUI::toOSCaseForMenu("Rename Modulator"), [this, lfo_id, msi, cms]() {
auto mecb = [this, lfo_id, msi](const std::string &nv) {
auto cp = synth->storage.getPatch().LFOBankLabel[lfo_id][msi];
strxcpy(cp, nv.c_str(), CUSTOM_CONTROLLER_LABEL_SIZE);
synth->refresh_editor = true;
};
promptForMiniEdit(synth->storage.getPatch().LFOBankLabel[lfo_id][msi],
"Set Modulator Name", "Rename Modulator",
juce::Point<int>(10, 10), mecb);
});
contextMenu.addItem(Surge::GUI::toOSCaseForMenu("Copy Modulator"),
[this, sc, lfo_id]() {
synth->storage.clipboard_copy(cp_lfo, sc, lfo_id);
Expand Down Expand Up @@ -1929,13 +1938,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c
modtxt, synth->getModDepth(ptag, ms, sc, modidx),
synth->isBipolarModulation(ms), Parameter::Menu);

char srctxt[512];

sprintf(
srctxt, "%s%s",
(char *)modulatorName(ms, true, showScene ? sc : -1)
.c_str(),
modulatorIndexExtension(current_scene, ms, modidx).c_str());
std::string srctxt = modulatorNameWithIndex(
current_scene, ms, modidx, true, showScene);

auto comp =
std::make_unique<Surge::Widgets::ModMenuCustomComponent>(
Expand Down Expand Up @@ -2087,8 +2091,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c
auto subm = juce::PopupMenu();
for (int i = 0; i < maxidx; ++i)
{
auto subn = modulatorName(ms, false) +
modulatorIndexExtension(current_scene, ms, i);
auto subn =
modulatorNameWithIndex(current_scene, ms, i, false, false);
subm.addItem(subn, [this, p, bvf, ms, i]() {
this->promptForUserValueEntry(p, bvf, ms, current_scene, i);
});
Expand Down Expand Up @@ -2141,11 +2145,6 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c
}
}

contextMenu.addItem(Surge::GUI::toOSCaseForMenu("Modulation List..."), [this]() {
if (!isAnyOverlayPresent(MODULATION_EDITOR))
showOverlay(MODULATION_EDITOR);
});

contextMenu.addSeparator();
createMIDILearnMenuEntries(contextMenu, false, p->id, control);

Expand Down
8 changes: 3 additions & 5 deletions src/surge-xt/gui/overlays/ModulationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,9 @@ struct ModulationListContents : public juce::Component, public Surge::GUI::SkinC
SurgeSynthesizer::ID ptagid;
if (synth->fromSynthSideId(d.destination_id + d.idBase, ptagid))
synth->getParameterName(ptagid, nm);
std::string sname = editor->ed->modulatorName(d.source_id, false);
if (d.inScene < 0)
sname = editor->ed->modulatorName(d.source_id, false, d.source_scene);
if (d.inScene >= 0)
sname += editor->ed->modulatorIndexExtension(d.inScene, d.source_id, d.source_index);

std::string sname = editor->ed->modulatorNameWithIndex(
d.source_scene, d.source_id, d.source_index, false, d.inScene < 0);

d.sname = sname + sceneMod;
d.pname = nm;
Expand Down

0 comments on commit a543a08

Please sign in to comment.