Browse Source

Un-deprecate helper functions, move to helpers.hpp

tags/v0.6.2b
Andrew Belt 6 years ago
parent
commit
fb4a0d879a
5 changed files with 165 additions and 117 deletions
  1. +129
    -0
      include/helpers.hpp
  2. +1
    -2
      include/plugin.hpp
  3. +1
    -81
      include/rack.hpp
  4. +17
    -17
      res/ComponentLibrary/TL1105_0.svg
  5. +17
    -17
      res/ComponentLibrary/TL1105_1.svg

+ 129
- 0
include/helpers.hpp View File

@@ -0,0 +1,129 @@
#include "plugin.hpp"
#include "engine.hpp"
#include "app.hpp"


namespace rack {


template <class TModuleWidget, typename... Tags>
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 <class TWidget>
TWidget *createWidget(Vec pos) {
TWidget *w = new TWidget();
w->box.pos = pos;
return w;
}

/** Deprecated. Use createWidget<TScrew>() instead */
template <class TScrew>
DEPRECATED TScrew *createScrew(Vec pos) {
return createWidget<TScrew>(pos);
}

template <class TParamWidget>
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 <class TParamWidget>
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 <class TPort>
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 <class TPort>
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 <class TPort>
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 <class TPort>
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<class TModuleLightWidget>
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<class TModuleLightWidget>
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

+ 1
- 2
include/plugin.hpp View File

@@ -74,8 +74,7 @@ struct Model {
return module; return module;
} }
ModuleWidget *createModuleWidget() override { ModuleWidget *createModuleWidget() override {
TModule *module = new TModule();
TModuleWidget *moduleWidget = new TModuleWidget(module);
TModuleWidget *moduleWidget = new TModuleWidget(createModule());
moduleWidget->model = this; moduleWidget->model = this;
return moduleWidget; return moduleWidget;
} }


+ 1
- 81
include/rack.hpp View File

@@ -9,84 +9,4 @@
#include "app.hpp" #include "app.hpp"
#include "ui.hpp" #include "ui.hpp"
#include "componentlibrary.hpp" #include "componentlibrary.hpp"


