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.

92 lines
2.4KB

  1. #pragma once
  2. // Include headers that plugins will likely use, for convenience
  3. #include "util/common.hpp"
  4. #include "asset.hpp"
  5. #include "plugin.hpp"
  6. #include "engine.hpp"
  7. #include "widgets.hpp"
  8. #include "app.hpp"
  9. #include "ui.hpp"
  10. #include "componentlibrary.hpp"
  11. namespace rack {
  12. ////////////////////
  13. // helpers
  14. ////////////////////
  15. template <class TModuleWidget, typename... Tags>
  16. Model *createModel(std::string manufacturer, std::string slug, std::string name, Tags... tags) {
  17. struct TModel : Model {
  18. ModuleWidget *createModuleWidget() override {
  19. ModuleWidget *moduleWidget = new TModuleWidget();
  20. moduleWidget->model = this;
  21. return moduleWidget;
  22. }
  23. };
  24. Model *model = new TModel();
  25. model->manufacturer = manufacturer;
  26. model->slug = slug;
  27. model->name = name;
  28. model->tags = {tags...};
  29. return model;
  30. }
  31. /** Deprecated, use Widget::create<TScrew>() instead */
  32. template <class TScrew>
  33. DEPRECATED TScrew *createScrew(Vec pos) {
  34. TScrew *screw = new TScrew();
  35. screw->box.pos = pos;
  36. return screw;
  37. }
  38. /** Deprecated, use ParamWidget::create<TParamWidget>() instead */
  39. template <class TParamWidget>
  40. DEPRECATED TParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) {
  41. TParamWidget *param = new TParamWidget();
  42. param->box.pos = pos;
  43. param->module = module;
  44. param->paramId = paramId;
  45. param->setLimits(minValue, maxValue);
  46. param->setDefaultValue(defaultValue);
  47. return param;
  48. }
  49. /** Deprecated, use Port::create<TPort>(..., Port::INPUT, ...) instead */
  50. template <class TPort>
  51. DEPRECATED TPort *createInput(Vec pos, Module *module, int inputId) {
  52. TPort *port = new TPort();
  53. port->box.pos = pos;
  54. port->module = module;
  55. port->type = Port::INPUT;
  56. port->portId = inputId;
  57. return port;
  58. }
  59. /** Deprecated, use Port::create<TPort>(..., Port::OUTPUT, ...) instead */
  60. template <class TPort>
  61. DEPRECATED TPort *createOutput(Vec pos, Module *module, int outputId) {
  62. TPort *port = new TPort();
  63. port->box.pos = pos;
  64. port->module = module;
  65. port->type = Port::OUTPUT;
  66. port->portId = outputId;
  67. return port;
  68. }
  69. /** Deprecated, use ModuleLightWidget::create<TModuleLightWidget>() instead */
  70. template<class TModuleLightWidget>
  71. DEPRECATED TModuleLightWidget *createLight(Vec pos, Module *module, int firstLightId) {
  72. TModuleLightWidget *light = new TModuleLightWidget();
  73. light->box.pos = pos;
  74. light->module = module;
  75. light->firstLightId = firstLightId;
  76. return light;
  77. }
  78. } // namespace rack