Alternative folder setup for custom files, override MenuBar.cpp

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2021-10-22 14:08:57 +01:00
parent 0a0f09bc8a
commit 88beb01572
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
11 changed files with 951 additions and 294 deletions

646
src/override/MenuBar.cpp Normal file
View file

@ -0,0 +1,646 @@
/*
* DISTRHO Cardinal Plugin
* Copyright (C) 2021 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 MenuBar.cpp
* Copyright (C) 2016-2021 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 <thread>
#include <utility>
#include <osdialog.h>
#include <app/MenuBar.hpp>
#include <app/TipWindow.hpp>
#include <widget/OpaqueWidget.hpp>
#include <ui/Button.hpp>
#include <ui/MenuItem.hpp>
#include <ui/MenuSeparator.hpp>
#include <ui/SequentialLayout.hpp>
#include <ui/Slider.hpp>
#include <ui/TextField.hpp>
#include <ui/PasswordField.hpp>
#include <ui/ProgressBar.hpp>
#include <ui/Label.hpp>
#include <engine/Engine.hpp>
#include <window/Window.hpp>
#include <asset.hpp>
#include <context.hpp>
#include <settings.hpp>
#include <helpers.hpp>
#include <system.hpp>
#include <plugin.hpp>
#include <patch.hpp>
#include <library.hpp>
#ifdef NDEBUG
# undef DEBUG
#endif
#include "../PluginContext.hpp"
namespace rack {
namespace app {
namespace menuBar {
struct MenuButton : ui::Button {
void step() override {
box.size.x = bndLabelWidth(APP->window->vg, -1, text.c_str()) + 1.0;
Widget::step();
}
void draw(const DrawArgs& args) override {
BNDwidgetState state = BND_DEFAULT;
if (APP->event->hoveredWidget == this)
state = BND_HOVER;
if (APP->event->draggedWidget == this)
state = BND_ACTIVE;
bndMenuItem(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str());
Widget::draw(args);
}
};
////////////////////
// File
////////////////////
struct FileButton : MenuButton {
const bool isStandalone;
FileButton(const bool standalone)
: MenuButton(), isStandalone(standalone) {}
void onAction(const ActionEvent& e) override {
ui::Menu* menu = createMenu();
menu->cornerFlags = BND_CORNER_TOP;
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
menu->addChild(createMenuItem("New", RACK_MOD_CTRL_NAME "+N", []() {
APP->patch->loadTemplateDialog();
}));
menu->addChild(createMenuItem("Open", RACK_MOD_CTRL_NAME "+O", []() {
APP->patch->loadDialog();
}));
/*
menu->addChild(createMenuItem("Save", RACK_MOD_CTRL_NAME "+S", []() {
APP->patch->saveDialog();
}));
menu->addChild(createMenuItem("Save as", RACK_MOD_CTRL_NAME "+Shift+S", []() {
APP->patch->saveAsDialog();
}));
menu->addChild(createMenuItem("Save template", "", []() {
APP->patch->saveTemplateDialog();
}));
*/
menu->addChild(createMenuItem("Revert", RACK_MOD_CTRL_NAME "+" RACK_MOD_SHIFT_NAME "+O", []() {
APP->patch->revertDialog();
}, APP->patch->path == ""));
if (isStandalone) {
menu->addChild(new ui::MenuSeparator);
menu->addChild(createMenuItem("Quit", RACK_MOD_CTRL_NAME "+Q", []() {
APP->window->close();
}));
};
}
};
////////////////////
// Edit
////////////////////
struct EditButton : MenuButton {
void onAction(const ActionEvent& e) override {
ui::Menu* menu = createMenu();
menu->cornerFlags = BND_CORNER_TOP;
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
struct UndoItem : ui::MenuItem {
void step() override {
text = "Undo " + APP->history->getUndoName();
disabled = !APP->history->canUndo();
MenuItem::step();
}
void onAction(const ActionEvent& e) override {
APP->history->undo();
}
};
menu->addChild(createMenuItem<UndoItem>("", RACK_MOD_CTRL_NAME "+Z"));
struct RedoItem : ui::MenuItem {
void step() override {
text = "Redo " + APP->history->getRedoName();
disabled = !APP->history->canRedo();
MenuItem::step();
}
void onAction(const ActionEvent& e) override {
APP->history->redo();
}
};
menu->addChild(createMenuItem<RedoItem>("", RACK_MOD_CTRL_NAME "+" RACK_MOD_SHIFT_NAME "+Z"));
menu->addChild(createMenuItem("Clear cables", "", [=]() {
APP->patch->disconnectDialog();
}));
menu->addChild(new ui::MenuSeparator);
APP->scene->rack->appendSelectionContextMenu(menu);
}
};
////////////////////
// View
////////////////////
struct ZoomQuantity : Quantity {
void setValue(float value) override {
APP->scene->rackScroll->setZoom(std::pow(2.f, value));
}
float getValue() override {
return std::log2(APP->scene->rackScroll->getZoom());
}
float getMinValue() override {
return -2.f;
}
float getMaxValue() override {
return 2.f;
}
float getDefaultValue() override {
return 0.0;
}
float getDisplayValue() override {
return std::round(std::pow(2.f, getValue()) * 100);
}
void setDisplayValue(float displayValue) override {
setValue(std::log2(displayValue / 100));
}
std::string getLabel() override {
return "Zoom";
}
std::string getUnit() override {
return "%";
}
};
struct ZoomSlider : ui::Slider {
ZoomSlider() {
quantity = new ZoomQuantity;
}
~ZoomSlider() {
delete quantity;
}
};
struct CableOpacityQuantity : Quantity {
void setValue(float value) override {
settings::cableOpacity = math::clamp(value, getMinValue(), getMaxValue());
}
float getValue() override {
return settings::cableOpacity;
}
float getDefaultValue() override {
return 0.5;
}
float getDisplayValue() override {
return getValue() * 100;
}
void setDisplayValue(float displayValue) override {
setValue(displayValue / 100);
}
std::string getLabel() override {
return "Cable opacity";
}
std::string getUnit() override {
return "%";
}
};
struct CableOpacitySlider : ui::Slider {
CableOpacitySlider() {
quantity = new CableOpacityQuantity;
}
~CableOpacitySlider() {
delete quantity;
}
};
struct CableTensionQuantity : Quantity {
void setValue(float value) override {
settings::cableTension = math::clamp(value, getMinValue(), getMaxValue());
}
float getValue() override {
return settings::cableTension;
}
float getDefaultValue() override {
return 0.5;
}
std::string getLabel() override {
return "Cable tension";
}
int getDisplayPrecision() override {
return 2;
}
};
struct CableTensionSlider : ui::Slider {
CableTensionSlider() {
quantity = new CableTensionQuantity;
}
~CableTensionSlider() {
delete quantity;
}
};
struct RackBrightnessQuantity : Quantity {
void setValue(float value) override {
settings::rackBrightness = math::clamp(value, getMinValue(), getMaxValue());
}
float getValue() override {
return settings::rackBrightness;
}
float getDefaultValue() override {
return 1.0;
}
float getDisplayValue() override {
return getValue() * 100;
}
void setDisplayValue(float displayValue) override {
setValue(displayValue / 100);
}
std::string getUnit() override {
return "%";
}
std::string getLabel() override {
return "Room brightness";
}
int getDisplayPrecision() override {
return 3;
}
};
struct RackBrightnessSlider : ui::Slider {
RackBrightnessSlider() {
quantity = new RackBrightnessQuantity;
}
~RackBrightnessSlider() {
delete quantity;
}
};
struct HaloBrightnessQuantity : Quantity {
void setValue(float value) override {
settings::haloBrightness = math::clamp(value, getMinValue(), getMaxValue());
}
float getValue() override {
return settings::haloBrightness;
}
float getDefaultValue() override {
return 0.25;
}
float getDisplayValue() override {
return getValue() * 100;
}
void setDisplayValue(float displayValue) override {
setValue(displayValue / 100);
}
std::string getUnit() override {
return "%";
}
std::string getLabel() override {
return "Light bloom";
}
int getDisplayPrecision() override {
return 3;
}
};
struct HaloBrightnessSlider : ui::Slider {
HaloBrightnessSlider() {
quantity = new HaloBrightnessQuantity;
}
~HaloBrightnessSlider() {
delete quantity;
}
};
struct KnobScrollSensitivityQuantity : Quantity {
void setValue(float value) override {
value = math::clamp(value, getMinValue(), getMaxValue());
settings::knobScrollSensitivity = std::pow(2.f, value);
}
float getValue() override {
return std::log2(settings::knobScrollSensitivity);
}
float getMinValue() override {
return std::log2(1e-4f);
}
float getMaxValue() override {
return std::log2(1e-2f);
}
float getDefaultValue() override {
return std::log2(1e-3f);
}
float getDisplayValue() override {
return std::pow(2.f, getValue() - getDefaultValue());
}
void setDisplayValue(float displayValue) override {
setValue(std::log2(displayValue) + getDefaultValue());
}
std::string getLabel() override {
return "Scroll wheel knob sensitivity";
}
int getDisplayPrecision() override {
return 2;
}
};
struct KnobScrollSensitivitySlider : ui::Slider {
KnobScrollSensitivitySlider() {
quantity = new KnobScrollSensitivityQuantity;
}
~KnobScrollSensitivitySlider() {
delete quantity;
}
};
struct ViewButton : MenuButton {
void onAction(const ActionEvent& e) override {
ui::Menu* menu = createMenu();
menu->cornerFlags = BND_CORNER_TOP;
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
menu->addChild(createBoolPtrMenuItem("Show tooltips", "", &settings::tooltips));
ZoomSlider* zoomSlider = new ZoomSlider;
zoomSlider->box.size.x = 250.0;
menu->addChild(zoomSlider);
CableOpacitySlider* cableOpacitySlider = new CableOpacitySlider;
cableOpacitySlider->box.size.x = 250.0;
menu->addChild(cableOpacitySlider);
CableTensionSlider* cableTensionSlider = new CableTensionSlider;
cableTensionSlider->box.size.x = 250.0;
menu->addChild(cableTensionSlider);
RackBrightnessSlider* rackBrightnessSlider = new RackBrightnessSlider;
rackBrightnessSlider->box.size.x = 250.0;
menu->addChild(rackBrightnessSlider);
HaloBrightnessSlider* haloBrightnessSlider = new HaloBrightnessSlider;
haloBrightnessSlider->box.size.x = 250.0;
menu->addChild(haloBrightnessSlider);
menu->addChild(new ui::MenuSeparator);
// menu->addChild(createBoolPtrMenuItem("Hide cursor while dragging", "", &settings::allowCursorLock));
static const std::vector<std::string> knobModeLabels = {
"Linear",
"Scaled linear",
"Absolute rotary",
"Relative rotary",
};
static const std::vector<int> knobModes = {0, 2, 3};
menu->addChild(createSubmenuItem("Knob mode", knobModeLabels[settings::knobMode], [=](ui::Menu* menu) {
for (int knobMode : knobModes) {
menu->addChild(createCheckMenuItem(knobModeLabels[knobMode], "",
[=]() {return settings::knobMode == knobMode;},
[=]() {settings::knobMode = (settings::KnobMode) knobMode;}
));
}
}));
menu->addChild(createBoolPtrMenuItem("Scroll wheel knob control", "", &settings::knobScroll));
KnobScrollSensitivitySlider* knobScrollSensitivitySlider = new KnobScrollSensitivitySlider;
knobScrollSensitivitySlider->box.size.x = 250.0;
menu->addChild(knobScrollSensitivitySlider);
menu->addChild(createBoolPtrMenuItem("Lock module positions", "", &settings::lockModules));
}
};
////////////////////
// Engine
////////////////////
struct EngineButton : MenuButton {
void onAction(const ActionEvent& e) override {
ui::Menu* menu = createMenu();
menu->cornerFlags = BND_CORNER_TOP;
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
std::string cpuMeterText = "F3";
if (settings::cpuMeter)
cpuMeterText += " " CHECKMARK_STRING;
menu->addChild(createMenuItem("Performance meters", cpuMeterText, [=]() {
settings::cpuMeter ^= true;
}));
menu->addChild(createSubmenuItem("Threads | DO NOT USE", string::f("%d", settings::threadCount), [=](ui::Menu* menu) {
// BUG This assumes SMT is enabled.
int cores = system::getLogicalCoreCount() / 2;
for (int i = 1; i <= 2 * cores; i++) {
std::string rightText;
if (i == cores)
rightText += "(most modules)";
else if (i == 1)
rightText += "(lowest CPU usage)";
menu->addChild(createCheckMenuItem(string::f("%d", i), rightText,
[=]() {return settings::threadCount == i;},
[=]() {settings::threadCount = i;}
));
}
}));
}
};
////////////////////
// Help
////////////////////
struct HelpButton : MenuButton {
void onAction(const ActionEvent& e) override {
ui::Menu* menu = createMenu();
menu->cornerFlags = BND_CORNER_TOP;
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
menu->addChild(createMenuItem("Tips", "", [=]() {
APP->scene->addChild(tipWindowCreate());
}));
menu->addChild(createMenuItem("VCV User manual", "F1", [=]() {
system::openBrowser("https://vcvrack.com/manual/");
}));
menu->addChild(createMenuItem("Cardinal Project page", "", [=]() {
system::openBrowser("https://github.com/DISTRHO/Cardinal/");
}));
menu->addChild(new ui::MenuSeparator);
menu->addChild(createMenuLabel(APP_EDITION + " " + APP_EDITION_NAME));
menu->addChild(createMenuLabel("VCVRack " + APP_VERSION + " Compatible"));
}
};
////////////////////
// MenuBar
////////////////////
struct MeterLabel : ui::Label {
int frameIndex = 0;
double frameDurationTotal = 0.0;
double frameDurationAvg = 0.0;
double uiLastTime = 0.0;
double uiLastThreadTime = 0.0;
double uiFrac = 0.0;
void step() override {
// Compute frame rate
double frameDuration = APP->window->getLastFrameDuration();
frameDurationTotal += frameDuration;
frameIndex++;
if (frameDurationTotal >= 1.0) {
frameDurationAvg = frameDurationTotal / frameIndex;
frameDurationTotal = 0.0;
frameIndex = 0;
}
// Compute UI thread CPU
// double time = system::getTime();
// double uiDuration = time - uiLastTime;
// if (uiDuration >= 1.0) {
// double threadTime = system::getThreadTime();
// uiFrac = (threadTime - uiLastThreadTime) / uiDuration;
// uiLastThreadTime = threadTime;
// uiLastTime = time;
// }
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);
Label::step();
}
};
struct MenuBar : widget::OpaqueWidget {
CardinalPluginContext* const context;
MeterLabel* meterLabel;
MenuBar(CardinalPluginContext* const ctx, const bool isStandalone)
: context(ctx)
{
const float margin = 5;
box.size.y = BND_WIDGET_HEIGHT + 2 * margin;
ui::SequentialLayout* layout = new ui::SequentialLayout;
layout->margin = math::Vec(margin, margin);
layout->spacing = math::Vec(0, 0);
addChild(layout);
FileButton* fileButton = new FileButton(isStandalone);
fileButton->text = "File";
layout->addChild(fileButton);
EditButton* editButton = new EditButton;
editButton->text = "Edit";
layout->addChild(editButton);
ViewButton* viewButton = new ViewButton;
viewButton->text = "View";
layout->addChild(viewButton);
EngineButton* engineButton = new EngineButton;
engineButton->text = "Engine";
layout->addChild(engineButton);
HelpButton* helpButton = new HelpButton;
helpButton->text = "Help";
layout->addChild(helpButton);
// ui::Label* titleLabel = new ui::Label;
// titleLabel->color.a = 0.5;
// layout->addChild(titleLabel);
meterLabel = new MeterLabel;
meterLabel->box.pos.y = margin;
meterLabel->box.size.x = 300;
meterLabel->alignment = ui::Label::RIGHT_ALIGNMENT;
meterLabel->color.a = 0.5;
addChild(meterLabel);
}
void draw(const DrawArgs& args) override {
bndMenuBackground(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_ALL);
bndBevel(args.vg, 0.0, 0.0, box.size.x, box.size.y);
Widget::draw(args);
}
void step() override {
meterLabel->box.pos.x = box.size.x - meterLabel->box.size.x - 5;
Widget::step();
}
};
} // namespace menuBar
widget::Widget* createMenuBar() {
return new widget::Widget;
}
widget::Widget* createMenuBar(CardinalPluginContext* const context, const bool isStandalone) {
menuBar::MenuBar* menuBar = new menuBar::MenuBar(context, isStandalone);
return menuBar;
}
} // namespace app
} // namespace rack

458
src/override/Window.cpp Normal file
View file

@ -0,0 +1,458 @@
/*
* DISTRHO Cardinal Plugin
* Copyright (C) 2021 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 Window.cpp
* Copyright (C) 2016-2021 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 <map>
#include <queue>
#include <thread>
#include <osdialog.h>
#include <window/Window.hpp>
#include <asset.hpp>
#include <widget/Widget.hpp>
#include <app/Scene.hpp>
#include <context.hpp>
#include <patch.hpp>
#include <settings.hpp>
#include <plugin.hpp> // used in Window::screenshot
#include <system.hpp> // used in Window::screenshot
#ifdef NDEBUG
# undef DEBUG
#endif
#include "DistrhoUI.hpp"
#include "../WindowParameters.hpp"
namespace rack {
namespace window {
static const math::Vec minWindowSize = math::Vec(640, 480);
void Font::loadFile(const std::string& filename, NVGcontext* vg) {
this->vg = vg;
handle = nvgCreateFont(vg, filename.c_str(), filename.c_str());
if (handle < 0)
throw Exception("Failed to load font %s", filename.c_str());
INFO("Loaded font %s", filename.c_str());
}
Font::~Font() {
// There is no NanoVG deleteFont() function yet, so do nothing
}
std::shared_ptr<Font> Font::load(const std::string& filename) {
return APP->window->loadFont(filename);
}
void Image::loadFile(const std::string& filename, NVGcontext* vg) {
this->vg = vg;
handle = nvgCreateImage(vg, filename.c_str(), NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY);
if (handle <= 0)
throw Exception("Failed to load image %s", filename.c_str());
INFO("Loaded image %s", filename.c_str());
}
Image::~Image() {
// TODO What if handle is invalid?
if (handle >= 0)
nvgDeleteImage(vg, handle);
}
std::shared_ptr<Image> Image::load(const std::string& filename) {
return APP->window->loadImage(filename);
}
struct WindowParams {
float rackBrightness = 1.0f;
};
struct Window::Internal {
DISTRHO_NAMESPACE::UI* ui = nullptr;
DISTRHO_NAMESPACE::WindowParameters params;
DISTRHO_NAMESPACE::WindowParametersCallback* callback = nullptr;
math::Vec size = minWindowSize;
std::string lastWindowTitle;
int mods = 0;
int frame = 0;
int frameSwapInterval = 1;
double monitorRefreshRate = 60.0; // FIXME
double frameTime = 0.0;
double lastFrameDuration = 0.0;
std::map<std::string, std::shared_ptr<Font>> fontCache;
std::map<std::string, std::shared_ptr<Image>> imageCache;
bool fbDirtyOnSubpixelChange = true;
};
Window::Window() {
internal = new Internal;
}
void WindowInit(Window* const window, DISTRHO_NAMESPACE::UI* const ui)
{
const GLubyte* vendor = glGetString(GL_VENDOR);
const GLubyte* renderer = glGetString(GL_RENDERER);
const GLubyte* version = glGetString(GL_VERSION);
INFO("Renderer: %s %s", vendor, renderer);
INFO("OpenGL: %s", version);
window->internal->ui = ui;
window->vg = ui->getContext();
window->fbVg = nvgCreateSharedGL2(window->vg, NVG_ANTIALIAS);
// Load default Blendish font
window->uiFont = window->loadFont(asset::system("res/fonts/DejaVuSans.ttf"));
if (window->uiFont != nullptr)
bndSetFont(window->uiFont->handle);
// Init settings
WindowParametersRestore(window);
if (APP->scene) {
widget::Widget::ContextCreateEvent e;
APP->scene->onContextCreate(e);
}
}
void WindowMods(Window* const window, const int mods)
{
window->internal->mods = mods;
}
Window::~Window() {
if (APP->scene) {
widget::Widget::ContextDestroyEvent e;
APP->scene->onContextDestroy(e);
}
// Fonts and Images in the cache must be deleted before the NanoVG context is deleted
internal->fontCache.clear();
internal->imageCache.clear();
delete internal;
}
math::Vec Window::getSize() {
return internal->size;
}
void Window::setSize(math::Vec size) {
internal->size = size.max(minWindowSize);
}
void Window::run() {
internal->frame = 0;
}
void Window::step() {
double frameTime = system::getTime();
double lastFrameTime = internal->frameTime;
internal->frameTime = frameTime;
internal->lastFrameDuration = frameTime - lastFrameTime;
// DEBUG("%.2lf Hz", 1.0 / internal->lastFrameDuration);
// Make event handlers and step() have a clean NanoVG context
// nvgReset(vg);
if (uiFont != nullptr)
bndSetFont(uiFont->handle);
// Set window title
std::string windowTitle = APP_NAME + " " + APP_EDITION_NAME + " " + APP_VERSION;
if (APP->patch->path != "") {
windowTitle += " - ";
if (!APP->history->isSaved())
windowTitle += "*";
windowTitle += system::getFilename(APP->patch->path);
}
if (windowTitle != internal->lastWindowTitle) {
internal->ui->getWindow().setTitle(windowTitle.c_str());
internal->lastWindowTitle = windowTitle;
}
// Get desired pixel ratio
float newPixelRatio = internal->ui->getScaleFactor();
if (newPixelRatio != pixelRatio) {
pixelRatio = newPixelRatio;
APP->event->handleDirty();
}
// Get framebuffer/window ratio
int winWidth = internal->ui->getWidth();
int winHeight = internal->ui->getHeight();
int fbWidth = winWidth;// * newPixelRatio;
int fbHeight = winHeight;// * newPixelRatio;
windowRatio = (float)fbWidth / winWidth;
if (APP->scene) {
// DEBUG("%f %f %d %d", pixelRatio, windowRatio, fbWidth, winWidth);
// Resize scene
APP->scene->box.size = math::Vec(fbWidth, fbHeight).div(pixelRatio);
// Step scene
APP->scene->step();
// Render scene
// Update and render
nvgScale(vg, pixelRatio, pixelRatio);
// Draw scene
widget::Widget::DrawArgs args;
args.vg = vg;
args.clipBox = APP->scene->box.zeroPos();
APP->scene->draw(args);
glViewport(0, 0, fbWidth, fbHeight);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
internal->frame++;
}
void Window::screenshot(const std::string&) {
}
void Window::screenshotModules(const std::string&, float) {
}
void Window::close() {
internal->ui->getWindow().close();
}
void Window::cursorLock() {
}
void Window::cursorUnlock() {
}
bool Window::isCursorLocked() {
return false;
}
int Window::getMods() {
return internal->mods;
}
void Window::setFullScreen(bool) {
}
bool Window::isFullScreen() {
return false;
}
double Window::getMonitorRefreshRate() {
return internal->monitorRefreshRate;
}
double Window::getFrameTime() {
return internal->frameTime;
}
double Window::getLastFrameDuration() {
return internal->lastFrameDuration;
}
double Window::getFrameDurationRemaining() {
double frameDurationDesired = internal->frameSwapInterval / internal->monitorRefreshRate;
return frameDurationDesired - (system::getTime() - internal->frameTime);
}
std::shared_ptr<Font> Window::loadFont(const std::string& filename) {
const auto& pair = internal->fontCache.find(filename);
if (pair != internal->fontCache.end())
return pair->second;
// Load font
std::shared_ptr<Font> font;
try {
font = std::make_shared<Font>();
font->loadFile(filename, vg);
}
catch (Exception& e) {
WARN("%s", e.what());
font = NULL;
}
internal->fontCache[filename] = font;
return font;
}
std::shared_ptr<Image> Window::loadImage(const std::string& filename) {
const auto& pair = internal->imageCache.find(filename);
if (pair != internal->imageCache.end())
return pair->second;
// Load image
std::shared_ptr<Image> image;
try {
image = std::make_shared<Image>();
image->loadFile(filename, vg);
}
catch (Exception& e) {
WARN("%s", e.what());
image = NULL;
}
internal->imageCache[filename] = image;
return image;
}
bool& Window::fbDirtyOnSubpixelChange() {
return internal->fbDirtyOnSubpixelChange;
}
} // namespace window
} // namespace rack
START_NAMESPACE_DISTRHO
void WindowParametersSave(rack::window::Window* const window)
{
if (d_isNotEqual(window->internal->params.cableOpacity, rack::settings::cableOpacity))
{
window->internal->params.cableOpacity = rack::settings::cableOpacity;
if (window->internal->callback != nullptr)
window->internal->callback->WindowParametersChanged(kWindowParameterCableOpacity,
rack::settings::cableOpacity);
}
if (d_isNotEqual(window->internal->params.cableTension, rack::settings::cableTension))
{
window->internal->params.cableTension = rack::settings::cableTension;
if (window->internal->callback != nullptr)
window->internal->callback->WindowParametersChanged(kWindowParameterCableTension,
rack::settings::cableTension);
}
if (d_isNotEqual(window->internal->params.rackBrightness, rack::settings::rackBrightness))
{
window->internal->params.rackBrightness = rack::settings::rackBrightness;
if (window->internal->callback != nullptr)
window->internal->callback->WindowParametersChanged(kWindowParameterRackBrightness,
rack::settings::rackBrightness);
}
if (d_isNotEqual(window->internal->params.haloBrightness, rack::settings::haloBrightness))
{
window->internal->params.haloBrightness = rack::settings::haloBrightness;
if (window->internal->callback != nullptr)
window->internal->callback->WindowParametersChanged(kWindowParameterHaloBrightness,
rack::settings::haloBrightness);
}
if (d_isNotEqual(window->internal->params.knobScrollSensitivity, rack::settings::knobScrollSensitivity))
{
window->internal->params.knobScrollSensitivity = rack::settings::knobScrollSensitivity;
if (window->internal->callback != nullptr)
window->internal->callback->WindowParametersChanged(kWindowParameterWheelSensitivity,
rack::settings::knobScrollSensitivity);
}
if (window->internal->params.knobMode != rack::settings::knobMode)
{
window->internal->params.knobMode = rack::settings::knobMode;
if (window->internal->callback != nullptr)
window->internal->callback->WindowParametersChanged(kWindowParameterKnobMode,
rack::settings::knobMode);
}
if (window->internal->params.tooltips != rack::settings::tooltips)
{
window->internal->params.tooltips = rack::settings::tooltips;
if (window->internal->callback != nullptr)
window->internal->callback->WindowParametersChanged(kWindowParameterShowTooltips,
rack::settings::tooltips);
}
if (window->internal->params.knobScroll != rack::settings::knobScroll)
{
window->internal->params.knobScroll = rack::settings::knobScroll;
if (window->internal->callback != nullptr)
window->internal->callback->WindowParametersChanged(kWindowParameterWheelKnobControl,
rack::settings::knobScroll);
}
if (window->internal->params.lockModules != rack::settings::lockModules)
{
window->internal->params.lockModules = rack::settings::lockModules;
if (window->internal->callback != nullptr)
window->internal->callback->WindowParametersChanged(kWindowParameterLockModulePositions,
rack::settings::lockModules);
}
}
void WindowParametersRestore(rack::window::Window* const window)
{
rack::settings::cableOpacity = window->internal->params.cableOpacity;
rack::settings::cableTension = window->internal->params.cableTension;
rack::settings::rackBrightness = window->internal->params.rackBrightness;
rack::settings::haloBrightness = window->internal->params.haloBrightness;
rack::settings::knobScrollSensitivity = window->internal->params.knobScrollSensitivity;
rack::settings::knobMode = static_cast<rack::settings::KnobMode>(window->internal->params.knobMode);
rack::settings::tooltips = window->internal->params.tooltips;
rack::settings::knobScroll = window->internal->params.knobScroll;
rack::settings::lockModules = window->internal->params.lockModules;
}
void WindowParametersSetCallback(rack::window::Window* const window, WindowParametersCallback* const callback)
{
window->internal->callback = callback;
}
void WindowParametersSetValues(rack::window::Window* const window, const WindowParameters& params)
{
window->internal->params = params;
}
END_NAMESPACE_DISTRHO

84
src/override/asset.cpp Normal file
View file

@ -0,0 +1,84 @@
/*
* DISTRHO Cardinal Plugin
* Copyright (C) 2021 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.
*/
#include <asset.hpp>
#include <system.hpp>
#include <plugin/Plugin.hpp>
#include <algorithm>
#include "DistrhoUtils.hpp"
namespace rack {
namespace asset {
std::string userDir; // ignored
std::string systemDir; // points to plugin resources dir (or installed/local Rack dir)
std::string bundlePath; // points to plugin manifests dir (or empty)
// get rid of "res/" prefix
static inline std::string& trim(std::string& s)
{
if (std::strncmp(s.c_str(), "res" DISTRHO_OS_SEP_STR, 4) == 0)
s = s.substr(4, s.size()-4);
#if DISTRHO_OS_SEP != '/'
if (std::strncmp(s.c_str(), "res/", 4) == 0)
s = s.substr(4, s.size()-4);
#endif
return s;
}
// ignored, returns the same as `system`
std::string user(std::string filename) {
return system(filename);
}
// get system resource, trimming "res/" prefix if we are loaded as a plugin bundle
std::string system(std::string filename) {
return system::join(systemDir, bundlePath.empty() ? filename : trim(filename));
}
// get plugin resource, also trims "res/" as needed
std::string plugin(plugin::Plugin* plugin, std::string filename) {
DISTRHO_SAFE_ASSERT_RETURN(plugin != nullptr, {});
return system::join(plugin->path, bundlePath.empty() ? filename : trim(filename));
}
// path to plugin manifest
std::string pluginManifest(const std::string& dirname) {
if (bundlePath.empty())
{
if (dirname == "Core")
return system::join(systemDir, "Core.json");
return system::join(systemDir, "..", "..", "plugins", dirname, "plugin.json");
}
return system::join(bundlePath, dirname + ".json");
}
// path to plugin files
std::string pluginPath(const std::string& dirname) {
if (bundlePath.empty())
{
if (dirname == "Core")
return systemDir;
return system::join(systemDir, "..", "..", "plugins", dirname);
}
return system::join(systemDir, dirname);
}
}
}

