BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

commit ae27d9100edc4a5b235cad3163074a14057183a8
parent 3e95653e65f706cc68347e98f125b86fffff8dea
Author: Matt Demanett <matt@demanett.net>
Date:   Sat,  6 Jan 2018 14:11:05 -0500

Switch module.

Diffstat:
Ares-src/Switch-src.svg | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ares/Switch.svg | 0
Msrc/BogaudioModules.cpp | 1+
Msrc/BogaudioModules.hpp | 4++++
Asrc/Switch.cpp | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 218 insertions(+), 0 deletions(-)

diff --git a/res-src/Switch-src.svg b/res-src/Switch-src.svg @@ -0,0 +1,115 @@ +<svg + version="1.1" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + width="45" + height="380" + viewBox="0 0 45 380" +> + <style> + text { + fill: #333; + font-family: 'Roboto', sans-serif; + font-weight: bold; + } + text.title { + font-family: 'Comfortaa', sans-serif; + font-weight: normal; + } + text.brand { + font-family: 'Audiowide', sans-serif; + font-weight: bold; + } + </style> + + <defs> + <symbol id="button" viewBox="0 0 18px 18px"> + <g transform="translate(9 9)"> + <circle cx="0" cy="0" r="8.5" stroke-width="1" stroke="#00f" fill="#f00" /> + </g> + </symbol> + + <symbol id="input" viewBox="0 0 24px 24px"> + <g transform="translate(12 12)"> + <circle cx="0" cy="0" r="5" stroke-width="1" stroke="#0f0" fill="#0f0" /> + <circle cx="0" cy="0" r="10.5" stroke-width="3" stroke="#0f0" fill="none" /> + </g> + </symbol> + + <symbol id="output" viewBox="0 0 24px 24px"> + <g transform="translate(12 12)"> + <circle cx="0" cy="0" r="5" stroke-width="1" stroke="#f00" fill="#f00" /> + <circle cx="0" cy="0" r="10.5" stroke-width="3" stroke="#f00" fill="none" /> + </g> + </symbol> + </defs> + + <rect width="100%" height="100%" fill="#ddd" /> + <polyline points="1,1 44,1 44,379 1,379 1,1" stroke="#e4e4e4" stroke-width="0.5" fill="none" /> + <polyline points="0.5,0.5 44.5,0.5 44.5,379.5 0.5,379.5 0.5,0.5" stroke="#ebebeb" stroke-width="0.8" fill="none" /> + <polyline points="0,0 45,0 45,380 0,380 0,0" stroke="#f2f2f2" stroke-width="1" fill="none" /> + + <!-- <polyline points="22.5,0 22.5,380" stroke-width="0.5" stroke="#0f0" /> --> + <!-- <rect width="45" height="7" fill="#0f0" transform="translate(0 80)" /> --> + <!-- <rect width="45" height="7" fill="#0f0" transform="translate(0 199)" /> --> + <!-- <rect width="45" height="7" fill="#0f0" transform="translate(0 318)" /> --> + + <g transform="rotate(-90) translate(-376 13)"> + <text class="title" font-size="7pt" letter-spacing="2.5px">SWITCH</text> + <g transform="translate(0 12)"> + <text class="brand" font-size="7pt" letter-spacing="2px">BGA</text> + <rect width="3.0" height="3" fill="#ddd" transform="translate(11.5 -5)" /> + </g> + </g> + + <g transform="translate(0 18)"> + <g transform="translate(5.5 0)"> + <rect width="34" height="62" rx="5" fill="#fafafa" /> + <use id="GATE_PARAM" xlink:href="#button" transform="translate(8 4)" /> + <use id="GATE_INPUT" xlink:href="#input" transform="translate(5 26)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(5.5 58)">GATE</text> + </g> + + <g transform="translate(0 69)"> + <g transform="translate(5.5 0)"> + <rect width="34" height="10" fill="#fafafa" transform="translate(0 29)" /> + <rect width="34" height="35" rx="5" fill="#fafafa" /> + <use id="HIGH1_INPUT" xlink:href="#input" transform="translate(5 3)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(6.0 35)">HIGH</text> + </g> + <g transform="translate(5.5 36)"> + <rect width="34" height="10" fill="#fafafa" transform="translate(0 28)" /> + <rect width="34" height="35" rx="5" fill="#fafafa" /> + <use id="LOW1_INPUT" xlink:href="#input" transform="translate(5 3)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(8.0 35)">LOW</text> + </g> + <g transform="translate(5.5 77)"> + <rect width="34" height="10" fill="#bbb" transform="translate(0 -3)" /> + <rect width="34" height="35" rx="5" fill="#bbb" /> + <use id="OUT1_OUTPUT" xlink:href="#output" transform="translate(5 0)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(8.5 32)">OUT</text> + </g> + </g> + + <g transform="translate(0 188)"> + <g transform="translate(5.5 0)"> + <rect width="34" height="10" fill="#fafafa" transform="translate(0 29)" /> + <rect width="34" height="35" rx="5" fill="#fafafa" /> + <use id="HIGH2_INPUT" xlink:href="#input" transform="translate(5 3)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(6.0 35)">HIGH</text> + </g> + <g transform="translate(5.5 36)"> + <rect width="34" height="10" fill="#fafafa" transform="translate(0 28)" /> + <rect width="34" height="35" rx="5" fill="#fafafa" /> + <use id="LOW2_INPUT" xlink:href="#input" transform="translate(5 3)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(8.0 35)">LOW</text> + </g> + <g transform="translate(5.5 77)"> + <rect width="34" height="10" fill="#bbb" transform="translate(0 -3)" /> + <rect width="34" height="35" rx="5" fill="#bbb" /> + <use id="OUT2_OUTPUT" xlink:href="#output" transform="translate(5 0)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(8.5 32)">OUT</text> + </g> + </g> + </g> +</svg> diff --git a/res/Switch.svg b/res/Switch.svg Binary files differ. diff --git a/src/BogaudioModules.cpp b/src/BogaudioModules.cpp @@ -24,4 +24,5 @@ void init(rack::Plugin *p) { p->addModel(createModel<OffsetWidget>("Bogaudio", "Bogaudio-Offset", "Offset", ATTENUATOR_TAG, UTILITY_TAG)); p->addModel(createModel<ReftoneWidget>("Bogaudio", "Bogaudio-Reftone", "Reftone", UTILITY_TAG)); p->addModel(createModel<SampleHoldWidget>("Bogaudio", "Bogaudio-SampleHold", "S&H", SAMPLE_AND_HOLD_TAG, DUAL_TAG, UTILITY_TAG)); + p->addModel(createModel<SwitchWidget>("Bogaudio", "Bogaudio-Switch", "Switch", UTILITY_TAG)); } diff --git a/src/BogaudioModules.hpp b/src/BogaudioModules.hpp @@ -61,4 +61,8 @@ struct ReftoneWidget : ModuleWidget { ReftoneWidget(); }; +struct SwitchWidget : ModuleWidget { + SwitchWidget(); +}; + } // namespae bogaudio diff --git a/src/Switch.cpp b/src/Switch.cpp @@ -0,0 +1,98 @@ + +#include "BogaudioModules.hpp" + +namespace bogaudio { + +struct Switch : Module { + enum ParamsIds { + GATE_PARAM, + NUM_PARAMS + }; + + enum InputsIds { + GATE_INPUT, + HIGH1_INPUT, + LOW1_INPUT, + HIGH2_INPUT, + LOW2_INPUT, + NUM_INPUTS + }; + + enum OutputsIds { + OUT1_OUTPUT, + OUT2_OUTPUT, + NUM_OUTPUTS + }; + + enum LightsIds { + NUM_LIGHTS + }; + + SchmittTrigger _trigger; + + Switch() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { + reset(); + } + + virtual void reset() override; + virtual void step() override; +}; + +void Switch::reset() { + _trigger.reset(); +} + +void Switch::step() { + _trigger.process(params[GATE_PARAM].value + inputs[GATE_INPUT].value); + if (_trigger.isHigh()) { + outputs[OUT1_OUTPUT].value = inputs[HIGH1_INPUT].value; + outputs[OUT2_OUTPUT].value = inputs[HIGH2_INPUT].value; + } + else { + outputs[OUT1_OUTPUT].value = inputs[LOW1_INPUT].value; + outputs[OUT2_OUTPUT].value = inputs[LOW2_INPUT].value; + } +} + +} // namespace bogaudio + + +SwitchWidget::SwitchWidget() { + bogaudio::Switch *module = new bogaudio::Switch(); + setModule(module); + box.size = Vec(RACK_GRID_WIDTH * 3, RACK_GRID_HEIGHT); + + { + SVGPanel *panel = new SVGPanel(); + panel->box.size = box.size; + panel->setBackground(SVG::load(assetPlugin(plugin, "res/Switch.svg"))); + addChild(panel); + } + + addChild(createScrew<ScrewSilver>(Vec(0, 0))); + addChild(createScrew<ScrewSilver>(Vec(box.size.x - 15, 365))); + + // generated by svg_widgets.rb + auto gateParamPosition = Vec(13.5, 22.0); + + auto gateInputPosition = Vec(10.5, 44.0); + auto high1InputPosition = Vec(10.5, 90.0); + auto low1InputPosition = Vec(10.5, 126.0); + auto high2InputPosition = Vec(10.5, 209.0); + auto low2InputPosition = Vec(10.5, 245.0); + + auto out1OutputPosition = Vec(10.5, 164.0); + auto out2OutputPosition = Vec(10.5, 283.0); + // end generated by svg_widgets.rb + + addParam(createParam<Button18>(gateParamPosition, module, bogaudio::Switch::GATE_PARAM, 0.0, 1.0, 0.0)); + + addInput(createInput<Port24>(gateInputPosition, module, bogaudio::Switch::GATE_INPUT)); + addInput(createInput<Port24>(high1InputPosition, module, bogaudio::Switch::HIGH1_INPUT)); + addInput(createInput<Port24>(low1InputPosition, module, bogaudio::Switch::LOW1_INPUT)); + addInput(createInput<Port24>(high2InputPosition, module, bogaudio::Switch::HIGH2_INPUT)); + addInput(createInput<Port24>(low2InputPosition, module, bogaudio::Switch::LOW2_INPUT)); + + addOutput(createOutput<Port24>(out1OutputPosition, module, bogaudio::Switch::OUT1_OUTPUT)); + addOutput(createOutput<Port24>(out2OutputPosition, module, bogaudio::Switch::OUT2_OUTPUT)); +}