From 4a629b46c31ed12942b87d6b3f27e71959872239 Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 3 Feb 2022 01:34:57 +0000 Subject: [PATCH] Add panel for midi in expander --- plugins/Cardinal/orig/ExpanderMIDI.svg | 107 ++++++++++++++++++++++ plugins/Cardinal/res/ExpanderMIDI.svg | 117 +++++++++++++++++++++++++ plugins/Cardinal/src/AudioFile.cpp | 13 +-- plugins/Cardinal/src/Carla.cpp | 3 +- plugins/Cardinal/src/Expanders.cpp | 57 ++++++++++-- plugins/Cardinal/src/HostAudio.cpp | 3 +- plugins/Cardinal/src/HostCV.cpp | 3 +- plugins/Cardinal/src/HostMIDI.cpp | 3 +- plugins/Cardinal/src/ModuleWidgets.hpp | 40 +++++---- 9 files changed, 311 insertions(+), 35 deletions(-) create mode 100644 plugins/Cardinal/orig/ExpanderMIDI.svg create mode 100644 plugins/Cardinal/res/ExpanderMIDI.svg diff --git a/plugins/Cardinal/orig/ExpanderMIDI.svg b/plugins/Cardinal/orig/ExpanderMIDI.svg new file mode 100644 index 0000000..cad2c37 --- /dev/null +++ b/plugins/Cardinal/orig/ExpanderMIDI.svg @@ -0,0 +1,107 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + MIDI + + diff --git a/plugins/Cardinal/res/ExpanderMIDI.svg b/plugins/Cardinal/res/ExpanderMIDI.svg new file mode 100644 index 0000000..45f5d9b --- /dev/null +++ b/plugins/Cardinal/res/ExpanderMIDI.svg @@ -0,0 +1,117 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/Cardinal/src/AudioFile.cpp b/plugins/Cardinal/src/AudioFile.cpp index 8a1dc1c..38d5e9f 100644 --- a/plugins/Cardinal/src/AudioFile.cpp +++ b/plugins/Cardinal/src/AudioFile.cpp @@ -16,10 +16,9 @@ */ #include "plugincontext.hpp" +#include "ModuleWidgets.hpp" #include "extra/Thread.hpp" -#include "dgl/src/nanovg/nanovg.h" - #include "CarlaNativePlugin.h" #ifndef HEADLESS @@ -470,7 +469,7 @@ struct AudioFileListWidget : ImGuiWidget { } }; -struct AudioFileWidget : ModuleWidget { +struct AudioFileWidget : ModuleWidgetWithSideScrews<> { static constexpr const float padding = 29.0f; CarlaInternalPluginModule* const module; @@ -479,16 +478,12 @@ struct AudioFileWidget : ModuleWidget { float lastPosition = 0.0f; AudioFileWidget(CarlaInternalPluginModule* const m) - : ModuleWidget(), - module(m) + : module(m) { setModule(module); setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/AudioFile.svg"))); - addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); - addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); - addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + createAndAddScrews(); addOutput(createOutput(Vec(box.size.x - RACK_GRID_WIDTH * 5/2 - padding, RACK_GRID_HEIGHT - RACK_GRID_WIDTH - padding), module, 0)); diff --git a/plugins/Cardinal/src/Carla.cpp b/plugins/Cardinal/src/Carla.cpp index cd6a597..392d148 100644 --- a/plugins/Cardinal/src/Carla.cpp +++ b/plugins/Cardinal/src/Carla.cpp @@ -453,7 +453,8 @@ struct CarlaModuleWidget : ModuleWidgetWith9HP, IdleCallback { { setModule(module); setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Carla.svg"))); - setSideScrews(); + + createAndAddScrews(); for (uint i=0; i { + static constexpr const float startX = 14.0f; + static constexpr const float startY = 90.0f; + static constexpr const float padding = 49.0f; + CardinalExpanderForInputMIDIWidget(CardinalExpanderForInputMIDI* const module) { setModule(module); - box.size.x = RACK_GRID_WIDTH * 2; + setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ExpanderMIDI.svg"))); - addChild(createWidget(Vec(0, 0))); - addChild(createWidget(Vec(0, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - for (int i=0; i<6; ++i) - addInput(createInput(Vec(15, 50 + 29 * i), module, i)); + for (int i=0; i(Vec(startX + 5.0f, startY + padding * i), module, i)); + } + + void drawOutputJacksArea(NVGcontext* const vg, const int numOutputs) { + nvgBeginPath(vg); + nvgRoundedRect(vg, 12.0f, startY - 2.0f, box.size.x - 12.0f, padding * numOutputs, 4); + nvgFillColor(vg, nvgRGB(0xd0, 0xd0, 0xd0)); + nvgFill(vg); + } + + void draw(const DrawArgs& args) override + { + drawBackground(args.vg); + + nvgScissor(args.vg, startX, 0.0f, box.size.x - startX, box.size.y); + + for (int i=0; iwindow->loadSvg(asset::plugin(pluginInstance, "res/HostAudio.svg"))); - setSideScrews(); + + createAndAddScrews(); for (uint i=0; iwindow->loadSvg(asset::plugin(pluginInstance, "res/HostCV.svg"))); - setSideScrews(); + + createAndAddScrews(); for (uint i=0; iwindow->loadSvg(asset::plugin(pluginInstance, "res/HostMIDI.svg"))); - setSideScrews(); + + createAndAddScrews(); createAndAddInput(0, HostMIDI::PITCH_INPUT); createAndAddInput(1, HostMIDI::GATE_INPUT); diff --git a/plugins/Cardinal/src/ModuleWidgets.hpp b/plugins/Cardinal/src/ModuleWidgets.hpp index 91d532d..b16d8c5 100644 --- a/plugins/Cardinal/src/ModuleWidgets.hpp +++ b/plugins/Cardinal/src/ModuleWidgets.hpp @@ -25,28 +25,13 @@ using namespace rack; -template +template struct ModuleWidgetWithSideScrews : ModuleWidget { static constexpr const float startX_In = 14.0f; static constexpr const float startY = 74.0f; static constexpr const float padding = 29.0f; static constexpr const float middleX = startX_In + (startX_Out - startX_In) * 0.5f + padding * 0.35f; - void setSideScrews() { - addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); - addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); - addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); - } - - void setupTextLines(NVGcontext* const vg) { - nvgBeginPath(vg); - nvgRect(vg, startX_Out - 2.5f, startY - 2.0f, padding, padding); - nvgFontFaceId(vg, 0); - nvgFontSize(vg, 11); - nvgTextAlign(vg, NVG_ALIGN_CENTER); - } - void createAndAddInput(const uint paramId) { createAndAddInput(paramId, paramId); } @@ -63,6 +48,20 @@ struct ModuleWidgetWithSideScrews : ModuleWidget { addOutput(createOutput(Vec(startX_Out, startY + padding * posY), module, paramId)); } + void createAndAddScrews() { + if (box.size.x > RACK_GRID_WIDTH * 3) { + addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + } else { + addChild(createWidget(Vec(0, 0))); + addChild(createWidget(Vec(box.size.x - RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(0, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + addChild(createWidget(Vec(box.size.x - RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + } + } + void drawBackground(NVGcontext* const vg) { nvgBeginPath(vg); nvgRect(vg, 0, 0, box.size.x, box.size.y); @@ -84,7 +83,16 @@ struct ModuleWidgetWithSideScrews : ModuleWidget { nvgFillColor(vg, color::WHITE); nvgText(vg, middleX, y + 16, text, nullptr); } + + void setupTextLines(NVGcontext* const vg) { + nvgBeginPath(vg); + nvgRect(vg, startX_Out - 2.5f, startY - 2.0f, padding, padding); + nvgFontFaceId(vg, 0); + nvgFontSize(vg, 11); + nvgTextAlign(vg, NVG_ALIGN_CENTER); + } }; +typedef ModuleWidgetWithSideScrews<0> ModuleWidgetWith3HP; typedef ModuleWidgetWithSideScrews<81> ModuleWidgetWith8HP; typedef ModuleWidgetWithSideScrews<96> ModuleWidgetWith9HP;