From da89bdb76e904bd09a1f0587f4b9867508326306 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sun, 7 May 2017 05:39:45 -0700 Subject: [PATCH] Added more switches --- include/app.hpp | 36 ++++++------------------------- include/components.hpp | 48 ++++++++++++++++++++++++++++++++++++++++- src/app/Knob.cpp | 8 +++++++ src/app/ParamWidget.cpp | 3 +-- src/app/SVGSwitch.cpp | 11 +++++----- 5 files changed, 69 insertions(+), 37 deletions(-) diff --git a/include/app.hpp b/include/app.hpp index c0cf7a61..6ebc23cd 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -129,6 +129,8 @@ struct Knob : ParamWidget { void onDragStart(); void onDragMove(Vec mouseRel); void onDragEnd(); + /** Tell engine to smoothly vary this parameter */ + void onChange(); }; struct SpriteKnob : Knob, SpriteWidget { @@ -164,7 +166,6 @@ struct SVGSlider : Knob, FramebufferWidget { }; struct Switch : ParamWidget { - virtual void setIndex(int index) {} }; struct SVGSwitch : virtual Switch, FramebufferWidget { @@ -175,8 +176,8 @@ struct SVGSwitch : virtual Switch, FramebufferWidget { SVGSwitch(); /** Adds an SVG file to represent the next switch position */ void addFrame(std::shared_ptr svg); - void setIndex(int index); void step(); + void onChange(); }; /** A switch that cycles through each mechanical position */ @@ -184,31 +185,10 @@ struct ToggleSwitch : virtual Switch { void onDragStart() { // Cycle through values // e.g. a range of [0.0, 3.0] would have modes 0, 1, 2, and 3. - float v = value + 1.0; - setValue(v <= maxValue ? v : minValue); - } - void onChange() { - int index = (int)roundf(value); - setIndex(index); - ParamWidget::onChange(); - } -}; - -/** FIXME I don't think this should exist. The audio engine should read from a MomentarySwitch and increment its internal state, instead of relying on the knob to do that logic. */ -struct ModeSwitch : virtual Switch { - void onDragStart() { - setIndex(1); - } - void onDragEnd() { - setIndex(0); - } - void onDragDrop(Widget *origin) { - if (origin != this) - return; - // Cycle through values - // e.g. a range of [0.0, 3.0] would have modes 0, 1, 2, and 3. - float v = value + 1.0; - setValue(v <= maxValue ? v : minValue); + if (value >= maxValue) + setValue(minValue); + else + setValue(value + 1.0); } }; @@ -216,11 +196,9 @@ struct ModeSwitch : virtual Switch { struct MomentarySwitch : virtual Switch { void onDragStart() { setValue(maxValue); - setIndex(1); } void onDragEnd() { setValue(minValue); - setIndex(0); } }; diff --git a/include/components.hpp b/include/components.hpp index c0348570..9ab83697 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -413,7 +413,7 @@ struct SmallLight : BASE { }; //////////////////// -// Switches +// Switches and Buttons //////////////////// struct NKK : SVGSwitch, ToggleSwitch { @@ -426,6 +426,52 @@ struct NKK : SVGSwitch, ToggleSwitch { } }; +struct CKSS : SVGSwitch, ToggleSwitch { + CKSS() { + addFrame(SVG::load("res/ComponentLibrary/CKSS0.svg")); + addFrame(SVG::load("res/ComponentLibrary/CKSS1.svg")); + sw->wrap(); + box.size = sw->box.size; + } +}; + +struct CKD6 : SVGSwitch, MomentarySwitch { + CKD6() { + addFrame(SVG::load("res/ComponentLibrary/CKD6_0.svg")); + addFrame(SVG::load("res/ComponentLibrary/CKD6_1.svg")); + sw->wrap(); + box.size = sw->box.size; + } +}; + +struct TL1105 : SVGSwitch, MomentarySwitch { + TL1105() { + addFrame(SVG::load("res/ComponentLibrary/TL1105_0.svg")); + addFrame(SVG::load("res/ComponentLibrary/TL1105_1.svg")); + sw->wrap(); + box.size = sw->box.size; + } +}; + +struct BefacoSwitch : SVGSwitch, ToggleSwitch { + BefacoSwitch() { + addFrame(SVG::load("res/ComponentLibrary/BefacoSwitch_0.svg")); + addFrame(SVG::load("res/ComponentLibrary/BefacoSwitch_1.svg")); + addFrame(SVG::load("res/ComponentLibrary/BefacoSwitch_2.svg")); + sw->wrap(); + box.size = sw->box.size; + } +}; + +struct BefacoPush : SVGSwitch, MomentarySwitch { + BefacoPush() { + addFrame(SVG::load("res/ComponentLibrary/BefacoPush_0.svg")); + addFrame(SVG::load("res/ComponentLibrary/BefacoPush_1.svg")); + sw->wrap(); + box.size = sw->box.size; + } +}; + //////////////////// // Misc diff --git a/src/app/Knob.cpp b/src/app/Knob.cpp index a78220f5..7410ff8d 100644 --- a/src/app/Knob.cpp +++ b/src/app/Knob.cpp @@ -1,5 +1,6 @@ #include "app.hpp" #include "gui.hpp" +#include "engine.hpp" // For GLFW_KEY_LEFT_CONTROL, etc. #include @@ -24,5 +25,12 @@ void Knob::onDragEnd() { guiCursorUnlock(); } +void Knob::onChange() { + if (!module) + return; + + engineSetParamSmooth(module, paramId, value); +} + } // namespace rack diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index 7b3fca88..7f708809 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -23,8 +23,7 @@ void ParamWidget::onChange() { if (!module) return; - // module->params[paramId] = value; - engineSetParamSmooth(module, paramId, value); + module->params[paramId] = value; } diff --git a/src/app/SVGSwitch.cpp b/src/app/SVGSwitch.cpp index a914b051..4d3d10f6 100644 --- a/src/app/SVGSwitch.cpp +++ b/src/app/SVGSwitch.cpp @@ -19,15 +19,16 @@ void SVGSwitch::addFrame(std::shared_ptr svg) { sw->svg = svg; } -void SVGSwitch::setIndex(int index) { +void SVGSwitch::step() { + FramebufferWidget::step(); +} + +void SVGSwitch::onChange() { + int index = roundf(mapf(value, minValue, maxValue, 0, frames.size() - 1)); if (0 <= index && index < (int)frames.size()) sw->svg = frames[index]; dirty = true; } -void SVGSwitch::step() { - FramebufferWidget::step(); -} - } // namespace rack