commit 7fb7c023ff570cea5f113682df4c6f1c79fb10c5
parent 2b23479d9b5364c2b47d007a2bc44cc8323257e1
Author: Matt Demanett <matt@demanett.net>
Date: Thu, 26 Apr 2018 23:11:25 -0400
Bool and Sums: logic and arithmetic utilities.
Diffstat:
9 files changed, 363 insertions(+), 0 deletions(-)
diff --git a/res-src/Bool-src.svg b/res-src/Bool-src.svg
@@ -0,0 +1,84 @@
+<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" />
+
+ <g transform="rotate(-90) translate(-376 13)">
+ <text class="title" font-size="7pt" letter-spacing="2.5px">BOOL</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(7.5 18)">
+ <rect width="34" height="63.5" rx="5" fill="#fafafa" transform="translate(-2 0)" />
+ <rect width="34" height="10" fill="#fafafa" transform="translate(-2 53.5)" />
+ <use id="A_INPUT" xlink:href="#input" transform="translate(3 5)" />
+ <use id="B_INPUT" xlink:href="#input" transform="translate(3 35)" />
+ </g>
+ <g transform="translate(7.5 82)">
+ <rect width="34" height="123" rx="5" fill="#bbb" transform="translate(-2 0)" />
+ <rect width="34" height="10" fill="#bbb" transform="translate(-2 0)" />
+ <use id="AND_OUTPUT" xlink:href="#output" transform="translate(3 4)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(6.3 37)">AND</text>
+ <use id="OR_OUTPUT" xlink:href="#output" transform="translate(3 44)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(9.5 77)">OR</text>
+ <use id="XOR_OUTPUT" xlink:href="#output" transform="translate(3 84)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(6.5 117)">XOR</text>
+ </g>
+
+ <g transform="translate(0 217)">
+ <g transform="translate(5.5 0)">
+ <rect width="34" height="10" fill="#fafafa" transform="translate(0 22)" />
+ <rect width="34" height="32" rx="5" fill="#fafafa" />
+ <use id="NOT_INPUT" xlink:href="#input" transform="translate(5 4)" />
+ </g>
+ <g transform="translate(5.5 35)">
+ <rect width="34" height="10" fill="#bbb" transform="translate(0 -3)" />
+ <rect width="34" height="39" rx="5" fill="#bbb" />
+ <use id="NOT_OUTPUT" xlink:href="#output" transform="translate(5 2)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(8.3 34)">NOT</text>
+ </g>
+ </g>
+</svg>
diff --git a/res-src/Sums-src.svg b/res-src/Sums-src.svg
@@ -0,0 +1,86 @@
+<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" />
+
+ <g transform="rotate(-90) translate(-376 13)">
+ <text class="title" font-size="7pt" letter-spacing="2.5px">SUMS</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(7.5 18)">
+ <rect width="34" height="63.5" rx="5" fill="#fafafa" transform="translate(-2 0)" />
+ <rect width="34" height="10" fill="#fafafa" transform="translate(-2 53.5)" />
+ <use id="A_INPUT" xlink:href="#input" transform="translate(3 5)" />
+ <use id="B_INPUT" xlink:href="#input" transform="translate(3 35)" />
+ </g>
+ <g transform="translate(7.5 82)">
+ <rect width="34" height="163" rx="5" fill="#bbb" transform="translate(-2 0)" />
+ <rect width="34" height="10" fill="#bbb" transform="translate(-2 0)" />
+ <use id="SUM_OUTPUT" xlink:href="#output" transform="translate(3 4)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(6.3 37)">SUM</text>
+ <use id="DIFFERENCE_OUTPUT" xlink:href="#output" transform="translate(3 44)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(5 77)">DIFF</text>
+ <use id="MAX_OUTPUT" xlink:href="#output" transform="translate(3 84)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(6.5 117)">MAX</text>
+ <use id="MIN_OUTPUT" xlink:href="#output" transform="translate(3 124)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(6.5 157)">MIN</text>
+ </g>
+
+ <g transform="translate(0 258)">
+ <g transform="translate(5.5 0)">
+ <rect width="34" height="10" fill="#fafafa" transform="translate(0 22)" />
+ <rect width="34" height="32" rx="5" fill="#fafafa" />
+ <use id="NEGATE_INPUT" xlink:href="#input" transform="translate(5 4)" />
+ </g>
+ <g transform="translate(5.5 35)">
+ <rect width="34" height="10" fill="#bbb" transform="translate(0 -3)" />
+ <rect width="34" height="39" rx="5" fill="#bbb" />
+ <use id="NEGATE_OUTPUT" xlink:href="#output" transform="translate(5 2)" />
+ <text font-size="5pt" letter-spacing="2px" transform="translate(8.3 34)">NEG</text>
+ </g>
+ </g>
+</svg>
diff --git a/res/Bool.svg b/res/Bool.svg
Binary files differ.
diff --git a/res/Sums.svg b/res/Sums.svg
Binary files differ.
diff --git a/src/Bool.cpp b/src/Bool.cpp
@@ -0,0 +1,50 @@
+
+#include "Bool.hpp"
+
+void Bool::step() {
+ bool a = inputs[A_INPUT].value > 2.0f;
+ bool b = inputs[B_INPUT].value > 2.0f;
+ outputs[AND_OUTPUT].value = a && b ? 5.0f : 0.0f;
+ outputs[OR_OUTPUT].value = a || b ? 5.0f : 0.0f;
+ outputs[XOR_OUTPUT].value = a ^ b ? 5.0f : 0.0f;
+
+ outputs[NOT_OUTPUT].value = (inputs[NOT_INPUT].active && inputs[NOT_INPUT].value > 2.0f) ? 0.0f : 5.0f;
+}
+
+struct BoolWidget : ModuleWidget {
+ BoolWidget(Bool* 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/Bool.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 aInputPosition = Vec(10.5, 23.0);
+ auto bInputPosition = Vec(10.5, 53.0);
+ auto notInputPosition = Vec(10.5, 221.0);
+
+ auto andOutputPosition = Vec(10.5, 86.0);
+ auto orOutputPosition = Vec(10.5, 126.0);
+ auto xorOutputPosition = Vec(10.5, 166.0);
+ auto notOutputPosition = Vec(10.5, 254.0);
+ // end generated by svg_widgets.rb
+
+ addInput(Port::create<Port24>(aInputPosition, Port::INPUT, module, Bool::A_INPUT));
+ addInput(Port::create<Port24>(bInputPosition, Port::INPUT, module, Bool::B_INPUT));
+ addInput(Port::create<Port24>(notInputPosition, Port::INPUT, module, Bool::NOT_INPUT));
+
+ addOutput(Port::create<Port24>(andOutputPosition, Port::OUTPUT, module, Bool::AND_OUTPUT));
+ addOutput(Port::create<Port24>(orOutputPosition, Port::OUTPUT, module, Bool::OR_OUTPUT));
+ addOutput(Port::create<Port24>(xorOutputPosition, Port::OUTPUT, module, Bool::XOR_OUTPUT));
+ addOutput(Port::create<Port24>(notOutputPosition, Port::OUTPUT, module, Bool::NOT_OUTPUT));
+ }
+};
+
+Model* modelBool = Model::create<Bool, BoolWidget>("Bogaudio", "Bogaudio-Bool", "Bool", LOGIC_TAG, UTILITY_TAG);
diff --git a/src/Bool.hpp b/src/Bool.hpp
@@ -0,0 +1,39 @@
+#pragma once
+
+#include "bogaudio.hpp"
+
+extern Model* modelBool;
+
+namespace bogaudio {
+
+struct Bool : Module {
+ enum ParamsIds {
+ NUM_PARAMS
+ };
+
+ enum InputsIds {
+ A_INPUT,
+ B_INPUT,
+ NOT_INPUT,
+ NUM_INPUTS
+ };
+
+ enum OutputsIds {
+ AND_OUTPUT,
+ OR_OUTPUT,
+ XOR_OUTPUT,
+ NOT_OUTPUT,
+ NUM_OUTPUTS
+ };
+
+ enum LightsIds {
+ NUM_LIGHTS
+ };
+
+ Bool() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
+ }
+
+ virtual void step() override;
+};
+
+} // namespace bogaudio
diff --git a/src/Sums.cpp b/src/Sums.cpp
@@ -0,0 +1,58 @@
+
+#include "Sums.hpp"
+
+void Sums::step() {
+ float a = inputs[A_INPUT].value;
+ float b = inputs[B_INPUT].value;
+ outputs[SUM_OUTPUT].value = a + b;
+ outputs[DIFFERENCE_OUTPUT].value = a - b;
+ outputs[MAX_OUTPUT].value = std::max(a, b);
+ outputs[MIN_OUTPUT].value = std::min(a, b);
+
+ if (inputs[NEGATE_INPUT].active) {
+ outputs[NEGATE_OUTPUT].value = -inputs[NEGATE_INPUT].value;
+ }
+ else {
+ outputs[NEGATE_OUTPUT].value = 0.0f;
+ }
+}
+
+struct SumsWidget : ModuleWidget {
+ SumsWidget(Sums* 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/Sums.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 aInputPosition = Vec(10.5, 23.0);
+ auto bInputPosition = Vec(10.5, 53.0);
+ auto negateInputPosition = Vec(10.5, 262.0);
+
+ auto sumOutputPosition = Vec(10.5, 86.0);
+ auto differenceOutputPosition = Vec(10.5, 126.0);
+ auto maxOutputPosition = Vec(10.5, 166.0);
+ auto minOutputPosition = Vec(10.5, 206.0);
+ auto negateOutputPosition = Vec(10.5, 295.0);
+ // end generated by svg_widgets.rb
+
+ addInput(Port::create<Port24>(aInputPosition, Port::INPUT, module, Sums::A_INPUT));
+ addInput(Port::create<Port24>(bInputPosition, Port::INPUT, module, Sums::B_INPUT));
+ addInput(Port::create<Port24>(negateInputPosition, Port::INPUT, module, Sums::NEGATE_INPUT));
+
+ addOutput(Port::create<Port24>(sumOutputPosition, Port::OUTPUT, module, Sums::SUM_OUTPUT));
+ addOutput(Port::create<Port24>(differenceOutputPosition, Port::OUTPUT, module, Sums::DIFFERENCE_OUTPUT));
+ addOutput(Port::create<Port24>(maxOutputPosition, Port::OUTPUT, module, Sums::MAX_OUTPUT));
+ addOutput(Port::create<Port24>(minOutputPosition, Port::OUTPUT, module, Sums::MIN_OUTPUT));
+ addOutput(Port::create<Port24>(negateOutputPosition, Port::OUTPUT, module, Sums::NEGATE_OUTPUT));
+ }
+};
+
+Model* modelSums = Model::create<Sums, SumsWidget>("Bogaudio", "Bogaudio-Sums", "Sums", LOGIC_TAG, UTILITY_TAG);
diff --git a/src/Sums.hpp b/src/Sums.hpp
@@ -0,0 +1,40 @@
+#pragma once
+
+#include "bogaudio.hpp"
+
+extern Model* modelSums;
+
+namespace bogaudio {
+
+struct Sums : Module {
+ enum ParamsIds {
+ NUM_PARAMS
+ };
+
+ enum InputsIds {
+ A_INPUT,
+ B_INPUT,
+ NEGATE_INPUT,
+ NUM_INPUTS
+ };
+
+ enum OutputsIds {
+ SUM_OUTPUT,
+ DIFFERENCE_OUTPUT,
+ MAX_OUTPUT,
+ MIN_OUTPUT,
+ NEGATE_OUTPUT,
+ NUM_OUTPUTS
+ };
+
+ enum LightsIds {
+ NUM_LIGHTS
+ };
+
+ Sums() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
+ }
+
+ virtual void step() override;
+};
+
+} // namespace bogaudio
diff --git a/src/bogaudio.cpp b/src/bogaudio.cpp
@@ -16,6 +16,7 @@
#include "Analyzer.hpp"
#include "ADSR.hpp"
+#include "Bool.hpp"
#include "Detune.hpp"
#include "DGate.hpp"
#include "Manual.hpp"
@@ -25,6 +26,7 @@
#include "Reftone.hpp"
#include "SampleHold.hpp"
#include "Stack.hpp"
+#include "Sums.hpp"
#include "Switch.hpp"
#include "VCA.hpp"
@@ -59,6 +61,7 @@ void init(rack::Plugin *p) {
#ifdef EXPERIMENTAL
p->addModel(modelADSR);
+ p->addModel(modelBool);
#endif
p->addModel(modelDetune);
p->addModel(modelDGate);
@@ -71,6 +74,9 @@ void init(rack::Plugin *p) {
p->addModel(modelReftone);
p->addModel(modelSampleHold);
p->addModel(modelStack);
+#ifdef EXPERIMENTAL
+ p->addModel(modelSums);
+#endif
p->addModel(modelSwitch);
p->addModel(modelVCA);