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.

85 lines
2.0KB

  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. template <class TScrew>
  30. TScrew *createScrew(Vec pos) {
  31. TScrew *screw = new TScrew();
  32. screw->box.pos = pos;
  33. return screw;
  34. }
  35. template <class TParamWidget>
  36. TParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) {
  37. TParamWidget *param = new TParamWidget();
  38. param->box.pos = pos;
  39. param->module = module;
  40. param->paramId = paramId;
  41. param->setLimits(minValue, maxValue);
  42. param->setDefaultValue(defaultValue);
  43. return param;
  44. }
  45. template <class TPort>
  46. TPort *createInput(Vec pos, Module *module, int inputId) {
  47. TPort *port = new TPort();
  48. port->box.pos = pos;
  49. port->module = module;
  50. port->type = Port::INPUT;
  51. port->portId = inputId;
  52. return port;
  53. }
  54. template <class TPort>
  55. TPort *createOutput(Vec pos, Module *module, int outputId) {
  56. TPort *port = new TPort();
  57. port->box.pos = pos;
  58. port->module = module;
  59. port->type = Port::OUTPUT;
  60. port->portId = outputId;
  61. return port;
  62. }
  63. template<class TModuleLightWidget>
  64. TModuleLightWidget *createLight(Vec pos, Module *module, int firstLightId) {
  65. TModuleLightWidget *light = new TModuleLightWidget();
  66. light->box.pos = pos;
  67. light->module = module;
  68. light->firstLightId = firstLightId;
  69. return light;
  70. }
  71. } // namespace rack