diff --git a/include/app/ModuleWidget.hpp b/include/app/ModuleWidget.hpp index e858ec3b..3c61df83 100644 --- a/include/app/ModuleWidget.hpp +++ b/include/app/ModuleWidget.hpp @@ -24,8 +24,13 @@ struct ModuleWidget : OpaqueWidget { math::Vec dragPos; math::Vec oldPos; - ModuleWidget(Module *module); + ModuleWidget() {} + DEPRECATED ModuleWidget(Module *module) { + setModule(module); + } ~ModuleWidget(); + + void setModule(Module *module); /** Convenience functions for adding special widgets (calls addChild()) */ void addInput(PortWidget *input); void addOutput(PortWidget *output); diff --git a/include/engine/Port.hpp b/include/engine/Port.hpp index bd8fe168..4c563a45 100644 --- a/include/engine/Port.hpp +++ b/include/engine/Port.hpp @@ -33,6 +33,18 @@ struct Port { void setVoltage(float voltage, int channel = 0) { values[channel] = voltage; } + + void setChannels(int channels) { + // Set higher channel values to 0 + for (int c = channels; c < this->channels; c++) { + values[c] = 0.f; + } + this->channels = channels; + } + + int getChannels() { + return channels; + } }; diff --git a/src/Core/AudioInterface.cpp b/src/Core/AudioInterface.cpp index d85594f9..181dba57 100644 --- a/src/Core/AudioInterface.cpp +++ b/src/Core/AudioInterface.cpp @@ -237,7 +237,8 @@ void AudioInterface::step() { struct AudioInterfaceWidget : ModuleWidget { - AudioInterfaceWidget(AudioInterface *module) : ModuleWidget(module) { + AudioInterfaceWidget(AudioInterface *module) { + setModule(module); setPanel(SVG::load(asset::system("res/Core/AudioInterface.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); diff --git a/src/Core/Blank.cpp b/src/Core/Blank.cpp index fc0a1353..6a2ce965 100644 --- a/src/Core/Blank.cpp +++ b/src/Core/Blank.cpp @@ -83,7 +83,8 @@ struct BlankWidget : ModuleWidget { Widget *bottomRightScrew; Widget *rightHandle; - BlankWidget(Module *module) : ModuleWidget(module) { + BlankWidget(Module *module) { + setModule(module); box.size = Vec(RACK_GRID_WIDTH * 10, RACK_GRID_HEIGHT); panel = new BlankPanel; diff --git a/src/Core/CV_MIDI.cpp b/src/Core/CV_MIDI.cpp index 2262a035..f4ff89a4 100644 --- a/src/Core/CV_MIDI.cpp +++ b/src/Core/CV_MIDI.cpp @@ -235,7 +235,7 @@ struct CV_MIDI : Module { } void step() override { - for (int c = 0; c < inputs[PITCH_INPUT].channels; c++) { + for (int c = 0; c < inputs[PITCH_INPUT].getChannels(); c++) { int vel = (int) std::round(inputs[VEL_INPUT].normalize(10.f * 100 / 127, c) / 10.f * 127); vel = clamp(vel, 0, 127); midiOutput.setVel(vel, c); @@ -286,7 +286,8 @@ struct CV_MIDI : Module { struct CV_MIDIWidget : ModuleWidget { - CV_MIDIWidget(CV_MIDI *module) : ModuleWidget(module) { + CV_MIDIWidget(CV_MIDI *module) { + setModule(module); setPanel(SVG::load(asset::system("res/Core/CV-MIDI.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); diff --git a/src/Core/MIDICCToCVInterface.cpp b/src/Core/MIDICCToCVInterface.cpp index 93753c78..6769be9d 100644 --- a/src/Core/MIDICCToCVInterface.cpp +++ b/src/Core/MIDICCToCVInterface.cpp @@ -220,7 +220,8 @@ struct MidiCcWidget : Grid16MidiWidget { struct MIDICCToCVInterfaceWidget : ModuleWidget { - MIDICCToCVInterfaceWidget(MIDICCToCVInterface *module) : ModuleWidget(module) { + MIDICCToCVInterfaceWidget(MIDICCToCVInterface *module) { + setModule(module); setPanel(SVG::load(asset::system("res/Core/MIDICCToCVInterface.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); diff --git a/src/Core/MIDIToCVInterface.cpp b/src/Core/MIDIToCVInterface.cpp index c37f2a05..1adc7399 100644 --- a/src/Core/MIDIToCVInterface.cpp +++ b/src/Core/MIDIToCVInterface.cpp @@ -259,7 +259,8 @@ struct MIDIToCVInterface : Module { struct MIDIToCVInterfaceWidget : ModuleWidget { - MIDIToCVInterfaceWidget(MIDIToCVInterface *module) : ModuleWidget(module) { + MIDIToCVInterfaceWidget(MIDIToCVInterface *module) { + setModule(module); setPanel(SVG::load(asset::system("res/Core/MIDIToCVInterface.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); diff --git a/src/Core/MIDITriggerToCVInterface.cpp b/src/Core/MIDITriggerToCVInterface.cpp index ca9716d3..0a77839c 100644 --- a/src/Core/MIDITriggerToCVInterface.cpp +++ b/src/Core/MIDITriggerToCVInterface.cpp @@ -207,7 +207,8 @@ struct MidiTrigWidget : Grid16MidiWidget { struct MIDITriggerToCVInterfaceWidget : ModuleWidget { - MIDITriggerToCVInterfaceWidget(MIDITriggerToCVInterface *module) : ModuleWidget(module) { + MIDITriggerToCVInterfaceWidget(MIDITriggerToCVInterface *module) { + setModule(module); setPanel(SVG::load(asset::system("res/Core/MIDITriggerToCVInterface.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); diff --git a/src/Core/Notes.cpp b/src/Core/Notes.cpp index ae50e5f5..a4d2d1bb 100644 --- a/src/Core/Notes.cpp +++ b/src/Core/Notes.cpp @@ -7,7 +7,8 @@ using namespace rack; struct NotesWidget : ModuleWidget { TextField *textField; - NotesWidget(Module *module) : ModuleWidget(module) { + NotesWidget(Module *module) { + setModule(module); setPanel(SVG::load(asset::system("res/Core/Notes.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); diff --git a/src/Core/QuadMIDIToCVInterface.cpp b/src/Core/QuadMIDIToCVInterface.cpp index f57daecb..d25ca8e9 100644 --- a/src/Core/QuadMIDIToCVInterface.cpp +++ b/src/Core/QuadMIDIToCVInterface.cpp @@ -302,7 +302,8 @@ struct QuadMIDIToCVInterface : Module { struct QuadMIDIToCVInterfaceWidget : ModuleWidget { - QuadMIDIToCVInterfaceWidget(QuadMIDIToCVInterface *module) : ModuleWidget(module) { + QuadMIDIToCVInterfaceWidget(QuadMIDIToCVInterface *module) { + setModule(module); setPanel(SVG::load(asset::system("res/Core/QuadMIDIToCVInterface.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index e259c048..8bd5253b 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -15,16 +15,16 @@ namespace rack { -ModuleWidget::ModuleWidget(Module *module) { - this->module = module; -} - ModuleWidget::~ModuleWidget() { if (module) { delete module; } } +void ModuleWidget::setModule(Module *module) { + this->module = module; +} + void ModuleWidget::addInput(PortWidget *input) { assert(input->type == PortWidget::INPUT); inputs.push_back(input); diff --git a/src/app/Scene.cpp b/src/app/Scene.cpp index 7e40a62e..948be49f 100644 --- a/src/app/Scene.cpp +++ b/src/app/Scene.cpp @@ -53,7 +53,9 @@ void Scene::step() { zoomWidget->box.size = rackWidget->box.size.mult(zoomWidget->zoom); moduleBrowser->box.size = box.size; - zoomWidget->setZoom(settings::zoom); + // Set zoom every few frames + if (app()->window->frame % 10 == 0) + zoomWidget->setZoom(settings::zoom); // Request latest version from server if (!devMode && checkVersion && !checkedVersion) {