commit eeb52cc954fadb5bbfe4b24a9802835226d7af02
parent b6a29bb716446b9016b783a2552dd6503661eb9c
Author: Matt Demanett <matt@demanett.net>
Date: Sun, 12 Apr 2020 23:40:04 -0400
INV: add green/red lights to indicate whether inverting and fixed poly mode to toggle channel stats on manual button. SWITCH: ditto poly fix, and fixed high/low inputs to use mono inputs with poly triggers.
Diffstat:
6 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/README.md b/README.md
@@ -847,7 +847,7 @@ _Polyphony:_ <a href="#polyphony">Polyphonic</a>, with polyphony defined by the
A signal-routing module with two through channels. If the button is held or the GATE input is high, the HIGH input for each channel is routed to the corresponding OUT. Otherwise, each LOW input is routed to each OUT.
-If LTCH (latch) mode is enabled, a button click or trigger pulse at GATE will toggle the output to HIGH; a second click or trigger resets it to LOW.
+If LATCH is enabled, a button click or trigger pulse at GATE will toggle the output to HIGH; a second click or trigger resets it to LOW.
_Polyphony:_ If polyphonic input is present at GATE, then the module is polyphonic in the standard way, independently switching the independent polyphonic channels on the high/low inputs (the button will switch all channels). Additionally, if the input at GATE is not present or monophonic, but polyphonic cables are are present at any high/low inputs, and such an input is switched to the output, it is duplicated to the output with channels intact.
diff --git a/res-src/Inv-src.svg b/res-src/Inv-src.svg
@@ -48,6 +48,10 @@
<circle cx="0" cy="0" r="10.5" stroke-width="3" stroke="#f00" fill="none" />
</g>
</symbol>
+
+ <symbol id="light" viewBox="0 0 6.4px 6.4px">
+ <rect width="6.4" height="6.4" fill="#0f0" />
+ </symbol>
</defs>
<rect width="100%" height="100%" fill="#ddd" />
@@ -79,7 +83,9 @@
<rect width="34" height="10" fill="#bbb" transform="translate(0 0)" />
<rect width="34" height="39" rx="5" fill="#bbb" />
<use id="OUT1_OUTPUT" xlink:href="#output" transform="translate(5 3)" />
- <text font-size="5pt" letter-spacing="1px" transform="translate(9 35)">OUT</text>
+ <text font-size="5pt" letter-spacing="1px" transform="translate(14 35)">OUT</text>
+ <use id="LOW1_LIGHT" xlink:href="#light" transform="translate(5 29.3)" />
+ <use id="HIGH1_LIGHT" xlink:href="#light" transform="translate(5 29.3)" />
</g>
</g>
@@ -99,7 +105,9 @@
<rect width="34" height="10" fill="#bbb" transform="translate(0 0)" />
<rect width="34" height="39" rx="5" fill="#bbb" />
<use id="OUT2_OUTPUT" xlink:href="#output" transform="translate(5 3)" />
- <text font-size="5pt" letter-spacing="1px" transform="translate(9 35)">OUT</text>
+ <text font-size="5pt" letter-spacing="1px" transform="translate(14 35)">OUT</text>
+ <use id="LOW2_LIGHT" xlink:href="#light" transform="translate(5 29.3)" />
+ <use id="HIGH2_LIGHT" xlink:href="#light" transform="translate(5 29.3)" />
</g>
</g>
</svg>
diff --git a/res/Inv.svg b/res/Inv.svg
Binary files differ.
diff --git a/src/Inv.cpp b/src/Inv.cpp
@@ -76,6 +76,8 @@ void Inv::processAll(const ProcessArgs& args) {
void Inv::processDual(int i) {
int channels = inputs[IN1_INPUT + 2 * i].getChannels();
outputs[OUT1_OUTPUT + i].setChannels(channels);
+ int lightsOn = 0;
+
for (int c = 0; c < channels; ++c) {
bool triggered = _trigger[i][c].process(params[GATE1_PARAM + 2 * i].getValue() + inputs[GATE1_INPUT + 2 * i].getPolyVoltage(c));
if (_latch[i]) {
@@ -88,11 +90,15 @@ void Inv::processDual(int i) {
}
float in = inputs[IN1_INPUT + 2 * i].getPolyVoltage(c);
- if (_latchedHigh[i][c] || _trigger[i][c].isHigh()) {
+ if (_latchedHigh[i][c] || (!_latch[i] && _trigger[i][c].isHigh())) {
in = -in;
+ ++lightsOn;
}
outputs[OUT1_OUTPUT + i].setVoltage(in, c);
}
+
+ float red = lights[HIGH1_LIGHT + 2 * i].value = lightsOn / (float)channels;
+ lights[LOW1_LIGHT + 2 * i].value = 1.0f - red;
}
struct InvWidget : ModuleWidget {
@@ -125,6 +131,9 @@ struct InvWidget : ModuleWidget {
auto out1OutputPosition = Vec(10.5, 134.0);
auto out2OutputPosition = Vec(10.5, 299.0);
+
+ auto low1LightPosition = Vec(10.5, 160.3);
+ auto low2LightPosition = Vec(10.5, 325.3);
// end generated by svg_widgets.rb
addParam(createParam<Button18>(gate1ParamPosition, module, Inv::GATE1_PARAM));
@@ -139,6 +148,9 @@ struct InvWidget : ModuleWidget {
addOutput(createOutput<Port24>(out1OutputPosition, module, Inv::OUT1_OUTPUT));
addOutput(createOutput<Port24>(out2OutputPosition, module, Inv::OUT2_OUTPUT));
+
+ addChild(createLight<SmallLight<GreenRedLight>>(low1LightPosition, module, Inv::LOW1_LIGHT));
+ addChild(createLight<SmallLight<GreenRedLight>>(low2LightPosition, module, Inv::LOW2_LIGHT));
}
void appendContextMenu(Menu* menu) override {
diff --git a/src/Inv.hpp b/src/Inv.hpp
@@ -29,13 +29,21 @@ struct Inv : BGModule {
NUM_OUTPUTS
};
+ enum LightsIds {
+ LOW1_LIGHT,
+ HIGH1_LIGHT,
+ LOW2_LIGHT,
+ HIGH2_LIGHT,
+ NUM_LIGHTS
+ };
+
bool _saveLatchedToPatch = false;
Trigger _trigger[2][maxChannels];
bool _latch[2] {};
bool _latchedHigh[2][maxChannels] {{},{}};
Inv() {
- config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS);
+ config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
configParam(GATE1_PARAM, 0.0f, 1.0f, 0.0f, "Channel 1 gate");
configParam(LATCH1_PARAM, 0.0f, 1.0f, 0.0f, "Channel 1 latch");
configParam(GATE2_PARAM, 0.0f, 1.0f, 0.0f, "Channel 2 gate");
diff --git a/src/Switch.cpp b/src/Switch.cpp
@@ -72,7 +72,7 @@ void bogaudio::Switch::processChannel(const ProcessArgs& args, int c) {
_latchedHigh[c] = false;
}
- if (_latchedHigh[c] || _trigger[c].isHigh()) {
+ if (_latchedHigh[c] || (!_latch && _trigger[c].isHigh())) {
++_high1LightSum;
++_high2LightSum;
@@ -85,10 +85,10 @@ void bogaudio::Switch::processChannel(const ProcessArgs& args, int c) {
}
else {
outputs[OUT1_OUTPUT].setChannels(_channels);
- outputs[OUT1_OUTPUT].setVoltage(inputs[HIGH1_INPUT].getVoltage(c), c);
+ outputs[OUT1_OUTPUT].setVoltage(inputs[HIGH1_INPUT].getPolyVoltage(c), c);
outputs[OUT2_OUTPUT].setChannels(_channels);
- outputs[OUT2_OUTPUT].setVoltage(inputs[HIGH2_INPUT].getVoltage(c), c);
+ outputs[OUT2_OUTPUT].setVoltage(inputs[HIGH2_INPUT].getPolyVoltage(c), c);
}
}
else {
@@ -104,10 +104,10 @@ void bogaudio::Switch::processChannel(const ProcessArgs& args, int c) {
}
else {
outputs[OUT1_OUTPUT].setChannels(_channels);
- outputs[OUT1_OUTPUT].setVoltage(inputs[LOW1_INPUT].getVoltage(c), c);
+ outputs[OUT1_OUTPUT].setVoltage(inputs[LOW1_INPUT].getPolyVoltage(c), c);
outputs[OUT2_OUTPUT].setChannels(_channels);
- outputs[OUT2_OUTPUT].setVoltage(inputs[LOW2_INPUT].getVoltage(c), c);
+ outputs[OUT2_OUTPUT].setVoltage(inputs[LOW2_INPUT].getPolyVoltage(c), c);
}
}
}