From 2ff1ee5c867f732d362a6cf2b809c7f2cbd66034 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 14 Feb 2018 10:44:37 -0500 Subject: [PATCH] Allow separation from Module and ModuleWidget in Model subclass --- include/app.hpp | 2 +- include/engine.hpp | 6 +- include/plugin.hpp | 35 +++++++ include/rack.hpp | 3 +- src/app/ModuleWidget.cpp | 20 ++-- src/core/AudioInterface.cpp | 181 ++++++++++++++++++------------------ src/core/Blank.cpp | 102 +++++++++++--------- src/core/MidiToCV.cpp | 105 +++++++++++---------- src/core/Notes.cpp | 67 +++++++------ src/core/core.cpp | 12 +-- src/core/core.hpp | 35 ++----- 11 files changed, 301 insertions(+), 267 deletions(-) diff --git a/include/app.hpp b/include/app.hpp index 637d6506..4aa57478 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -60,8 +60,8 @@ struct ModuleWidget : OpaqueWidget { std::vector outputs; std::vector params; + ModuleWidget(Module *module); ~ModuleWidget(); - void setModule(Module *module); /** Convenience functions for adding special widgets (calls addChild()) */ void addInput(Port *input); void addOutput(Port *output); diff --git a/include/engine.hpp b/include/engine.hpp index ef102e7c..1c3ebcd6 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -50,9 +50,9 @@ struct Module { /** For CPU usage meter */ float cpuTime = 0.0; - /** Deprecated, use constructor below this one */ - Module() DEPRECATED {} - /** Constructs Module with a fixed number of params, inputs, and outputs */ + /** Constructs a Module with no params, inputs, outputs, and lights */ + Module() {} + /** Constructs a Module with a fixed number of params, inputs, outputs, and lights */ Module(int numParams, int numInputs, int numOutputs, int numLights = 0) { params.resize(numParams); inputs.resize(numInputs); diff --git a/include/plugin.hpp b/include/plugin.hpp index aa5512e6..54be270c 100644 --- a/include/plugin.hpp +++ b/include/plugin.hpp @@ -11,6 +11,7 @@ struct ModuleWidget; struct Module; struct Model; + // Subclass this and return a pointer to a new one when init() is called struct Plugin { /** A list of the models available by this plugin, add with addModel() */ @@ -39,6 +40,7 @@ struct Plugin { void addModel(Model *model); }; + struct Model { Plugin *plugin = NULL; /** An identifier for the model, e.g. "VCO". Used for saving patches. The slug, manufacturerSlug pair must be unique. */ @@ -54,10 +56,43 @@ struct Model { std::list tags; virtual ~Model() {} + /** Creates a headless Module */ virtual Module *createModule() { return NULL; } + /** Creates a ModuleWidget with a Module attached */ virtual ModuleWidget *createModuleWidget() { return NULL; } + /** Creates a ModuleWidget with no Module, useful for previews */ + virtual ModuleWidget *createModuleWidgetNull() { return NULL; } + + /** Create Model subclass which constructs a specific Module and ModuleWidget subclass */ + template + static Model *create(std::string manufacturer, std::string slug, std::string name, Tags... tags) { + struct TModel : Model { + Module *createModule() override { + TModule *module = new TModule(); + return module; + } + ModuleWidget *createModuleWidget() override { + TModule *module = new TModule(); + TModuleWidget *moduleWidget = new TModuleWidget(module); + moduleWidget->model = this; + return moduleWidget; + } + ModuleWidget *createModuleWidgetNull() override { + TModuleWidget *moduleWidget = new TModuleWidget(NULL); + moduleWidget->model = this; + return moduleWidget; + } + }; + TModel *o = new TModel(); + o->manufacturer = manufacturer; + o->slug = slug; + o->name = name; + o->tags = {tags...}; + return o; + } }; + void pluginInit(); void pluginDestroy(); void pluginLogIn(std::string email, std::string password); diff --git a/include/rack.hpp b/include/rack.hpp index e2868985..59d6ce95 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -18,8 +18,9 @@ namespace rack { // helpers //////////////////// +/** Deprecated, use Model::create(...) instead */ template -Model *createModel(std::string manufacturer, std::string slug, std::string name, Tags... tags) { +DEPRECATED Model *createModel(std::string manufacturer, std::string slug, std::string name, Tags... tags) { struct TModel : Model { ModuleWidget *createModuleWidget() override { ModuleWidget *moduleWidget = new TModuleWidget(); diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 358b2523..da9a080d 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -7,22 +7,22 @@ namespace rack { +ModuleWidget::ModuleWidget(Module *module) { + if (module) { + engineAddModule(module); + } + this->module = module; +} + ModuleWidget::~ModuleWidget() { // Make sure WireWidget destructors are called *before* removing `module` from the rack. disconnect(); // Remove and delete the Module instance - setModule(NULL); -} - -void ModuleWidget::setModule(Module *module) { - if (this->module) { - engineRemoveModule(this->module); - delete this->module; - } if (module) { - engineAddModule(module); + engineRemoveModule(module); + delete module; + module = NULL; } - this->module = module; } void ModuleWidget::addInput(Port *input) { diff --git a/src/core/AudioInterface.cpp b/src/core/AudioInterface.cpp index 64c55d60..c9c66ac8 100644 --- a/src/core/AudioInterface.cpp +++ b/src/core/AudioInterface.cpp @@ -210,99 +210,102 @@ void AudioInterface::step() { } -AudioInterfaceWidget::AudioInterfaceWidget() { - AudioInterface *module = new AudioInterface(); - setModule(module); - box.size = Vec(15*12, 380); - { - Panel *panel = new LightPanel(); - panel->box.size = box.size; - addChild(panel); - } +struct AudioInterfaceWidget : ModuleWidget { + AudioInterfaceWidget(AudioInterface *module) : ModuleWidget(module) { + box.size = Vec(15*12, 380); + { + Panel *panel = new LightPanel(); + panel->box.size = box.size; + addChild(panel); + } - addChild(Widget::create(Vec(15, 0))); - addChild(Widget::create(Vec(box.size.x-30, 0))); - addChild(Widget::create(Vec(15, 365))); - addChild(Widget::create(Vec(box.size.x-30, 365))); - - Vec margin = Vec(5, 2); - float labelHeight = 15; - float yPos = margin.y + 100; - float xPos; - - { - Label *label = new Label(); - label->box.pos = Vec(margin.x, yPos); - label->text = "Outputs (DACs)"; - addChild(label); - yPos += labelHeight + margin.y; - } + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x-30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x-30, 365))); + + Vec margin = Vec(5, 2); + float labelHeight = 15; + float yPos = margin.y + 100; + float xPos; + + { + Label *label = new Label(); + label->box.pos = Vec(margin.x, yPos); + label->text = "Outputs (DACs)"; + addChild(label); + yPos += labelHeight + margin.y; + } - yPos += 5; - xPos = 10; - for (int i = 0; i < 4; i++) { - addInput(Port::create(Vec(xPos, yPos), Port::INPUT, module, AudioInterface::AUDIO_INPUT + i)); - Label *label = new Label(); - label->box.pos = Vec(xPos + 4, yPos + 28); - label->text = stringf("%d", i + 1); - addChild(label); + yPos += 5; + xPos = 10; + for (int i = 0; i < 4; i++) { + addInput(Port::create(Vec(xPos, yPos), Port::INPUT, module, AudioInterface::AUDIO_INPUT + i)); + Label *label = new Label(); + label->box.pos = Vec(xPos + 4, yPos + 28); + label->text = stringf("%d", i + 1); + addChild(label); - xPos += 37 + margin.x; - } - yPos += 35 + margin.y; - - yPos += 5; - xPos = 10; - for (int i = 4; i < 8; i++) { - addInput(Port::create(Vec(xPos, yPos), Port::INPUT, module, AudioInterface::AUDIO_INPUT + i)); - Label *label = new Label(); - label->box.pos = Vec(xPos + 4, yPos + 28); - label->text = stringf("%d", i + 1); - addChild(label); - - xPos += 37 + margin.x; - } - yPos += 35 + margin.y; - - { - Label *label = new Label(); - label->box.pos = Vec(margin.x, yPos); - label->text = "Inputs (ADCs)"; - addChild(label); - yPos += labelHeight + margin.y; - } + xPos += 37 + margin.x; + } + yPos += 35 + margin.y; + + yPos += 5; + xPos = 10; + for (int i = 4; i < 8; i++) { + addInput(Port::create(Vec(xPos, yPos), Port::INPUT, module, AudioInterface::AUDIO_INPUT + i)); + Label *label = new Label(); + label->box.pos = Vec(xPos + 4, yPos + 28); + label->text = stringf("%d", i + 1); + addChild(label); + + xPos += 37 + margin.x; + } + yPos += 35 + margin.y; + + { + Label *label = new Label(); + label->box.pos = Vec(margin.x, yPos); + label->text = "Inputs (ADCs)"; + addChild(label); + yPos += labelHeight + margin.y; + } - yPos += 5; - xPos = 10; - for (int i = 0; i < 4; i++) { - Port *port = Port::create(Vec(xPos, yPos), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + i); - addOutput(port); - Label *label = new Label(); - label->box.pos = Vec(xPos + 4, yPos + 28); - label->text = stringf("%d", i + 1); - addChild(label); - - xPos += 37 + margin.x; - } - yPos += 35 + margin.y; - - yPos += 5; - xPos = 10; - for (int i = 4; i < 8; i++) { - addOutput(Port::create(Vec(xPos, yPos), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + i)); - Label *label = new Label(); - label->box.pos = Vec(xPos + 4, yPos + 28); - label->text = stringf("%d", i + 1); - addChild(label); - - xPos += 37 + margin.x; + yPos += 5; + xPos = 10; + for (int i = 0; i < 4; i++) { + Port *port = Port::create(Vec(xPos, yPos), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + i); + addOutput(port); + Label *label = new Label(); + label->box.pos = Vec(xPos + 4, yPos + 28); + label->text = stringf("%d", i + 1); + addChild(label); + + xPos += 37 + margin.x; + } + yPos += 35 + margin.y; + + yPos += 5; + xPos = 10; + for (int i = 4; i < 8; i++) { + addOutput(Port::create(Vec(xPos, yPos), Port::OUTPUT, module, AudioInterface::AUDIO_OUTPUT + i)); + Label *label = new Label(); + label->box.pos = Vec(xPos + 4, yPos + 28); + label->text = stringf("%d", i + 1); + addChild(label); + + xPos += 37 + margin.x; + } + yPos += 35 + margin.y; + + AudioWidget *audioWidget = construct(); + audioWidget->audioIO = &module->audioIO; + addChild(audioWidget); + + // Lights + addChild(ModuleLightWidget::create>(Vec(40, 20), module, AudioInterface::ACTIVE_LIGHT)); } - yPos += 35 + margin.y; +}; - AudioWidget *audioWidget = construct(); - audioWidget->audioIO = &module->audioIO; - addChild(audioWidget); - // Lights - addChild(ModuleLightWidget::create>(Vec(40, 20), module, AudioInterface::ACTIVE_LIGHT)); -} +Model *modelAudioInterface = Model::create("Core", "AudioInterface", "Audio Interface", EXTERNAL_TAG); \ No newline at end of file diff --git a/src/core/Blank.cpp b/src/core/Blank.cpp index ba4c0e49..2069accd 100644 --- a/src/core/Blank.cpp +++ b/src/core/Blank.cpp @@ -56,58 +56,68 @@ struct ModuleResizeHandle : Widget { }; -BlankWidget::BlankWidget() { - box.size = Vec(RACK_GRID_WIDTH * 10, RACK_GRID_HEIGHT); +struct BlankWidget : ModuleWidget { + Panel *panel; + Widget *topRightScrew; + Widget *bottomRightScrew; + Widget *rightHandle; + + BlankWidget(Module *module) : ModuleWidget(module) { + box.size = Vec(RACK_GRID_WIDTH * 10, RACK_GRID_HEIGHT); + + { + panel = new LightPanel(); + panel->box.size = box.size; + addChild(panel); + } - { - panel = new LightPanel(); - panel->box.size = box.size; - addChild(panel); + ModuleResizeHandle *leftHandle = new ModuleResizeHandle(); + ModuleResizeHandle *rightHandle = new ModuleResizeHandle(); + rightHandle->right = true; + this->rightHandle = rightHandle; + addChild(leftHandle); + addChild(rightHandle); + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(15, 365))); + topRightScrew = Widget::create(Vec(box.size.x - 30, 0)); + bottomRightScrew = Widget::create(Vec(box.size.x - 30, 365)); + addChild(topRightScrew); + addChild(bottomRightScrew); } - ModuleResizeHandle *leftHandle = new ModuleResizeHandle(); - ModuleResizeHandle *rightHandle = new ModuleResizeHandle(); - rightHandle->right = true; - this->rightHandle = rightHandle; - addChild(leftHandle); - addChild(rightHandle); - - addChild(Widget::create(Vec(15, 0))); - addChild(Widget::create(Vec(15, 365))); - topRightScrew = Widget::create(Vec(box.size.x - 30, 0)); - bottomRightScrew = Widget::create(Vec(box.size.x - 30, 365)); - addChild(topRightScrew); - addChild(bottomRightScrew); -} - -void BlankWidget::step() { - panel->box.size = box.size; - topRightScrew->box.pos.x = box.size.x - 30; - bottomRightScrew->box.pos.x = box.size.x - 30; - if (box.size.x < RACK_GRID_WIDTH * 6) { - topRightScrew->visible = bottomRightScrew->visible = false; - } - else { - topRightScrew->visible = bottomRightScrew->visible = true; + void step() override { + panel->box.size = box.size; + topRightScrew->box.pos.x = box.size.x - 30; + bottomRightScrew->box.pos.x = box.size.x - 30; + if (box.size.x < RACK_GRID_WIDTH * 6) { + topRightScrew->visible = bottomRightScrew->visible = false; + } + else { + topRightScrew->visible = bottomRightScrew->visible = true; + } + rightHandle->box.pos.x = box.size.x - rightHandle->box.size.x; + ModuleWidget::step(); } - rightHandle->box.pos.x = box.size.x - rightHandle->box.size.x; - ModuleWidget::step(); -} -json_t *BlankWidget::toJson() { - json_t *rootJ = ModuleWidget::toJson(); + json_t *toJson() override { + json_t *rootJ = ModuleWidget::toJson(); + + // // width + json_object_set_new(rootJ, "width", json_real(box.size.x)); + + return rootJ; + } - // // width - json_object_set_new(rootJ, "width", json_real(box.size.x)); + void fromJson(json_t *rootJ) override { + ModuleWidget::fromJson(rootJ); - return rootJ; -} + // width + json_t *widthJ = json_object_get(rootJ, "width"); + if (widthJ) + box.size.x = json_number_value(widthJ); + } +}; -void BlankWidget::fromJson(json_t *rootJ) { - ModuleWidget::fromJson(rootJ); - // width - json_t *widthJ = json_object_get(rootJ, "width"); - if (widthJ) - box.size.x = json_number_value(widthJ); -} +Model *modelBlank = Model::create("Core", "Blank", "Blank", BLANK_TAG); diff --git a/src/core/MidiToCV.cpp b/src/core/MidiToCV.cpp index fa50d974..598fdb18 100644 --- a/src/core/MidiToCV.cpp +++ b/src/core/MidiToCV.cpp @@ -6,7 +6,7 @@ /* - * MIDIToCVInterface converts midi note on/off events, velocity , channel aftertouch, pitch wheel and mod wheel to + * MidiToCvInterface converts midi note on/off events, velocity , channel aftertouch, pitch wheel and mod wheel to * CV */ struct MidiValue { @@ -16,7 +16,7 @@ struct MidiValue { }; -struct MIDIToCVInterface : Module { +struct MidiToCvInterface : Module { enum ParamIds { RESET_PARAM, NUM_PARAMS @@ -51,12 +51,12 @@ struct MIDIToCVInterface : Module { SchmittTrigger resetTrigger; - MIDIToCVInterface() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { + MidiToCvInterface() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { pitchWheel.val = 64; // pitchWheel.tSmooth.set(0, 0); } - ~MIDIToCVInterface() { + ~MidiToCvInterface() { }; void step() override; @@ -85,7 +85,7 @@ struct MIDIToCVInterface : Module { }; /* -void MIDIToCVInterface::resetMidi() { +void MidiToCvInterface::resetMidi() { mod.val = 0; mod.tSmooth.set(0, 0); pitchWheel.val = 64; @@ -98,7 +98,7 @@ void MIDIToCVInterface::resetMidi() { } */ -void MIDIToCVInterface::step() { +void MidiToCvInterface::step() { /* if (isPortOpen()) { std::vector message; @@ -143,7 +143,7 @@ void MIDIToCVInterface::step() { lights[ACTIVE_LIGHT].value = midiInput.isActive() ? 1.0 : 0.0; } -void MIDIToCVInterface::pressNote(int note) { +void MidiToCvInterface::pressNote(int note) { // Remove existing similar note auto it = std::find(notes.begin(), notes.end(), note); if (it != notes.end()) @@ -154,7 +154,7 @@ void MIDIToCVInterface::pressNote(int note) { gate = true; } -void MIDIToCVInterface::releaseNote(int note) { +void MidiToCvInterface::releaseNote(int note) { // Remove the note auto it = std::find(notes.begin(), notes.end(), note); if (it != notes.end()) @@ -174,7 +174,7 @@ void MIDIToCVInterface::releaseNote(int note) { } } -void MIDIToCVInterface::processMidi(std::vector msg) { +void MidiToCvInterface::processMidi(std::vector msg) { /* int channel = msg[0] & 0xf; int status = (msg[0] >> 4) & 0xf; @@ -229,55 +229,58 @@ void MIDIToCVInterface::processMidi(std::vector msg) { } -MidiToCVWidget::MidiToCVWidget() { - MIDIToCVInterface *module = new MIDIToCVInterface(); - setModule(module); - box.size = Vec(15 * 9, 380); +struct MidiToCvInterfaceWidget : ModuleWidget { + MidiToCvInterfaceWidget(MidiToCvInterface *module) : ModuleWidget(module) { + box.size = Vec(15 * 9, 380); - { - Panel *panel = new LightPanel(); - panel->box.size = box.size; - addChild(panel); - } + { + Panel *panel = new LightPanel(); + panel->box.size = box.size; + addChild(panel); + } - float margin = 5; - float labelHeight = 15; - float yPos = margin; - float yGap = 35; - - addChild(Widget::create(Vec(15, 0))); - addChild(Widget::create(Vec(box.size.x - 30, 0))); - addChild(Widget::create(Vec(15, 365))); - addChild(Widget::create(Vec(box.size.x - 30, 365))); - - { - Label *label = new Label(); - label->box.pos = Vec(box.size.x - margin - 7 * 15, margin); - label->text = "MIDI to CV"; - addChild(label); - yPos = labelHeight * 2; - } + float margin = 5; + float labelHeight = 15; + float yPos = margin; + float yGap = 35; + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); + + { + Label *label = new Label(); + label->box.pos = Vec(box.size.x - margin - 7 * 15, margin); + label->text = "MIDI to CV"; + addChild(label); + yPos = labelHeight * 2; + } + + addParam(ParamWidget::create(Vec(7 * 15, labelHeight), module, MidiToCvInterface::RESET_PARAM, 0.0, 1.0, 0.0)); + addChild(ModuleLightWidget::create>(Vec(7 * 15 + 5, labelHeight + 5), module, MidiToCvInterface::RESET_LIGHT)); - addParam(ParamWidget::create(Vec(7 * 15, labelHeight), module, MIDIToCVInterface::RESET_PARAM, 0.0, 1.0, 0.0)); - addChild(ModuleLightWidget::create>(Vec(7 * 15 + 5, labelHeight + 5), module, MIDIToCVInterface::RESET_LIGHT)); + std::string labels[MidiToCvInterface::NUM_OUTPUTS] = {"1V/oct", "Gate", "Velocity", "Mod Wheel", "Pitch Wheel", "Aftertouch"}; - std::string labels[MIDIToCVInterface::NUM_OUTPUTS] = {"1V/oct", "Gate", "Velocity", "Mod Wheel", "Pitch Wheel", "Aftertouch"}; + for (int i = 0; i < MidiToCvInterface::NUM_OUTPUTS; i++) { + Label *label = new Label(); + label->box.pos = Vec(margin, yPos); + label->text = labels[i]; + addChild(label); - for (int i = 0; i < MIDIToCVInterface::NUM_OUTPUTS; i++) { - Label *label = new Label(); - label->box.pos = Vec(margin, yPos); - label->text = labels[i]; - addChild(label); + addOutput(Port::create(Vec(15 * 6, yPos - 5), Port::OUTPUT, module, i)); - addOutput(Port::create(Vec(15 * 6, yPos - 5), Port::OUTPUT, module, i)); + yPos += yGap + margin; + } + + MidiWidget *midiWidget = construct(); + midiWidget->midiIO = &module->midiInput; + addChild(midiWidget); - yPos += yGap + margin; + // Lights + addChild(ModuleLightWidget::create>(Vec(40, 20), module, MidiToCvInterface::ACTIVE_LIGHT)); } +}; - MidiWidget *midiWidget = construct(); - midiWidget->midiIO = &module->midiInput; - addChild(midiWidget); - // Lights - addChild(ModuleLightWidget::create>(Vec(40, 20), module, MIDIToCVInterface::ACTIVE_LIGHT)); -} +Model *modelMidiToCvInterface = Model::create("Core", "MIDIToCVInterface", "MIDI-to-CV Interface", MIDI_TAG, EXTERNAL_TAG); diff --git a/src/core/Notes.cpp b/src/core/Notes.cpp index e207bf2d..dfe5c611 100644 --- a/src/core/Notes.cpp +++ b/src/core/Notes.cpp @@ -4,41 +4,48 @@ using namespace rack; -NotesWidget::NotesWidget() { - box.size = Vec(RACK_GRID_WIDTH * 18, RACK_GRID_HEIGHT); - - { - Panel *panel = new LightPanel(); - panel->box.size = box.size; - addChild(panel); +struct NotesWidget : ModuleWidget { + TextField *textField; + + NotesWidget(Module *module) : ModuleWidget(module) { + box.size = Vec(RACK_GRID_WIDTH * 18, RACK_GRID_HEIGHT); + + { + Panel *panel = new LightPanel(); + panel->box.size = box.size; + addChild(panel); + } + + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); + + textField = new TextField(); + textField->box.pos = Vec(15, 15); + textField->box.size = box.size.minus(Vec(30, 30)); + textField->multiline = true; + addChild(textField); } - addChild(Widget::create(Vec(15, 0))); - addChild(Widget::create(Vec(15, 365))); - addChild(Widget::create(Vec(box.size.x - 30, 0))); - addChild(Widget::create(Vec(box.size.x - 30, 365))); + json_t *toJson() override { + json_t *rootJ = ModuleWidget::toJson(); - textField = new TextField(); - textField->box.pos = Vec(15, 15); - textField->box.size = box.size.minus(Vec(30, 30)); - textField->multiline = true; - addChild(textField); -} + // text + json_object_set_new(rootJ, "text", json_string(textField->text.c_str())); -json_t *NotesWidget::toJson() { - json_t *rootJ = ModuleWidget::toJson(); + return rootJ; + } - // text - json_object_set_new(rootJ, "text", json_string(textField->text.c_str())); + void fromJson(json_t *rootJ) override { + ModuleWidget::fromJson(rootJ); - return rootJ; -} + // text + json_t *textJ = json_object_get(rootJ, "text"); + if (textJ) + textField->text = json_string_value(textJ); + } +}; -void NotesWidget::fromJson(json_t *rootJ) { - ModuleWidget::fromJson(rootJ); - // text - json_t *textJ = json_object_get(rootJ, "text"); - if (textJ) - textField->text = json_string_value(textJ); -} +Model *modelNotes = Model::create("Core", "Notes", "Notes", BLANK_TAG); diff --git a/src/core/core.cpp b/src/core/core.cpp index ad4de7b7..4df1dc4b 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -3,18 +3,16 @@ void init(rack::Plugin *p) { p->slug = "Core"; -#ifdef VERSION p->version = TOSTRING(VERSION); -#endif - p->addModel(createModel("Core", "AudioInterface", "Audio Interface", EXTERNAL_TAG)); + p->addModel(modelAudioInterface); + p->addModel(modelMidiToCvInterface); + p->addModel(modelBlank); + p->addModel(modelNotes); - p->addModel(createModel("Core", "MIDIToCVInterface", "MIDI-to-CV Interface", MIDI_TAG, EXTERNAL_TAG)); + // TODO // p->addModel(createModel("Core", "MIDICCToCVInterface", "MIDI CC-to-CV Interface", MIDI_TAG, EXTERNAL_TAG)); // p->addModel(createModel("Core", "MIDIClockToCVInterface", "MIDI Clock-to-CV Interface", MIDI_TAG, EXTERNAL_TAG, CLOCK_TAG)); // p->addModel(createModel("Core", "MIDITriggerToCVInterface", "MIDI Trigger-to-CV Interface", MIDI_TAG, EXTERNAL_TAG)); // p->addModel(createModel("Core", "QuadMIDIToCVInterface", "Quad MIDI-to-CV Interface", MIDI_TAG, EXTERNAL_TAG, QUAD_TAG)); - - p->addModel(createModel("Core", "Blank", "Blank", BLANK_TAG)); - p->addModel(createModel("Core", "Notes", "Notes", BLANK_TAG)); } diff --git a/src/core/core.hpp b/src/core/core.hpp index 17fd465d..0415a7a3 100644 --- a/src/core/core.hpp +++ b/src/core/core.hpp @@ -4,17 +4,16 @@ using namespace rack; +extern Model *modelAudioInterface; +extern Model *modelMidiToCvInterface; +extern Model *modelBlank; +extern Model *modelNotes; + + //////////////////// // module widgets //////////////////// -struct AudioInterfaceWidget : ModuleWidget { - AudioInterfaceWidget(); -}; - -struct MidiToCVWidget : ModuleWidget { - MidiToCVWidget(); -}; // struct MIDICCToCVWidget : ModuleWidget { // MIDICCToCVWidget(); @@ -35,25 +34,3 @@ struct MidiToCVWidget : ModuleWidget { // QuadMidiToCVWidget(); // void step() override; // }; - -struct BridgeWidget : ModuleWidget { - BridgeWidget(); -}; - -struct BlankWidget : ModuleWidget { - Panel *panel; - Widget *topRightScrew; - Widget *bottomRightScrew; - Widget *rightHandle; - BlankWidget(); - void step() override; - json_t *toJson() override; - void fromJson(json_t *rootJ) override; -}; - -struct NotesWidget : ModuleWidget { - TextField *textField; - NotesWidget(); - json_t *toJson() override; - void fromJson(json_t *rootJ) override; -};