commit 025794301165f10286395b58d361fbed80db624a
parent bff5f32ab915e9b7bae84fa691ff50cecb8c949f
Author: Matt Demanett <matt@demanett.net>
Date: Fri, 13 Sep 2019 21:28:15 -0400
Poly: VCM, MUTE8.
Diffstat:
4 files changed, 87 insertions(+), 41 deletions(-)
diff --git a/src/Mute8.cpp b/src/Mute8.cpp
@@ -8,18 +8,24 @@ const float Mute8::slewTimeMS = 5.0f;
void Mute8::reset() {
for (int i = 0; i < 8; ++i) {
- _triggers[i].reset();
+ for (int c = 0; c < maxChannels; ++c) {
+ _triggers[i][c].reset();
+ }
}
}
void Mute8::sampleRateChange() {
float sampleRate = APP->engine->getSampleRate();
for (int i = 0; i < 8; ++i) {
- _slewLimiters[i].setParams(sampleRate, slewTimeMS, maxDecibels - minDecibels);
+ for (int c = 0; c < maxChannels; ++c) {
+ _slewLimiters[i][c].setParams(sampleRate, slewTimeMS, maxDecibels - minDecibels);
+ }
}
}
-void Mute8::processChannel(const ProcessArgs& args, int _c) {
+void Mute8::processChannel(const ProcessArgs& args, int c) {
+ assert(c == 0);
+
bool solo = false;
for (int i = 0; i < 8; ++i) {
solo = solo || params[MUTE1_PARAM + i].getValue() > 1.5f;
@@ -30,17 +36,41 @@ void Mute8::processChannel(const ProcessArgs& args, int _c) {
}
void Mute8::stepChannel(int i, bool solo) {
- _triggers[i].process(inputs[MUTE1_INPUT + i].getVoltage());
- bool muted = solo ? params[MUTE1_PARAM + i].getValue() < 2.0f : (params[MUTE1_PARAM + i].getValue() > 0.5f || _triggers[i].isHigh());
- if (muted) {
- lights[MUTE1_LIGHT + i].value = 1.0f;
- _amplifiers[i].setLevel(_slewLimiters[i].next(minDecibels));
+ bool allMuted = solo ? params[MUTE1_PARAM + i].getValue() < 2.0f : params[MUTE1_PARAM + i].getValue() > 0.5f;
+
+ if (inputs[INPUT1_INPUT + i].isConnected()) {
+ int n = inputs[INPUT1_INPUT + i].getChannels();
+ outputs[OUTPUT1_OUTPUT + i].setChannels(n);
+ int mutedCount = 0;
+ for (int c = 0; c < n; ++c) {
+ _triggers[i][c].process(inputs[MUTE1_INPUT + i].getPolyVoltage(c));
+ bool muted = allMuted || _triggers[i][c].isHigh();
+ if (muted) {
+ ++mutedCount;
+ _amplifiers[i][c].setLevel(_slewLimiters[i][c].next(minDecibels));
+ }
+ else {
+ _amplifiers[i][c].setLevel(_slewLimiters[i][c].next(maxDecibels));
+ }
+ outputs[OUTPUT1_OUTPUT + i].setChannels(n);
+ outputs[OUTPUT1_OUTPUT + i].setVoltage(_amplifiers[i][c].next(inputs[INPUT1_INPUT + i].getVoltage(c)), c);
+ }
+ lights[MUTE1_LIGHT + i].value = mutedCount / (float)n;
}
else {
- lights[MUTE1_LIGHT + i].value = 0.0f;
- _amplifiers[i].setLevel(_slewLimiters[i].next(maxDecibels));
+ _triggers[i][0].process(inputs[MUTE1_INPUT + i].getVoltage());
+ bool muted = allMuted || _triggers[i][0].isHigh();
+ if (muted) {
+ lights[MUTE1_LIGHT + i].value = 1.0f;
+ _amplifiers[i][0].setLevel(_slewLimiters[i][0].next(minDecibels));
+ }
+ else {
+ lights[MUTE1_LIGHT + i].value = 0.0f;
+ _amplifiers[i][0].setLevel(_slewLimiters[i][0].next(maxDecibels));
+ }
+ outputs[OUTPUT1_OUTPUT + i].setChannels(1);
+ outputs[OUTPUT1_OUTPUT + i].setVoltage(_amplifiers[i][0].next(5.0f));
}
- outputs[OUTPUT1_OUTPUT + i].setVoltage(_amplifiers[i].next(inputs[INPUT1_INPUT + i].isConnected() ? inputs[INPUT1_INPUT + i].getVoltageSum() : 5.0f));
}
struct Mute8Widget : ModuleWidget {
diff --git a/src/Mute8.hpp b/src/Mute8.hpp
@@ -70,9 +70,9 @@ struct Mute8 : BGModule {
static const float minDecibels;
static const float slewTimeMS;
- Amplifier _amplifiers[8];
- bogaudio::dsp::SlewLimiter _slewLimiters[8];
- Trigger _triggers[8];
+ Amplifier _amplifiers[8][maxChannels];
+ bogaudio::dsp::SlewLimiter _slewLimiters[8][maxChannels];
+ Trigger _triggers[8][maxChannels];
Mute8() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
@@ -91,7 +91,7 @@ struct Mute8 : BGModule {
void reset() override;
void sampleRateChange() override;
- void processChannel(const ProcessArgs& args, int _c) override;
+ void processChannel(const ProcessArgs& args, int c) override;
void stepChannel(int i, bool solo);
};
diff --git a/src/VCM.cpp b/src/VCM.cpp
@@ -5,41 +5,54 @@ bool VCM::LevelParamQuantity::isLinear() {
return dynamic_cast<VCM*>(module)->isLinear();
}
-void VCM::processChannel(const ProcessArgs& args, int _c) {
+bool VCM::active() {
+ return outputs[MIX_OUTPUT].isConnected();
+}
+
+int VCM::channels() {
+ return std::max(
+ std::max(inputs[IN1_INPUT].getChannels(), inputs[IN2_INPUT].getChannels()),
+ std::max(inputs[IN3_INPUT].getChannels(), inputs[IN4_INPUT].getChannels())
+ );
+}
+
+void VCM::always(const ProcessArgs& args) {
+ lights[LINEAR_LIGHT].value = isLinear();
+}
+
+void VCM::processChannel(const ProcessArgs& args, int c) {
bool linear = isLinear();
- lights[LINEAR_LIGHT].value = linear;
- if (outputs[MIX_OUTPUT].isConnected()) {
- float out = channelStep(inputs[IN1_INPUT], params[LEVEL1_PARAM], inputs[CV1_INPUT], _amplifier1, linear);
- out += channelStep(inputs[IN2_INPUT], params[LEVEL2_PARAM], inputs[CV2_INPUT], _amplifier2, linear);
- out += channelStep(inputs[IN3_INPUT], params[LEVEL3_PARAM], inputs[CV3_INPUT], _amplifier3, linear);
- out += channelStep(inputs[IN4_INPUT], params[LEVEL4_PARAM], inputs[CV4_INPUT], _amplifier4, linear);
- float level = params[MIX_PARAM].getValue();
- if (inputs[MIX_CV_INPUT].isConnected()) {
- level *= clamp(inputs[MIX_CV_INPUT].getVoltage() / 10.0f, 0.0f, 1.0f);
- }
- out *= level;
- if (!_disableOutputLimit) {
- out = clamp(out, -12.0f, 12.0f);
- }
- outputs[MIX_OUTPUT].setVoltage(level * out);
+ float out = channelStep(c, inputs[IN1_INPUT], params[LEVEL1_PARAM], inputs[CV1_INPUT], _amplifier1[c], linear);
+ out += channelStep(c, inputs[IN2_INPUT], params[LEVEL2_PARAM], inputs[CV2_INPUT], _amplifier2[c], linear);
+ out += channelStep(c, inputs[IN3_INPUT], params[LEVEL3_PARAM], inputs[CV3_INPUT], _amplifier3[c], linear);
+ out += channelStep(c, inputs[IN4_INPUT], params[LEVEL4_PARAM], inputs[CV4_INPUT], _amplifier4[c], linear);
+ float level = params[MIX_PARAM].getValue();
+ if (inputs[MIX_CV_INPUT].isConnected()) {
+ level *= clamp(inputs[MIX_CV_INPUT].getPolyVoltage(c) / 10.0f, 0.0f, 1.0f);
+ }
+ out *= level;
+ if (!_disableOutputLimit) {
+ out = clamp(out, -12.0f, 12.0f);
}
+ outputs[MIX_OUTPUT].setChannels(_channels);
+ outputs[MIX_OUTPUT].setVoltage(level * out, c);
}
-float VCM::channelStep(Input& input, Param& knob, Input& cv, Amplifier& amplifier, bool linear) {
+float VCM::channelStep(int c, Input& input, Param& knob, Input& cv, Amplifier& amplifier, bool linear) {
if (!input.isConnected()) {
return 0.0f;
}
float level = knob.getValue();
if (cv.isConnected()) {
- level *= clamp(cv.getVoltage() / 10.0f, 0.0f, 1.0f);
+ level *= clamp(cv.getPolyVoltage(c) / 10.0f, 0.0f, 1.0f);
}
if (linear) {
- return level * input.getVoltageSum();
+ return level * input.getPolyVoltage(c);
}
level = 1.0f - level;
level *= Amplifier::minDecibels;
amplifier.setLevel(level);
- return amplifier.next(input.getVoltageSum());
+ return amplifier.next(input.getPolyVoltage(c));
}
struct VCMWidget : DisableOutputLimitModuleWidget {
diff --git a/src/VCM.hpp b/src/VCM.hpp
@@ -44,10 +44,10 @@ struct VCM : DisableOutputLimitModule {
NUM_LIGHTS
};
- Amplifier _amplifier1;
- Amplifier _amplifier2;
- Amplifier _amplifier3;
- Amplifier _amplifier4;
+ Amplifier _amplifier1[maxChannels];
+ Amplifier _amplifier2[maxChannels];
+ Amplifier _amplifier3[maxChannels];
+ Amplifier _amplifier4[maxChannels];
struct LevelParamQuantity : AmpliferParamQuantity {
bool isLinear() override;
@@ -65,8 +65,11 @@ struct VCM : DisableOutputLimitModule {
}
inline bool isLinear() { return params[LINEAR_PARAM].getValue() > 0.5f; }
- void processChannel(const ProcessArgs& args, int _c) override;
- float channelStep(Input& input, Param& knob, Input& cv, Amplifier& amplifier, bool linear);
+ bool active() override;
+ int channels() override;
+ void always(const ProcessArgs& args) override;
+ void processChannel(const ProcessArgs& args, int c) override;
+ float channelStep(int c, Input& input, Param& knob, Input& cv, Amplifier& amplifier, bool linear);
};
} // namespace bogaudio