Move all liblo stuff to the same file, add crude auto-deploy mode

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2022-01-24 11:28:23 +00:00
parent 31c108c9ae
commit e29243af60
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
7 changed files with 347 additions and 175 deletions

View file

@ -1,5 +1,5 @@
--- ../Rack/src/app/Scene.cpp 2021-12-14 21:35:44.414568198 +0000
+++ Scene.cpp 2022-01-23 17:13:24.715889665 +0000
+++ Scene.cpp 2022-01-24 11:12:33.268767988 +0000
@@ -1,3 +1,30 @@
+/*
+ * DISTRHO Cardinal Plugin
@ -31,11 +31,28 @@
#include <thread>
#include <osdialog.h>
@@ -14,31 +41,49 @@
@@ -7,6 +34,7 @@
#include <app/TipWindow.hpp>
#include <app/MenuBar.hpp>
#include <context.hpp>
+#include <engine/Engine.hpp>
#include <system.hpp>
#include <network.hpp>
#include <history.hpp>
@@ -14,31 +42,58 @@
#include <patch.hpp>
#include <asset.hpp>
+#ifdef NDEBUG
+# undef DEBUG
+#endif
+
+#ifdef HAVE_LIBLO
+# include <lo/lo.h>
+#endif
+
+#include "../CardinalCommon.hpp"
+#include "DistrhoUtils.hpp"
+
namespace rack {
@ -74,16 +91,16 @@
+ nvgStroke(args.vg);
+
+ nvgStrokeColor(args.vg, nvgRGBf(0, 0, 0));
+
+ nvgBeginPath(args.vg);
+ nvgMoveTo(args.vg, box.size.x+1, 0);
+ nvgLineTo(args.vg, 0, box.size.y+1);
+ nvgStroke(args.vg);
- void onDragMove(const DragMoveEvent& e) override {
- size = size.plus(e.mouseDelta);
- APP->window->setSize(size.round());
+ nvgBeginPath(args.vg);
+ nvgMoveTo(args.vg, box.size.x+1, 0);
+ nvgLineTo(args.vg, 0, box.size.y+1);
+ nvgStroke(args.vg);
+
+ nvgBeginPath(args.vg);
+ nvgMoveTo(args.vg, box.size.x + 6, 0);
+ nvgLineTo(args.vg, 0, box.size.y + 6);
+ nvgStroke(args.vg);
@ -95,25 +112,42 @@
}
};
@@ -46,12 +91,15 @@
@@ -46,9 +101,32 @@
struct Scene::Internal {
ResizeHandle* resizeHandle;
- double lastAutosaveTime = 0.0;
-
bool heldArrowKeys[4] = {};
+
+#ifdef HAVE_LIBLO
+ double lastSceneChangeTime = 0.0;
+ int historyActionIndex = -1;
+
+ bool oscAutoDeploy = false;
+ bool oscConnected = false;
+ lo_server oscServer = nullptr;
+
+ static int osc_handler(const char* const path, const char* const types, lo_arg** argv, const int argc, lo_message, void* const self)
+ {
+ d_stdout("osc_handler(\"%s\", \"%s\", %p, %i)", path, types, argv, argc);
+
+ if (std::strcmp(path, "/resp") == 0 && argc == 2 && types[0] == 's' && types[1] == 's') {
+ d_stdout("osc_handler(\"%s\", ...) - got resp | '%s' '%s'", path, &argv[0]->s, &argv[1]->s);
+ if (std::strcmp(&argv[0]->s, "hello") == 0 && std::strcmp(&argv[1]->s, "ok") == 0)
+ static_cast<Internal*>(self)->oscConnected = true;
+ }
+ return 0;
+ }
+
+ ~Internal() {
+ lo_server_free(oscServer);
+ }
+#endif
};
+void hideResizeHandle(Scene* scene) {
+ scene->internal->resizeHandle->hide();
+}
+
+
Scene::Scene() {
internal = new Internal;
@@ -67,13 +115,8 @@
@@ -67,17 +145,17 @@
browser->hide();
addChild(browser);
@ -128,7 +162,16 @@
addChild(internal->resizeHandle);
}
@@ -89,32 +132,13 @@
+void hideResizeHandle(Scene* scene) {
+ scene->internal->resizeHandle->hide();
+}
+
+
Scene::~Scene() {
delete internal;
}
@@ -89,32 +167,13 @@
void Scene::step() {
@ -162,7 +205,30 @@
// Scroll RackScrollWidget with arrow keys
math::Vec arrowDelta;
if (internal->heldArrowKeys[0]) {
@@ -172,7 +196,7 @@
@@ -143,6 +202,22 @@
rackScroll->offset += arrowDelta * arrowSpeed;
}
+#ifdef HAVE_LIBLO
+ if (internal->oscServer != nullptr) {
+ while (lo_server_recv_noblock(internal->oscServer, 0) != 0) {}
+
+ if (internal->oscAutoDeploy) {
+ const int actionIndex = APP->history->actionIndex;
+ const double time = system::getTime();
+ if (internal->historyActionIndex != actionIndex && time - internal->lastSceneChangeTime >= 5.0) {
+ internal->historyActionIndex = actionIndex;
+ internal->lastSceneChangeTime = time;
+ patchUtils::deployToRemote();
+ }
+ }
+ }
+#endif
+
Widget::step();
}
@@ -172,7 +247,7 @@
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) {
// DEBUG("key '%d '%c' scancode %d '%c' keyName '%s'", e.key, e.key, e.scancode, e.scancode, e.keyName.c_str());
if (e.keyName == "n" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
@ -171,7 +237,7 @@
e.consume(this);
}
if (e.keyName == "q" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
@@ -180,19 +204,20 @@
@@ -180,19 +255,20 @@
e.consume(this);
}
if (e.keyName == "o" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
@ -196,7 +262,7 @@
e.consume(this);
}
if (e.keyName == "z" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
@@ -232,10 +257,8 @@
@@ -232,10 +308,8 @@
settings::cpuMeter ^= true;
e.consume(this);
}
@ -205,11 +271,11 @@
- // The MenuBar will be hidden when the mouse moves over the RackScrollWidget.
- // menuBar->hide();
+ if (e.key == GLFW_KEY_F7 && (e.mods & RACK_MOD_MASK) == 0) {
+ patchUtils::deployToMOD();
+ patchUtils::deployToRemote();
e.consume(this);
}
@@ -326,13 +349,6 @@
@@ -326,13 +400,6 @@
// Key commands that can be overridden by children
if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) {
@ -223,7 +289,7 @@
if (e.keyName == "v" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
rack->pasteClipboardAction();
e.consume(this);
@@ -351,7 +367,7 @@
@@ -351,7 +418,7 @@
std::string extension = system::getExtension(path);
if (extension == ".vcv") {
@ -232,3 +298,77 @@
e.consume(this);
return;
}
@@ -368,3 +435,73 @@
} // namespace app
} // namespace rack
+
+
+namespace patchUtils {
+
+
+bool connectToRemote() {
+ rack::app::Scene::Internal* const internal = APP->scene->internal;
+
+ if (internal->oscServer == nullptr) {
+ const lo_server oscServer = lo_server_new_with_proto(nullptr, LO_UDP, nullptr);
+ DISTRHO_SAFE_ASSERT_RETURN(oscServer != nullptr, false);
+ lo_server_add_method(oscServer, "/resp", nullptr, rack::app::Scene::Internal::osc_handler, internal);
+ internal->oscServer = oscServer;
+ }
+
+ const lo_address addr = lo_address_new_with_proto(LO_UDP, REMOTE_HOST, REMOTE_HOST_PORT);
+ DISTRHO_SAFE_ASSERT_RETURN(addr != nullptr, false);
+ lo_send(addr, "/hello", "");
+ lo_address_free(addr);
+
+ return true;
+}
+
+
+bool isRemoteConnected() {
+#ifdef HAVE_LIBLO
+ return APP->scene->internal->oscConnected;
+#else
+ return false;
+#endif
+}
+
+
+bool isRemoteAutoDeployed() {
+#ifdef HAVE_LIBLO
+ return APP->scene->internal->oscAutoDeploy;
+#else
+ return false;
+#endif
+}
+
+
+void setRemoteAutoDeploy(bool autoDeploy) {
+#ifdef HAVE_LIBLO
+ APP->scene->internal->oscAutoDeploy = autoDeploy;
+#endif
+}
+
+
+void deployToRemote() {
+#ifdef HAVE_LIBLO
+ const lo_address addr = lo_address_new_with_proto(LO_UDP, REMOTE_HOST, REMOTE_HOST_PORT);
+ DISTRHO_SAFE_ASSERT_RETURN(addr != nullptr,);
+
+ APP->engine->prepareSave();
+ APP->patch->saveAutosave();
+ APP->patch->cleanAutosave();
+ std::vector<uint8_t> data(rack::system::archiveDirectory(APP->patch->autosavePath, 1));
+
+ if (const lo_blob blob = lo_blob_new(data.size(), data.data())) {
+ lo_send(addr, "/load", "b", blob);
+ lo_blob_free(blob);
+ }
+
+ lo_address_free(addr);
+#endif
+}
+
+
+} // namespace patchUtils