From ae19e33774b1aadc8b23c7a5bd13184b50241b09 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 8 Nov 2019 14:42:35 -0500 Subject: [PATCH] Make PortInfo a virtual class. --- include/app/ParamWidget.hpp | 2 +- include/app/PortWidget.hpp | 4 ++-- include/engine/Module.hpp | 15 ++++++++++++--- include/engine/ParamQuantity.hpp | 2 +- include/engine/PortInfo.hpp | 8 ++++++++ src/app/PortWidget.cpp | 6 +++--- 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/app/ParamWidget.hpp b/include/app/ParamWidget.hpp index eaa2ce9d..a7b6afc5 100644 --- a/include/app/ParamWidget.hpp +++ b/include/app/ParamWidget.hpp @@ -13,7 +13,7 @@ namespace app { /** Manages an engine::Param on a ModuleWidget. */ struct ParamWidget : widget::OpaqueWidget { engine::Module* module = NULL; - int paramId = 0; + int paramId; ui::Tooltip* tooltip = NULL; /** For triggering the Change event. `*/ diff --git a/include/app/PortWidget.hpp b/include/app/PortWidget.hpp index e961847d..82f039d5 100644 --- a/include/app/PortWidget.hpp +++ b/include/app/PortWidget.hpp @@ -14,8 +14,8 @@ namespace app { /** Manages an engine::Port on a ModuleWidget. */ struct PortWidget : widget::OpaqueWidget { engine::Module* module = NULL; - engine::Port::Type type = engine::Port::INPUT; - int portId = 0; + engine::Port::Type type; + int portId; ui::Tooltip* tooltip = NULL; bool hovered = false; diff --git a/include/engine/Module.hpp b/include/engine/Module.hpp index c1146da9..90888848 100644 --- a/include/engine/Module.hpp +++ b/include/engine/Module.hpp @@ -24,7 +24,8 @@ namespace engine { /** DSP processor instance for your module. */ struct Module { - plugin::Model* model = NULL; /** Unique ID for referring to the module in the engine. + plugin::Model* model = NULL; + /** Unique ID for referring to the module in the engine. Assigned when added to the engine. */ int id = -1; @@ -120,12 +121,16 @@ struct Module { paramQuantities[paramId] = q; } + template void configInput(int portId, std::string name = "") { assert(portId < (int) inputs.size() && portId < (int) inputInfos.size()); if (inputInfos[portId]) delete inputInfos[portId]; - PortInfo* p = new PortInfo; + PortInfo* p = new TPortInfo; + p->module = this; + p->type = Port::INPUT; + p->portId = portId; if (name == "") p->name = string::f("#%d", portId + 1); else @@ -133,12 +138,16 @@ struct Module { inputInfos[portId] = p; } + template void configOutput(int portId, std::string name = "") { assert(portId < (int) outputs.size() && portId < (int) outputInfos.size()); if (outputInfos[portId]) delete outputInfos[portId]; - PortInfo* p = new PortInfo; + PortInfo* p = new TPortInfo; + p->module = this; + p->type = Port::OUTPUT; + p->portId = portId; if (name == "") p->name = string::f("#%d", portId + 1); else diff --git a/include/engine/ParamQuantity.hpp b/include/engine/ParamQuantity.hpp index 9a525a1a..662737b0 100644 --- a/include/engine/ParamQuantity.hpp +++ b/include/engine/ParamQuantity.hpp @@ -13,7 +13,7 @@ struct Module; /** A Quantity that wraps an engine::Param. */ struct ParamQuantity : Quantity { Module* module = NULL; - int paramId = 0; + int paramId; /** The minimum allowed value. */ float minValue = 0.f; diff --git a/include/engine/PortInfo.hpp b/include/engine/PortInfo.hpp index 0c9512ae..b0752758 100644 --- a/include/engine/PortInfo.hpp +++ b/include/engine/PortInfo.hpp @@ -8,12 +8,20 @@ namespace engine { struct PortInfo { + Module* module = NULL; + Port::Type type; + int portId; + /** The name of the port, using sentence capitalization. e.g. "Sine", "Pitch input", "Mode CV" */ std::string name; /** An optional one-sentence description of the parameter. */ std::string description; + + virtual ~PortInfo() {} + virtual std::string getName() {return name;} + virtual std::string getDescription() {return description;} }; diff --git a/src/app/PortWidget.cpp b/src/app/PortWidget.cpp index 5ccad992..94a20f59 100644 --- a/src/app/PortWidget.cpp +++ b/src/app/PortWidget.cpp @@ -22,7 +22,7 @@ struct PortTooltip : ui::Tooltip { // Label text = (portWidget->type == engine::Port::INPUT) ? "Input" : "Output"; text += ": "; - text += portInfo->name; + text += portInfo->getName(); // Voltage, number of channels int channels = port->getChannels(); for (int i = 0; i < channels; i++) { @@ -33,7 +33,7 @@ struct PortTooltip : ui::Tooltip { text += string::f("% .3fV", port->getVoltage(i)); } // Description - std::string description = portInfo->description; + std::string description = portInfo->getDescription(); if (description != "") { text += "\n"; text += description; @@ -48,7 +48,7 @@ struct PortTooltip : ui::Tooltip { text += "Connected to "; text += otherPw->module->model->getFullName(); text += ": "; - text += otherPw->getPortInfo()->name; + text += otherPw->getPortInfo()->getName(); } } Tooltip::step();