From fb4a0d879aa372c38af74b60393674ea05c343bc Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 11 Jul 2018 18:39:14 -0400 Subject: [PATCH] Un-deprecate helper functions, move to helpers.hpp --- include/helpers.hpp | 129 ++++++++++++++++++++++++++++++ include/plugin.hpp | 3 +- include/rack.hpp | 82 +------------------ res/ComponentLibrary/TL1105_0.svg | 34 ++++---- res/ComponentLibrary/TL1105_1.svg | 34 ++++---- 5 files changed, 165 insertions(+), 117 deletions(-) create mode 100644 include/helpers.hpp diff --git a/include/helpers.hpp b/include/helpers.hpp new file mode 100644 index 00000000..037b1a94 --- /dev/null +++ b/include/helpers.hpp @@ -0,0 +1,129 @@ +#include "plugin.hpp" +#include "engine.hpp" +#include "app.hpp" + + +namespace rack { + + +template +Model *createModel(std::string author, std::string slug, std::string name, Tags... tags) { + struct TModel : Model { + Module *createModule() override { + TModule *module = new TModule(); + return module; + } + ModuleWidget *createModuleWidget() override { + TModuleWidget *moduleWidget = new TModuleWidget(createModule()); + moduleWidget->model = this; + return moduleWidget; + } + ModuleWidget *createModuleWidgetNull() override { + TModuleWidget *moduleWidget = new TModuleWidget(NULL); + moduleWidget->model = this; + return moduleWidget; + } + }; + Model *model = new TModel(); + model->author = author; + model->slug = slug; + model->name = name; + model->tags = {tags...}; + return model; +} + +template +TWidget *createWidget(Vec pos) { + TWidget *w = new TWidget(); + w->box.pos = pos; + return w; +} + +/** Deprecated. Use createWidget() instead */ +template +DEPRECATED TScrew *createScrew(Vec pos) { + return createWidget(pos); +} + +template +TParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) { + TParamWidget *param = new TParamWidget(); + param->box.pos = pos; + param->module = module; + param->paramId = paramId; + param->setLimits(minValue, maxValue); + param->setDefaultValue(defaultValue); + return param; +} + +template +TParamWidget *createParamCentered(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) { + TParamWidget *param = new TParamWidget(); + param->box.pos = pos.minus(param->box.size.div(2)); + param->module = module; + param->paramId = paramId; + param->setLimits(minValue, maxValue); + param->setDefaultValue(defaultValue); + return param; +} + +template +TPort *createInput(Vec pos, Module *module, int inputId) { + TPort *port = new TPort(); + port->box.pos = pos; + port->module = module; + port->type = Port::INPUT; + port->portId = inputId; + return port; +} + +template +TPort *createInputCentered(Vec pos, Module *module, int inputId) { + TPort *port = new TPort(); + port->box.pos = pos.minus(port->box.size.div(2)); + port->module = module; + port->type = Port::INPUT; + port->portId = inputId; + return port; +} + +template +TPort *createOutput(Vec pos, Module *module, int outputId) { + TPort *port = new TPort(); + port->box.pos = pos; + port->module = module; + port->type = Port::OUTPUT; + port->portId = outputId; + return port; +} + +template +TPort *createOutputCentered(Vec pos, Module *module, int outputId) { + TPort *port = new TPort(); + port->box.pos = pos.minus(port->box.size.div(2)); + port->module = module; + port->type = Port::OUTPUT; + port->portId = outputId; + return port; +} + +template +TModuleLightWidget *createLight(Vec pos, Module *module, int firstLightId) { + TModuleLightWidget *light = new TModuleLightWidget(); + light->box.pos = pos; + light->module = module; + light->firstLightId = firstLightId; + return light; +} + +template +TModuleLightWidget *createLightCentered(Vec pos, Module *module, int firstLightId) { + TModuleLightWidget *light = new TModuleLightWidget(); + light->box.pos = pos.minus(light->box.size.div(2)); + light->module = module; + light->firstLightId = firstLightId; + return light; +} + + +} // namespace rack diff --git a/include/plugin.hpp b/include/plugin.hpp index f3089d9d..8c3ecc8d 100644 --- a/include/plugin.hpp +++ b/include/plugin.hpp @@ -74,8 +74,7 @@ struct Model { return module; } ModuleWidget *createModuleWidget() override { - TModule *module = new TModule(); - TModuleWidget *moduleWidget = new TModuleWidget(module); + TModuleWidget *moduleWidget = new TModuleWidget(createModule()); moduleWidget->model = this; return moduleWidget; } diff --git a/include/rack.hpp b/include/rack.hpp index 16c4f317..1ddc066a 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -9,84 +9,4 @@ #include "app.hpp" #include "ui.hpp" #include "componentlibrary.hpp" - - -namespace rack { - - -//////////////////// -// helpers -//////////////////// - -/** Deprecated, use Model::create(...) instead */ -template -DEPRECATED Model *createModel(std::string author, std::string slug, std::string name, Tags... tags) { - struct TModel : Model { - ModuleWidget *createModuleWidget() override { - ModuleWidget *moduleWidget = new TModuleWidget(); - moduleWidget->model = this; - return moduleWidget; - } - }; - Model *model = new TModel(); - model->author = author; - model->slug = slug; - model->name = name; - model->tags = {tags...}; - return model; -} - -/** Deprecated, use Widget::create() instead */ -template -DEPRECATED TScrew *createScrew(Vec pos) { - TScrew *screw = new TScrew(); - screw->box.pos = pos; - return screw; -} - -/** Deprecated, use ParamWidget::create() instead */ -template -DEPRECATED TParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) { - TParamWidget *param = new TParamWidget(); - param->box.pos = pos; - param->module = module; - param->paramId = paramId; - param->setLimits(minValue, maxValue); - param->setDefaultValue(defaultValue); - return param; -} - -/** Deprecated, use Port::create(..., Port::INPUT, ...) instead */ -template -DEPRECATED TPort *createInput(Vec pos, Module *module, int inputId) { - TPort *port = new TPort(); - port->box.pos = pos; - port->module = module; - port->type = Port::INPUT; - port->portId = inputId; - return port; -} - -/** Deprecated, use Port::create(..., Port::OUTPUT, ...) instead */ -template -DEPRECATED TPort *createOutput(Vec pos, Module *module, int outputId) { - TPort *port = new TPort(); - port->box.pos = pos; - port->module = module; - port->type = Port::OUTPUT; - port->portId = outputId; - return port; -} - -/** Deprecated, use ModuleLightWidget::create() instead */ -template -DEPRECATED TModuleLightWidget *createLight(Vec pos, Module *module, int firstLightId) { - TModuleLightWidget *light = new TModuleLightWidget(); - light->box.pos = pos; - light->module = module; - light->firstLightId = firstLightId; - return light; -} - - -} // namespace rack +#include "helpers.hpp" diff --git a/res/ComponentLibrary/TL1105_0.svg b/res/ComponentLibrary/TL1105_0.svg index ea6a7255..1f746886 100644 --- a/res/ComponentLibrary/TL1105_0.svg +++ b/res/ComponentLibrary/TL1105_0.svg @@ -9,12 +9,12 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="15.999999" - height="15.997643" - viewBox="0 0 4.2333331 4.2327099" + width="5.4186664mm" + height="5.4178686mm" + viewBox="0 0 5.4186663 5.4178686" version="1.1" id="svg12484" - inkscape:version="0.92.2 5c3e80d, 2017-08-06" + inkscape:version="0.92.2 2405546, 2018-03-11" sodipodi:docname="TL1105_0.svg"> @@ -25,9 +25,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="44.8" - inkscape:cx="1.1769543" - inkscape:cy="7.1864792" + inkscape:zoom="11.2" + inkscape:cx="6.3388991" + inkscape:cy="5.196676" inkscape:document-units="mm" inkscape:current-layer="g12430" showgrid="false" @@ -35,12 +35,12 @@ fit-margin-left="0" fit-margin-right="0" fit-margin-bottom="0" - inkscape:window-width="2560" - inkscape:window-height="1422" + inkscape:window-width="1600" + inkscape:window-height="882" inkscape:window-x="0" inkscape:window-y="18" inkscape:window-maximized="0" - units="px" /> + units="mm" /> @@ -57,13 +57,13 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(-87.434409,-107.81432)"> + transform="translate(-86.841742,-107.22174)"> + style="opacity:1;vector-effect:none;fill:#2b2d2b;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.89770651;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> diff --git a/res/ComponentLibrary/TL1105_1.svg b/res/ComponentLibrary/TL1105_1.svg index c58cb7cb..b27a3b2a 100644 --- a/res/ComponentLibrary/TL1105_1.svg +++ b/res/ComponentLibrary/TL1105_1.svg @@ -9,12 +9,12 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="15.999999" - height="15.997643" - viewBox="0 0 4.2333331 4.2327099" + width="5.4186664mm" + height="5.4178686mm" + viewBox="0 0 5.4186663 5.4178686" version="1.1" id="svg12484" - inkscape:version="0.92.2 5c3e80d, 2017-08-06" + inkscape:version="0.92.2 2405546, 2018-03-11" sodipodi:docname="TL1105_1.svg"> @@ -25,9 +25,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="44.8" - inkscape:cx="5.4698259" - inkscape:cy="8.0360204" + inkscape:zoom="15.839192" + inkscape:cx="5.770688" + inkscape:cy="6.8891413" inkscape:document-units="mm" inkscape:current-layer="g12476" showgrid="false" @@ -35,12 +35,12 @@ fit-margin-left="0" fit-margin-right="0" fit-margin-bottom="0" - inkscape:window-width="2560" - inkscape:window-height="1422" + inkscape:window-width="1600" + inkscape:window-height="882" inkscape:window-x="0" inkscape:window-y="18" inkscape:window-maximized="0" - units="px" /> + units="mm" /> @@ -57,14 +57,14 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(-155.97001,-114.87325)"> + transform="translate(-155.37735,-114.28067)"> + style="opacity:1;vector-effect:none;fill:#676967;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.89770651;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />