You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.3KB

  1. #include "plugin.hpp"
  2. #include "engine.hpp"
  3. #include "app.hpp"
  4. namespace rack {
  5. template <class TModule, class TModuleWidget, typename... Tags>
  6. Model *createModel(std::string author, std::string slug, std::string name, Tags... tags) {
  7. struct TModel : Model {
  8. Module *createModule() override {
  9. TModule *module = new TModule();
  10. return module;
  11. }
  12. ModuleWidget *createModuleWidget() override {
  13. TModule *module = new TModule();
  14. TModuleWidget *moduleWidget = new TModuleWidget(module);
  15. moduleWidget->model = this;
  16. return moduleWidget;
  17. }
  18. ModuleWidget *createModuleWidgetNull() override {
  19. TModuleWidget *moduleWidget = new TModuleWidget(NULL);
  20. moduleWidget->model = this;
  21. return moduleWidget;
  22. }
  23. };
  24. Model *model = new TModel();
  25. model->author = author;
  26. model->slug = slug;
  27. model->name = name;
  28. model->tags = {tags...};
  29. return model;
  30. }
  31. template <class TWidget>
  32. TWidget *createWidget(math::Vec pos) {
  33. TWidget *w = new TWidget();
  34. w->box.pos = pos;
  35. return w;
  36. }
  37. template <class TParamWidget>
  38. TParamWidget *createParam(math::Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) {
  39. TParamWidget *param = new TParamWidget();
  40. param->box.pos = pos;
  41. param->module = module;
  42. param->paramId = paramId;
  43. param->setLimits(minValue, maxValue);
  44. param->setDefaultValue(defaultValue);
  45. return param;
  46. }
  47. template <class TParamWidget>
  48. TParamWidget *createParamCentered(math::Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) {
  49. TParamWidget *param = new TParamWidget();
  50. param->box.pos = pos.minus(param->box.size.div(2));
  51. param->module = module;
  52. param->paramId = paramId;
  53. param->setLimits(minValue, maxValue);
  54. param->setDefaultValue(defaultValue);
  55. return param;
  56. }
  57. template <class TPort>
  58. TPort *createInput(math::Vec pos, Module *module, int inputId) {
  59. TPort *port = new TPort();
  60. port->box.pos = pos;
  61. port->module = module;
  62. port->type = Port::INPUT;
  63. port->portId = inputId;
  64. return port;
  65. }
  66. template <class TPort>
  67. TPort *createInputCentered(math::Vec pos, Module *module, int inputId) {
  68. TPort *port = new TPort();
  69. port->box.pos = pos.minus(port->box.size.div(2));
  70. port->module = module;
  71. port->type = Port::INPUT;
  72. port->portId = inputId;
  73. return port;
  74. }
  75. template <class TPort>
  76. TPort *createOutput(math::Vec pos, Module *module, int outputId) {
  77. TPort *port = new TPort();
  78. port->box.pos = pos;
  79. port->module = module;
  80. port->type = Port::OUTPUT;
  81. port->portId = outputId;
  82. return port;
  83. }
  84. template <class TPort>
  85. TPort *createOutputCentered(math::Vec pos, Module *module, int outputId) {
  86. TPort *port = new TPort();
  87. port->box.pos = pos.minus(port->box.size.div(2));
  88. port->module = module;
  89. port->type = Port::OUTPUT;
  90. port->portId = outputId;
  91. return port;
  92. }
  93. template <class TModuleLightWidget>
  94. TModuleLightWidget *createLight(math::Vec pos, Module *module, int firstLightId) {
  95. TModuleLightWidget *light = new TModuleLightWidget();
  96. light->box.pos = pos;
  97. light->module = module;
  98. light->firstLightId = firstLightId;
  99. return light;
  100. }
  101. template <class TModuleLightWidget>
  102. TModuleLightWidget *createLightCentered(math::Vec pos, Module *module, int firstLightId) {
  103. TModuleLightWidget *light = new TModuleLightWidget();
  104. light->box.pos = pos.minus(light->box.size.div(2));
  105. light->module = module;
  106. light->firstLightId = firstLightId;
  107. return light;
  108. }
  109. } // namespace rack