59
src/override/common.cpp Normal file
View file

@ -0,0 +1,59 @@
/*
* DISTRHO Cardinal Plugin
* Copyright (C) 2021 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.
*/
#include <common.hpp>
#include <string.hpp>
#include "DistrhoPluginUtils.hpp"
// fopen_u8
#ifdef ARCH_WIN
#include <windows.h>
FILE* fopen_u8(const char* filename, const char* mode)
{
return _wfopen(rack::string::UTF8toUTF16(filename).c_str(), rack::string::UTF8toUTF16(mode).c_str());
}
#endif
// Define the global names to indicate this is Cardinal and not VCVRack
namespace rack {
const std::string APP_NAME = "Cardinal";
const std::string APP_EDITION = getPluginFormatName();
const std::string APP_EDITION_NAME = "Audio Plugin";
const std::string APP_VERSION_MAJOR = "2";
const std::string APP_VERSION = "2.0";
#if defined(ARCH_WIN)
const std::string APP_ARCH = "win";
#elif defined(ARCH_MAC)
const std::string APP_ARCH = "mac";
#else
const std::string APP_ARCH = "lin";
#endif
const std::string API_URL = "";
Exception::Exception(const char* format, ...)
{
va_list args;
va_start(args, format);
msg = string::fV(format, args);
va_end(args);
}
}

