From af6fbd09adaf1c83e3755b889e5ef8e1cf19f5ea Mon Sep 17 00:00:00 2001 From: Mario Kruselj Date: Thu, 2 Sep 2021 18:20:04 +0200 Subject: [PATCH 1/4] Fix incorrect mod index name in slider RMB menu Also don't show "Switch to..." options if modlist size is 1 --- src/gui/SurgeGUIEditorValueCallbacks.cpp | 52 ++++++++++++---------- src/gui/widgets/ModulationSourceButton.cpp | 33 +++++++------- 2 files changed, 46 insertions(+), 39 deletions(-) diff --git a/src/gui/SurgeGUIEditorValueCallbacks.cpp b/src/gui/SurgeGUIEditorValueCallbacks.cpp index 0772b3e1b5c..23425ab4474 100644 --- a/src/gui/SurgeGUIEditorValueCallbacks.cpp +++ b/src/gui/SurgeGUIEditorValueCallbacks.cpp @@ -356,8 +356,6 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c cms->buildHamburgerMenu(contextMenu, true); - contextMenu.addSeparator(); - int n_total_md = synth->storage.getPatch().param_ptr.size(); const int max_md = 4096; @@ -390,24 +388,25 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c if (((md < n_global_params) || ((parameter->scene - 1) == activeScene)) && synth->isAnyActiveModulation(md, thisms, use_scene)) { - char modtxt[TXT_SIZE]; - auto pmd = synth->storage.getPatch().param_ptr[md]; auto indices = synth->getModulationIndicesBetween(md, thisms, use_scene); auto hasIdx = synth->supportsIndexedModulator(use_scene, thisms); + char modtxt[TXT_SIZE]; + for (auto modidx : indices) { - pmd->get_display_of_modulation_depth( + parameter->get_display_of_modulation_depth( modtxt, synth->getModDepth(md, thisms, use_scene, modidx), synth->isBipolarModulation(thisms), Parameter::Menu); - char tmptxt[1024]; // leave room for that ubuntu 20.0 error + char tmptxt[TXT_SIZE * 2]; // leave room for that ubuntu 20.0 error - if (pmd->ctrlgroup == cg_LFO) + if (parameter->ctrlgroup == cg_LFO) { char pname[TXT_SIZE]; - pmd->create_fullname( - pmd->get_name(), pname, pmd->ctrlgroup, pmd->ctrlgroup_entry, - modulatorName(pmd->ctrlgroup_entry, true).c_str()); + parameter->create_fullname( + parameter->get_name(), pname, parameter->ctrlgroup, + parameter->ctrlgroup_entry, + modulatorName(parameter->ctrlgroup_entry, true).c_str()); snprintf(tmptxt, TXT_SIZE, "Edit %s%s -> %s: %s", (char *)modulatorName(thisms, true).c_str(), modulatorIndexExtension(use_scene, thisms, modidx).c_str(), @@ -418,7 +417,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c snprintf(tmptxt, TXT_SIZE, "Edit %s%s -> %s: %s", (char *)modulatorName(thisms, true).c_str(), modulatorIndexExtension(use_scene, thisms, modidx).c_str(), - pmd->get_full_name(), modtxt); + parameter->get_full_name(), modtxt); } auto clearOp = [this, parameter, use_scene, bvf, thisms, modidx]() { @@ -450,11 +449,12 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c if (((md < n_global_params) || ((parameter->scene - 1) == activeScene)) && synth->isAnyActiveModulation(md, thisms, use_scene)) { - auto pmd = synth->storage.getPatch().param_ptr[md]; auto indices = synth->getModulationIndicesBetween(md, thisms, use_scene); + auto hasIdx = synth->supportsIndexedModulator(use_scene, thisms); + for (auto modidx : indices) { - char tmptxt[1024]; + char tmptxt[TXT_SIZE * 2]; if (parameter->ctrlgroup == cg_LFO) { @@ -1889,31 +1889,36 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c modsources ms = (modsources)k; int startScene = current_scene, endScene = current_scene + 1; bool showScene = false; + if (p->scene == 0) { startScene = 0; endScene = n_scenes; showScene = true; } + for (int sc = startScene; sc < endScene; ++sc) { auto indices = synth->getModulationIndicesBetween(ptag, ms, sc); + for (auto modidx : indices) { if (synth->isActiveModulation(ptag, ms, sc, modidx)) { - char modtxt[256]; + char modtxt[TXT_SIZE * 2]; + p->get_display_of_modulation_depth( modtxt, synth->getModDepth(ptag, ms, sc, modidx), synth->isBipolarModulation(ms), Parameter::Menu); - char tmptxt[512]; - sprintf(tmptxt, "Edit %s%s -> %s: %s", - (char *)modulatorName(ms, true, showScene ? sc : -1) - .c_str(), - modulatorIndexExtension(current_scene, ms, sc, modidx) - .c_str(), - p->get_full_name(), modtxt); + char tmptxt[TXT_SIZE]; + + sprintf( + tmptxt, "Edit %s%s -> %s: %s", + (char *)modulatorName(ms, true, showScene ? sc : -1) + .c_str(), + modulatorIndexExtension(current_scene, ms, modidx).c_str(), + p->get_full_name(), modtxt); contextMenu.addItem(tmptxt, [this, p, sc, bvf, ms, modidx]() { this->promptForUserValueEntry(p, bvf, ms, sc, modidx); @@ -1943,9 +1948,10 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c { if (synth->isActiveModulation(ptag, ms, sc, modidx)) { - char tmptxt[256]; + char tmptxt[TXT_SIZE * 2]; + snprintf( - tmptxt, 256, "Clear %s%s -> %s", + tmptxt, TXT_SIZE, "Clear %s%s -> %s", (char *)modulatorName(ms, true, showScene ? sc : -1) .c_str(), modulatorIndexExtension(current_scene, ms, modidx).c_str(), diff --git a/src/gui/widgets/ModulationSourceButton.cpp b/src/gui/widgets/ModulationSourceButton.cpp index 525c2f03782..9c1f94ef229 100644 --- a/src/gui/widgets/ModulationSourceButton.cpp +++ b/src/gui/widgets/ModulationSourceButton.cpp @@ -285,25 +285,26 @@ void ModulationSourceButton::buildHamburgerMenu(juce::PopupMenu &menu, menu.addSeparator(); } - - for (auto e : modlist) + else { - auto modName = std::get<3>(e); - - if (addedToModbuttonContextMenu) + if (modlist.size() > 1) { - modName = "Switch to " + modName; + for (auto e : modlist) + { + auto modName = std::get<3>(e); + modName = "Switch to " + modName; + + menu.addItem(modName, [this, idx]() { + this->modlistIndex = idx; + mouseMode = HAMBURGER; + notifyValueChanged(); + mouseMode = NONE; + repaint(); + }); + + idx++; + } } - - menu.addItem(modName, [this, idx]() { - this->modlistIndex = idx; - mouseMode = HAMBURGER; - notifyValueChanged(); - mouseMode = NONE; - repaint(); - }); - - idx++; } } From 78bdfac8cc0d28d16f3414c3367283d8177a2526 Mon Sep 17 00:00:00 2001 From: Mario Kruselj Date: Thu, 2 Sep 2021 18:47:42 +0200 Subject: [PATCH 2/4] Fix txt array sizes Also add TXT_SIZE to some that still used magic numbers --- src/gui/SurgeGUIEditorValueCallbacks.cpp | 35 +++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/gui/SurgeGUIEditorValueCallbacks.cpp b/src/gui/SurgeGUIEditorValueCallbacks.cpp index 23425ab4474..b307884990f 100644 --- a/src/gui/SurgeGUIEditorValueCallbacks.cpp +++ b/src/gui/SurgeGUIEditorValueCallbacks.cpp @@ -398,7 +398,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c parameter->get_display_of_modulation_depth( modtxt, synth->getModDepth(md, thisms, use_scene, modidx), synth->isBipolarModulation(thisms), Parameter::Menu); - char tmptxt[TXT_SIZE * 2]; // leave room for that ubuntu 20.0 error + char tmptxt[TXT_SIZE * 4]; // leave room for that ubuntu 20.0 error if (parameter->ctrlgroup == cg_LFO) { @@ -454,7 +454,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c for (auto modidx : indices) { - char tmptxt[TXT_SIZE * 2]; + char tmptxt[TXT_SIZE * 4]; if (parameter->ctrlgroup == cg_LFO) { @@ -624,8 +624,9 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c .modsources[modsource]); contextMenu.addSeparator(); - char vtxt[1024]; - snprintf(vtxt, 1024, "%s: %.*f %%", + + char vtxt[TXT_SIZE * 4]; + snprintf(vtxt, TXT_SIZE * 4, "%s: %.*f %%", Surge::GUI::toOSCaseForMenu("Edit Value").c_str(), (detailedMode ? 6 : 2), 100 * cms->get_output(0)); contextMenu.addItem(vtxt, [this, bvf, modsource]() { @@ -871,7 +872,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c contextMenu.addSeparator(); - char txt[TXT_SIZE], txt2[512]; + char txt[TXT_SIZE], txt2[TXT_SIZE * 2]; + p->get_display(txt); snprintf(txt2, 512, "%s: %s", Surge::GUI::toOSCaseForMenu("Edit Value").c_str(), txt); @@ -1139,8 +1141,9 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c { for (int i = p->val_min.i; i <= max; i += incr) { - char txt[256]; + char txt[TXT_SIZE]; float ef = (1.0f * i - p->val_min.i) / (p->val_max.i - p->val_min.i); + p->get_display(txt, true, ef); std::string displaytxt = txt; @@ -1561,17 +1564,17 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c // FIXME : What's a better aprpoach? if (p->ctrltype == ct_fmratio) { - char txt[256], ntxt[256]; - memset(txt, 0, 256); - strxcpy(txt, p->get_name(), 256); + char txt[TXT_SIZE], ntxt[TXT_SIZE]; + memset(txt, 0, TXT_SIZE); + strxcpy(txt, p->get_name(), TXT_SIZE); if (p->absolute) { - snprintf(ntxt, 256, "M%c Frequency", txt[1]); + snprintf(ntxt, TXT_SIZE, "M%c Frequency", txt[1]); } else { - snprintf(ntxt, 256, "M%c Ratio", + snprintf(ntxt, TXT_SIZE, "M%c Ratio", txt[1]); // Ladies and gentlemen, MC Ratio! } @@ -1786,7 +1789,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c if ((!synth->isAnyActiveModulation(ptag, ms, current_scene) || isIndexed) && synth->isValidModulation(ptag, ms)) { - char tmptxt[512]; + char tmptxt[TXT_SIZE * 2]; sprintf(tmptxt, "%s", modulatorName(ms, false).c_str()); auto *popMenu = &addMIDISub; @@ -1905,13 +1908,13 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c { if (synth->isActiveModulation(ptag, ms, sc, modidx)) { - char modtxt[TXT_SIZE * 2]; + char modtxt[TXT_SIZE]; p->get_display_of_modulation_depth( modtxt, synth->getModDepth(ptag, ms, sc, modidx), synth->isBipolarModulation(ms), Parameter::Menu); - char tmptxt[TXT_SIZE]; + char tmptxt[TXT_SIZE * 4]; sprintf( tmptxt, "Edit %s%s -> %s: %s", @@ -1948,7 +1951,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c { if (synth->isActiveModulation(ptag, ms, sc, modidx)) { - char tmptxt[TXT_SIZE * 2]; + char tmptxt[TXT_SIZE * 4]; snprintf( tmptxt, TXT_SIZE, "Clear %s%s -> %s", @@ -2623,7 +2626,7 @@ void SurgeGUIEditor::valueChanged(Surge::GUI::IComponentTagValue *control) if (p->is_nonlocal_on_change()) frame->repaint(); - char pname[256], pdisp[128], txt[128]; + char pname[TXT_SIZE], pdisp[TXT_SIZE], txt[TXT_SIZE]; bool modulate = false; // This allows us to turn on and off the editor. FIXME mseg check it From 4f5e65bfa7e4ad923293e73ec62db8a277d53483 Mon Sep 17 00:00:00 2001 From: Mario Kruselj Date: Thu, 2 Sep 2021 19:30:09 +0200 Subject: [PATCH 3/4] More gcc char array sizings --- src/gui/SurgeGUIEditorValueCallbacks.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/SurgeGUIEditorValueCallbacks.cpp b/src/gui/SurgeGUIEditorValueCallbacks.cpp index b307884990f..e25a6da62eb 100644 --- a/src/gui/SurgeGUIEditorValueCallbacks.cpp +++ b/src/gui/SurgeGUIEditorValueCallbacks.cpp @@ -2626,7 +2626,7 @@ void SurgeGUIEditor::valueChanged(Surge::GUI::IComponentTagValue *control) if (p->is_nonlocal_on_change()) frame->repaint(); - char pname[TXT_SIZE], pdisp[TXT_SIZE], txt[TXT_SIZE]; + char pname[TXT_SIZE * 4], pdisp[TXT_SIZE * 4], txt[TXT_SIZE * 4]; bool modulate = false; // This allows us to turn on and off the editor. FIXME mseg check it @@ -2759,7 +2759,7 @@ void SurgeGUIEditor::valueChanged(Surge::GUI::IComponentTagValue *control) bvf->repaint(); synth->getParameterName(ptagid, pname); synth->getParameterDisplay(ptagid, pdisp); - char pdispalt[256]; + char pdispalt[TXT_SIZE * 4]; synth->getParameterDisplayAlt(ptagid, pdispalt); if (p->ctrltype == ct_polymode) modulate = true; From d1e2a4499dfa2cb7d747a668398d6438d21dfa77 Mon Sep 17 00:00:00 2001 From: Mario Kruselj Date: Thu, 2 Sep 2021 19:54:19 +0200 Subject: [PATCH 4/4] Argh --- src/gui/SurgeGUIEditorValueCallbacks.cpp | 37 +++++++++++------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/gui/SurgeGUIEditorValueCallbacks.cpp b/src/gui/SurgeGUIEditorValueCallbacks.cpp index e25a6da62eb..8ba04ae48f5 100644 --- a/src/gui/SurgeGUIEditorValueCallbacks.cpp +++ b/src/gui/SurgeGUIEditorValueCallbacks.cpp @@ -398,7 +398,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c parameter->get_display_of_modulation_depth( modtxt, synth->getModDepth(md, thisms, use_scene, modidx), synth->isBipolarModulation(thisms), Parameter::Menu); - char tmptxt[TXT_SIZE * 4]; // leave room for that ubuntu 20.0 error + char tmptxt[1024]; // leave room for that ubuntu 20.0 error if (parameter->ctrlgroup == cg_LFO) { @@ -454,7 +454,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c for (auto modidx : indices) { - char tmptxt[TXT_SIZE * 4]; + char tmptxt[TXT_SIZE * 2]; if (parameter->ctrlgroup == cg_LFO) { @@ -624,9 +624,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c .modsources[modsource]); contextMenu.addSeparator(); - - char vtxt[TXT_SIZE * 4]; - snprintf(vtxt, TXT_SIZE * 4, "%s: %.*f %%", + char vtxt[1024]; + snprintf(vtxt, 1024, "%s: %.*f %%", Surge::GUI::toOSCaseForMenu("Edit Value").c_str(), (detailedMode ? 6 : 2), 100 * cms->get_output(0)); contextMenu.addItem(vtxt, [this, bvf, modsource]() { @@ -872,8 +871,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c contextMenu.addSeparator(); - char txt[TXT_SIZE], txt2[TXT_SIZE * 2]; - + char txt[TXT_SIZE], txt2[512]; p->get_display(txt); snprintf(txt2, 512, "%s: %s", Surge::GUI::toOSCaseForMenu("Edit Value").c_str(), txt); @@ -1141,9 +1139,8 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c { for (int i = p->val_min.i; i <= max; i += incr) { - char txt[TXT_SIZE]; + char txt[256]; float ef = (1.0f * i - p->val_min.i) / (p->val_max.i - p->val_min.i); - p->get_display(txt, true, ef); std::string displaytxt = txt; @@ -1564,17 +1561,17 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c // FIXME : What's a better aprpoach? if (p->ctrltype == ct_fmratio) { - char txt[TXT_SIZE], ntxt[TXT_SIZE]; - memset(txt, 0, TXT_SIZE); - strxcpy(txt, p->get_name(), TXT_SIZE); + char txt[256], ntxt[256]; + memset(txt, 0, 256); + strxcpy(txt, p->get_name(), 256); if (p->absolute) { - snprintf(ntxt, TXT_SIZE, "M%c Frequency", txt[1]); + snprintf(ntxt, 256, "M%c Frequency", txt[1]); } else { - snprintf(ntxt, TXT_SIZE, "M%c Ratio", + snprintf(ntxt, 256, "M%c Ratio", txt[1]); // Ladies and gentlemen, MC Ratio! } @@ -1789,7 +1786,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c if ((!synth->isAnyActiveModulation(ptag, ms, current_scene) || isIndexed) && synth->isValidModulation(ptag, ms)) { - char tmptxt[TXT_SIZE * 2]; + char tmptxt[512]; sprintf(tmptxt, "%s", modulatorName(ms, false).c_str()); auto *popMenu = &addMIDISub; @@ -1908,13 +1905,13 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c { if (synth->isActiveModulation(ptag, ms, sc, modidx)) { - char modtxt[TXT_SIZE]; + char modtxt[256]; p->get_display_of_modulation_depth( modtxt, synth->getModDepth(ptag, ms, sc, modidx), synth->isBipolarModulation(ms), Parameter::Menu); - char tmptxt[TXT_SIZE * 4]; + char tmptxt[512]; sprintf( tmptxt, "Edit %s%s -> %s: %s", @@ -1951,7 +1948,7 @@ int32_t SurgeGUIEditor::controlModifierClicked(Surge::GUI::IComponentTagValue *c { if (synth->isActiveModulation(ptag, ms, sc, modidx)) { - char tmptxt[TXT_SIZE * 4]; + char tmptxt[TXT_SIZE]; snprintf( tmptxt, TXT_SIZE, "Clear %s%s -> %s", @@ -2626,7 +2623,7 @@ void SurgeGUIEditor::valueChanged(Surge::GUI::IComponentTagValue *control) if (p->is_nonlocal_on_change()) frame->repaint(); - char pname[TXT_SIZE * 4], pdisp[TXT_SIZE * 4], txt[TXT_SIZE * 4]; + char pname[256], pdisp[128], txt[128]; bool modulate = false; // This allows us to turn on and off the editor. FIXME mseg check it @@ -2759,7 +2756,7 @@ void SurgeGUIEditor::valueChanged(Surge::GUI::IComponentTagValue *control) bvf->repaint(); synth->getParameterName(ptagid, pname); synth->getParameterDisplay(ptagid, pdisp); - char pdispalt[TXT_SIZE * 4]; + char pdispalt[256]; synth->getParameterDisplayAlt(ptagid, pdispalt); if (p->ctrltype == ct_polymode) modulate = true;