BogaudioModules

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

commit 5d351ce4aba45009a42e30914ed7fab785d922cb
parent 289d31889b9668d415cef587e1cf5531fb5c3ea1
Author: Matt Demanett <matt@demanett.net>
Date:   Thu, 10 May 2018 00:15:06 -0400

Flip-flop logic module.

Diffstat:
Ares-src/FlipFlop-src.svg | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ares/FlipFlop.svg | 0
Asrc/FlipFlop.cpp | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/FlipFlop.hpp | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/bogaudio.cpp | 2++
5 files changed, 259 insertions(+), 0 deletions(-)

diff --git a/res-src/FlipFlop-src.svg b/res-src/FlipFlop-src.svg @@ -0,0 +1,96 @@ +<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="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="10" fill="#0f0" transform="translate(0 68)" /> --> + <!-- <rect width="45" height="10" fill="#0f0" transform="translate(0 127)" /> --> + <!-- <rect width="45" height="10" fill="#0f0" transform="translate(0 177)" /> --> + + <g transform="rotate(-90) translate(-376 13)"> + <text class="title" font-size="7pt" letter-spacing="1.5px">FLIPFLOP</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="10" fill="#fafafa" transform="translate(0 63)" /> + <rect width="34" height="70" rx="5" fill="#fafafa" /> + <use id="IN1_INPUT" xlink:href="#input" transform="translate(5 3)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(6.5 35)">TRIG</text> + <use id="RESET1_INPUT" xlink:href="#input" transform="translate(5 38)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(3.5 70)">RESET</text> + </g> + <g transform="translate(5.5 76)"> + <rect width="34" height="10" fill="#bbb" transform="translate(0 -3)" /> + <rect width="34" height="70" rx="5" fill="#bbb" /> + <use id="A1_OUTPUT" xlink:href="#output" transform="translate(5 0)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(15 32)">A</text> + <use id="B1_OUTPUT" xlink:href="#output" transform="translate(5 35)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(15 67)">B</text> + </g> + </g> + + <g transform="translate(0 169)"> + <g transform="translate(5.5 0)"> + <rect width="34" height="10" fill="#fafafa" transform="translate(0 63)" /> + <rect width="34" height="70" rx="5" fill="#fafafa" /> + <use id="IN2_INPUT" xlink:href="#input" transform="translate(5 3)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(6.5 35)">TRIG</text> + <use id="RESET2_INPUT" xlink:href="#input" transform="translate(5 38)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(3.5 70)">RESET</text> + </g> + <g transform="translate(5.5 76)"> + <rect width="34" height="10" fill="#bbb" transform="translate(0 -3)" /> + <rect width="34" height="70" rx="5" fill="#bbb" /> + <use id="A2_OUTPUT" xlink:href="#output" transform="translate(5 0)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(15 32)">A</text> + <use id="B2_OUTPUT" xlink:href="#output" transform="translate(5 35)" /> + <text font-size="5pt" letter-spacing="2px" transform="translate(15 67)">B</text> + </g> + </g> +</svg> diff --git a/res/FlipFlop.svg b/res/FlipFlop.svg Binary files differ. diff --git a/src/FlipFlop.cpp b/src/FlipFlop.cpp @@ -0,0 +1,100 @@ + +#include "FlipFlop.hpp" + +void FlipFlop::onReset() { + _flipped1 = false; + _flipped2 = false; + _trigger1.reset(); + _resetTrigger1.reset(); + _trigger2.reset(); + _resetTrigger2.reset(); +} + +void FlipFlop::step() { + channelStep( + inputs[IN1_INPUT], + inputs[RESET1_INPUT], + outputs[A1_OUTPUT], + outputs[B1_OUTPUT], + _trigger1, + _resetTrigger1, + _flipped1 + ); + channelStep( + inputs[IN2_INPUT], + inputs[RESET2_INPUT], + outputs[A2_OUTPUT], + outputs[B2_OUTPUT], + _trigger2, + _resetTrigger2, + _flipped2 + ); +} + +void FlipFlop::channelStep( + Input& triggerInput, + Input& resetInput, + Output& aOutput, + Output& bOutput, + PositiveZeroCrossing& trigger, + SchmittTrigger& resetTrigger, + bool& flipped +) { + bool triggered = trigger.next(triggerInput.value); + resetTrigger.process(resetInput.value); + if (resetTrigger.isHigh()) { + flipped = false; + } + else if (triggered) { + flipped = !flipped; + } + + if (flipped) { + aOutput.value = 0.0f; + bOutput.value = 5.0f; + } + else { + aOutput.value = 5.0f; + bOutput.value = 0.0f; + } +} + +struct FlipFlopWidget : ModuleWidget { + FlipFlopWidget(FlipFlop* module) : ModuleWidget(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/FlipFlop.svg"))); + addChild(panel); + } + + addChild(Widget::create<ScrewSilver>(Vec(0, 0))); + addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365))); + + // generated by svg_widgets.rb + auto in1InputPosition = Vec(10.5, 21.0); + auto reset1InputPosition = Vec(10.5, 56.0); + auto in2InputPosition = Vec(10.5, 172.0); + auto reset2InputPosition = Vec(10.5, 207.0); + + auto a1OutputPosition = Vec(10.5, 94.0); + auto b1OutputPosition = Vec(10.5, 129.0); + auto a2OutputPosition = Vec(10.5, 245.0); + auto b2OutputPosition = Vec(10.5, 280.0); + // end generated by svg_widgets.rb + + addInput(Port::create<Port24>(in1InputPosition, Port::INPUT, module, FlipFlop::IN1_INPUT)); + addInput(Port::create<Port24>(reset1InputPosition, Port::INPUT, module, FlipFlop::RESET1_INPUT)); + addInput(Port::create<Port24>(in2InputPosition, Port::INPUT, module, FlipFlop::IN2_INPUT)); + addInput(Port::create<Port24>(reset2InputPosition, Port::INPUT, module, FlipFlop::RESET2_INPUT)); + + addOutput(Port::create<Port24>(a1OutputPosition, Port::OUTPUT, module, FlipFlop::A1_OUTPUT)); + addOutput(Port::create<Port24>(b1OutputPosition, Port::OUTPUT, module, FlipFlop::B1_OUTPUT)); + addOutput(Port::create<Port24>(a2OutputPosition, Port::OUTPUT, module, FlipFlop::A2_OUTPUT)); + addOutput(Port::create<Port24>(b2OutputPosition, Port::OUTPUT, module, FlipFlop::B2_OUTPUT)); + } +}; + +Model* modelFlipFlop = Model::create<FlipFlop, FlipFlopWidget>("Bogaudio", "Bogaudio-FlipFlop", "FlipFlop", LOGIC_TAG, DUAL_TAG, UTILITY_TAG); diff --git a/src/FlipFlop.hpp b/src/FlipFlop.hpp @@ -0,0 +1,61 @@ +#pragma once + +#include "bogaudio.hpp" +#include "dsp/signal.hpp" + +using namespace bogaudio::dsp; + +extern Model* modelFlipFlop; + +namespace bogaudio { + +struct FlipFlop : Module { + enum ParamsIds { + NUM_PARAMS + }; + + enum InputsIds { + IN1_INPUT, + RESET1_INPUT, + IN2_INPUT, + RESET2_INPUT, + NUM_INPUTS + }; + + enum OutputsIds { + A1_OUTPUT, + B1_OUTPUT, + A2_OUTPUT, + B2_OUTPUT, + NUM_OUTPUTS + }; + + enum LightsIds { + NUM_LIGHTS + }; + + bool _flipped1; + bool _flipped2; + PositiveZeroCrossing _trigger1; + SchmittTrigger _resetTrigger1; + PositiveZeroCrossing _trigger2; + SchmittTrigger _resetTrigger2; + + FlipFlop() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { + onReset(); + } + + virtual void onReset() override; + virtual void step() override; + void channelStep( + Input& triggerInput, + Input& resetInput, + Output& aOutput, + Output& bOutput, + PositiveZeroCrossing& trigger, + SchmittTrigger& resetTrigger, + bool& flipped + ); +}; + +} // namespace bogaudio diff --git a/src/bogaudio.cpp b/src/bogaudio.cpp @@ -21,6 +21,7 @@ #include "Bool.hpp" #include "Detune.hpp" #include "DGate.hpp" +#include "FlipFlop.hpp" #include "Follow.hpp" #include "Manual.hpp" #include "Mult.hpp" @@ -77,6 +78,7 @@ void init(rack::Plugin *p) { p->addModel(modelDetune); p->addModel(modelDGate); #ifdef EXPERIMENTAL + p->addModel(modelFlipFlop); p->addModel(modelFollow); #endif p->addModel(modelManual);