| @@ -129,6 +129,8 @@ struct Knob : ParamWidget { | |||||
| void onDragStart(); | void onDragStart(); | ||||
| void onDragMove(Vec mouseRel); | void onDragMove(Vec mouseRel); | ||||
| void onDragEnd(); | void onDragEnd(); | ||||
| /** Tell engine to smoothly vary this parameter */ | |||||
| void onChange(); | |||||
| }; | }; | ||||
| struct SpriteKnob : Knob, SpriteWidget { | struct SpriteKnob : Knob, SpriteWidget { | ||||
| @@ -164,7 +166,6 @@ struct SVGSlider : Knob, FramebufferWidget { | |||||
| }; | }; | ||||
| struct Switch : ParamWidget { | struct Switch : ParamWidget { | ||||
| virtual void setIndex(int index) {} | |||||
| }; | }; | ||||
| struct SVGSwitch : virtual Switch, FramebufferWidget { | struct SVGSwitch : virtual Switch, FramebufferWidget { | ||||
| @@ -175,8 +176,8 @@ struct SVGSwitch : virtual Switch, FramebufferWidget { | |||||
| SVGSwitch(); | SVGSwitch(); | ||||
| /** Adds an SVG file to represent the next switch position */ | /** Adds an SVG file to represent the next switch position */ | ||||
| void addFrame(std::shared_ptr<SVG> svg); | void addFrame(std::shared_ptr<SVG> svg); | ||||
| void setIndex(int index); | |||||
| void step(); | void step(); | ||||
| void onChange(); | |||||
| }; | }; | ||||
| /** A switch that cycles through each mechanical position */ | /** A switch that cycles through each mechanical position */ | ||||
| @@ -184,31 +185,10 @@ struct ToggleSwitch : virtual Switch { | |||||
| void onDragStart() { | void onDragStart() { | ||||
| // Cycle through values | // Cycle through values | ||||
| // e.g. a range of [0.0, 3.0] would have modes 0, 1, 2, and 3. | // 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 { | struct MomentarySwitch : virtual Switch { | ||||
| void onDragStart() { | void onDragStart() { | ||||
| setValue(maxValue); | setValue(maxValue); | ||||
| setIndex(1); | |||||
| } | } | ||||
| void onDragEnd() { | void onDragEnd() { | ||||
| setValue(minValue); | setValue(minValue); | ||||
| setIndex(0); | |||||
| } | } | ||||
| }; | }; | ||||
| @@ -413,7 +413,7 @@ struct SmallLight : BASE { | |||||
| }; | }; | ||||
| //////////////////// | //////////////////// | ||||
| // Switches | |||||
| // Switches and Buttons | |||||
| //////////////////// | //////////////////// | ||||
| struct NKK : SVGSwitch, ToggleSwitch { | 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 | // Misc | ||||
| @@ -1,5 +1,6 @@ | |||||
| #include "app.hpp" | #include "app.hpp" | ||||
| #include "gui.hpp" | #include "gui.hpp" | ||||
| #include "engine.hpp" | |||||
| // For GLFW_KEY_LEFT_CONTROL, etc. | // For GLFW_KEY_LEFT_CONTROL, etc. | ||||
| #include <GLFW/glfw3.h> | #include <GLFW/glfw3.h> | ||||
| @@ -24,5 +25,12 @@ void Knob::onDragEnd() { | |||||
| guiCursorUnlock(); | guiCursorUnlock(); | ||||
| } | } | ||||
| void Knob::onChange() { | |||||
| if (!module) | |||||
| return; | |||||
| engineSetParamSmooth(module, paramId, value); | |||||
| } | |||||
| } // namespace rack | } // namespace rack | ||||
| @@ -23,8 +23,7 @@ void ParamWidget::onChange() { | |||||
| if (!module) | if (!module) | ||||
| return; | return; | ||||
| // module->params[paramId] = value; | |||||
| engineSetParamSmooth(module, paramId, value); | |||||
| module->params[paramId] = value; | |||||
| } | } | ||||
| @@ -19,15 +19,16 @@ void SVGSwitch::addFrame(std::shared_ptr<SVG> svg) { | |||||
| sw->svg = 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()) | if (0 <= index && index < (int)frames.size()) | ||||
| sw->svg = frames[index]; | sw->svg = frames[index]; | ||||
| dirty = true; | dirty = true; | ||||
| } | } | ||||
| void SVGSwitch::step() { | |||||
| FramebufferWidget::step(); | |||||
| } | |||||
| } // namespace rack | } // namespace rack | ||||