commit 770ce08984f2ef60fdae75ef9e39b645d6c34625
parent 2971a91b4877a2c8819276fb9a416b434d6fba65
Author: Matt Demanett <matt@demanett.net>
Date: Mon, 1 Feb 2021 22:03:27 -0500
MANUAL, 4MAN: add +10V output option.
Diffstat:
5 files changed, 68 insertions(+), 6 deletions(-)
diff --git a/README-prerelease.md b/README-prerelease.md
@@ -1235,17 +1235,17 @@ _Polyphony:_ <a href="#polyphony">Polyphonic</a>, with polyphony defined by the
#### <a name="manual"></a> MANUAL
-A manual trigger/gate with 8 outputs. A constant high value is sent from each output for as long as the TRIG button is held.
+A manual trigger/gate with 8 outputs. A constant +5V is sent from each output for as long as the TRIG button is held; 0V is output otherwise. The high output voltage may be set to +10V on the context menu.
-MANUAL may be set to output a trigger pulse (+5V for 10ms) on patch load (akin to a Max/Msp loadbang). This is off by default; enable clicking "Trigger on Load" on the module's context (right-click) menu. The pulse is emitted 100ms after the patch starts processing samples.
+MANUAL may be set to output a trigger pulse (the high output voltage for 10ms) on patch load (akin to a Max/Msp loadbang). This is off by default; enable clicking "Trigger on Load" on the module's context (right-click) menu. The pulse is emitted 100ms after the patch starts processing samples.
_Polyphony:_ Monophonic.
-#### <a name="4man"></a> 4MAN
+#### <a name="fourman"></a> 4MAN
A version of MANUAL with four independent trigger buttons with separate outputs.
-The "Trigger on load" option, as on MANUAL, applies to all four outputs if enabled.
+The "Trigger on load" and "Output" options, as on MANUAL, apply to all four outputs if enabled.
_Polyphony:_ Monophonic.
diff --git a/src/FourMan.cpp b/src/FourMan.cpp
@@ -1,6 +1,8 @@
#include "FourMan.hpp"
+#define OUTPUT_SCALE "output_scale"
+
void FourMan::reset() {
for (int i = 0; i < 4; i++) {
_trigger[i].reset();
@@ -12,6 +14,20 @@ void FourMan::sampleRateChange() {
_sampleTime = APP->engine->getSampleTime();
}
+json_t* FourMan::toJson(json_t* root) {
+ root = TriggerOnLoadModule::toJson(root);
+ json_object_set_new(root, OUTPUT_SCALE, json_real(_outputScale));
+ return root;
+}
+
+void FourMan::fromJson(json_t* root) {
+ TriggerOnLoadModule::fromJson(root);
+ json_t* os = json_object_get(root, OUTPUT_SCALE);
+ if (os) {
+ _outputScale = json_real_value(os);
+ }
+}
+
void FourMan::processAll(const ProcessArgs& args) {
bool initialPulse = false;
if (_initialDelay && !_initialDelay->next()) {
@@ -27,7 +43,7 @@ void FourMan::processAll(const ProcessArgs& args) {
}
high = _pulse[i].process(_sampleTime);
- outputs[OUT1_OUTPUT + i].setVoltage(high ? 5.0f : 0.0f);
+ outputs[OUT1_OUTPUT + i].setVoltage(high ? (5.0f * _outputScale) : 0.0f);
}
}
@@ -64,6 +80,18 @@ struct FourManWidget : TriggerOnLoadModuleWidget {
addOutput(createOutput<Port24>(out3OutputPosition, module, FourMan::OUT3_OUTPUT));
addOutput(createOutput<Port24>(out4OutputPosition, module, FourMan::OUT4_OUTPUT));
}
+
+ void contextMenu(Menu* menu) override {
+ TriggerOnLoadModuleWidget::contextMenu(menu);
+
+ auto m = dynamic_cast<FourMan*>(module);
+ assert(m);
+
+ OptionsMenuItem* o = new OptionsMenuItem("Output");
+ o->addItem(OptionMenuItem("+10V", [m]() { return m->_outputScale == 2.0f; }, [m]() { m->_outputScale = 2.0f; }));
+ o->addItem(OptionMenuItem("+5V", [m]() { return m->_outputScale == 1.0f; }, [m]() { m->_outputScale = 1.0f; }));
+ OptionsMenuItem::addToMenu(o, menu);
+ }
};
Model* modelFourMan = createModel<FourMan, FourManWidget>("Bogaudio-FourMan", "4MAN", "Quad button-controlled gates / triggers", "Controller", "Quad");
diff --git a/src/FourMan.hpp b/src/FourMan.hpp
@@ -33,6 +33,7 @@ struct FourMan : TriggerOnLoadModule {
rack::dsp::PulseGenerator _pulse[4];
float _sampleTime = 1.0f;
bogaudio::dsp::Timer* _initialDelay = NULL;
+ float _outputScale = 1.0f;
FourMan() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS);
@@ -51,6 +52,8 @@ struct FourMan : TriggerOnLoadModule {
void reset() override;
void sampleRateChange() override;
+ json_t* toJson(json_t* root) override;
+ void fromJson(json_t* root) override;
void processAll(const ProcessArgs& args) override;
bool shouldTriggerOnNextLoad() override {
return true;
diff --git a/src/Manual.cpp b/src/Manual.cpp
@@ -1,6 +1,8 @@
#include "Manual.hpp"
+#define OUTPUT_SCALE "output_scale"
+
void Manual::reset() {
_trigger.reset();
_pulse.process(10.0f);
@@ -10,6 +12,20 @@ void Manual::sampleRateChange() {
_sampleTime = APP->engine->getSampleTime();
}
+json_t* Manual::toJson(json_t* root) {
+ root = TriggerOnLoadModule::toJson(root);
+ json_object_set_new(root, OUTPUT_SCALE, json_real(_outputScale));
+ return root;
+}
+
+void Manual::fromJson(json_t* root) {
+ TriggerOnLoadModule::fromJson(root);
+ json_t* os = json_object_get(root, OUTPUT_SCALE);
+ if (os) {
+ _outputScale = json_real_value(os);
+ }
+}
+
void Manual::processAll(const ProcessArgs& args) {
bool initialPulse = false;
if (_initialDelay && !_initialDelay->next()) {
@@ -24,7 +40,7 @@ void Manual::processAll(const ProcessArgs& args) {
}
high = _pulse.process(_sampleTime);
- float out = high ? 5.0f : 0.0f;
+ float out = high ? (5.0f * _outputScale) : 0.0f;
outputs[OUT1_OUTPUT].setVoltage(out);
outputs[OUT2_OUTPUT].setVoltage(out);
outputs[OUT3_OUTPUT].setVoltage(out);
@@ -70,6 +86,18 @@ struct ManualWidget : TriggerOnLoadModuleWidget {
addOutput(createOutput<Port24>(out7OutputPosition, module, Manual::OUT7_OUTPUT));
addOutput(createOutput<Port24>(out8OutputPosition, module, Manual::OUT8_OUTPUT));
}
+
+ void contextMenu(Menu* menu) override {
+ TriggerOnLoadModuleWidget::contextMenu(menu);
+
+ auto m = dynamic_cast<Manual*>(module);
+ assert(m);
+
+ OptionsMenuItem* o = new OptionsMenuItem("Output");
+ o->addItem(OptionMenuItem("+10V", [m]() { return m->_outputScale == 2.0f; }, [m]() { m->_outputScale = 2.0f; }));
+ o->addItem(OptionMenuItem("+5V", [m]() { return m->_outputScale == 1.0f; }, [m]() { m->_outputScale = 1.0f; }));
+ OptionsMenuItem::addToMenu(o, menu);
+ }
};
Model* modelManual = bogaudio::createModel<Manual, ManualWidget>("Bogaudio-Manual", "MANUAL", "Button controlled gates / triggers", "Controller");
diff --git a/src/Manual.hpp b/src/Manual.hpp
@@ -34,6 +34,7 @@ struct Manual : TriggerOnLoadModule {
rack::dsp::PulseGenerator _pulse;
float _sampleTime;
bogaudio::dsp::Timer* _initialDelay = NULL;
+ float _outputScale = 1.0f;
Manual() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS);
@@ -49,6 +50,8 @@ struct Manual : TriggerOnLoadModule {
void reset() override;
void sampleRateChange() override;
+ json_t* toJson(json_t* root) override;
+ void fromJson(json_t* root) override;
void processAll(const ProcessArgs& args) override;
bool shouldTriggerOnNextLoad() override {
return true;