Update and adapt to Rack 2.3

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2023-05-20 19:38:29 +02:00
parent 03055c2563
commit 1262f318da
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
41 changed files with 901 additions and 727 deletions

View file

@ -1,9 +1,9 @@
--- ../Rack/src/app/MenuBar.cpp 2022-09-21 19:49:12.198540676 +0100
+++ MenuBar.cpp 2022-12-30 14:50:06.801891005 +0000
--- ../Rack/src/app/MenuBar.cpp 2023-05-20 17:03:33.005081737 +0200
+++ MenuBar.cpp 2023-05-20 19:32:57.019576570 +0200
@@ -1,8 +1,33 @@
+/*
+ * DISTRHO Cardinal Plugin
+ * Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2021-2023 Filipe Coelho <falktx@falktx.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
@ -20,7 +20,7 @@
+
+/**
+ * This file is an edited version of VCVRack's app/MenuBar.cpp
+ * Copyright (C) 2016-2021 VCV.
+ * Copyright (C) 2016-2023 VCV.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
@ -44,7 +44,7 @@
#include <window/Window.hpp>
#include <asset.hpp>
#include <context.hpp>
@@ -25,8 +51,28 @@
@@ -25,8 +51,26 @@
#include <patch.hpp>
#include <library.hpp>
@ -56,8 +56,6 @@
+#ifdef HAVE_LIBLO
+# include <lo/lo.h>
+#endif
+
+void switchDarkMode(bool darkMode);
namespace rack {
+namespace asset {
@ -73,7 +71,7 @@
namespace app {
namespace menuBar {
@@ -48,79 +94,160 @@
@@ -48,79 +92,180 @@
};
@ -97,15 +95,16 @@
struct FileButton : MenuButton {
+ const bool isStandalone;
+#if ! CARDINAL_VARIANT_MINI
+ std::vector<std::string> demoPatches;
+#endif
+
+ FileButton(const bool standalone)
+ : MenuButton(), isStandalone(standalone)
+ {
+#if ! CARDINAL_VARIANT_MINI
+#if CARDINAL_VARIANT_MINI
+ const std::string patchesDir = asset::patchesPath() + DISTRHO_OS_SEP_STR "mini";
+#else
+ const std::string patchesDir = asset::patchesPath() + DISTRHO_OS_SEP_STR "examples";
+#endif
+
+ if (system::isDirectory(patchesDir))
+ {
@ -114,7 +113,6 @@
+ return string::lowercase(a) < string::lowercase(b);
+ });
+ }
+#endif
+ }
+
void onAction(const ActionEvent& e) override {
@ -125,31 +123,36 @@
- menu->addChild(createMenuItem("New", RACK_MOD_CTRL_NAME "+N", []() {
- APP->patch->loadTemplateDialog();
+#ifndef DISTRHO_OS_WASM
+ const char* const NewShortcut = RACK_MOD_CTRL_NAME "+N";
+ constexpr const char* const NewShortcut = RACK_MOD_CTRL_NAME "+N";
+#else
+ const char* const NewShortcut = "";
+ constexpr const char* const NewShortcut = "";
+#endif
+ menu->addChild(createMenuItem("New", NewShortcut, []() {
+ patchUtils::loadTemplateDialog();
+ patchUtils::loadTemplateDialog(false);
+ }));
+
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
+#ifndef DISTRHO_OS_WASM
+ menu->addChild(createMenuItem("New (factory template)", "", []() {
+ patchUtils::loadTemplateDialog(true);
}));
- menu->addChild(createMenuItem("Open", RACK_MOD_CTRL_NAME "+O", []() {
- APP->patch->loadDialog();
+#if ! CARDINAL_VARIANT_MINI
+#ifndef DISTRHO_OS_WASM
+ menu->addChild(createMenuItem("Open / Import...", RACK_MOD_CTRL_NAME "+O", []() {
+ patchUtils::loadDialog();
}));
- menu->addChild(createSubmenuItem("Open recent", "", [](ui::Menu* menu) {
- for (const std::string& path : settings::recentPatchPaths) {
- std::string name = system::getStem(path);
- menu->addChild(createMenuItem(name, "", [=]() {
menu->addChild(createSubmenuItem("Open recent", "", [](ui::Menu* menu) {
for (const std::string& path : settings::recentPatchPaths) {
std::string name = system::getStem(path);
menu->addChild(createMenuItem(name, "", [=]() {
- APP->patch->loadPathDialog(path);
- }));
- }
- }, settings::recentPatchPaths.empty()));
-
+ patchUtils::loadPathDialog(path, false);
}));
}
}, settings::recentPatchPaths.empty()));
menu->addChild(createMenuItem("Save", RACK_MOD_CTRL_NAME "+S", []() {
- APP->patch->saveDialog();
+ // NOTE: will do nothing if path is empty, intentionally
@ -188,20 +191,31 @@
+ patchUtils::revertDialog();
+ }, APP->patch->path.empty()));
- menu->addChild(createMenuItem("Overwrite template", "", []() {
menu->addChild(createMenuItem("Overwrite template", "", []() {
- APP->patch->saveTemplateDialog();
- }));
+#if defined(HAVE_LIBLO) && ! CARDINAL_VARIANT_MINI
+ menu->addChild(new ui::MenuSeparator);
+
+ patchUtils::saveTemplateDialog();
}));
+#if defined(HAVE_LIBLO) || ! DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
+#ifdef __MOD_DEVICES__
+#define REMOTE_NAME "MOD"
+#else
+#define REMOTE_NAME "Remote"
+#endif
menu->addChild(new ui::MenuSeparator);
- // Load selection
- menu->addChild(createMenuItem("Import selection", "", [=]() {
- APP->scene->rack->loadSelectionDialog();
- }, false, true));
+ remoteUtils::RemoteDetails* const remoteDetails = remoteUtils::getRemote();
+
+ if (remoteDetails != nullptr && remoteDetails->connected) {
+ menu->addChild(createMenuItem("Deploy to MOD", "F7", [remoteDetails]() {
+ menu->addChild(createMenuItem("Deploy to " REMOTE_NAME, "F7", [remoteDetails]() {
+ remoteUtils::sendFullPatchToRemote(remoteDetails);
+ }));
+ menu->addChild(createCheckMenuItem("Auto deploy to MOD", "",
+ menu->addChild(createCheckMenuItem("Auto deploy to " REMOTE_NAME, "",
+ [remoteDetails]() {return remoteDetails->autoDeploy;},
+ [remoteDetails]() {
+ remoteDetails->autoDeploy = !remoteDetails->autoDeploy;
@ -209,34 +223,29 @@
+ }
+ ));
+ } else {
+ menu->addChild(createMenuItem("Connect to MOD", "", []() {
+ menu->addChild(createMenuItem("Connect to " REMOTE_NAME, "", []() {
+ DISTRHO_SAFE_ASSERT(remoteUtils::connectToRemote());
+ }));
+ }
+#endif
+
+#if ! CARDINAL_VARIANT_MINI
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
+#ifndef DISTRHO_OS_WASM
menu->addChild(new ui::MenuSeparator);
// Load selection
- menu->addChild(createMenuItem("Import selection", "", [=]() {
- APP->scene->rack->loadSelectionDialog();
+ menu->addChild(createMenuItem("Import selection...", "", [=]() {
+ patchUtils::loadSelectionDialog();
}, false, true));
- menu->addChild(new ui::MenuSeparator);
-
- menu->addChild(createMenuItem("Quit", RACK_MOD_CTRL_NAME "+Q", []() {
- APP->window->close();
+ // Load selection
+ menu->addChild(createMenuItem("Import selection...", "", [=]() {
+ patchUtils::loadSelectionDialog();
+ }, false, true));
+
+ menu->addChild(createMenuItem("Export uncompressed json...", "", []() {
+ patchUtils::saveAsDialogUncompressed();
}));
+#endif
+#endif
+
+#if ! CARDINAL_VARIANT_MINI
+ if (!demoPatches.empty())
+ {
+ menu->addChild(new ui::MenuSeparator);
@ -262,7 +271,6 @@
+ }));
+ }));
+ }
+#endif
+
+#ifndef DISTRHO_OS_WASM
+ if (isStandalone) {
@ -276,7 +284,7 @@
}
};
@@ -166,7 +293,7 @@
@@ -166,7 +311,7 @@
menu->addChild(new ui::MenuSeparator);
@ -285,7 +293,7 @@
}
};
@@ -256,7 +383,7 @@
@@ -256,7 +401,7 @@
return settings::cableTension;
}
float getDefaultValue() override {
@ -294,7 +302,7 @@
}
float getDisplayValue() override {
return getValue() * 100;
@@ -393,36 +520,37 @@
@@ -393,49 +538,36 @@
};
@ -327,17 +335,34 @@
- menu->addChild(createMenuItem("Fullscreen", fullscreenText, [=]() {
- APP->window->setFullScreen(!fullscreen);
- }));
+ menu->addChild(createMenuLabel("Appearance"));
- double frameRate = APP->window->getMonitorRefreshRate() / settings::frameSwapInterval;
- menu->addChild(createSubmenuItem("Frame rate", string::f("%.0f Hz", frameRate), [=](ui::Menu* menu) {
-
- menu->addChild(createSubmenuItem("Frame rate", string::f("%.0f Hz", settings::frameRateLimit), [=](ui::Menu* menu) {
- for (int i = 1; i <= 6; i++) {
- double frameRate = APP->window->getMonitorRefreshRate() / i;
- menu->addChild(createCheckMenuItem(string::f("%.0f Hz", frameRate), "",
- [=]() {return settings::frameSwapInterval == i;},
- [=]() {settings::frameSwapInterval = i;}
- [=]() {return settings::frameRateLimit == frameRate;},
- [=]() {settings::frameRateLimit = frameRate;}
- ));
- }
- }));
-
- menu->addChild(new ui::MenuSeparator);
menu->addChild(createMenuLabel("Appearance"));
- static const std::vector<std::string> uiThemes = {"dark", "light", "hcdark"};
- static const std::vector<std::string> uiThemeLabels = {"Dark", "Light", "High contrast dark"};
- menu->addChild(createIndexSubmenuItem("Theme", uiThemeLabels,
- [=]() -> size_t {
- auto it = std::find(uiThemes.begin(), uiThemes.end(), settings::uiTheme);
- if (it == uiThemes.end())
- return -1;
- return it - uiThemes.begin();
- },
- [=](size_t i) {
- settings::uiTheme = uiThemes[i];
- ui::refreshTheme();
- }
- ));
+ std::string darkModeText;
+ if (settings::darkMode)
+ darkModeText = CHECKMARK_STRING;
@ -345,15 +370,11 @@
+ switchDarkMode(!settings::darkMode);
+ plugin::updateStaticPluginsDarkMode();
+ setAllFramebufferWidgetsDirty(APP->scene);
}));
+ }));
- menu->addChild(new ui::MenuSeparator);
- menu->addChild(createMenuLabel("Appearance"));
-
menu->addChild(createBoolPtrMenuItem("Show tooltips", "", &settings::tooltips));
ZoomSlider* zoomSlider = new ZoomSlider;
@@ -446,9 +574,18 @@
@@ -460,9 +592,18 @@
menu->addChild(haloBrightnessSlider);
menu->addChild(new ui::MenuSeparator);
@ -372,13 +393,14 @@
static const std::vector<std::string> knobModeLabels = {
"Linear",
@@ -473,11 +610,34 @@
@@ -487,11 +628,34 @@
menu->addChild(knobScrollSensitivitySlider);
menu->addChild(new ui::MenuSeparator);
- menu->addChild(createMenuLabel("Module dragging"));
- menu->addChild(createMenuLabel("Module"));
+ menu->addChild(createMenuLabel("Window"));
+
- menu->addChild(createBoolPtrMenuItem("Lock positions", "", &settings::lockModules));
+#ifdef DISTRHO_OS_WASM
+ const bool fullscreen = APP->window->isFullScreen();
+ std::string rightText = "F11";
@ -388,8 +410,7 @@
+ APP->window->setFullScreen(!fullscreen);
+ }));
+#endif
- menu->addChild(createBoolPtrMenuItem("Lock positions", "", &settings::lockModules));
+
+ menu->addChild(createBoolPtrMenuItem("Invert zoom", "", &settings::invertZoom));
- menu->addChild(createBoolPtrMenuItem("Auto-squeeze algorithm (experimental)", "", &settings::squeezeModules));
@ -410,7 +431,7 @@
}
};
@@ -487,47 +647,6 @@
@@ -501,47 +665,6 @@
////////////////////
@ -458,7 +479,7 @@
struct EngineButton : MenuButton {
void onAction(const ActionEvent& e) override {
ui::Menu* menu = createMenu();
@@ -541,268 +660,46 @@
@@ -555,268 +678,46 @@
settings::cpuMeter ^= true;
}));
@ -614,10 +635,10 @@
+ }));
}
- }
-
- MenuItem::step();
- }
-
- void onAction(const ActionEvent& e) override {
- std::thread t([=] {
- library::syncUpdate(slug);
@ -726,11 +747,11 @@
- });
- t.detach();
- }
-
- void step() override {
- notification->box.pos = math::Vec(0, 0);
- notification->visible = library::hasUpdates();
-
- // Popup when updates finish downloading
- if (library::restartRequested) {
- library::restartRequested = false;
@ -760,7 +781,7 @@
}
};
@@ -813,65 +710,23 @@
@@ -827,32 +728,17 @@
struct HelpButton : MenuButton {
@ -778,32 +799,29 @@
- menu->addChild(createMenuItem("Tips", "", [=]() {
- APP->scene->addChild(tipWindowCreate());
- }));
-
+ menu->addChild(createMenuItem("Rack User manual", "F1", [=]() {
+ patchUtils::openBrowser("https://vcvrack.com/manual");
}));
- menu->addChild(createMenuItem("User manual", "F1", [=]() {
- system::openBrowser("https://vcvrack.com/manual");
- }));
-
- menu->addChild(createMenuItem("Support", "", [=]() {
- system::openBrowser("https://vcvrack.com/support");
+ menu->addChild(createMenuItem("Rack User manual", "F1", [=]() {
+ patchUtils::openBrowser("https://vcvrack.com/manual");
}));
- }));
-
- menu->addChild(createMenuItem("VCVRack.com", "", [=]() {
- system::openBrowser("https://vcvrack.com/");
+ menu->addChild(createMenuItem("Cardinal Project page", "", [=]() {
+ menu->addChild(createMenuItem("Cardinal project page", "", [=]() {
+ patchUtils::openBrowser("https://github.com/DISTRHO/Cardinal/");
}));
menu->addChild(new ui::MenuSeparator);
@@ -861,29 +747,9 @@
system::openDirectory(asset::user(""));
}));
- menu->addChild(createMenuLabel(APP_NAME + " " + APP_EDITION_NAME + " " + APP_VERSION));
-
- menu->addChild(createMenuItem("Open user folder", "", [=]() {
- system::openDirectory(asset::user(""));
- }));
-
- menu->addChild(createMenuItem("Changelog", "", [=]() {
- system::openBrowser("https://github.com/VCVRack/Rack/blob/v2/CHANGELOG.md");
- }));
@ -822,34 +840,42 @@
- }, false, true));
- }
- }
-
+ menu->addChild(new ui::MenuSeparator);
- void step() override {
- notification->box.pos = math::Vec(0, 0);
- notification->visible = library::isAppUpdateAvailable();
- MenuButton::step();
+ menu->addChild(createMenuLabel("Cardinal " + APP_EDITION + " " + CARDINAL_VERSION));
+ menu->addChild(createMenuLabel("Rack " + APP_VERSION + " Compatible"));
}
};
@@ -910,9 +765,14 @@
// uiLastTime = time;
// }
@@ -926,15 +792,19 @@
+#if CARDINAL_VARIANT_MINI
+ text = string::f("%.1f fps", 1.0 / frameDurationAvg);
text = "";
- if (box.size.x >= 460) {
+ if (box.size.x >= 400) {
double fps = std::isfinite(frameDurationAvg) ? 1.0 / frameDurationAvg : 0.0;
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
double meterAverage = APP->engine->getMeterAverage();
double meterMax = APP->engine->getMeterMax();
- text += string::f("%.1f fps %.1f%% avg %.1f%% max", fps, meterAverage * 100, meterMax * 100);
+ text = string::f("%.1f fps %.1f%% avg %.1f%% max", fps, meterAverage * 100, meterMax * 100);
+#else
double meterAverage = APP->engine->getMeterAverage();
double meterMax = APP->engine->getMeterMax();
text = string::f("%.1f fps %.1f%% avg %.1f%% max", 1.0 / frameDurationAvg, meterAverage * 100, meterMax * 100);
+ text = string::f("%.1f fps", fps);
+#endif
+
text += " ";
}
- text += APP_NAME + " " + APP_EDITION_NAME + " " + APP_VERSION + " " + APP_OS_NAME + " " + APP_CPU_NAME;
+ text += "Cardinal " + APP_EDITION + " " + CARDINAL_VERSION;
Label::step();
}
};
@@ -921,7 +781,9 @@
@@ -944,7 +814,9 @@
struct MenuBar : widget::OpaqueWidget {
MeterLabel* meterLabel;
InfoLabel* infoLabel;
- MenuBar() {
+ MenuBar(const bool isStandalone)
@ -858,7 +884,7 @@
const float margin = 5;
box.size.y = BND_WIDGET_HEIGHT + 2 * margin;
@@ -930,7 +792,7 @@
@@ -953,7 +825,7 @@
layout->spacing = math::Vec(0, 0);
addChild(layout);
@ -867,11 +893,11 @@
fileButton->text = "File";
layout->addChild(fileButton);
@@ -942,13 +804,11 @@
@@ -965,13 +837,11 @@
viewButton->text = "View";
layout->addChild(viewButton);
+#if ! CARDINAL_VARIANT_MINI
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
EngineButton* engineButton = new EngineButton;
engineButton->text = "Engine";
layout->addChild(engineButton);
@ -883,7 +909,7 @@
HelpButton* helpButton = new HelpButton;
helpButton->text = "Help";
@@ -984,7 +844,7 @@
@@ -1003,7 +873,7 @@
widget::Widget* createMenuBar() {