57
src/override/context.cpp Normal file
View file

@ -0,0 +1,57 @@
#include <context.hpp>
#include <window/Window.hpp>
#include <patch.hpp>
#include <engine/Engine.hpp>
#include <app/Scene.hpp>
#include <history.hpp>
#include <settings.hpp>
#include "DistrhoPluginUtils.hpp"
namespace rack {
Context::~Context() {
// Deleting NULL is safe in C++.
// Set pointers to NULL so other objects will segfault when attempting to access them
delete window;
window = NULL;
delete patch;
patch = NULL;
delete scene;
scene = NULL;
delete event;
event = NULL;
delete history;
history = NULL;
delete engine;
engine = NULL;
}
static thread_local Context* threadContext = nullptr;
Context* contextGet() {
DISTRHO_SAFE_ASSERT(threadContext != nullptr);
return threadContext;
}
// Apple's clang incorrectly compiles this function when -O2 or higher is enabled.
#ifdef ARCH_MAC
__attribute__((optnone))
#endif
void contextSet(Context* const context) {
// DISTRHO_SAFE_ASSERT(threadContext == nullptr);
threadContext = context;
}
} // namespace rack

42
src/override/dep.cpp Normal file
View file

@ -0,0 +1,42 @@
/*
* DISTRHO Cardinal Plugin
* Copyright (C) 2021 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.
*/
#include "OpenGL.hpp"
// fix blendish build, missing symbol in debug mode
#ifdef DEBUG
extern "C" {
float bnd_clamp(float v, float mn, float mx) {
return (v > mx)?mx:(v < mn)?mn:v;
}
}
#endif
// fix bogaudio build, another missing symbol
#ifdef DEBUG
namespace bogaudio {
struct FollowerBase {
static float efGainMaxDecibelsDebug;
};
float FollowerBase::efGainMaxDecibelsDebug = 12.0f;
}
#endif
// Compile those nice implementation-in-header little libraries
#define NANOSVG_IMPLEMENTATION
#define NANOSVG_ALL_COLOR_KEYWORDS
#include <nanosvg.h>