namespace rack {


////////////////////
// helpers
////////////////////

/** Deprecated, use Model::create<TModule, TModuleWidget>(...) instead */
template <class TModuleWidget, typename... Tags>
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<TScrew>() instead */
template <class TScrew>
DEPRECATED TScrew *createScrew(Vec pos) {
TScrew *screw = new TScrew();
screw->box.pos = pos;
return screw;
}

/** Deprecated, use ParamWidget::create<TParamWidget>() instead */
template <class TParamWidget>
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<TPort>(..., Port::INPUT, ...) instead */
template <class TPort>
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<TPort>(..., Port::OUTPUT, ...) instead */
template <class TPort>
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<TModuleLightWidget>() instead */
template<class TModuleLightWidget>
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"

+ 17
- 17
res/ComponentLibrary/TL1105_0.svg View File

@@ -9,12 +9,12 @@
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" 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" version="1.1"
id="svg12484" 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"> sodipodi:docname="TL1105_0.svg">
<defs <defs
id="defs12478" /> id="defs12478" />
@@ -25,9 +25,9 @@
borderopacity="1.0" borderopacity="1.0"
inkscape:pageopacity="0.0" inkscape:pageopacity="0.0"
inkscape:pageshadow="2" 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:document-units="mm"
inkscape:current-layer="g12430" inkscape:current-layer="g12430"
showgrid="false" showgrid="false"
@@ -35,12 +35,12 @@
fit-margin-left="0" fit-margin-left="0"
fit-margin-right="0" fit-margin-right="0"
fit-margin-bottom="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-x="0"
inkscape:window-y="18" inkscape:window-y="18"
inkscape:window-maximized="0" inkscape:window-maximized="0"
units="px" />
units="mm" />
<metadata <metadata
id="metadata12481"> id="metadata12481">
<rdf:RDF> <rdf:RDF>
@@ -57,13 +57,13 @@
inkscape:label="Layer 1" inkscape:label="Layer 1"
inkscape:groupmode="layer" inkscape:groupmode="layer"
id="layer1" id="layer1"
transform="translate(-87.434409,-107.81432)">
transform="translate(-86.841742,-107.22174)">
<g <g
transform="matrix(0.15583204,0,0,-0.15583204,44.616575,295.36332)" transform="matrix(0.15583204,0,0,-0.15583204,44.616575,295.36332)"
id="g12430" id="g12430"
style="stroke-width:2.26383328"> style="stroke-width:2.26383328">
<g <g
transform="translate(301.93513,1189.951)"
transform="matrix(1.28,0,0,1.28,305.73837,1189.9507)"
id="g5959-5" id="g5959-5"
style="stroke-width:2.26383328"> style="stroke-width:2.26383328">
<path <path
@@ -73,19 +73,19 @@
d="m 0,0 c 0,-7.5 -6.083,-13.58 -13.584,-13.58 -7.5,0 -13.582,6.08 -13.582,13.58 0,7.503 6.082,13.582 13.582,13.582 C -6.083,13.582 0,7.503 0,0" /> d="m 0,0 c 0,-7.5 -6.083,-13.58 -13.584,-13.58 -7.5,0 -13.582,6.08 -13.582,13.58 0,7.503 6.082,13.582 13.582,13.582 C -6.083,13.582 0,7.503 0,0" />
</g> </g>
<circle <circle
style="opacity:1;vector-effect:none;fill:#676967;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.26383328;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
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"
id="circle12436" id="circle12436"
cx="288.35214" cx="288.35214"
cy="-1190.6586"
r="11.277138"
cy="-1190.8564"
r="14.434736"
transform="scale(1,-1)" /> transform="scale(1,-1)" />
<circle <circle
transform="scale(1,-1)" transform="scale(1,-1)"
r="11.277138"
r="14.434736"
cy="-1189.952" cy="-1189.952"
cx="288.35214" cx="288.35214"
id="path12411" id="path12411"
style="opacity:1;vector-effect:none;fill:#2b2d2b;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.26383328;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
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" />
</g> </g>
</g> </g>
</svg> </svg>

+ 17
- 17
res/ComponentLibrary/TL1105_1.svg View File

@@ -9,12 +9,12 @@
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" 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" version="1.1"
id="svg12484" 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"> sodipodi:docname="TL1105_1.svg">
<defs <defs
id="defs12478" /> id="defs12478" />
@@ -25,9 +25,9 @@
borderopacity="1.0" borderopacity="1.0"
inkscape:pageopacity="0.0" inkscape:pageopacity="0.0"
inkscape:pageshadow="2" 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:document-units="mm"
inkscape:current-layer="g12476" inkscape:current-layer="g12476"
showgrid="false" showgrid="false"
@@ -35,12 +35,12 @@
fit-margin-left="0" fit-margin-left="0"
fit-margin-right="0" fit-margin-right="0"
fit-margin-bottom="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-x="0"
inkscape:window-y="18" inkscape:window-y="18"
inkscape:window-maximized="0" inkscape:window-maximized="0"
units="px" />
units="mm" />
<metadata <metadata
id="metadata12481"> id="metadata12481">
<rdf:RDF> <rdf:RDF>
@@ -57,14 +57,14 @@
inkscape:label="Layer 1" inkscape:label="Layer 1"
inkscape:groupmode="layer" inkscape:groupmode="layer"
id="layer1" id="layer1"
transform="translate(-155.97001,-114.87325)">
transform="translate(-155.37735,-114.28067)">
<g <g
id="g12476" id="g12476"
transform="matrix(0.15583204,0,0,-0.15583204,113.15218,302.42225)" transform="matrix(0.15583204,0,0,-0.15583204,113.15218,302.42225)"
style="stroke-width:2.26383328"> style="stroke-width:2.26383328">
<g <g
id="g12468" id="g12468"
transform="translate(301.93513,1189.951)"
transform="matrix(1.28,0,0,1.28,305.73837,1189.9507)"
style="stroke-width:2.26383328"> style="stroke-width:2.26383328">
<path <path
d="m 0,0 c 0,-7.5 -6.083,-13.58 -13.584,-13.58 -7.5,0 -13.582,6.08 -13.582,13.58 0,7.503 6.082,13.582 13.582,13.582 C -6.083,13.582 0,7.503 0,0" d="m 0,0 c 0,-7.5 -6.083,-13.58 -13.584,-13.58 -7.5,0 -13.582,6.08 -13.582,13.58 0,7.503 6.082,13.582 13.582,13.582 C -6.083,13.582 0,7.503 0,0"
@@ -74,17 +74,17 @@
</g> </g>
<circle <circle
transform="scale(1,-1)" transform="scale(1,-1)"
r="11.277138"
cy="-1189.2383"
r="14.434736"
cy="-1189.0385"
cx="288.35214" cx="288.35214"
id="circle12472" id="circle12472"
style="opacity:1;vector-effect:none;fill:#676967;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.26383328;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
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" />
<circle <circle
style="opacity:1;vector-effect:none;fill:#141514;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.26383328;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
style="opacity:1;vector-effect:none;fill:#141514;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"
id="circle12474" id="circle12474"
cx="288.35214" cx="288.35214"
cy="-1189.952" cy="-1189.952"
r="11.277138"
r="14.434736"
transform="scale(1,-1)" /> transform="scale(1,-1)" />
</g> </g>
</g> </g>


Loading…
Cancel
Save