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.

90 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 "app.hpp"
  8. #include "componentlibrary.hpp"
  9. namespace rack {
  10. ////////////////////
  11. // helpers
  12. ////////////////////
  13. template <class TModuleWidget, typename... Tags>
  14. Model *createModel(std::string manufacturer, std::string slug, std::string name, Tags... tags) {
  15. struct TModel : Model {
  16. ModuleWidget *createModuleWidget() override {
  17. ModuleWidget *moduleWidget = new TModuleWidget();
  18. moduleWidget->model = this;
  19. return moduleWidget;
  20. }
  21. };
  22. Model *model = new TModel();
  23. model->manufacturer = manufacturer;
  24. model->slug = slug;
  25. model->name = name;
  26. model->tags = {tags...};
  27. return model;
  28. }
  29. /** Deprecated, use Widget::create<TScrew>() instead */
  30. template <class TScrew>
  31. DEPRECATED TScrew *createScrew(Vec pos) {
  32. TScrew *screw = new TScrew();
  33. screw->box.pos = pos;
  34. return screw;
  35. }
  36. /** Deprecated, use ParamWidget::create<TParamWidget>() instead */
  37. template <class TParamWidget>
  38. DEPRECATED TParamWidget *createParam(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. /** Deprecated, use Port::create<TPort>(..., Port::INPUT, ...) instead */
  48. template <class TPort>
  49. DEPRECATED TPort *createInput(Vec pos, Module *module, int inputId) {
  50. TPort *port = new TPort();
  51. port->box.pos = pos;
  52. port->module = module;
  53. port->type = Port::INPUT;
  54. port->portId = inputId;
  55. return port;
  56. }
  57. /** Deprecated, use Port::create<TPort>(..., Port::OUTPUT, ...) instead */
  58. template <class TPort>
  59. DEPRECATED TPort *createOutput(Vec pos, Module *module, int outputId) {
  60. TPort *port = new TPort();
  61. port->box.pos = pos;
  62. port->module = module;
  63. port->type = Port::OUTPUT;
  64. port->portId = outputId;
  65. return port;
  66. }
  67. /** Deprecated, use ModuleLightWidget::create<TModuleLightWidget>() instead */
  68. template<class TModuleLightWidget>
  69. DEPRECATED TModuleLightWidget *createLight(Vec pos, Module *module, int firstLightId) {
  70. TModuleLightWidget *light = new TModuleLightWidget();
  71. light->box.pos = pos;
  72. light->module = module;
  73. light->firstLightId = firstLightId;
  74. return light;
  75. }
  76. } // namespace rack