From f1bd4b714d2fdeb7be7a345df7892cbfe343992b Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 4 Jan 2019 01:16:43 -0500 Subject: [PATCH] Change Port::set/getValue to set/getVoltage --- include/engine/Input.hpp | 4 ++-- include/engine/Port.hpp | 10 ++++++---- src/Core/AudioInterface.cpp | 16 ++++++++-------- src/Core/MIDICCToCVInterface.cpp | 2 +- src/Core/MIDIToCVInterface.cpp | 24 ++++++++++++------------ src/Core/MIDITriggerToCVInterface.cpp | 4 ++-- src/Core/QuadMIDIToCVInterface.cpp | 8 ++++---- src/engine/Engine.cpp | 2 +- src/main.cpp | 15 ++++++++------- src/plugin/Model.cpp | 6 ++++-- 10 files changed, 48 insertions(+), 43 deletions(-) diff --git a/include/engine/Input.hpp b/include/engine/Input.hpp index 201f2c8a..48766577 100644 --- a/include/engine/Input.hpp +++ b/include/engine/Input.hpp @@ -8,8 +8,8 @@ namespace rack { struct Input : Port { /** Returns the value if a wire is plugged in, otherwise returns the given default value */ - float normalize(float normalValue, int index = 0) { - return active ? getValue(index) : normalValue; + float normalize(float normalVoltage, int index = 0) { + return active ? getVoltage(index) : normalVoltage; } }; diff --git a/include/engine/Port.hpp b/include/engine/Port.hpp index ff5f563a..cc820e4b 100644 --- a/include/engine/Port.hpp +++ b/include/engine/Port.hpp @@ -12,6 +12,9 @@ static const int PORT_MAX_CHANNELS = 16; struct Port { /** Voltage of the port */ union { + /** Accessing this directly is deprecated. + Use getVoltage() and setVoltage() instead + */ float value; float values[PORT_MAX_CHANNELS] = {}; }; @@ -21,12 +24,11 @@ struct Port { bool active = false; Light plugLights[2]; - float getValue(int index = 0) { + float getVoltage(int index = 0) { return values[index]; } - - void setValue(float value, int index = 0) { - this->values[index] = value; + void setVoltage(float voltage, int index = 0) { + values[index] = voltage; } }; diff --git a/src/Core/AudioInterface.cpp b/src/Core/AudioInterface.cpp index b3a25d19..f2a6729d 100644 --- a/src/Core/AudioInterface.cpp +++ b/src/Core/AudioInterface.cpp @@ -71,7 +71,7 @@ struct AudioInterfaceIO : audio::IO { else { // Timed out, fill output with zeros memset(output, 0, frames * numOutputs * sizeof(float)); - DEBUG("Audio Interface IO underflow"); + // DEBUG("Audio Interface IO underflow"); } } @@ -172,7 +172,7 @@ void AudioInterface::step() { else { // Give up on pulling input audioIO.active = false; - DEBUG("Audio Interface underflow"); + // DEBUG("Audio Interface underflow"); } } @@ -185,10 +185,10 @@ void AudioInterface::step() { memset(&inputFrame, 0, sizeof(inputFrame)); } for (int i = 0; i < audioIO.numInputs; i++) { - outputs[AUDIO_OUTPUT + i].value = 10.f * inputFrame.samples[i]; + outputs[AUDIO_OUTPUT + i].setVoltage(10.f * inputFrame.samples[i]); } for (int i = audioIO.numInputs; i < AUDIO_INPUTS; i++) { - outputs[AUDIO_OUTPUT + i].value = 0.f; + outputs[AUDIO_OUTPUT + i].setVoltage(0.f); } // Outputs: rack engine -> audio engine @@ -197,7 +197,7 @@ void AudioInterface::step() { if (!outputBuffer.full()) { Frame outputFrame; for (int i = 0; i < AUDIO_OUTPUTS; i++) { - outputFrame.samples[i] = inputs[AUDIO_INPUT + i].value / 10.f; + outputFrame.samples[i] = inputs[AUDIO_INPUT + i].getVoltage() / 10.f; } outputBuffer.push(outputFrame); } @@ -222,7 +222,7 @@ void AudioInterface::step() { // Give up on pushing output audioIO.active = false; outputBuffer.clear(); - DEBUG("Audio Interface underflow"); + // DEBUG("Audio Interface underflow"); } } @@ -232,9 +232,9 @@ void AudioInterface::step() { // Turn on light if at least one port is enabled in the nearby pair for (int i = 0; i < AUDIO_INPUTS / 2; i++) - lights[INPUT_LIGHT + i].value = (audioIO.active && audioIO.numOutputs >= 2*i+1); + lights[INPUT_LIGHT + i].setBrightness(audioIO.active && audioIO.numOutputs >= 2*i+1); for (int i = 0; i < AUDIO_OUTPUTS / 2; i++) - lights[OUTPUT_LIGHT + i].value = (audioIO.active && audioIO.numInputs >= 2*i+1); + lights[OUTPUT_LIGHT + i].setBrightness(audioIO.active && audioIO.numInputs >= 2*i+1); } diff --git a/src/Core/MIDICCToCVInterface.cpp b/src/Core/MIDICCToCVInterface.cpp index 9fbe1afc..0fee1632 100644 --- a/src/Core/MIDICCToCVInterface.cpp +++ b/src/Core/MIDICCToCVInterface.cpp @@ -51,7 +51,7 @@ struct MIDICCToCVInterface : Module { int learnedCc = learnedCcs[i]; float value = rescale(clamp(ccs[learnedCc], -127, 127), 0, 127, 0.f, 10.f); ccFilters[i].lambda = lambda; - outputs[CC_OUTPUT + i].value = ccFilters[i].process(value); + outputs[CC_OUTPUT + i].setVoltage(ccFilters[i].process(value)); } } diff --git a/src/Core/MIDIToCVInterface.cpp b/src/Core/MIDIToCVInterface.cpp index 330858e7..d954f7ae 100644 --- a/src/Core/MIDIToCVInterface.cpp +++ b/src/Core/MIDIToCVInterface.cpp @@ -148,23 +148,23 @@ struct MIDIToCVInterface : Module { } float deltaTime = context()->engine->getSampleTime(); - outputs[CV_OUTPUT].value = (lastNote - 60) / 12.f; - outputs[GATE_OUTPUT].value = gate ? 10.f : 0.f; - outputs[VELOCITY_OUTPUT].value = rescale(noteData[lastNote].velocity, 0, 127, 0.f, 10.f); + outputs[CV_OUTPUT].setVoltage((lastNote - 60) / 12.f); + outputs[GATE_OUTPUT].setVoltage(gate ? 10.f : 0.f); + outputs[VELOCITY_OUTPUT].setVoltage(rescale(noteData[lastNote].velocity, 0, 127, 0.f, 10.f)); - outputs[AFTERTOUCH_OUTPUT].value = rescale(noteData[lastNote].aftertouch, 0, 127, 0.f, 10.f); + outputs[AFTERTOUCH_OUTPUT].setVoltage(rescale(noteData[lastNote].aftertouch, 0, 127, 0.f, 10.f)); pitchFilter.lambda = 100.f * deltaTime; - outputs[PITCH_OUTPUT].value = pitchFilter.process(rescale(pitch, 0, 16384, -5.f, 5.f)); + outputs[PITCH_OUTPUT].setVoltage(pitchFilter.process(rescale(pitch, 0, 16384, -5.f, 5.f))); modFilter.lambda = 100.f * deltaTime; - outputs[MOD_OUTPUT].value = modFilter.process(rescale(mod, 0, 127, 0.f, 10.f)); + outputs[MOD_OUTPUT].setVoltage(modFilter.process(rescale(mod, 0, 127, 0.f, 10.f))); - outputs[RETRIGGER_OUTPUT].value = retriggerPulse.process(deltaTime) ? 10.f : 0.f; - outputs[CLOCK_1_OUTPUT].value = clockPulses[0].process(deltaTime) ? 10.f : 0.f; - outputs[CLOCK_2_OUTPUT].value = clockPulses[1].process(deltaTime) ? 10.f : 0.f; + outputs[RETRIGGER_OUTPUT].setVoltage(retriggerPulse.process(deltaTime) ? 10.f : 0.f); + outputs[CLOCK_1_OUTPUT].setVoltage(clockPulses[0].process(deltaTime) ? 10.f : 0.f); + outputs[CLOCK_2_OUTPUT].setVoltage(clockPulses[1].process(deltaTime) ? 10.f : 0.f); - outputs[START_OUTPUT].value = startPulse.process(deltaTime) ? 10.f : 0.f; - outputs[STOP_OUTPUT].value = stopPulse.process(deltaTime) ? 10.f : 0.f; - outputs[CONTINUE_OUTPUT].value = continuePulse.process(deltaTime) ? 10.f : 0.f; + outputs[START_OUTPUT].setVoltage(startPulse.process(deltaTime) ? 10.f : 0.f); + outputs[STOP_OUTPUT].setVoltage(stopPulse.process(deltaTime) ? 10.f : 0.f); + outputs[CONTINUE_OUTPUT].setVoltage(continuePulse.process(deltaTime) ? 10.f : 0.f); } void processMessage(midi::Message msg) { diff --git a/src/Core/MIDITriggerToCVInterface.cpp b/src/Core/MIDITriggerToCVInterface.cpp index 88942777..6ee7dc9d 100644 --- a/src/Core/MIDITriggerToCVInterface.cpp +++ b/src/Core/MIDITriggerToCVInterface.cpp @@ -75,7 +75,7 @@ struct MIDITriggerToCVInterface : Module { for (int i = 0; i < 16; i++) { if (gateTimes[i] > 0.f) { - outputs[TRIG_OUTPUT + i].value = velocity ? rescale(velocities[i], 0, 127, 0.f, 10.f) : 10.f; + outputs[TRIG_OUTPUT + i].setVoltage(velocity ? rescale(velocities[i], 0, 127, 0.f, 10.f) : 10.f); // If the gate is off, wait 1 ms before turning the pulse off. // This avoids drum controllers sending a pulse with 0 ms duration. if (!gates[i]) { @@ -83,7 +83,7 @@ struct MIDITriggerToCVInterface : Module { } } else { - outputs[TRIG_OUTPUT + i].value = 0.f; + outputs[TRIG_OUTPUT + i].setVoltage(0.f); } } } diff --git a/src/Core/QuadMIDIToCVInterface.cpp b/src/Core/QuadMIDIToCVInterface.cpp index e3999ea4..682ba425 100644 --- a/src/Core/QuadMIDIToCVInterface.cpp +++ b/src/Core/QuadMIDIToCVInterface.cpp @@ -251,10 +251,10 @@ struct QuadMIDIToCVInterface : Module { for (int i = 0; i < 4; i++) { uint8_t lastNote = notes[i]; uint8_t lastGate = (gates[i] || pedalgates[i]); - outputs[CV_OUTPUT + i].value = (lastNote - 60) / 12.f; - outputs[GATE_OUTPUT + i].value = lastGate ? 10.f : 0.f; - outputs[VELOCITY_OUTPUT + i].value = rescale(noteData[lastNote].velocity, 0, 127, 0.f, 10.f); - outputs[AFTERTOUCH_OUTPUT + i].value = rescale(noteData[lastNote].aftertouch, 0, 127, 0.f, 10.f); + outputs[CV_OUTPUT + i].setVoltage((lastNote - 60) / 12.f); + outputs[GATE_OUTPUT + i].setVoltage(lastGate ? 10.f : 0.f); + outputs[VELOCITY_OUTPUT + i].setVoltage(rescale(noteData[lastNote].velocity, 0, 127, 0.f, 10.f)); + outputs[AFTERTOUCH_OUTPUT + i].setVoltage(rescale(noteData[lastNote].aftertouch, 0, 127, 0.f, 10.f)); } } diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index cfc66b84..b77e2d59 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -132,7 +132,7 @@ static void Engine_step(Engine *engine) { // Bypass module for (Output &output : module->outputs) { output.numChannels = 1; - output.setValue(0.f); + output.setVoltage(0.f); } module->cpuTime = 0.f; } diff --git a/src/main.cpp b/src/main.cpp index 3e17b79e..a40083f7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,13 +62,6 @@ int main(int argc, char *argv[]) { random::init(); asset::init(devMode); logger::init(devMode); - midi::init(); - rtmidiInit(); - bridgeInit(); - keyboard::init(); - gamepad::init(); - ui::init(); - plugin::init(devMode); // Log environment INFO("%s %s", APP_NAME.c_str(), APP_VERSION.c_str()); @@ -77,6 +70,14 @@ int main(int argc, char *argv[]) { INFO("System directory: %s", asset::systemDir.c_str()); INFO("User directory: %s", asset::userDir.c_str()); + midi::init(); + rtmidiInit(); + bridgeInit(); + keyboard::init(); + gamepad::init(); + ui::init(); + plugin::init(devMode); + // Initialize app context()->engine = new Engine; context()->event = new event::State; diff --git a/src/plugin/Model.cpp b/src/plugin/Model.cpp index 6f6f64d6..c03550f9 100644 --- a/src/plugin/Model.cpp +++ b/src/plugin/Model.cpp @@ -9,7 +9,9 @@ void Model::fromJson(json_t *rootJ) { if (nameJ) name = json_string_value(nameJ); - DEBUG("name: %s", name.c_str()); + json_t *descriptionJ = json_object_get(rootJ, "description"); + if (descriptionJ) + description = json_string_value(descriptionJ); json_t *tagsJ = json_object_get(rootJ, "tags"); if (tagsJ) { @@ -17,7 +19,7 @@ void Model::fromJson(json_t *rootJ) { json_t *tagJ; json_array_foreach(tagsJ, i, tagJ) { std::string tag = json_string_value(tagJ); - DEBUG("tag: %s", tag.c_str()); + tags.push_back(tag); } } }