From 6e6baf1ea58b0ad024b3c4684cc2d98658678750 Mon Sep 17 00:00:00 2001 From: Mario Kruselj Date: Mon, 24 May 2021 11:04:22 +0200 Subject: [PATCH 1/3] Redo LFO presets menu in JUCE --- src/gui/SurgeGUIEditor.cpp | 78 +++++++++++++++++++------------------- src/gui/SurgeGUIEditor.h | 2 +- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/gui/SurgeGUIEditor.cpp b/src/gui/SurgeGUIEditor.cpp index 03f2f6bd2d3..9e066e42e7f 100644 --- a/src/gui/SurgeGUIEditor.cpp +++ b/src/gui/SurgeGUIEditor.cpp @@ -5123,10 +5123,7 @@ void SurgeGUIEditor::showLfoMenu(VSTGUI::CPoint &where) menuRect.offset(where.x, where.y); auto m = makeLfoMenu(menuRect); - frame->addView(m); - m->invalid(); - m->popup(); - frame->removeView(m, true); + m.showMenuAsync(juce::PopupMenu::Options()); } void SurgeGUIEditor::toggleTuning() @@ -5327,7 +5324,7 @@ void SurgeGUIEditor::showSettingsMenu(CRect &menuRect) settingsMenu.showMenuAsync(juce::PopupMenu::Options()); } -VSTGUI::COptionMenu *SurgeGUIEditor::makeLfoMenu(VSTGUI::CRect &menuRect) +juce::PopupMenu SurgeGUIEditor::makeLfoMenu(VSTGUI::CRect &menuRect) { int currentLfoId = modsource_editor[current_scene] - ms_lfo1; @@ -5345,37 +5342,37 @@ VSTGUI::COptionMenu *SurgeGUIEditor::makeLfoMenu(VSTGUI::CRect &menuRect) auto msurl = SurgeGUIEditor::helpURLForSpecial("lfo-presets"); auto hurl = SurgeGUIEditor::fullyResolvedHelpURL(msurl); - COptionMenu *lfoSubMenu = - new COptionMenu(menuRect, 0, 0, 0, 0, VSTGUI::COptionMenu::kNoDrawStyle); - addCallbackMenu(lfoSubMenu, "[?] LFO Presets", - [hurl]() { juce::URL(hurl).launchInDefaultBrowser(); }), - - lfoSubMenu->addSeparator(); - - addCallbackMenu(lfoSubMenu, Surge::GUI::toOSCaseForMenu("Save " + what + " As..."), - [this, currentLfoId, what]() { - // Prompt for a name - promptForMiniEdit("preset", "Enter the name for " + what + " preset:", - what + " Preset Name", CPoint(-1, -1), - [this, currentLfoId](const std::string &s) { - Surge::ModulatorPreset::savePresetToUser( - string_to_path(s), &(this->synth->storage), - current_scene, currentLfoId); - }); - // and save - }); + auto lfoSubMenu = juce::PopupMenu(); + + lfoSubMenu.addItem("[?] LFO Presets", [hurl]() { juce::URL(hurl).launchInDefaultBrowser(); }), + + lfoSubMenu.addSeparator(); + + lfoSubMenu.addItem(Surge::GUI::toOSCaseForMenu("Save " + what + " As..."), [this, currentLfoId, + what]() { + // Prompt for a name + promptForMiniEdit( + "preset", "Enter the name for " + what + " preset:", what + " Preset Name", + CPoint(-1, -1), [this, currentLfoId](const std::string &s) { + Surge::ModulatorPreset::savePresetToUser(string_to_path(s), &(this->synth->storage), + current_scene, currentLfoId); + }); + // and save + }); auto presetCategories = Surge::ModulatorPreset::getPresets(&(synth->storage)); if (!presetCategories.empty()) - lfoSubMenu->addSeparator(); + { + lfoSubMenu.addSeparator(); + } - std::unordered_map> subMenuMaps; + std::unordered_map> subMenuMaps; subMenuMaps[""] = std::make_pair(lfoSubMenu, true); + for (auto const &cat : presetCategories) { - COptionMenu *catSubMenu = - new COptionMenu(menuRect, 0, 0, 0, 0, VSTGUI::COptionMenu::kNoDrawStyle); + auto catSubMenu = juce::PopupMenu(); subMenuMaps[cat.path] = std::make_pair(catSubMenu, false); } @@ -5389,16 +5386,16 @@ VSTGUI::COptionMenu *SurgeGUIEditor::makeLfoMenu(VSTGUI::CRect &menuRect) auto catSubMenu = subMenuMaps[cat.path].first; - if (catSubMenu->getNbEntries() > 0 && cat.presets.size() > 0) + if (catSubMenu.getNumItems() > 0 && cat.presets.size() > 0) { - catSubMenu->addSeparator(); + catSubMenu.addSeparator(); } for (auto const &p : cat.presets) { auto pname = p.name; - addCallbackMenu(catSubMenu, pname, [this, p, currentLfoId]() { + catSubMenu.addItem(pname, [this, p, currentLfoId]() { Surge::ModulatorPreset::loadPresetFrom(p.path, &(this->synth->storage), current_scene, currentLfoId); @@ -5410,8 +5407,11 @@ VSTGUI::COptionMenu *SurgeGUIEditor::makeLfoMenu(VSTGUI::CRect &menuRect) if (isAnyOverlayPresent(MSEG_EDITOR)) { closeMSEGEditor(); + if (newshape == lt_mseg) + { showMSEGEditor(); + } } this->synth->refresh_editor = true; @@ -5432,28 +5432,28 @@ VSTGUI::COptionMenu *SurgeGUIEditor::makeLfoMenu(VSTGUI::CRect &menuRect) // should never happen continue; } - auto catSubMenu = subMenuMaps[cat.path].first; + auto catSubMenu = subMenuMaps[cat.path].first; auto parentMenu = lfoSubMenu; + if (subMenuMaps.find(cat.parentPath) != subMenuMaps.end()) { parentMenu = subMenuMaps[cat.parentPath].first; + if (!subMenuMaps[cat.parentPath].second) { subMenuMaps[cat.parentPath].second = true; } } - auto catname = cat.name; - - parentMenu->addEntry(catSubMenu, catname.c_str()); - catSubMenu->forget(); + parentMenu.addSubMenu(cat.name, catSubMenu); } - lfoSubMenu->addSeparator(); + lfoSubMenu.addSeparator(); + + lfoSubMenu.addItem(Surge::GUI::toOSCaseForMenu("Rescan Presets"), + []() { Surge::ModulatorPreset::forcePresetRescan(); }); - addCallbackMenu(lfoSubMenu, Surge::GUI::toOSCaseForMenu("Rescan Presets"), - []() { Surge::ModulatorPreset::forcePresetRescan(); }); return lfoSubMenu; } diff --git a/src/gui/SurgeGUIEditor.h b/src/gui/SurgeGUIEditor.h index de300aebf32..49e0ccaf5fd 100644 --- a/src/gui/SurgeGUIEditor.h +++ b/src/gui/SurgeGUIEditor.h @@ -565,7 +565,7 @@ class SurgeGUIEditor : public EditorType, juce::PopupMenu makeDataMenu(VSTGUI::CRect &rect); juce::PopupMenu makeMidiMenu(VSTGUI::CRect &rect); juce::PopupMenu makeDevMenu(VSTGUI::CRect &rect); - VSTGUI::COptionMenu *makeLfoMenu(VSTGUI::CRect &rect); + juce::PopupMenu makeLfoMenu(VSTGUI::CRect &rect); VSTGUI::COptionMenu *makeMonoModeOptionsMenu(VSTGUI::CRect &rect, bool updateDefaults); bool scannedForMidiPresets = false; From 986997179bfae59bf2e099aec614522af4a17d40 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Mon, 24 May 2021 08:23:20 -0400 Subject: [PATCH 2/3] Some partial fixes --- src/gui/SurgeGUIEditor.cpp | 43 +++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/gui/SurgeGUIEditor.cpp b/src/gui/SurgeGUIEditor.cpp index 9e066e42e7f..b25a596f8ad 100644 --- a/src/gui/SurgeGUIEditor.cpp +++ b/src/gui/SurgeGUIEditor.cpp @@ -5367,35 +5367,43 @@ juce::PopupMenu SurgeGUIEditor::makeLfoMenu(VSTGUI::CRect &menuRect) lfoSubMenu.addSeparator(); } - std::unordered_map> subMenuMaps; - subMenuMaps[""] = std::make_pair(lfoSubMenu, true); + std::unordered_map, bool>> subMenuMaps; for (auto const &cat : presetCategories) { - auto catSubMenu = juce::PopupMenu(); - subMenuMaps[cat.path] = std::make_pair(catSubMenu, false); + subMenuMaps[cat.path] = std::make_pair(std::make_unique(), false); } for (auto const &cat : presetCategories) { + juce::PopupMenu *catSubMenu; if (subMenuMaps.find(cat.path) == subMenuMaps.end()) { - // should never happen - continue; + if (cat.path.empty()) + { + catSubMenu = &lfoSubMenu; + } + else + { + // should never happen + continue; + } + } + else + { + catSubMenu = subMenuMaps[cat.path].first.get(); } - auto catSubMenu = subMenuMaps[cat.path].first; - - if (catSubMenu.getNumItems() > 0 && cat.presets.size() > 0) + if (catSubMenu->getNumItems() > 0 && cat.presets.size() > 0) { - catSubMenu.addSeparator(); + catSubMenu->addSeparator(); } for (auto const &p : cat.presets) { auto pname = p.name; - catSubMenu.addItem(pname, [this, p, currentLfoId]() { + catSubMenu->addItem(pname, [this, p, currentLfoId]() { Surge::ModulatorPreset::loadPresetFrom(p.path, &(this->synth->storage), current_scene, currentLfoId); @@ -5419,26 +5427,23 @@ juce::PopupMenu SurgeGUIEditor::makeLfoMenu(VSTGUI::CRect &menuRect) } } - /* - * With the escape menu hack need to add in child firstr order; this is - * sorted by string path so go backwards - */ for (auto it = presetCategories.rbegin(); it != presetCategories.rend(); it++) { const auto &cat = *it; if (subMenuMaps.find(cat.path) == subMenuMaps.end()) { + jassert(false); // should never happen continue; } - auto catSubMenu = subMenuMaps[cat.path].first; - auto parentMenu = lfoSubMenu; + auto catSubMenu = subMenuMaps[cat.path].first.get(); + auto parentMenu = &lfoSubMenu; if (subMenuMaps.find(cat.parentPath) != subMenuMaps.end()) { - parentMenu = subMenuMaps[cat.parentPath].first; + parentMenu = subMenuMaps[cat.parentPath].first.get(); if (!subMenuMaps[cat.parentPath].second) { @@ -5446,7 +5451,7 @@ juce::PopupMenu SurgeGUIEditor::makeLfoMenu(VSTGUI::CRect &menuRect) } } - parentMenu.addSubMenu(cat.name, catSubMenu); + parentMenu->addSubMenu(cat.name, *catSubMenu); } lfoSubMenu.addSeparator(); From fb2b2f657f7b5128190de0de8763440b825d28c1 Mon Sep 17 00:00:00 2001 From: Mario Kruselj Date: Mon, 24 May 2021 16:07:30 +0200 Subject: [PATCH 3/3] Use switch-case for what std::string --- src/gui/SurgeGUIEditor.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/gui/SurgeGUIEditor.cpp b/src/gui/SurgeGUIEditor.cpp index b25a596f8ad..2b1cd490e0e 100644 --- a/src/gui/SurgeGUIEditor.cpp +++ b/src/gui/SurgeGUIEditor.cpp @@ -5327,17 +5327,27 @@ void SurgeGUIEditor::showSettingsMenu(CRect &menuRect) juce::PopupMenu SurgeGUIEditor::makeLfoMenu(VSTGUI::CRect &menuRect) { int currentLfoId = modsource_editor[current_scene] - ms_lfo1; - int shapev = synth->storage.getPatch().scene[current_scene].lfo[currentLfoId].shape.val.i; - std::string what = "LFO"; - if (lt_mseg == shapev) + std::string what; + + switch (shapev) + { + case lt_mseg: what = "MSEG"; - if (lt_stepseq == shapev) + break; + case lt_stepseq: what = "Step Seq"; - if (lt_envelope == shapev) + break; + case lt_envelope: what = "Envelope"; - if (lt_formula == shapev) + break; + case lt_formula: what = "Formula"; + break; + default: + what = "LFO"; + break; + } auto msurl = SurgeGUIEditor::helpURLForSpecial("lfo-presets"); auto hurl = SurgeGUIEditor::fullyResolvedHelpURL(msurl);