Skip to content

Commit

Permalink
Bye bye COptionMenu! (#4673)
Browse files Browse the repository at this point in the history
We didn't like you at all.


(Also removed addCallbackMenu helper and JUCEfied all uses of it properly.)
  • Loading branch information
mkruselj authored Jun 23, 2021
1 parent 166f8d8 commit d050e50
Show file tree
Hide file tree
Showing 3 changed files with 555 additions and 604 deletions.
59 changes: 26 additions & 33 deletions src/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2289,41 +2289,44 @@ juce::PopupMenu SurgeGUIEditor::makeMpeMenu(VSTGUI::CRect &menuRect, bool showhe
return mpeSubMenu;
}

VSTGUI::COptionMenu *SurgeGUIEditor::makeMonoModeOptionsMenu(VSTGUI::CRect &menuRect,
bool updateDefaults)
juce::PopupMenu SurgeGUIEditor::makeMonoModeOptionsMenu(VSTGUI::CRect &menuRect,
bool updateDefaults)
{
COptionMenu *monoSubMenu = new COptionMenu(menuRect, 0, 0, 0, 0,
VSTGUI::COptionMenu::kNoDrawStyle |
VSTGUI::COptionMenu::kMultipleCheckStyle);
auto monoSubMenu = juce::PopupMenu();

auto mode = synth->storage.monoPedalMode;

if (updateDefaults)
{
mode = (MonoPedalMode)Surge::Storage::getUserDefaultValue(
&(this->synth->storage), Surge::Storage::MonoPedalMode, (int)HOLD_ALL_NOTES);
}

bool isChecked = (mode == HOLD_ALL_NOTES);

auto cb = addCallbackMenu(
monoSubMenu,
Surge::GUI::toOSCaseForMenu("Sustain Pedal Holds All Notes (No Note Off Retrigger)"),
[this, updateDefaults]() {
monoSubMenu.addItem(
Surge::GUI::toOSCaseForMenu("Sustain Pedal Holds All Notes (No Note Off Retrigger)"), true,
isChecked, [this, updateDefaults]() {
this->synth->storage.monoPedalMode = HOLD_ALL_NOTES;
if (updateDefaults)
{
Surge::Storage::updateUserDefaultValue(
&(this->synth->storage), Surge::Storage::MonoPedalMode, (int)HOLD_ALL_NOTES);
}
});
if (mode == HOLD_ALL_NOTES)
cb->setChecked(true);

cb = addCallbackMenu(monoSubMenu,
Surge::GUI::toOSCaseForMenu("Sustain Pedal Allows Note Off Retrigger"),
[this, updateDefaults]() {
this->synth->storage.monoPedalMode = RELEASE_IF_OTHERS_HELD;
if (updateDefaults)
Surge::Storage::updateUserDefaultValue(
&(this->synth->storage), Surge::Storage::MonoPedalMode,
(int)RELEASE_IF_OTHERS_HELD);
});
if (mode == RELEASE_IF_OTHERS_HELD)
cb->setChecked(true);

isChecked = (mode == RELEASE_IF_OTHERS_HELD);

monoSubMenu.addItem(Surge::GUI::toOSCaseForMenu("Sustain Pedal Allows Note Off Retrigger"),
true, isChecked, [this, updateDefaults]() {
this->synth->storage.monoPedalMode = RELEASE_IF_OTHERS_HELD;
if (updateDefaults)
{
Surge::Storage::updateUserDefaultValue(
&(this->synth->storage), Surge::Storage::MonoPedalMode,
(int)RELEASE_IF_OTHERS_HELD);
}
});

return monoSubMenu;
}
Expand Down Expand Up @@ -3419,16 +3422,6 @@ int SurgeGUIEditor::findLargestFittingZoomBetween(
return result;
}

std::shared_ptr<VSTGUI::CCommandMenuItem>
SurgeGUIEditor::addCallbackMenu(VSTGUI::COptionMenu *toThis, std::string label,
std::function<void()> op)
{
auto menu = std::make_shared<CCommandMenuItem>(CCommandMenuItem::Desc(label.c_str()));
menu->setActions([op](CCommandMenuItem *m) { op(); });
toThis->addEntry(menu);
return menu;
}

void SurgeGUIEditor::forceautomationchangefor(Parameter *p)
{
std::cout << "FIXME - REMOVE THIS" << __func__ << std::endl;
Expand Down
16 changes: 1 addition & 15 deletions src/gui/SurgeGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,20 +566,6 @@ class SurgeGUIEditor : public EditorType,
SurgeSynthEditor *juceEditor{nullptr};
int firstIdleCountdown = 0;

/*
** Utility Function
*/
std::shared_ptr<VSTGUI::CCommandMenuItem>
addCallbackMenu(VSTGUI::COptionMenu *toThis, std::string label, std::function<void()> op);

/*
* Why have this? To avoid rewrites when porting from COptionMenu signature
*/
void addCallbackMenu(juce::PopupMenu &menu, const std::string &label, std::function<void()> op)
{
menu.addItem(label, op);
}

juce::PopupMenu
makeSmoothMenu(VSTGUI::CRect &menuRect, const Surge::Storage::DefaultKey &key, int defaultValue,
std::function<void(ControllerModulationSource::SmoothingMode)> setSmooth);
Expand All @@ -596,7 +582,7 @@ class SurgeGUIEditor : public EditorType,
juce::PopupMenu makeMidiMenu(VSTGUI::CRect &rect);
juce::PopupMenu makeDevMenu(VSTGUI::CRect &rect);
juce::PopupMenu makeLfoMenu(VSTGUI::CRect &rect);
VSTGUI::COptionMenu *makeMonoModeOptionsMenu(VSTGUI::CRect &rect, bool updateDefaults);
juce::PopupMenu makeMonoModeOptionsMenu(VSTGUI::CRect &rect, bool updateDefaults);

public:
bool getShowVirtualKeyboard();
Expand Down
Loading

0 comments on commit d050e50

Please sign in to comment.