46
src/override/library.cpp Normal file
View file

@ -0,0 +1,46 @@
/*
* DISTRHO Cardinal Plugin
* Copyright (C) 2021 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.
*/
#include <library.hpp>
// Define the stuff needed for VCVRack but unused for Cardinal
namespace rack {
namespace library {
std::string appChangelogUrl;
std::string appDownloadUrl;
std::string appVersion;
std::string loginStatus;
std::map<std::string, UpdateInfo> updateInfos;
std::string updateStatus;
std::string updateSlug;
float updateProgress = 0.f;
bool isSyncing = false;
bool restartRequested = false;
void checkAppUpdate() {}
void checkUpdates() {}
bool hasUpdates() { return false; }
bool isAppUpdateAvailable() { return false; }
bool isLoggedIn() { return false; }
void logIn(const std::string&, const std::string&) {}
void logOut() {}
void syncUpdate(const std::string&) {}
void syncUpdates() {}
}
}

29
src/override/network.cpp Normal file
View file

@ -0,0 +1,29 @@
/*
* DISTRHO Cardinal Plugin
* Copyright (C) 2021 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.
*/
#include <network.hpp>
// Define the stuff needed for VCVRack but unused for Cardinal
namespace rack {
namespace network {
std::string encodeUrl(const std::string&) { return {}; }
json_t* requestJson(Method, const std::string&, json_t*, const CookieMap&) { return nullptr; }
bool requestDownload(const std::string&, const std::string&, float*, const CookieMap&) { return false; }
}
}