#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include namespace rack { template plugin::Model* createModel(const std::string& slug) { struct TModel : plugin::Model { engine::Module* createModule() override { engine::Module* m = new TModule; m->model = this; return m; } app::ModuleWidget* createModuleWidget(engine::Module* m) override { TModule *tm = NULL; if (m) { assert(m->model == this); tm = dynamic_cast(m); } app::ModuleWidget* mw = new TModuleWidget(tm); mw->model = this; return mw; } }; plugin::Model* o = new TModel; o->slug = slug; return o; } template TWidget* createWidget(math::Vec pos) { TWidget* o = new TWidget; o->box.pos = pos; return o; } template TWidget* createWidgetCentered(math::Vec pos) { TWidget* o = createWidget(pos); o->box.pos = o->box.pos.minus(o->box.size.div(2)); return o; } inline app::SvgPanel* createPanel(std::string svgPath) { app::SvgPanel* panel = new app::SvgPanel; std::shared_ptr svg = APP->window->loadSvg(svgPath); panel->setBackground(svg); return panel; } template TParamWidget* createParam(math::Vec pos, engine::Module* module, int paramId) { TParamWidget* o = new TParamWidget; o->box.pos = pos; o->app::ParamWidget::module = module; o->app::ParamWidget::paramId = paramId; o->initParamQuantity(); return o; } template TParamWidget* createParamCentered(math::Vec pos, engine::Module* module, int paramId) { TParamWidget* o = createParam(pos, module, paramId); o->box.pos = o->box.pos.minus(o->box.size.div(2)); return o; } template TPortWidget* createInput(math::Vec pos, engine::Module* module, int inputId) { TPortWidget* o = new TPortWidget; o->box.pos = pos; o->app::PortWidget::module = module; o->app::PortWidget::type = engine::Port::INPUT; o->app::PortWidget::portId = inputId; return o; } template TPortWidget* createInputCentered(math::Vec pos, engine::Module* module, int inputId) { TPortWidget* o = createInput(pos, module, inputId); o->box.pos = o->box.pos.minus(o->box.size.div(2)); return o; } template TPortWidget* createOutput(math::Vec pos, engine::Module* module, int outputId) { TPortWidget* o = new TPortWidget; o->box.pos = pos; o->app::PortWidget::module = module; o->app::PortWidget::type = engine::Port::OUTPUT; o->app::PortWidget::portId = outputId; return o; } template TPortWidget* createOutputCentered(math::Vec pos, engine::Module* module, int outputId) { TPortWidget* o = createOutput(pos, module, outputId); o->box.pos = o->box.pos.minus(o->box.size.div(2)); return o; } template TModuleLightWidget* createLight(math::Vec pos, engine::Module* module, int firstLightId) { TModuleLightWidget* o = new TModuleLightWidget; o->box.pos = pos; o->app::ModuleLightWidget::module = module; o->app::ModuleLightWidget::firstLightId = firstLightId; return o; } template TModuleLightWidget* createLightCentered(math::Vec pos, engine::Module* module, int firstLightId) { TModuleLightWidget* o = createLight(pos, module, firstLightId); o->box.pos = o->box.pos.minus(o->box.size.div(2)); return o; } /** Creates a param with a light and calls setFirstLightId() on it. */ template TParamWidget* createLightParam(math::Vec pos, engine::Module* module, int paramId, int firstLightId) { TParamWidget* o = createParam(pos, module, paramId); o->setFirstLightId(firstLightId); return o; } template TParamWidget* createLightParamCentered(math::Vec pos, engine::Module* module, int paramId, int firstLightId) { TParamWidget* o = createLightParam(pos, module, paramId, firstLightId); o->box.pos = o->box.pos.minus(o->box.size.div(2)); return o; } template TMenuLabel * createMenuLabel(std::string text) { TMenuLabel* o = new TMenuLabel; o->text = text; return o; } template TMenuItem * createMenuItem(std::string text, std::string rightText = "") { TMenuItem* o = new TMenuItem; o->text = text; o->rightText = rightText; return o; } template TMenu * createMenu() { TMenu* o = new TMenu; o->box.pos = APP->scene->mousePos; ui::MenuOverlay* menuOverlay = new ui::MenuOverlay; menuOverlay->addChild(o); APP->scene->addChild(menuOverlay); return o; } } // namespace rack