From b98283034d963a8d9810b5104f6b3931c6bd55d7 Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 1 Dec 2022 20:42:15 +0000 Subject: [PATCH] Reduce diff vs Rack, regarding ModuleWidget.cpp file Signed-off-by: falkTX --- src/CardinalModuleWidget.cpp | 37 -- src/override/ModuleWidget.cpp | 488 ++++++++++--------- src/override/diffs/Engine.cpp.diff | 4 +- src/override/diffs/MenuBar.cpp.diff | 4 +- src/override/diffs/Model.cpp.diff | 4 +- src/override/diffs/ModuleWidget.cpp.diff | 592 +++++------------------ src/override/diffs/OpenGlWidget.cpp.diff | 4 +- src/override/diffs/Scene.cpp.diff | 4 +- src/override/diffs/Window.cpp.diff | 4 +- src/override/diffs/blendish.c.diff | 4 +- src/override/diffs/common.cpp.diff | 4 +- src/override/diffs/context.cpp.diff | 13 +- src/override/diffs/minblep.cpp.diff | 4 +- src/override/diffs/plugin.cpp.diff | 4 +- 14 files changed, 404 insertions(+), 766 deletions(-) diff --git a/src/CardinalModuleWidget.cpp b/src/CardinalModuleWidget.cpp index 854e2fd..7adc2fc 100644 --- a/src/CardinalModuleWidget.cpp +++ b/src/CardinalModuleWidget.cpp @@ -45,43 +45,6 @@ namespace rack { namespace app { -// Create ModulePresetPathItems for each patch in a directory. -static void appendPresetItems(ui::Menu* menu, WeakPtr moduleWidget, std::string presetDir) { - bool foundPresets = false; - - if (system::isDirectory(presetDir)) - { - // Note: This is not cached, so opening this menu each time might have a bit of latency. - std::vector entries = system::getEntries(presetDir); - std::sort(entries.begin(), entries.end()); - for (std::string path : entries) { - std::string name = system::getStem(path); - // Remove "1_", "42_", "001_", etc at the beginning of preset filenames - std::regex r("^\\d+_"); - name = std::regex_replace(name, r, ""); - - if (system::getExtension(path) == ".vcvm" && name != "template") - { - if (!foundPresets) - menu->addChild(new ui::MenuSeparator); - - foundPresets = true; - - menu->addChild(createMenuItem(name, "", [=]() { - if (!moduleWidget) - return; - try { - moduleWidget->loadAction(path); - } - catch (Exception& e) { - async_dialog_message(e.what()); - } - })); - } - } - } -}; - static void CardinalModuleWidget__saveSelectionDialog(RackWidget* const w) { std::string selectionDir = asset::user("selections"); diff --git a/src/override/ModuleWidget.cpp b/src/override/ModuleWidget.cpp index 438b8cf..002c510 100644 --- a/src/override/ModuleWidget.cpp +++ b/src/override/ModuleWidget.cpp @@ -397,71 +397,71 @@ void ModuleWidget::onHoverKey(const HoverKeyEvent& e) { } void ModuleWidget::onButton(const ButtonEvent& e) { - const bool selected = APP->scene->rack->isSelected(this); - - if (selected) { - if (e.button == GLFW_MOUSE_BUTTON_RIGHT) { - if (e.action == GLFW_PRESS) { - // Open selection context menu on right-click - ui::Menu* menu = createMenu(); - patchUtils::appendSelectionContextMenu(menu); - } - e.consume(this); - } - - if (e.button == GLFW_MOUSE_BUTTON_LEFT) { - if (e.action == GLFW_PRESS) { - // Toggle selection on Shift-click - if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { - APP->scene->rack->select(this, false); - e.consume(NULL); - return; - } - - // If module positions are locked, don't consume left-click - if (settings::lockModules) { - return; - } - - internal->dragOffset = e.pos; - } - - e.consume(this); - } - - return; - } - - // Dispatch event to children - Widget::onButton(e); - e.stopPropagating(); - if (e.isConsumed()) - return; - - if (e.button == GLFW_MOUSE_BUTTON_LEFT) { - if (e.action == GLFW_PRESS) { - // Toggle selection on Shift-click - if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { - APP->scene->rack->select(this, true); - e.consume(NULL); - return; - } - - // If module positions are locked, don't consume left-click - if (settings::lockModules) { - return; - } - - internal->dragOffset = e.pos; - } - e.consume(this); - } - - // Open context menu on right-click - if (e.button == GLFW_MOUSE_BUTTON_RIGHT && e.action == GLFW_PRESS) { - createContextMenu(); - e.consume(this); - } + bool selected = APP->scene->rack->isSelected(this); + + if (selected) { + if (e.button == GLFW_MOUSE_BUTTON_RIGHT) { + if (e.action == GLFW_PRESS) { + // Open selection context menu on right-click + ui::Menu* menu = createMenu(); + patchUtils::appendSelectionContextMenu(menu); + } + e.consume(this); + } + + if (e.button == GLFW_MOUSE_BUTTON_LEFT) { + if (e.action == GLFW_PRESS) { + // Toggle selection on Shift-click + if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + APP->scene->rack->select(this, false); + e.consume(NULL); + return; + } + + // If module positions are locked, don't consume left-click + if (settings::lockModules) { + return; + } + + internal->dragOffset = e.pos; + } + + e.consume(this); + } + + return; + } + + // Dispatch event to children + Widget::onButton(e); + e.stopPropagating(); + if (e.isConsumed()) + return; + + if (e.button == GLFW_MOUSE_BUTTON_LEFT) { + if (e.action == GLFW_PRESS) { + // Toggle selection on Shift-click + if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + APP->scene->rack->select(this, true); + e.consume(NULL); + return; + } + + // If module positions are locked, don't consume left-click + if (settings::lockModules) { + return; + } + + internal->dragOffset = e.pos; + } + e.consume(this); + } + + // Open context menu on right-click + if (e.button == GLFW_MOUSE_BUTTON_RIGHT && e.action == GLFW_PRESS) { + createContextMenu(); + e.consume(this); + } } void ModuleWidget::onDragStart(const DragStartEvent& e) { @@ -653,37 +653,39 @@ void ModuleWidget::loadTemplate() { } void ModuleWidget::loadDialog() { - std::string presetDir = model->getUserPresetDirectory(); - system::createDirectories(presetDir); - - WeakPtr weakThis = this; - - async_dialog_filebrowser(false, nullptr, presetDir.c_str(), "Load preset", [=](char* pathC) { - // Delete directories if empty - DEFER({ - try { - system::remove(presetDir); - system::remove(system::getDirectory(presetDir)); - } - catch (Exception& e) { - // Ignore exceptions if directory cannot be removed. - } - }); - - if (!weakThis) - return; - if (!pathC) - return; - - try { - weakThis->loadAction(pathC); - } - catch (Exception& e) { - async_dialog_message(e.what()); - } - - std::free(pathC); - }); + std::string presetDir = model->getUserPresetDirectory(); + system::createDirectories(presetDir); + + WeakPtr weakThis = this; + async_dialog_filebrowser(false, nullptr, presetDir.c_str(), "Load preset", [=](char* pathC) { + + // Delete directories if empty + DEFER({ + try { + system::remove(presetDir); + system::remove(system::getDirectory(presetDir)); + } + catch (Exception& e) { + // Ignore exceptions if directory cannot be removed. + } + }); + + if (!weakThis) + return; + if (!pathC) { + // No path selected + return; + } + DEFER({std::free(pathC);}); + + try { + weakThis->loadAction(pathC); + } + catch (Exception& e) { + async_dialog_message(e.what()); + } + + }); } void ModuleWidget::save(std::string filename) { @@ -742,37 +744,38 @@ void ModuleWidget::clearTemplateDialog() { } void ModuleWidget::saveDialog() { - const std::string presetDir = model->getUserPresetDirectory(); - system::createDirectories(presetDir); - - WeakPtr weakThis = this; - - async_dialog_filebrowser(true, "preset.vcvm", presetDir.c_str(), "Save preset", [=](char* pathC) { - // Delete directories if empty - DEFER({ - try { - system::remove(presetDir); - system::remove(system::getDirectory(presetDir)); - } - catch (Exception& e) { - // Ignore exceptions if directory cannot be removed. - } - }); - - if (!weakThis) - return; - if (!pathC) - return; - - std::string path = pathC; - std::free(pathC); - - // Automatically append .vcvm extension - if (system::getExtension(path) != ".vcvm") - path += ".vcvm"; - - weakThis->save(path); - }); + std::string presetDir = model->getUserPresetDirectory(); + system::createDirectories(presetDir); + + WeakPtr weakThis = this; + async_dialog_filebrowser(true, "preset.vcvm", presetDir.c_str(), "Save preset", [=](char* pathC) { + + // Delete directories if empty + DEFER({ + try { + system::remove(presetDir); + system::remove(system::getDirectory(presetDir)); + } + catch (Exception& e) { + // Ignore exceptions if directory cannot be removed. + } + }); + + if (!weakThis) + return; + if (!pathC) { + // No path selected + return; + } + DEFER({std::free(pathC);}); + + std::string path = pathC; + // Automatically append .vcvm extension + if (system::getExtension(path) != ".vcvm") + path += ".vcvm"; + + weakThis->save(path); + }); } void ModuleWidget::disconnect() { @@ -975,16 +978,12 @@ static void appendPresetItems(ui::Menu* menu, WeakPtr moduleWidget std::regex r("^\\d+_"); name = std::regex_replace(name, r, ""); - if (system::isDirectory(path)) { - hasPresets = true; - - menu->addChild(createSubmenuItem(name, "", [=](ui::Menu* menu) { - if (!moduleWidget) - return; - appendPresetItems(menu, moduleWidget, path); - })); + if (false) { } else if (system::getExtension(path) == ".vcvm" && name != "template") { + if (!hasPresets) + menu->addChild(new ui::MenuSeparator); + hasPresets = true; menu->addChild(createMenuItem(name, "", [=]() { @@ -994,15 +993,12 @@ static void appendPresetItems(ui::Menu* menu, WeakPtr moduleWidget moduleWidget->loadAction(path); } catch (Exception& e) { - osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK, e.what()); + async_dialog_message(e.what()); } })); } } } - if (!hasPresets) { - menu->addChild(createMenuLabel("(None)")); - } }; @@ -1012,108 +1008,122 @@ void ModuleWidget::createContextMenu() { WeakPtr weakThis = this; - // Brand and module name - menu->addChild(createMenuLabel(model->name)); - menu->addChild(createMenuLabel(model->plugin->brand)); + // Brand and module name + menu->addChild(createMenuLabel(model->name)); + menu->addChild(createMenuLabel(model->plugin->brand)); + + // Info + menu->addChild(createSubmenuItem("Info", "", [=](ui::Menu* menu) { + model->appendContextMenu(menu); + })); + + // Preset + menu->addChild(createSubmenuItem("Preset", "", [=](ui::Menu* menu) { + menu->addChild(createMenuItem("Copy", RACK_MOD_CTRL_NAME "+C", [=]() { + if (!weakThis) + return; + weakThis->copyClipboard(); + })); + + menu->addChild(createMenuItem("Paste", RACK_MOD_CTRL_NAME "+V", [=]() { + if (!weakThis) + return; + weakThis->pasteClipboardAction(); + })); + + menu->addChild(createMenuItem("Open", "", [=]() { + if (!weakThis) + return; + weakThis->loadDialog(); + })); + + /* TODO requires setting up user dir + menu->addChild(createMenuItem("Save as", "", [=]() { + if (!weakThis) + return; + weakThis->saveDialog(); + })); + + menu->addChild(createMenuItem("Save default", "", [=]() { + if (!weakThis) + return; + weakThis->saveTemplateDialog(); + })); + + menu->addChild(createMenuItem("Clear default", "", [=]() { + if (!weakThis) + return; + weakThis->clearTemplateDialog(); + }, !weakThis->hasTemplate())); + + // Scan `/presets//` for presets. + menu->addChild(new ui::MenuSeparator); + menu->addChild(createMenuLabel("User presets")); + appendPresetItems(menu, weakThis, weakThis->model->getUserPresetDirectory()); + */ + + // Scan `/presets/` for presets. + /* TODO enable only after setting up user dir + menu->addChild(new ui::MenuSeparator); + menu->addChild(createMenuLabel("Factory presets")); + */ + appendPresetItems(menu, weakThis, weakThis->model->getFactoryPresetDirectory()); + })); + + // Initialize + menu->addChild(createMenuItem("Initialize", RACK_MOD_CTRL_NAME "+I", [=]() { + if (!weakThis) + return; + weakThis->resetAction(); + })); + + // Randomize + menu->addChild(createMenuItem("Randomize", RACK_MOD_CTRL_NAME "+R", [=]() { + if (!weakThis) + return; + weakThis->randomizeAction(); + })); + + // Disconnect cables + menu->addChild(createMenuItem("Disconnect cables", RACK_MOD_CTRL_NAME "+U", [=]() { + if (!weakThis) + return; + weakThis->disconnectAction(); + })); + + // Bypass + std::string bypassText = RACK_MOD_CTRL_NAME "+E"; + bool bypassed = module && module->isBypassed(); + if (bypassed) + bypassText += " " CHECKMARK_STRING; + menu->addChild(createMenuItem("Bypass", bypassText, [=]() { + if (!weakThis) + return; + weakThis->bypassAction(!bypassed); + })); + + // Duplicate + menu->addChild(createMenuItem("Duplicate", RACK_MOD_CTRL_NAME "+D", [=]() { + if (!weakThis) + return; + weakThis->cloneAction(false); + })); - // Info - menu->addChild(createSubmenuItem("Info", "", [weakThis](ui::Menu* menu) { + // Duplicate with cables + menu->addChild(createMenuItem("└ with cables", RACK_MOD_SHIFT_NAME "+" RACK_MOD_CTRL_NAME "+D", [=]() { if (!weakThis) return; - weakThis->model->appendContextMenu(menu); - })); - - // Preset - menu->addChild(createSubmenuItem("Preset", "", [weakThis](ui::Menu* menu) { - menu->addChild(createMenuItem("Copy", RACK_MOD_CTRL_NAME "+C", [weakThis]() { - if (!weakThis) - return; - weakThis->copyClipboard(); - })); - - menu->addChild(createMenuItem("Paste", RACK_MOD_CTRL_NAME "+V", [weakThis]() { - if (!weakThis) - return; - weakThis->pasteClipboardAction(); - })); - - menu->addChild(createMenuItem("Open", "", [weakThis]() { - if (!weakThis) - return; - weakThis->loadDialog(); - })); - - /* TODO requires setting up user dir - menu->addChild(createMenuItem("Save as", "", [weakThis]() { - if (!weakThis) - return; - CardinalModuleWidget__saveDialog(weakThis); - })); - - // Scan `/presets//` for presets. - menu->addChild(new ui::MenuSeparator); - menu->addChild(createMenuLabel("User presets")); - appendPresetItems(menu, weakThis, weakThis->model->getUserPresetDirectory()); - */ - - // Scan `/presets/` for presets. - appendPresetItems(menu, weakThis, weakThis->model->getFactoryPresetDirectory()); - })); - - // Initialize - menu->addChild(createMenuItem("Initialize", RACK_MOD_CTRL_NAME "+I", [weakThis]() { - if (!weakThis) - return; - weakThis->resetAction(); - })); - - // Randomize - menu->addChild(createMenuItem("Randomize", RACK_MOD_CTRL_NAME "+R", [weakThis]() { - if (!weakThis) - return; - weakThis->randomizeAction(); - })); - - // Disconnect cables - menu->addChild(createMenuItem("Disconnect cables", RACK_MOD_CTRL_NAME "+U", [weakThis]() { - if (!weakThis) - return; - weakThis->disconnectAction(); - })); - - // Bypass - std::string bypassText = RACK_MOD_CTRL_NAME "+E"; - bool bypassed = module && module->isBypassed(); - if (bypassed) - bypassText += " " CHECKMARK_STRING; - menu->addChild(createMenuItem("Bypass", bypassText, [weakThis, bypassed]() { - if (!weakThis) - return; - weakThis->bypassAction(!bypassed); - })); - - // Duplicate - menu->addChild(createMenuItem("Duplicate", RACK_MOD_CTRL_NAME "+D", [weakThis]() { - if (!weakThis) - return; - weakThis->cloneAction(false); - })); - - // Duplicate with cables - menu->addChild(createMenuItem("└ with cables", RACK_MOD_SHIFT_NAME "+" RACK_MOD_CTRL_NAME "+D", [weakThis]() { - if (!weakThis) - return; - weakThis->cloneAction(true); - })); - - // Delete - menu->addChild(createMenuItem("Delete", "Backspace/Delete", [weakThis]() { - if (!weakThis) - return; - weakThis->removeAction(); - }, false, true)); - - appendContextMenu(menu); + weakThis->cloneAction(true); + })); + + // Delete + menu->addChild(createMenuItem("Delete", "Backspace/Delete", [=]() { + if (!weakThis) + return; + weakThis->removeAction(); + }, false, true)); + + appendContextMenu(menu); } math::Vec ModuleWidget::getGridPosition() { @@ -1148,4 +1158,4 @@ engine::Module* ModuleWidget::releaseModule() { } // namespace app -} // namespace rack \ No newline at end of file +} // namespace rack diff --git a/src/override/diffs/Engine.cpp.diff b/src/override/diffs/Engine.cpp.diff index 59d9496..89c13e4 100644 --- a/src/override/diffs/Engine.cpp.diff +++ b/src/override/diffs/Engine.cpp.diff @@ -1,5 +1,5 @@ ---- ../Rack/src/engine/Engine.cpp 2022-11-23 23:11:38.000000000 +0000 -+++ Engine.cpp 2022-11-25 22:31:29.000000000 +0000 +--- ../Rack/src/engine/Engine.cpp 2022-09-21 20:25:53.592040301 +0100 ++++ Engine.cpp 2022-11-29 19:49:19.196926572 +0000 @@ -1,3 +1,30 @@ +/* + * DISTRHO Cardinal Plugin diff --git a/src/override/diffs/MenuBar.cpp.diff b/src/override/diffs/MenuBar.cpp.diff index 186ef5f..ece100e 100644 --- a/src/override/diffs/MenuBar.cpp.diff +++ b/src/override/diffs/MenuBar.cpp.diff @@ -1,5 +1,5 @@ ---- ../Rack/src/app/MenuBar.cpp 2022-11-23 23:11:38.000000000 +0000 -+++ MenuBar.cpp 2022-11-25 23:27:58.000000000 +0000 +--- ../Rack/src/app/MenuBar.cpp 2022-09-21 20:25:53.590040258 +0100 ++++ MenuBar.cpp 2022-11-29 19:49:19.196926572 +0000 @@ -1,8 +1,33 @@ +/* + * DISTRHO Cardinal Plugin diff --git a/src/override/diffs/Model.cpp.diff b/src/override/diffs/Model.cpp.diff index cbe6c0f..f1ad26c 100644 --- a/src/override/diffs/Model.cpp.diff +++ b/src/override/diffs/Model.cpp.diff @@ -1,5 +1,5 @@ ---- ../Rack/src/plugin/Model.cpp 2022-11-23 23:11:38.000000000 +0000 -+++ Model.cpp 2022-11-23 23:06:41.000000000 +0000 +--- ../Rack/src/plugin/Model.cpp 2022-09-21 20:25:53.592040301 +0100 ++++ Model.cpp 2022-09-21 20:18:50.294557597 +0100 @@ -1,3 +1,30 @@ +/* + * DISTRHO Cardinal Plugin diff --git a/src/override/diffs/ModuleWidget.cpp.diff b/src/override/diffs/ModuleWidget.cpp.diff index 1c9300b..c32ce74 100644 --- a/src/override/diffs/ModuleWidget.cpp.diff +++ b/src/override/diffs/ModuleWidget.cpp.diff @@ -1,5 +1,5 @@ ---- ../Rack/src/app/ModuleWidget.cpp 2022-11-23 23:11:38.000000000 +0000 -+++ ModuleWidget.cpp 2022-11-30 20:10:06.000000000 +0000 +--- ../Rack/src/app/ModuleWidget.cpp 2022-09-21 20:25:53.590040258 +0100 ++++ ModuleWidget.cpp 2022-12-01 20:41:02.583687336 +0000 @@ -1,3 +1,32 @@ +/* + * DISTRHO Cardinal Plugin @@ -33,485 +33,151 @@ #include #include -@@ -368,71 +397,71 @@ - } - - void ModuleWidget::onButton(const ButtonEvent& e) { -- bool selected = APP->scene->rack->isSelected(this); -- -- if (selected) { -- if (e.button == GLFW_MOUSE_BUTTON_RIGHT) { -- if (e.action == GLFW_PRESS) { -- // Open selection context menu on right-click -- ui::Menu* menu = createMenu(); +@@ -375,7 +404,7 @@ + if (e.action == GLFW_PRESS) { + // Open selection context menu on right-click + ui::Menu* menu = createMenu(); - APP->scene->rack->appendSelectionContextMenu(menu); -- } -- e.consume(this); -- } -- -- if (e.button == GLFW_MOUSE_BUTTON_LEFT) { -- if (e.action == GLFW_PRESS) { -- // Toggle selection on Shift-click -- if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { -- APP->scene->rack->select(this, false); -- e.consume(NULL); -- return; -- } -- -- // If module positions are locked, don't consume left-click -- if (settings::lockModules) { -- return; -- } -+ const bool selected = APP->scene->rack->isSelected(this); - -- internal->dragOffset = e.pos; -- } -- -- e.consume(this); -- } -- -- return; -- } -- -- // Dispatch event to children -- Widget::onButton(e); -- e.stopPropagating(); -- if (e.isConsumed()) -- return; -- -- if (e.button == GLFW_MOUSE_BUTTON_LEFT) { -- if (e.action == GLFW_PRESS) { -- // Toggle selection on Shift-click -- if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { -- APP->scene->rack->select(this, true); -- e.consume(NULL); -- return; -- } -- -- // If module positions are locked, don't consume left-click -- if (settings::lockModules) { -- return; -- } -- -- internal->dragOffset = e.pos; -- } -- e.consume(this); -- } -- -- // Open context menu on right-click -- if (e.button == GLFW_MOUSE_BUTTON_RIGHT && e.action == GLFW_PRESS) { -- createContextMenu(); -- e.consume(this); -- } -+ if (selected) { -+ if (e.button == GLFW_MOUSE_BUTTON_RIGHT) { -+ if (e.action == GLFW_PRESS) { -+ // Open selection context menu on right-click -+ ui::Menu* menu = createMenu(); -+ patchUtils::appendSelectionContextMenu(menu); -+ } -+ e.consume(this); -+ } -+ -+ if (e.button == GLFW_MOUSE_BUTTON_LEFT) { -+ if (e.action == GLFW_PRESS) { -+ // Toggle selection on Shift-click -+ if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { -+ APP->scene->rack->select(this, false); -+ e.consume(NULL); -+ return; -+ } -+ -+ // If module positions are locked, don't consume left-click -+ if (settings::lockModules) { -+ return; -+ } -+ -+ internal->dragOffset = e.pos; -+ } -+ -+ e.consume(this); -+ } -+ -+ return; -+ } -+ -+ // Dispatch event to children -+ Widget::onButton(e); -+ e.stopPropagating(); -+ if (e.isConsumed()) -+ return; -+ -+ if (e.button == GLFW_MOUSE_BUTTON_LEFT) { -+ if (e.action == GLFW_PRESS) { -+ // Toggle selection on Shift-click -+ if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { -+ APP->scene->rack->select(this, true); -+ e.consume(NULL); -+ return; -+ } -+ -+ // If module positions are locked, don't consume left-click -+ if (settings::lockModules) { -+ return; -+ } -+ -+ internal->dragOffset = e.pos; -+ } -+ e.consume(this); -+ } -+ -+ // Open context menu on right-click -+ if (e.button == GLFW_MOUSE_BUTTON_RIGHT && e.action == GLFW_PRESS) { -+ createContextMenu(); -+ e.consume(this); -+ } - } - - void ModuleWidget::onDragStart(const DragStartEvent& e) { -@@ -624,36 +653,37 @@ - } - - void ModuleWidget::loadDialog() { -- std::string presetDir = model->getUserPresetDirectory(); -- system::createDirectories(presetDir); -+ std::string presetDir = model->getUserPresetDirectory(); -+ system::createDirectories(presetDir); - -- // Delete directories if empty -- DEFER({ -- try { -- system::remove(presetDir); -- system::remove(system::getDirectory(presetDir)); -- } -- catch (Exception& e) { -- // Ignore exceptions if directory cannot be removed. -- } -- }); -+ WeakPtr weakThis = this; ++ patchUtils::appendSelectionContextMenu(menu); + } + e.consume(this); + } +@@ -627,6 +656,9 @@ + std::string presetDir = model->getUserPresetDirectory(); + system::createDirectories(presetDir); + ++ WeakPtr weakThis = this; ++ async_dialog_filebrowser(false, nullptr, presetDir.c_str(), "Load preset", [=](char* pathC) { ++ + // Delete directories if empty + DEFER({ + try { +@@ -638,10 +670,8 @@ + } + }); - osdialog_filters* filters = osdialog_filters_parse(PRESET_FILTERS); - DEFER({osdialog_filters_free(filters);}); -+ async_dialog_filebrowser(false, nullptr, presetDir.c_str(), "Load preset", [=](char* pathC) { -+ // Delete directories if empty -+ DEFER({ -+ try { -+ system::remove(presetDir); -+ system::remove(system::getDirectory(presetDir)); -+ } -+ catch (Exception& e) { -+ // Ignore exceptions if directory cannot be removed. -+ } -+ }); -+ -+ if (!weakThis) -+ return; -+ if (!pathC) -+ return; -+ -+ try { -+ weakThis->loadAction(pathC); -+ } -+ catch (Exception& e) { -+ async_dialog_message(e.what()); -+ } - -- char* pathC = osdialog_file(OSDIALOG_OPEN, presetDir.c_str(), NULL, filters); -- if (!pathC) { -- // No path selected -- return; -- } -- DEFER({std::free(pathC);}); - -- try { +- char* pathC = osdialog_file(OSDIALOG_OPEN, presetDir.c_str(), NULL, filters); ++ if (!weakThis) ++ return; + if (!pathC) { + // No path selected + return; +@@ -649,11 +679,13 @@ + DEFER({std::free(pathC);}); + + try { - loadAction(pathC); -- } -- catch (Exception& e) { ++ weakThis->loadAction(pathC); + } + catch (Exception& e) { - osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK, e.what()); -- } -+ std::free(pathC); -+ }); ++ async_dialog_message(e.what()); + } ++ ++ }); } void ModuleWidget::save(std::string filename) { -@@ -712,36 +742,37 @@ - } +@@ -715,6 +747,9 @@ + std::string presetDir = model->getUserPresetDirectory(); + system::createDirectories(presetDir); - void ModuleWidget::saveDialog() { -- std::string presetDir = model->getUserPresetDirectory(); -- system::createDirectories(presetDir); -+ const std::string presetDir = model->getUserPresetDirectory(); -+ system::createDirectories(presetDir); ++ WeakPtr weakThis = this; ++ async_dialog_filebrowser(true, "preset.vcvm", presetDir.c_str(), "Save preset", [=](char* pathC) { ++ + // Delete directories if empty + DEFER({ + try { +@@ -726,10 +761,8 @@ + } + }); -- // Delete directories if empty -- DEFER({ -- try { -- system::remove(presetDir); -- system::remove(system::getDirectory(presetDir)); -- } -- catch (Exception& e) { -- // Ignore exceptions if directory cannot be removed. -- } -- }); -- - osdialog_filters* filters = osdialog_filters_parse(PRESET_FILTERS); - DEFER({osdialog_filters_free(filters);}); - - char* pathC = osdialog_file(OSDIALOG_SAVE, presetDir.c_str(), "Untitled.vcvm", filters); -- if (!pathC) { -- // No path selected -- return; -- } -- DEFER({std::free(pathC);}); -+ WeakPtr weakThis = this; - -- std::string path = pathC; -- // Automatically append .vcvm extension -- if (system::getExtension(path) != ".vcvm") -- path += ".vcvm"; -+ async_dialog_filebrowser(true, "preset.vcvm", presetDir.c_str(), "Save preset", [=](char* pathC) { -+ // Delete directories if empty -+ DEFER({ -+ try { -+ system::remove(presetDir); -+ system::remove(system::getDirectory(presetDir)); -+ } -+ catch (Exception& e) { -+ // Ignore exceptions if directory cannot be removed. -+ } -+ }); -+ -+ if (!weakThis) -+ return; -+ if (!pathC) -+ return; -+ -+ std::string path = pathC; -+ std::free(pathC); -+ -+ // Automatically append .vcvm extension -+ if (system::getExtension(path) != ".vcvm") -+ path += ".vcvm"; ++ if (!weakThis) ++ return; + if (!pathC) { + // No path selected + return; +@@ -741,7 +774,8 @@ + if (system::getExtension(path) != ".vcvm") + path += ".vcvm"; - save(path); -+ weakThis->save(path); -+ }); ++ weakThis->save(path); ++ }); } void ModuleWidget::disconnect() { -@@ -981,118 +1012,108 @@ - - WeakPtr weakThis = this; - -- // Brand and module name -- menu->addChild(createMenuLabel(model->name)); -- menu->addChild(createMenuLabel(model->plugin->brand)); -- -- // Info -- menu->addChild(createSubmenuItem("Info", "", [=](ui::Menu* menu) { -- model->appendContextMenu(menu); -- })); -- -- // Preset -- menu->addChild(createSubmenuItem("Preset", "", [=](ui::Menu* menu) { -- menu->addChild(createMenuItem("Copy", RACK_MOD_CTRL_NAME "+C", [=]() { -- if (!weakThis) -- return; -- weakThis->copyClipboard(); -- })); -- -- menu->addChild(createMenuItem("Paste", RACK_MOD_CTRL_NAME "+V", [=]() { -- if (!weakThis) -- return; -- weakThis->pasteClipboardAction(); -- })); -- -- menu->addChild(createMenuItem("Open", "", [=]() { -- if (!weakThis) -- return; -- weakThis->loadDialog(); -- })); -- -- menu->addChild(createMenuItem("Save as", "", [=]() { -- if (!weakThis) -- return; -- weakThis->saveDialog(); -- })); -- -- menu->addChild(createMenuItem("Save default", "", [=]() { -- if (!weakThis) -- return; -- weakThis->saveTemplateDialog(); -- })); -- -- menu->addChild(createMenuItem("Clear default", "", [=]() { -- if (!weakThis) -- return; -- weakThis->clearTemplateDialog(); -- }, !weakThis->hasTemplate())); -- -- // Scan `/presets//` for presets. -- menu->addChild(new ui::MenuSeparator); -- menu->addChild(createMenuLabel("User presets")); -- appendPresetItems(menu, weakThis, weakThis->model->getUserPresetDirectory()); -- -- // Scan `/presets/` for presets. -- menu->addChild(new ui::MenuSeparator); -- menu->addChild(createMenuLabel("Factory presets")); -- appendPresetItems(menu, weakThis, weakThis->model->getFactoryPresetDirectory()); -- })); -+ // Brand and module name -+ menu->addChild(createMenuLabel(model->name)); -+ menu->addChild(createMenuLabel(model->plugin->brand)); - -- // Initialize -- menu->addChild(createMenuItem("Initialize", RACK_MOD_CTRL_NAME "+I", [=]() { -+ // Info -+ menu->addChild(createSubmenuItem("Info", "", [weakThis](ui::Menu* menu) { - if (!weakThis) - return; -- weakThis->resetAction(); -- })); -+ weakThis->model->appendContextMenu(menu); -+ })); - -- // Randomize -- menu->addChild(createMenuItem("Randomize", RACK_MOD_CTRL_NAME "+R", [=]() { -- if (!weakThis) -- return; -- weakThis->randomizeAction(); -- })); -- -- // Disconnect cables -- menu->addChild(createMenuItem("Disconnect cables", RACK_MOD_CTRL_NAME "+U", [=]() { -- if (!weakThis) -- return; -- weakThis->disconnectAction(); -- })); -- -- // Bypass -- std::string bypassText = RACK_MOD_CTRL_NAME "+E"; -- bool bypassed = module && module->isBypassed(); -- if (bypassed) -- bypassText += " " CHECKMARK_STRING; -- menu->addChild(createMenuItem("Bypass", bypassText, [=]() { -- if (!weakThis) -- return; -- weakThis->bypassAction(!bypassed); -- })); -- -- // Duplicate -- menu->addChild(createMenuItem("Duplicate", RACK_MOD_CTRL_NAME "+D", [=]() { -- if (!weakThis) -- return; -- weakThis->cloneAction(false); -- })); -- -- // Duplicate with cables -- menu->addChild(createMenuItem("└ with cables", RACK_MOD_SHIFT_NAME "+" RACK_MOD_CTRL_NAME "+D", [=]() { -- if (!weakThis) -- return; -- weakThis->cloneAction(true); -- })); -- -- // Delete -- menu->addChild(createMenuItem("Delete", "Backspace/Delete", [=]() { -- if (!weakThis) -- return; -- weakThis->removeAction(); -- }, false, true)); -+ // Preset -+ menu->addChild(createSubmenuItem("Preset", "", [weakThis](ui::Menu* menu) { -+ menu->addChild(createMenuItem("Copy", RACK_MOD_CTRL_NAME "+C", [weakThis]() { -+ if (!weakThis) -+ return; -+ weakThis->copyClipboard(); -+ })); -+ -+ menu->addChild(createMenuItem("Paste", RACK_MOD_CTRL_NAME "+V", [weakThis]() { -+ if (!weakThis) -+ return; -+ weakThis->pasteClipboardAction(); -+ })); -+ -+ menu->addChild(createMenuItem("Open", "", [weakThis]() { -+ if (!weakThis) -+ return; -+ weakThis->loadDialog(); -+ })); -+ -+ /* TODO requires setting up user dir -+ menu->addChild(createMenuItem("Save as", "", [weakThis]() { -+ if (!weakThis) -+ return; -+ CardinalModuleWidget__saveDialog(weakThis); -+ })); -+ -+ // Scan `/presets//` for presets. -+ menu->addChild(new ui::MenuSeparator); -+ menu->addChild(createMenuLabel("User presets")); -+ appendPresetItems(menu, weakThis, weakThis->model->getUserPresetDirectory()); -+ */ -+ -+ // Scan `/presets/` for presets. -+ appendPresetItems(menu, weakThis, weakThis->model->getFactoryPresetDirectory()); -+ })); -+ -+ // Initialize -+ menu->addChild(createMenuItem("Initialize", RACK_MOD_CTRL_NAME "+I", [weakThis]() { -+ if (!weakThis) -+ return; -+ weakThis->resetAction(); -+ })); -+ -+ // Randomize -+ menu->addChild(createMenuItem("Randomize", RACK_MOD_CTRL_NAME "+R", [weakThis]() { -+ if (!weakThis) -+ return; -+ weakThis->randomizeAction(); -+ })); -+ -+ // Disconnect cables -+ menu->addChild(createMenuItem("Disconnect cables", RACK_MOD_CTRL_NAME "+U", [weakThis]() { -+ if (!weakThis) -+ return; -+ weakThis->disconnectAction(); -+ })); -+ -+ // Bypass -+ std::string bypassText = RACK_MOD_CTRL_NAME "+E"; -+ bool bypassed = module && module->isBypassed(); -+ if (bypassed) -+ bypassText += " " CHECKMARK_STRING; -+ menu->addChild(createMenuItem("Bypass", bypassText, [weakThis, bypassed]() { -+ if (!weakThis) -+ return; -+ weakThis->bypassAction(!bypassed); -+ })); -+ -+ // Duplicate -+ menu->addChild(createMenuItem("Duplicate", RACK_MOD_CTRL_NAME "+D", [weakThis]() { -+ if (!weakThis) -+ return; -+ weakThis->cloneAction(false); -+ })); -+ -+ // Duplicate with cables -+ menu->addChild(createMenuItem("└ with cables", RACK_MOD_SHIFT_NAME "+" RACK_MOD_CTRL_NAME "+D", [weakThis]() { -+ if (!weakThis) -+ return; -+ weakThis->cloneAction(true); -+ })); -+ -+ // Delete -+ menu->addChild(createMenuItem("Delete", "Backspace/Delete", [weakThis]() { -+ if (!weakThis) -+ return; -+ weakThis->removeAction(); -+ }, false, true)); - -- appendContextMenu(menu); -+ appendContextMenu(menu); - } - - math::Vec ModuleWidget::getGridPosition() { +@@ -944,16 +978,12 @@ + std::regex r("^\\d+_"); + name = std::regex_replace(name, r, ""); + +- if (system::isDirectory(path)) { +- hasPresets = true; +- +- menu->addChild(createSubmenuItem(name, "", [=](ui::Menu* menu) { +- if (!moduleWidget) +- return; +- appendPresetItems(menu, moduleWidget, path); +- })); ++ if (false) { + } + else if (system::getExtension(path) == ".vcvm" && name != "template") { ++ if (!hasPresets) ++ menu->addChild(new ui::MenuSeparator); ++ + hasPresets = true; + + menu->addChild(createMenuItem(name, "", [=]() { +@@ -963,15 +993,12 @@ + moduleWidget->loadAction(path); + } + catch (Exception& e) { +- osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK, e.what()); ++ async_dialog_message(e.what()); + } + })); + } + } + } +- if (!hasPresets) { +- menu->addChild(createMenuLabel("(None)")); +- } + }; + + +@@ -1010,6 +1037,7 @@ + weakThis->loadDialog(); + })); + ++ /* TODO requires setting up user dir + menu->addChild(createMenuItem("Save as", "", [=]() { + if (!weakThis) + return; +@@ -1032,10 +1060,13 @@ + menu->addChild(new ui::MenuSeparator); + menu->addChild(createMenuLabel("User presets")); + appendPresetItems(menu, weakThis, weakThis->model->getUserPresetDirectory()); ++ */ + + // Scan `/presets/` for presets. ++ /* TODO enable only after setting up user dir + menu->addChild(new ui::MenuSeparator); + menu->addChild(createMenuLabel("Factory presets")); ++ */ + appendPresetItems(menu, weakThis, weakThis->model->getFactoryPresetDirectory()); + })); + +@@ -1127,4 +1158,4 @@ + + + } // namespace app +-} // namespace rack +\ No newline at end of file ++} // namespace rack diff --git a/src/override/diffs/OpenGlWidget.cpp.diff b/src/override/diffs/OpenGlWidget.cpp.diff index 3a18876..261123f 100644 --- a/src/override/diffs/OpenGlWidget.cpp.diff +++ b/src/override/diffs/OpenGlWidget.cpp.diff @@ -1,5 +1,5 @@ ---- ../Rack/src/widget/OpenGlWidget.cpp 2022-11-23 23:11:38.000000000 +0000 -+++ OpenGlWidget.cpp 2022-11-23 23:06:41.000000000 +0000 +--- ../Rack/src/widget/OpenGlWidget.cpp 2022-09-21 20:25:53.593040323 +0100 ++++ OpenGlWidget.cpp 2022-09-21 20:18:50.294557597 +0100 @@ -1,3 +1,30 @@ +/* + * DISTRHO Cardinal Plugin diff --git a/src/override/diffs/Scene.cpp.diff b/src/override/diffs/Scene.cpp.diff index 5fac20a..4d1da9f 100644 --- a/src/override/diffs/Scene.cpp.diff +++ b/src/override/diffs/Scene.cpp.diff @@ -1,5 +1,5 @@ ---- ../Rack/src/app/Scene.cpp 2022-11-23 23:11:38.000000000 +0000 -+++ Scene.cpp 2022-11-25 22:32:04.000000000 +0000 +--- ../Rack/src/app/Scene.cpp 2022-09-21 20:25:53.591040280 +0100 ++++ Scene.cpp 2022-09-21 20:18:50.294557597 +0100 @@ -1,3 +1,30 @@ +/* + * DISTRHO Cardinal Plugin diff --git a/src/override/diffs/Window.cpp.diff b/src/override/diffs/Window.cpp.diff index be862b6..c9866e9 100644 --- a/src/override/diffs/Window.cpp.diff +++ b/src/override/diffs/Window.cpp.diff @@ -1,5 +1,5 @@ ---- ../Rack/src/window/Window.cpp 2022-11-23 23:11:38.000000000 +0000 -+++ Window.cpp 2022-11-25 22:32:06.000000000 +0000 +--- ../Rack/src/window/Window.cpp 2022-09-21 20:25:53.593040323 +0100 ++++ Window.cpp 2022-09-21 20:18:50.294557597 +0100 @@ -1,33 +1,87 @@ +/* + * DISTRHO Cardinal Plugin diff --git a/src/override/diffs/blendish.c.diff b/src/override/diffs/blendish.c.diff index 907df01..d1c1b8a 100644 --- a/src/override/diffs/blendish.c.diff +++ b/src/override/diffs/blendish.c.diff @@ -1,5 +1,5 @@ ---- ../Rack/dep/oui-blendish/blendish.c 2022-11-23 23:11:56.000000000 +0000 -+++ blendish.c 2022-11-23 23:06:41.000000000 +0000 +--- ../Rack/dep/oui-blendish/blendish.c 2022-09-21 20:26:10.733413463 +0100 ++++ blendish.c 2022-09-21 20:18:50.294557597 +0100 @@ -61,7 +61,7 @@ } diff --git a/src/override/diffs/common.cpp.diff b/src/override/diffs/common.cpp.diff index 36b5215..2569432 100644 --- a/src/override/diffs/common.cpp.diff +++ b/src/override/diffs/common.cpp.diff @@ -1,5 +1,5 @@ ---- ../Rack/src/common.cpp 2022-11-23 23:11:38.000000000 +0000 -+++ common.cpp 2022-11-25 22:32:13.000000000 +0000 +--- ../Rack/src/common.cpp 2022-09-21 20:25:53.591040280 +0100 ++++ common.cpp 2022-09-21 20:18:50.294557597 +0100 @@ -1,33 +1,77 @@ +/* + * DISTRHO Cardinal Plugin diff --git a/src/override/diffs/context.cpp.diff b/src/override/diffs/context.cpp.diff index 837b5b9..d34fba3 100644 --- a/src/override/diffs/context.cpp.diff +++ b/src/override/diffs/context.cpp.diff @@ -1,5 +1,5 @@ ---- ../Rack/src/context.cpp 2022-11-23 23:11:38.000000000 +0000 -+++ context.cpp 2022-11-25 22:31:32.000000000 +0000 +--- ../Rack/src/context.cpp 2022-09-21 20:25:53.591040280 +0100 ++++ context.cpp 2022-09-21 20:18:50.294557597 +0100 @@ -1,3 +1,30 @@ +/* + * DISTRHO Cardinal Plugin @@ -31,22 +31,21 @@ #include #include #include -@@ -6,10 +33,14 @@ +@@ -6,9 +33,13 @@ #include #include +#ifdef NDEBUG +# undef DEBUG +#endif -+ + +-namespace rack { +#include "DistrhoUtils.hpp" - namespace rack { ++namespace rack { -- Context::~Context() { // Deleting NULL is safe in C++. - @@ -44,7 +75,7 @@ static thread_local Context* threadContext = NULL; diff --git a/src/override/diffs/minblep.cpp.diff b/src/override/diffs/minblep.cpp.diff index b97a6f7..2af153a 100644 --- a/src/override/diffs/minblep.cpp.diff +++ b/src/override/diffs/minblep.cpp.diff @@ -1,5 +1,5 @@ ---- ../Rack/src/dsp/minblep.cpp 2022-11-23 23:11:38.000000000 +0000 -+++ minblep.cpp 2022-11-23 23:06:41.000000000 +0000 +--- ../Rack/src/dsp/minblep.cpp 2022-09-21 20:25:53.592040301 +0100 ++++ minblep.cpp 2022-09-21 20:18:50.295557620 +0100 @@ -1,3 +1,30 @@ +/* + * DISTRHO Cardinal Plugin diff --git a/src/override/diffs/plugin.cpp.diff b/src/override/diffs/plugin.cpp.diff index c2c7027..c49eb23 100644 --- a/src/override/diffs/plugin.cpp.diff +++ b/src/override/diffs/plugin.cpp.diff @@ -1,5 +1,5 @@ ---- ../Rack/src/plugin.cpp 2022-11-23 23:11:38.000000000 +0000 -+++ plugin.cpp 2022-11-25 23:27:58.000000000 +0000 +--- ../Rack/src/plugin.cpp 2022-09-21 20:25:53.592040301 +0100 ++++ plugin.cpp 2022-11-29 19:49:19.197926669 +0000 @@ -1,342 +1,41 @@ -#include -#include