commit f3a9f835ed2d1d298a78846eece0e5c2d04e9b09
parent 4db015af00269ebc9961f18c3b0ab7946134efe9
Author: Matt Demanett <matt@demanett.net>
Date: Wed, 11 Sep 2019 23:29:25 -0400
Poly: 8:1, 1:8, ADDR-SEQ.
Diffstat:
6 files changed, 141 insertions(+), 78 deletions(-)
diff --git a/src/AddrSeq.cpp b/src/AddrSeq.cpp
@@ -28,13 +28,17 @@ void AddrSeq::OutputParamQuantity::setDisplayValue(float v) {
}
void AddrSeq::reset() {
- _step = 0;
- _clock.reset();
- _reset.reset();
+ for (int i = 0; i < maxChannels; ++i) {
+ _step[i] = 0;
+ _clock[i].reset();
+ _reset[i].reset();
+ }
}
void AddrSeq::sampleRateChange() {
- _timer.setParams(APP->engine->getSampleRate(), 0.001f);
+ for (int i = 0; i < maxChannels; ++i) {
+ _timer[i].setParams(APP->engine->getSampleRate(), 0.001f);
+ }
}
json_t* AddrSeq::dataToJson() {
@@ -58,35 +62,41 @@ void AddrSeq::dataFromJson(json_t* root) {
}
}
-void AddrSeq::processChannel(const ProcessArgs& args, int _c) {
- bool reset = _reset.process(inputs[RESET_INPUT].getVoltage());
+int AddrSeq::channels() {
+ return std::max(1, std::max(inputs[CLOCK_INPUT].getChannels(), inputs[SELECT_INPUT].getChannels()));
+}
+
+void AddrSeq::processChannel(const ProcessArgs& args, int c) {
+ bool reset = _reset[c].process(inputs[RESET_INPUT].getVoltage());
if (reset) {
- _timer.reset();
+ _timer[c].reset();
}
- bool timer = _timer.next();
- bool clock = _clock.process(inputs[CLOCK_INPUT].getVoltage()) && !timer;
+ bool timer = _timer[c].next();
+ bool clock = _clock[c].process(inputs[CLOCK_INPUT].getPolyVoltage(c)) && !timer;
int steps = clamp(params[STEPS_PARAM].getValue(), 1.0f, 8.0f);
int reverse = 1 - 2 * (params[DIRECTION_PARAM].getValue() == 0.0f);
- _step = (_step + reverse * clock) % steps;
- _step += (_step < 0) * steps;
- _step -= _step * reset;
+ _step[c] = (_step[c] + reverse * clock) % steps;
+ _step[c] += (_step[c] < 0) * steps;
+ _step[c] -= _step[c] * reset;
float select = params[SELECT_PARAM].getValue();
- select += clamp(inputs[SELECT_INPUT].getVoltage(), 0.0f, 10.0f) * 0.1f * 8.0f;
+ select += clamp(inputs[SELECT_INPUT].getPolyVoltage(c), 0.0f, 10.0f) * 0.1f * 8.0f;
if (!_selectOnClock || clock) {
- _select = select;
+ _select[c] = select;
}
- int step = _step + roundf(_select);
+ int step = _step[c] + roundf(_select[c]);
step = step % 8;
- float out = 0.0f;
- for (int i = 0; i < 8; ++i) {
- out += params[OUT1_PARAM + i].getValue() * (step == i);
- lights[OUT1_LIGHT + i].value = step == i;
- }
+ float out = params[OUT1_PARAM + step].getValue();
out += _rangeOffset;
out *= _rangeScale;
- outputs[OUT_OUTPUT].setVoltage(out);
+ outputs[OUT_OUTPUT].setChannels(_channels);
+ outputs[OUT_OUTPUT].setVoltage(out, c);
+ if (c == 0) {
+ for (int i = 0; i < 8; ++i) {
+ lights[OUT1_LIGHT + i].value = step == i;
+ }
+ }
}
struct AddrSeqWidget : SelectOnClockModuleWidget {
diff --git a/src/AddrSeq.hpp b/src/AddrSeq.hpp
@@ -50,11 +50,11 @@ struct AddrSeq : SelectOnClockModule {
NUM_LIGHTS
};
- Trigger _clock;
- Trigger _reset;
- bogaudio::dsp::Timer _timer;
- int _step;
- float _select = 0.0f;
+ Trigger _clock[maxChannels];
+ Trigger _reset[maxChannels];
+ bogaudio::dsp::Timer _timer[maxChannels];
+ int _step[maxChannels];
+ float _select[maxChannels] {};
float _rangeOffset = 0.0f;
float _rangeScale = 10.0f;
@@ -85,7 +85,8 @@ struct AddrSeq : SelectOnClockModule {
void sampleRateChange() override;
json_t* dataToJson() override;
void dataFromJson(json_t* root) override;
- void processChannel(const ProcessArgs& args, int _c) override;
+ int channels() override;
+ void processChannel(const ProcessArgs& args, int c) override;
};
} // namespace bogaudio
diff --git a/src/EightOne.cpp b/src/EightOne.cpp
@@ -2,42 +2,61 @@
#include "EightOne.hpp"
void EightOne::reset() {
- _step = 0;
- _clock.reset();
- _reset.reset();
+ for (int i = 0; i < maxChannels; ++i) {
+ _step[i] = 0;
+ _clock[i].reset();
+ _reset[i].reset();
+ }
}
void EightOne::sampleRateChange() {
- _timer.setParams(APP->engine->getSampleRate(), 0.001f);
+ for (int i = 0; i < maxChannels; ++i) {
+ _timer[i].setParams(APP->engine->getSampleRate(), 0.001f);
+ }
+}
+
+int EightOne::channels() {
+ return std::max(1, std::max(inputs[CLOCK_INPUT].getChannels(), inputs[SELECT_INPUT].getChannels()));
}
-void EightOne::processChannel(const ProcessArgs& args, int _c) {
- bool reset = _reset.process(inputs[RESET_INPUT].getVoltage());
+void EightOne::processChannel(const ProcessArgs& args, int c) {
+ bool reset = _reset[c].process(inputs[RESET_INPUT].getVoltage());
if (reset) {
- _timer.reset();
+ _timer[c].reset();
}
- bool timer = _timer.next();
- bool clock = _clock.process(inputs[CLOCK_INPUT].getVoltage()) && !timer;
+ bool timer = _timer[c].next();
+ bool clock = _clock[c].process(inputs[CLOCK_INPUT].getPolyVoltage(c)) && !timer;
int steps = clamp(params[STEPS_PARAM].getValue(), 1.0f, 8.0f);
int reverse = 1 - 2 * (params[DIRECTION_PARAM].getValue() == 0.0f);
- _step = (_step + reverse * clock) % steps;
- _step += (_step < 0) * steps;
- _step -= _step * reset;
+ _step[c] = (_step[c] + reverse * clock) % steps;
+ _step[c] += (_step[c] < 0) * steps;
+ _step[c] -= _step[c] * reset;
float select = params[SELECT_PARAM].getValue();
- select += clamp(inputs[SELECT_INPUT].getVoltage(), 0.0f, 10.0f) * 0.1f * 8.0f;
+ select += clamp(inputs[SELECT_INPUT].getPolyVoltage(c), 0.0f, 10.0f) * 0.1f * 8.0f;
if (!_selectOnClock || clock) {
- _select = select;
+ _select[c] = select;
}
- int step = _step + roundf(_select);
+ int step = _step[c] + roundf(_select[c]);
step = step % 8;
- float out = 0.0f;
- for (int i = 0; i < 8; ++i) {
- out += inputs[IN1_INPUT + i].getVoltageSum() * (step == i);
- lights[IN1_LIGHT + i].value = step == i;
+ Input& in = inputs[IN1_INPUT + step];
+ if (_channels > 1) {
+ outputs[OUT_OUTPUT].setChannels(_channels);
+ outputs[OUT_OUTPUT].setVoltage(in.getPolyVoltage(c), c);
+ if (c == 0) {
+ for (int i = 0; i < 8; ++i) {
+ lights[IN1_LIGHT + i].value = step == i;
+ }
+ }
+ }
+ else {
+ outputs[OUT_OUTPUT].setChannels(in.getChannels());
+ outputs[OUT_OUTPUT].writeVoltages(in.getVoltages());
+ for (int i = 0; i < 8; ++i) {
+ lights[IN1_LIGHT + i].value = step == i;
+ }
}
- outputs[OUT_OUTPUT].setVoltage(out);
}
struct EightOneWidget : SelectOnClockModuleWidget {
diff --git a/src/EightOne.hpp b/src/EightOne.hpp
@@ -50,11 +50,11 @@ struct EightOne : SelectOnClockModule {
NUM_LIGHTS
};
- Trigger _clock;
- Trigger _reset;
- bogaudio::dsp::Timer _timer;
- int _step;
- float _select = 0.0f;
+ Trigger _clock[maxChannels];
+ Trigger _reset[maxChannels];
+ bogaudio::dsp::Timer _timer[maxChannels];
+ int _step[maxChannels];
+ float _select[maxChannels] {};
EightOne() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
@@ -68,7 +68,8 @@ struct EightOne : SelectOnClockModule {
void reset() override;
void sampleRateChange() override;
- void processChannel(const ProcessArgs& args, int _c) override;
+ int channels() override;
+ void processChannel(const ProcessArgs& args, int c) override;
};
} // namespace bogaudio
diff --git a/src/OneEight.cpp b/src/OneEight.cpp
@@ -2,40 +2,71 @@
#include "OneEight.hpp"
void OneEight::reset() {
- _step = 0;
- _clock.reset();
- _reset.reset();
+ for (int i = 0; i < maxChannels; ++i) {
+ _step[i] = 0;
+ _clock[i].reset();
+ _reset[i].reset();
+ }
}
void OneEight::sampleRateChange() {
- _timer.setParams(APP->engine->getSampleRate(), 0.001f);
+ for (int i = 0; i < maxChannels; ++i) {
+ _timer[i].setParams(APP->engine->getSampleRate(), 0.001f);
+ }
}
-void OneEight::processChannel(const ProcessArgs& args, int _c) {
- bool reset = _reset.process(inputs[RESET_INPUT].getVoltage());
+int OneEight::channels() {
+ return std::max(1, std::max(inputs[CLOCK_INPUT].getChannels(), inputs[SELECT_INPUT].getChannels()));
+}
+
+void OneEight::processChannel(const ProcessArgs& args, int c) {
+ bool reset = _reset[c].process(inputs[RESET_INPUT].getVoltage());
if (reset) {
- _timer.reset();
+ _timer[c].reset();
}
- bool timer = _timer.next();
- bool clock = _clock.process(inputs[CLOCK_INPUT].getVoltage()) && !timer;
+ bool timer = _timer[c].next();
+ bool clock = _clock[c].process(inputs[CLOCK_INPUT].getPolyVoltage(c)) && !timer;
int steps = clamp(params[STEPS_PARAM].getValue(), 1.0f, 8.0f);
int reverse = 1 - 2 * (params[DIRECTION_PARAM].getValue() == 0.0f);
- _step = (_step + reverse * clock) % steps;
- _step += (_step < 0) * steps;
- _step -= _step * reset;
+ _step[c] = (_step[c] + reverse * clock) % steps;
+ _step[c] += (_step[c] < 0) * steps;
+ _step[c] -= _step[c] * reset;
float select = params[SELECT_PARAM].getValue();
- select += clamp(inputs[SELECT_INPUT].getVoltage(), 0.0f, 10.0f) * 0.1f * 8.0f;
+ select += clamp(inputs[SELECT_INPUT].getPolyVoltage(c), 0.0f, 10.0f) * 0.1f * 8.0f;
if (!_selectOnClock || clock) {
- _select = select;
+ _select[c] = select;
}
- int step = _step + roundf(_select);
+ int step = _step[c] + roundf(_select[c]);
step = step % 8;
- float in = inputs[IN_INPUT].getVoltageSum() + !inputs[IN_INPUT].isConnected() * 10.0f;
- for (int i = 0; i < 8; ++i) {
- outputs[OUT1_OUTPUT + i].setVoltage((step == i) * in);
- lights[OUT1_LIGHT + i].value = step == i;
+ if (_channels > 1) {
+ float in = inputs[IN_INPUT].getPolyVoltage(c) + !inputs[IN_INPUT].isConnected() * 10.0f;
+ for (int i = 0; i < 8; ++i) {
+ outputs[OUT1_OUTPUT + i].setChannels(_channels);
+ outputs[OUT1_OUTPUT + i].setVoltage((step == i) * in, c);
+ }
+ if (c == 0) {
+ for (int i = 0; i < 8; ++i) {
+ lights[OUT1_LIGHT + i].value = step == i;
+ }
+ }
+ }
+ else if (!inputs[IN_INPUT].isConnected()) {
+ for (int i = 0; i < 8; ++i) {
+ outputs[OUT1_OUTPUT + i].setChannels(1);
+ outputs[OUT1_OUTPUT + i].setVoltage((step == i) * 10.0f);
+ lights[OUT1_LIGHT + i].value = step == i;
+ }
+ }
+ else {
+ float* in = inputs[IN_INPUT].getVoltages();
+ static float zeroes[maxChannels] {};
+ for (int i = 0; i < 8; ++i) {
+ outputs[OUT1_OUTPUT + i].setChannels(inputs[IN_INPUT].getChannels());
+ outputs[OUT1_OUTPUT + i].writeVoltages((step == i) ? in : zeroes);
+ lights[OUT1_LIGHT + i].value = step == i;
+ }
}
}
diff --git a/src/OneEight.hpp b/src/OneEight.hpp
@@ -50,11 +50,11 @@ struct OneEight : SelectOnClockModule {
NUM_LIGHTS
};
- Trigger _clock;
- Trigger _reset;
- bogaudio::dsp::Timer _timer;
- int _step;
- float _select = 0.0f;
+ Trigger _clock[maxChannels];
+ Trigger _reset[maxChannels];
+ bogaudio::dsp::Timer _timer[maxChannels];
+ int _step[maxChannels];
+ float _select[maxChannels] {};
OneEight() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
@@ -68,7 +68,8 @@ struct OneEight : SelectOnClockModule {
void reset() override;
void sampleRateChange() override;
- void processChannel(const ProcessArgs& args, int _c) override;
+ int channels() override;
+ void processChannel(const ProcessArgs& args, int c) override;
};
} // namespace bogaudio