|
- --- ../Rack/src/app/Scene.cpp 2023-06-11 21:02:02.640002965 +0200
- +++ Scene.cpp 2023-06-11 20:56:09.476002797 +0200
- @@ -1,12 +1,36 @@
- -#include <thread>
- -
- -#include <osdialog.h>
- +/*
- + * DISTRHO Cardinal Plugin
- + * 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
- + * published by the Free Software Foundation; either version 3 of
- + * the License, or any later version.
- + *
- + * This program is distributed in the hope that it will be useful,
- + * but WITHOUT ANY WARRANTY; without even the implied warranty of
- + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- + * GNU General Public License for more details.
- + *
- + * For a full copy of the GNU General Public License see the LICENSE file.
- + */
- +
- +/**
- + * This file is an edited version of VCVRack's app/Scene.cpp
- + * 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
- + * published by the Free Software Foundation; either version 3 of
- + * the License, or (at your option) any later version.
- + */
-
- #include <app/Scene.hpp>
- #include <app/Browser.hpp>
- #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,6 +38,14 @@
- #include <patch.hpp>
- #include <asset.hpp>
-
- +#ifdef NDEBUG
- +# undef DEBUG
- +#endif
- +
- +#include "../CardinalCommon.hpp"
- +#include "../CardinalRemote.hpp"
- +
- +#include <algorithm>
-
- namespace rack {
- namespace app {
- @@ -23,32 +55,72 @@
- math::Vec size;
-
- void draw(const DrawArgs& args) override {
- + nvgStrokeColor(args.vg, nvgRGBf(1, 1, 1));
- + nvgStrokeWidth(args.vg, 1);
- +
- nvgBeginPath(args.vg);
- - nvgMoveTo(args.vg, box.size.x, box.size.y);
- + nvgMoveTo(args.vg, box.size.x, 0);
- nvgLineTo(args.vg, 0, box.size.y);
- - nvgLineTo(args.vg, box.size.x, 0);
- - nvgClosePath(args.vg);
- - nvgFillColor(args.vg, nvgRGBAf(1, 1, 1, 0.15));
- - nvgFill(args.vg);
- + nvgStroke(args.vg);
- +
- + nvgBeginPath(args.vg);
- + nvgMoveTo(args.vg, box.size.x + 5, 0);
- + nvgLineTo(args.vg, 0, box.size.y + 5);
- + nvgStroke(args.vg);
- +
- + nvgBeginPath(args.vg);
- + nvgMoveTo(args.vg, box.size.x + 10, 0);
- + nvgLineTo(args.vg, 0, box.size.y + 10);
- + 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);
- +
- + nvgBeginPath(args.vg);
- + nvgMoveTo(args.vg, box.size.x + 6, 0);
- + nvgLineTo(args.vg, 0, box.size.y + 6);
- + nvgStroke(args.vg);
- +
- + nvgBeginPath(args.vg);
- + nvgMoveTo(args.vg, box.size.x + 11, 0);
- + nvgLineTo(args.vg, 0, box.size.y + 11);
- + nvgStroke(args.vg);
- + }
- +
- + void onHover(const HoverEvent& e) override {
- + e.consume(this);
- }
-
- - void onDragStart(const DragStartEvent& e) override {
- + void onEnter(const EnterEvent& e) override {
- + glfwSetCursor(APP->window->win, glfwCreateStandardCursor(GLFW_RESIZE_NWSE_CURSOR));
- + }
- +
- + void onLeave(const LeaveEvent& e) override {
- + glfwSetCursor(APP->window->win, nullptr);
- + }
- +
- + void onDragStart(const DragStartEvent&) override {
- size = APP->window->getSize();
- }
-
- void onDragMove(const DragMoveEvent& e) override {
- - size = size.plus(e.mouseDelta);
- + size = size.plus(e.mouseDelta.mult(APP->window->pixelRatio));
- APP->window->setSize(size.round());
- }
- };
-
-
- struct Scene::Internal {
- - ResizeHandle* resizeHandle;
- -
- - double lastAutosaveTime = 0.0;
- + ResizeHandle* resizeHandle = nullptr;
-
- bool heldArrowKeys[4] = {};
- +
- + double lastSceneChangeTime = 0.0;
- + int historyActionIndex = -1;
- };
-
-
- @@ -67,13 +139,11 @@
- browser->hide();
- addChild(browser);
-
- - if (settings::showTipsOnLaunch) {
- - addChild(tipWindowCreate());
- - }
- + if (isStandalone() || isMini())
- + return;
-
- internal->resizeHandle = new ResizeHandle;
- - internal->resizeHandle->box.size = math::Vec(15, 15);
- - internal->resizeHandle->hide();
- + internal->resizeHandle->box.size = math::Vec(16, 16);
- addChild(internal->resizeHandle);
- }
-
- @@ -99,22 +169,13 @@
- rackScroll->box.pos.y = menuBar->box.size.y;
- }
-
- - internal->resizeHandle->box.pos = box.size.minus(internal->resizeHandle->box.size);
- + if (internal->resizeHandle != nullptr)
- + internal->resizeHandle->box.pos = box.size.minus(internal->resizeHandle->box.size);
-
- // Resize owned descendants
- menuBar->box.size.x = box.size.x;
- rackScroll->box.size = box.size.minus(rackScroll->box.pos);
-
- - // Autosave periodically
- - if (settings::autosaveInterval > 0.0) {
- - double time = system::getTime();
- - if (time - internal->lastAutosaveTime >= settings::autosaveInterval) {
- - internal->lastAutosaveTime = time;
- - APP->patch->saveAutosave();
- - settings::save();
- - }
- - }
- -
- // Scroll RackScrollWidget with arrow keys
- math::Vec arrowDelta;
- if (internal->heldArrowKeys[0]) {
- @@ -143,6 +204,34 @@
- rackScroll->offset += arrowDelta * arrowSpeed;
- }
-
- + if (remoteUtils::RemoteDetails* const remoteDetails = remoteUtils::getRemote()) {
- + idleRemote(remoteDetails);
- +
- + if (remoteDetails->autoDeploy) {
- + const int actionIndex = APP->history->actionIndex;
- + const double time = system::getTime();
- +
- + if (internal->historyActionIndex == -1) {
- + internal->historyActionIndex = actionIndex;
- + internal->lastSceneChangeTime = time;
- + } else if (internal->historyActionIndex != actionIndex && actionIndex > 0 && time - internal->lastSceneChangeTime >= 1.0) {
- + const std::string& name(APP->history->actions[actionIndex - 1]->name);
- + static const std::vector<std::string> ignoredNames = {
- + "move knob",
- + "move modules",
- + "move switch",
- + };
- + if (std::find(ignoredNames.cbegin(), ignoredNames.cend(), name) == ignoredNames.cend()) {
- + printf("action '%s'\n", APP->history->actions[actionIndex - 1]->name.c_str());
- + remoteUtils::sendFullPatchToRemote(remoteDetails);
- + window::generateScreenshot();
- + }
- + internal->historyActionIndex = actionIndex;
- + internal->lastSceneChangeTime = time;
- + }
- + }
- + }
- +
- Widget::step();
- }
-
- @@ -172,7 +261,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) {
- - APP->patch->loadTemplateDialog();
- + patchUtils::loadTemplateDialog(false);
- e.consume(this);
- }
- if (e.keyName == "q" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
- @@ -180,19 +269,25 @@
- e.consume(this);
- }
- if (e.keyName == "o" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
- - APP->patch->loadDialog();
- + patchUtils::loadDialog();
- e.consume(this);
- }
- if (e.keyName == "o" && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) {
- - APP->patch->revertDialog();
- + patchUtils::revertDialog();
- e.consume(this);
- }
- if (e.keyName == "s" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
- - APP->patch->saveDialog();
- + // NOTE: for plugin versions it will do nothing if path is empty, intentionally
- + if (APP->patch->path.empty()) {
- + if (isStandalone())
- + patchUtils::saveAsDialog();
- + } else {
- + patchUtils::saveDialog(APP->patch->path);
- + }
- e.consume(this);
- }
- if (e.keyName == "s" && (e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) {
- - APP->patch->saveAsDialog();
- + patchUtils::saveAsDialog();
- e.consume(this);
- }
- if (e.keyName == "z" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
- @@ -220,24 +315,42 @@
- APP->scene->rackScroll->setZoom(std::pow(2.f, zoom));
- e.consume(this);
- }
- - if ((e.keyName == "0") && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
- + if ((e.keyName == "0" || e.keyName == "1") && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
- APP->scene->rackScroll->setZoom(1.f);
- e.consume(this);
- }
- + if (e.keyName == "2" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
- + APP->scene->rackScroll->setZoom(2.f);
- + e.consume(this);
- + }
- if (e.key == GLFW_KEY_F1 && (e.mods & RACK_MOD_MASK) == 0) {
- - system::openBrowser("https://vcvrack.com/manual/");
- + patchUtils::openBrowser("https://vcvrack.com/manual/");
- e.consume(this);
- }
- if (e.key == GLFW_KEY_F3 && (e.mods & RACK_MOD_MASK) == 0) {
- settings::cpuMeter ^= true;
- e.consume(this);
- }
- + if (e.key == GLFW_KEY_F7 && (e.mods & RACK_MOD_MASK) == 0) {
- + if (remoteUtils::RemoteDetails* const remoteDetails = remoteUtils::getRemote())
- + {
- + remoteUtils::sendFullPatchToRemote(remoteDetails);
- + window::generateScreenshot();
- + }
- + e.consume(this);
- + }
- + if (e.key == GLFW_KEY_F9 && (e.mods & RACK_MOD_MASK) == 0) {
- + window::generateScreenshot();
- + e.consume(this);
- + }
- +#ifdef DISTRHO_OS_WASM
- if (e.key == GLFW_KEY_F11 && (e.mods & RACK_MOD_MASK) == 0) {
- APP->window->setFullScreen(!APP->window->isFullScreen());
- // The MenuBar will be hidden when the mouse moves over the RackScrollWidget.
- // menuBar->hide();
- e.consume(this);
- }
- +#endif
-
- // Module selections
- if (e.keyName == "a" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
- @@ -326,13 +439,6 @@
-
- // Key commands that can be overridden by children
- if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) {
- - // Alternative key command for exiting fullscreen, since F11 doesn't work reliably on Mac due to "Show desktop" OS binding.
- - if (e.key == GLFW_KEY_ESCAPE && (e.mods & RACK_MOD_MASK) == 0) {
- - if (APP->window->isFullScreen()) {
- - APP->window->setFullScreen(false);
- - e.consume(this);
- - }
- - }
- if (e.keyName == "v" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) {
- rack->pasteClipboardAction();
- e.consume(this);
- @@ -351,7 +457,7 @@
- std::string extension = system::getExtension(path);
-
- if (extension == ".vcv") {
- - APP->patch->loadPathDialog(path);
- + patchUtils::loadPathDialog(path);
- e.consume(this);
- return;
- }
|