Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bye bye COptionMenu! #4673

Merged
merged 1 commit into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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