computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit b10fb507eeecc5a3ae1c5bb0888f06ffa2855026
parent 6c5b10b34377651218cff12736f3b8d48f11a5cc
Author: Adam M <[email protected]>
Date:   Tue, 12 Feb 2019 16:33:15 -0600

update example iso module to v1

Diffstat:
MMakefile | 3+++
Msrc/Computerscare.hpp | 119++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Msrc/ComputerscareIso.cpp | 54+++++++++++++++++++++++++++++++++++++++++++++---------
Msrc/ComputerscareSVGPanel.cpp | 38+++++++++++++++++++-------------------
4 files changed, 133 insertions(+), 81 deletions(-)

diff --git a/Makefile b/Makefile @@ -12,7 +12,10 @@ LDFLAGS += # Add .cpp and .c files to the build #SOURCES += $(wildcard src/*.cpp) +SOURCES += $(wildcard src/ComputerscareSVGPanel.cpp) + SOURCES += $(wildcard src/ComputerscareIso.cpp) + SOURCES += $(wildcard src/Computerscare.cpp) # Add files to the ZIP package when running `make dist` diff --git a/src/Computerscare.hpp b/src/Computerscare.hpp @@ -1,23 +1,28 @@ +#pragma once + #include "rack.hpp" #include "component.hpp" +#include "app/common.hpp" +#include "widget/TransparentWidget.hpp" +#include "widget/FramebufferWidget.hpp" +#include "widget/SvgWidget.hpp" +#include "app.hpp" + + using namespace rack; // Forward-declare the Plugin, defined in Template.cpp extern Plugin *pluginInstance; +// Forward-declare each Model, defined in each module source file +//extern Model *modelComputerscareDebug; +//extern Model *modelComputerscarePatchSequencer; +//extern Model *modelComputerscareLaundrySoup; +//extern Model *modelComputerscareILoveCookies; +//extern Model *modelComputerscareOhPeas; extern Model *modelComputerscareIso; -/*#ifndef COLOR_MAGENTA - #define COLOR_MAGENTA nvgRGB(240, 50, 230) -#endif -#ifndef COLOR_LIME - #define COLOR_LIME nvgRGB(210, 245, 60) -#endif -#ifndef COLOR_PINK - #define COLOR_PINK nvgRGB(250, 190, 190) -#endif - static const NVGcolor COLOR_COMPUTERSCARE_LIGHT_GREEN = nvgRGB(0xC0, 0xE7, 0xDE); static const NVGcolor COLOR_COMPUTERSCARE_GREEN = nvgRGB(0x24, 0xc9, 0xa6); static const NVGcolor COLOR_COMPUTERSCARE_RED = nvgRGB(0xC4, 0x34, 0x21); @@ -25,47 +30,50 @@ static const NVGcolor COLOR_COMPUTERSCARE_YELLOW = nvgRGB(0xE4, 0xC4, 0x21); static const NVGcolor COLOR_COMPUTERSCARE_BLUE = nvgRGB(0x24, 0x44, 0xC1); static const NVGcolor COLOR_COMPUTERSCARE_PINK = nvgRGB(0xAA, 0x18, 0x31); static const NVGcolor COLOR_COMPUTERSCARE_TRANSPARENT = nvgRGBA(0x00, 0x00,0x00,0x00); -*/ -// Forward-declare each Model, defined in each module source file -//extern Model *modelComputerscareDebug; -//extern Model *modelComputerscarePatchSequencer; -//extern Model *modelComputerscareLaundrySoup; -//extern Model *modelComputerscareILoveCookies; -//extern Model *modelComputerscareOhPeas; + +namespace rack { +namespace app { -//struct ComputerscareSVGPanel; -/*struct ComputerscareSVGPanel : FramebufferWidget { +struct ComputerscareSVGPanel; + +struct ComputerscareSVGPanel : widget::FramebufferWidget { void step() override; - void setBackground(std::shared_ptr<SVG> svg); + void setBackground(std::shared_ptr<Svg> svg); }; -struct IsoButton : SVGSwitch, ToggleSwitch { +} +} + + +struct IsoButton : SvgSwitch { IsoButton() { - addFrame(SVG::load(assetPlugin(plugin,"res/computerscare-iso-button-down.svg"))); - addFrame(SVG::load(assetPlugin(plugin,"res/computerscare-iso-button-up.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-iso-button-down.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-iso-button-up.svg"))); } }; -struct ComputerscareResetButton : SVGSwitch,MomentarySwitch { + +struct ComputerscareResetButton : SvgSwitch,MomentarySwitch { ComputerscareResetButton() { - addFrame(SVG::load(assetPlugin(plugin,"res/computerscare-rst-text.svg"))); - addFrame(SVG::load(assetPlugin(plugin,"res/computerscare-rst-text-red.svg"))); - //SVG::load(assetPlugin(plugin, "res/computerscare-pentagon-jack-1-outline-flipped.svg")); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-rst-text.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-rst-text-red.svg"))); + //APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-pentagon-jack-1-outline-flipped.svg")); } }; +/* struct ComputerscareClockButton : SVGSwitch,MomentarySwitch { ComputerscareClockButton() { - addFrame(SVG::load(assetPlugin(plugin,"res/computerscare-clk-text.svg"))); - addFrame(SVG::load(assetPlugin(plugin,"res/computerscare-clk-text-red.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-clk-text.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-clk-text-red.svg"))); } }; struct ComputerscareInvisibleButton : SVGSwitch,MomentarySwitch { ComputerscareInvisibleButton() { - addFrame(SVG::load(assetPlugin(plugin,"res/computerscare-invisible-button.svg"))); - addFrame(SVG::load(assetPlugin(plugin,"res/computerscare-invisible-button-frame2.svg"))); - //SVG::load(assetPlugin(plugin, "res/computerscare-pentagon-jack-1-outline-flipped.svg")); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-invisible-button.svg"))); + addFrame(APP->window->loadSvg(asset::plugin(pluginInstance,"res/computerscare-invisible-button-frame2.svg"))); + //APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-pentagon-jack-1-outline-flipped.svg")); } }; @@ -117,28 +125,30 @@ struct ComputerscareSmallLight : BASE { } }; +*/ + -struct OutPort : SVGPort { +struct OutPort : SvgPort { OutPort() { - background->svg = SVG::load(assetPlugin(plugin, "res/computerscare-pentagon-jack-1-outline-flipped.svg")); - background->wrap(); - box.size = background->box.size; + setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-pentagon-jack-1-outline-flipped.svg"))); + //background->wrap(); + //box.size = background->box.size; } }; -struct PointingUpPentagonPort : SVGPort { +struct PointingUpPentagonPort : SvgPort { PointingUpPentagonPort() { - background->svg = SVG::load(assetPlugin(plugin, "res/computerscare-pentagon-jack-pointing-up.svg")); - background->wrap(); - box.size = background->box.size; + setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-pentagon-jack-pointing-up.svg"))); + //background->wrap(); + //box.size = background->box.size; } }; -struct InPort : SVGPort { +struct InPort : SvgPort { InPort() { - background->svg = SVG::load(assetPlugin(plugin, "res/computerscare-pentagon-jack-1-outline.svg")); - background->wrap(); - box.size = background->box.size; + setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-pentagon-jack-1-outline.svg"))); + //background->wrap(); + //box.size = background->box.size; } }; @@ -149,30 +159,31 @@ struct InPort : SVGPort { struct LrgKnob : RoundBlackSnapKnob { LrgKnob() { - setSVG(SVG::load(assetPlugin(plugin, "res/computerscare-big-knob-effed.svg"))); - box.size = Vec(32,32); + setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-big-knob-effed.svg"))); } - void randomize() override { return; } + //void randomize() override { return; } }; + struct MediumSnapKnob : RoundBlackSnapKnob { MediumSnapKnob() { - setSVG(SVG::load(assetPlugin(plugin, "res/computerscare-medium-knob-effed.svg"))); + setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-medium-knob-effed.svg"))); } }; + struct SmoothKnob : RoundKnob { SmoothKnob() { - setSVG(SVG::load(assetPlugin(plugin, "res/computerscare-medium-knob-effed.svg"))); + setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-medium-knob-effed.svg"))); } }; struct SmallKnob : RoundKnob { SmallKnob() { - setSVG(SVG::load(assetPlugin(plugin, "res/computerscare-small-knob-effed.svg"))); + setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-small-knob-effed.svg"))); } }; struct BigSmoothKnob : RoundKnob { BigSmoothKnob() { - setSVG(SVG::load(assetPlugin(plugin, "res/computerscare-big-knob-effed.svg"))); + setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/computerscare-big-knob-effed.svg"))); } }; struct ComputerscareDotKnob : SmallKnob { @@ -180,6 +191,8 @@ struct ComputerscareDotKnob : SmallKnob { } }; + +/* //////////////////////////////////// struct SmallLetterDisplay : TransparentWidget { @@ -196,10 +209,10 @@ struct SmallLetterDisplay : TransparentWidget { bool doubleblink = false; SmallLetterDisplay() { - font = Font::load(assetPlugin(plugin,defaultFontPath)); + font = Font::load(asset::plugin(pluginInstance,defaultFontPath)); }; SmallLetterDisplay(std::string fontPath) { - font = Font::load(assetPlugin(plugin,fontPath)); + font = Font::load(asset::plugin(pluginInstance,fontPath)); }; void draw(NVGcontext *vg) override diff --git a/src/ComputerscareIso.cpp b/src/ComputerscareIso.cpp @@ -2,11 +2,15 @@ struct ComputerscareIso; +const int numKnobs = 16; + +const int numToggles = 16; struct ComputerscareIso : Module { enum ParamIds { - - NUM_PARAMS + KNOB, + TOGGLES = KNOB + numKnobs, + NUM_PARAMS = TOGGLES+numToggles }; enum InputIds { @@ -14,7 +18,7 @@ struct ComputerscareIso : Module { NUM_INPUTS }; enum OutputIds { - + POLY_OUTPUT, NUM_OUTPUTS }; enum LightIds { @@ -24,8 +28,23 @@ struct ComputerscareIso : Module { ComputerscareIso() { - config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); - printf("ujje\n"); + config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + + + printf("ujje\n"); + for (int i = 0; i < numKnobs; i++) { + + params[KNOB + i].config(0.0f, 10.0f, 0.0f); + params[KNOB+i].config(0.f, 10.f, 0.f, "Channel "+std::to_string(i) + " Voltage", " Volts"); + } + params[TOGGLES].config(0.0f, 1.0f, 0.0f); + outputs[POLY_OUTPUT].setChannels(16); + } + void step() override { + for (int i = 0; i < numKnobs; i++) { + outputs[POLY_OUTPUT].setVoltage(params[KNOB+i].getValue(),i); + } + } }; @@ -34,17 +53,34 @@ struct ComputerscareIsoWidget : ModuleWidget { ComputerscareIsoWidget(ComputerscareIso *module) { setModule(module); - setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscareIsoPanel.svg"))); + //setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscareIsoPanel.svg"))); - /*box.size = Vec(15*9, 380); + box.size = Vec(15*9, 380); { ComputerscareSVGPanel *panel = new ComputerscareSVGPanel(); panel->box.size = box.size; - panel->setBackground(SVG::load(assetPlugin(plugin,"res/ComputerscareIsoPanel.svg"))); + panel->setBackground(APP->window->loadSvg(asset::plugin(pluginInstance,"res/ComputerscareIsoPanel.svg"))); + + + addChild(panel); } - */ + addParam(createParam<Davies1900hBlackKnob>(Vec(28, 87), module, ComputerscareIso::KNOB)); + addParam(createParam<MediumSnapKnob>(Vec(68, 97), module, ComputerscareIso::KNOB+1)); + addParam(createParam<SmoothKnob>(Vec(68, 127), module, ComputerscareIso::KNOB+2)); + addParam(createParam<SmallKnob>(Vec(68, 157), module, ComputerscareIso::KNOB+3)); + addParam(createParam<BigSmoothKnob>(Vec(68, 187), module, ComputerscareIso::KNOB+4)); + addParam(createParam<MediumSnapKnob>(Vec(68, 267), module, ComputerscareIso::KNOB+5)); + + addParam(createParam<IsoButton>(Vec(20, 44), module, ComputerscareIso::TOGGLES)); + + //addInput(createInput<PJ301MPort>(Vec(33, 186), module, MyModule::PITCH_INPUT)); + + addOutput(createOutput<OutPort>(Vec(33, 275), module, ComputerscareIso::POLY_OUTPUT)); + + //addChild(createLight<MediumLight<RedLight>>(Vec(41, 59), module, MyModule::BLINK_LIGHT)); + } diff --git a/src/ComputerscareSVGPanel.cpp b/src/ComputerscareSVGPanel.cpp @@ -1,41 +1,41 @@ -#include "app.hpp" -#include "window.hpp" -#include "Computerscare.hpp" +#include "Computerscare.hpp" +namespace rack { +namespace app { -struct PanelBorder : TransparentWidget { - void draw(NVGcontext *vg) override { - NVGcolor borderColor = nvgRGBAf(0.5, 0.5, 0.5, 0.5); - nvgBeginPath(vg); - nvgRect(vg, 0.5, 0.5, box.size.x - 1.0, box.size.y - 1.0); - nvgStrokeColor(vg, borderColor); - nvgStrokeWidth(vg, 1.0); - //nvgStroke(vg); - } -}; +void PanelBorder::draw(const widget::DrawContext &ctx) { + NVGcolor borderColor = nvgRGBAf(0.5, 0.5, 0.5, 0.5); + nvgBeginPath(ctx.vg); + nvgRect(ctx.vg, 0.5, 0.5, box.size.x - 1.0, box.size.y - 1.0); + nvgStrokeColor(ctx.vg, borderColor); + nvgStrokeWidth(ctx.vg, 1.0); + //nvgStroke(ctx.vg); +} void ComputerscareSVGPanel::step() { - if (isNear(gPixelRatio, 1.0)) { + if (math::isNear(APP->window->pixelRatio, 1.0)) { // Small details draw poorly at low DPI, so oversample when drawing to the framebuffer oversample = 2.0; } - FramebufferWidget::step(); + widget::FramebufferWidget::step(); } -void ComputerscareSVGPanel::setBackground(std::shared_ptr<SVG> svg) { - SVGWidget *sw = new SVGWidget(); - sw->setSVG(svg); +void ComputerscareSVGPanel::setBackground(std::shared_ptr<Svg> svg) { + widget::SvgWidget *sw = new widget::SvgWidget; + sw->setSvg(svg); addChild(sw); // Set size box.size = sw->box.size.div(RACK_GRID_SIZE).round().mult(RACK_GRID_SIZE); - PanelBorder *pb = new PanelBorder(); + PanelBorder *pb = new PanelBorder; pb->box.size = box.size; addChild(pb); } +} // namespace app +} // namespace rack