From 42bbf44c3e7d31aebb5e65cbebdbba2d8dfe4939 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 20 Feb 2019 05:21:07 -0500 Subject: [PATCH] Make 8vert polyphonic. Remove 8vert lights. --- src/8vert.cpp | 38 +++++++++++++++++++++----------------- src/SequentialSwitch.cpp | 2 +- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/8vert.cpp b/src/8vert.cpp index 78a1f8f..3e8f42e 100644 --- a/src/8vert.cpp +++ b/src/8vert.cpp @@ -15,25 +15,38 @@ struct _8vert : Module { NUM_OUTPUTS }; enum LightIds { - ENUMS(OUT_LIGHTS, 8*2), NUM_LIGHTS }; _8vert() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); for (int i = 0; i < 8; i++) { - params[GAIN_PARAMS + i].config(-1.f, 1.f, 0.f, string::f("Ch %d gain", i+1)); + params[GAIN_PARAMS + i].config(-1.f, 1.f, 0.f, string::f("Ch %d gain", i + 1), "%", 0, 100); } } void process(const ProcessArgs &args) override { - float lastIn = 10.f; + float in[16] = {10.f}; + int channels = 1; + for (int i = 0; i < 8; i++) { - lastIn = inputs[i].getNormalVoltage(lastIn); - float out = lastIn * params[i].getValue(); - outputs[i].setVoltage(out); - lights[2*i + 0].setSmoothBrightness(out / 5.f, args.sampleTime); - lights[2*i + 1].setSmoothBrightness(-out / 5.f, args.sampleTime); + // Get input + if (inputs[IN_INPUTS + i].isConnected()) { + channels = inputs[IN_INPUTS + i].getChannels(); + inputs[IN_INPUTS + i].getVoltages(in); + } + + if (outputs[OUT_OUTPUTS + i].isConnected()) { + // Apply gain + float out[16]; + float gain = params[GAIN_PARAMS + i].getValue(); + for (int c = 0; c < channels; c++) + out[c] = gain * in[c]; + + // Set output + outputs[OUT_OUTPUTS + i].setChannels(channels); + outputs[OUT_OUTPUTS + i].setVoltages(out); + } } } }; @@ -75,15 +88,6 @@ struct _8vertWidget : ModuleWidget { addOutput(createOutput(Vec(86.393, 242.614), module, _8vert::OUT_OUTPUTS + 5)); addOutput(createOutput(Vec(86.393, 281.059), module, _8vert::OUT_OUTPUTS + 6)); addOutput(createOutput(Vec(86.393, 319.504), module, _8vert::OUT_OUTPUTS + 7)); - - addChild(createLight>(Vec(107.702, 50.414), module, _8vert::OUT_LIGHTS + 0*2)); - addChild(createLight>(Vec(107.702, 88.859), module, _8vert::OUT_LIGHTS + 1*2)); - addChild(createLight>(Vec(107.702, 127.304), module, _8vert::OUT_LIGHTS + 2*2)); - addChild(createLight>(Vec(107.702, 165.745), module, _8vert::OUT_LIGHTS + 3*2)); - addChild(createLight>(Vec(107.702, 204.19), module, _8vert::OUT_LIGHTS + 4*2)); - addChild(createLight>(Vec(107.702, 242.635), module, _8vert::OUT_LIGHTS + 5*2)); - addChild(createLight>(Vec(107.702, 281.076), module, _8vert::OUT_LIGHTS + 6*2)); - addChild(createLight>(Vec(107.702, 319.521), module, _8vert::OUT_LIGHTS + 7*2)); } }; diff --git a/src/SequentialSwitch.cpp b/src/SequentialSwitch.cpp index 4bd0fdb..b6ebd14 100644 --- a/src/SequentialSwitch.cpp +++ b/src/SequentialSwitch.cpp @@ -66,6 +66,7 @@ struct SequentialSwitch : Module { // Set output for (int i = 0; i < OUTPUTS; i++) { float gain = clickFilters[i].process(args.sampleTime, index == i); + outputs[OUT_OUTPUTS + i].setChannels(channels); if (gain != 0.f) { for (int c = 0; c < channels; c++) { float out = in[c] * gain; @@ -77,7 +78,6 @@ struct SequentialSwitch : Module { outputs[OUT_OUTPUTS + i].setVoltage(0.f); } } - outputs[OUT_OUTPUTS + i].setChannels(channels); } } else {