commit 2c2648fc4d778416cc5e89010f37b8830a0b11bd
parent bafaed824738459f48d2c21352edad35d89ad1f7
Author: Matt Demanett <matt@demanett.net>
Date: Wed, 12 Sep 2018 22:12:57 -0400
Make UMIX 8 inputs; move averaging mode toggle to context menu.
Diffstat:
4 files changed, 60 insertions(+), 23 deletions(-)
diff --git a/res-src/UMix-src.svg b/res-src/UMix-src.svg
@@ -43,11 +43,6 @@
</g>
</symbol>
- <symbol id="switch" viewBox="0 0 14px 24px">
- <rect width="14px" height="24px" stroke-width="1" stroke="#000" fill="#ddd" />
- <rect width="14px" height="12px" stroke-width="0" fill="#000" />
- </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" />
@@ -80,16 +75,18 @@
<g transform="translate(0 18)">
<g transform="translate(5.5 0)">
- <rect width="34" height="10" fill="#fafafa" transform="translate(0 172)" />
- <rect width="34" height="182" rx="5" fill="#fafafa" />
+ <rect width="34" height="10" fill="#fafafa" transform="translate(0 232)" />
+ <rect width="34" height="242" rx="5" fill="#fafafa" />
<use id="IN1_INPUT" xlink:href="#input" transform="translate(5 5)" />
<use id="IN2_INPUT" xlink:href="#input" transform="translate(5 35)" />
<use id="IN3_INPUT" xlink:href="#input" transform="translate(5 65)" />
<use id="IN4_INPUT" xlink:href="#input" transform="translate(5 95)" />
<use id="IN5_INPUT" xlink:href="#input" transform="translate(5 125)" />
<use id="IN6_INPUT" xlink:href="#input" transform="translate(5 155)" />
+ <use id="IN7_INPUT" xlink:href="#input" transform="translate(5 185)" />
+ <use id="IN8_INPUT" xlink:href="#input" transform="translate(5 215)" />
</g>
- <g transform="translate(5.5 185)">
+ <g transform="translate(5.5 245)">
<rect width="34" height="10" fill="#bbb" transform="translate(0 -3)" />
<rect width="34" height="36" rx="5" fill="#bbb" />
<use id="OUT_OUTPUT" xlink:href="#output" transform="translate(5 0)" />
@@ -97,13 +94,7 @@
</g>
</g>
- <g transform="translate(15.5 254)">
- <text font-size="5pt" letter-spacing="2px" transform="translate(-2 -1)">SUM</text>
- <use id="MODE_PARAM" xlink:href="#switch" transform="translate(0 2)" />
- <text font-size="5pt" letter-spacing="2px" transform="translate(-1 34)">AVG</text>
- </g>
-
- <g transform="translate(0 305)">
+ <g transform="translate(0 311)">
<text font-size="6pt" letter-spacing="2px" transform="translate(7 0)">LEVEL</text>
<use id="LEVEL_PARAM" xlink:href="#knob-small" transform="translate(0 -5)" />
<use xlink:href="#knobguide-maxtick" transform="translate(2.2 -2.5)" />
diff --git a/res/UMix.svg b/res/UMix.svg
Binary files differ.
diff --git a/src/UMix.cpp b/src/UMix.cpp
@@ -1,13 +1,28 @@
#include "UMix.hpp"
+#define SUM "sum"
+
+json_t* UMix::toJson() {
+ json_t* root = json_object();
+ json_object_set_new(root, SUM, json_boolean(_sum));
+ return root;
+}
+
+void UMix::fromJson(json_t* root) {
+ json_t* ll = json_object_get(root, SUM);
+ if (ll) {
+ _sum = json_is_true(ll);
+ }
+}
+
void UMix::step() {
if (!outputs[OUT_OUTPUT].active) {
return;
}
- if (params[MODE_PARAM].value > 0.5f) {
+ if (_sum) {
float out = 0.0f;
- for (int i = 0; i < 6; ++i) {
+ for (int i = 0; i < 8; ++i) {
out += inputs[IN1_INPUT + i].value;
}
outputs[OUT_OUTPUT].value = _saturator.next(params[LEVEL_PARAM].value * out);
@@ -15,7 +30,7 @@ void UMix::step() {
else {
float out = 0.0f;
int active = 0;
- for (int i = 0; i < 6; ++i) {
+ for (int i = 0; i < 8; ++i) {
if (inputs[IN1_INPUT + i].active) {
out += inputs[IN1_INPUT + i].value;
++active;
@@ -31,6 +46,24 @@ void UMix::step() {
}
}
+struct AverageMenuItem : MenuItem {
+ UMix* _module;
+
+ AverageMenuItem(UMix* module, const char* label)
+ : _module(module)
+ {
+ this->text = label;
+ }
+
+ void onAction(EventAction &e) override {
+ _module->_sum = !_module->_sum;
+ }
+
+ void step() override {
+ rightText = !_module->_sum ? "✔" : "";
+ }
+};
+
struct UMixWidget : ModuleWidget {
static constexpr int hp = 3;
@@ -48,8 +81,7 @@ struct UMixWidget : ModuleWidget {
addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 15, 365)));
// generated by svg_widgets.rb
- auto modeParamPosition = Vec(15.0, 255.5);
- auto levelParamPosition = Vec(14.5, 314.5);
+ auto levelParamPosition = Vec(14.5, 320.5);
auto in1InputPosition = Vec(10.5, 23.0);
auto in2InputPosition = Vec(10.5, 53.0);
@@ -57,11 +89,12 @@ struct UMixWidget : ModuleWidget {
auto in4InputPosition = Vec(10.5, 113.0);
auto in5InputPosition = Vec(10.5, 143.0);
auto in6InputPosition = Vec(10.5, 173.0);
+ auto in7InputPosition = Vec(10.5, 203.0);
+ auto in8InputPosition = Vec(10.5, 233.0);
- auto outOutputPosition = Vec(10.5, 203.0);
+ auto outOutputPosition = Vec(10.5, 263.0);
// end generated by svg_widgets.rb
- addParam(ParamWidget::create<SliderSwitch2State14>(modeParamPosition, module, UMix::MODE_PARAM, 0.0, 1.0, 1.0));
addParam(ParamWidget::create<Knob16>(levelParamPosition, module, UMix::LEVEL_PARAM, 0.0, 1.0, 1.0));
addInput(Port::create<Port24>(in1InputPosition, Port::INPUT, module, UMix::IN1_INPUT));
@@ -70,9 +103,18 @@ struct UMixWidget : ModuleWidget {
addInput(Port::create<Port24>(in4InputPosition, Port::INPUT, module, UMix::IN4_INPUT));
addInput(Port::create<Port24>(in5InputPosition, Port::INPUT, module, UMix::IN5_INPUT));
addInput(Port::create<Port24>(in6InputPosition, Port::INPUT, module, UMix::IN6_INPUT));
+ addInput(Port::create<Port24>(in7InputPosition, Port::INPUT, module, UMix::IN7_INPUT));
+ addInput(Port::create<Port24>(in8InputPosition, Port::INPUT, module, UMix::IN8_INPUT));
addOutput(Port::create<Port24>(outOutputPosition, Port::OUTPUT, module, UMix::OUT_OUTPUT));
}
+
+ void appendContextMenu(Menu* menu) override {
+ UMix* umix = dynamic_cast<UMix*>(module);
+ assert(umix);
+ menu->addChild(new MenuLabel());
+ menu->addChild(new AverageMenuItem(umix, "Average"));
+ }
};
Model* modelUMix = createModel<UMix, UMixWidget>("Bogaudio-UMix", "UMix", "unity mixer", MIXER_TAG);
diff --git a/src/UMix.hpp b/src/UMix.hpp
@@ -11,7 +11,6 @@ namespace bogaudio {
struct UMix : Module {
enum ParamsIds {
- MODE_PARAM,
LEVEL_PARAM,
NUM_PARAMS
};
@@ -23,6 +22,8 @@ struct UMix : Module {
IN4_INPUT,
IN5_INPUT,
IN6_INPUT,
+ IN7_INPUT,
+ IN8_INPUT,
NUM_INPUTS
};
@@ -35,11 +36,14 @@ struct UMix : Module {
NUM_LIGHTS
};
+ bool _sum = true;
Saturator _saturator;
UMix() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
}
+ json_t* toJson() override;
+ void fromJson(json_t* root) override;
void step() override;
};