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.

helpers.hpp 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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(Vec pos) {
  33. TWidget *w = new TWidget();
  34. w->box.pos = pos;
  35. return w;
  36. }
  37. /** Deprecated. Use createWidget<TScrew>() instead */
  38. template <class TScrew>
  39. DEPRECATED TScrew *createScrew(Vec pos) {
  40. return createWidget<TScrew>(pos);
  41. }
  42. template <class TParamWidget>
  43. TParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) {
  44. TParamWidget *param = new TParamWidget();
  45. param->box.pos = pos;
  46. param->module = module;
  47. param->paramId = paramId;
  48. param->setLimits(minValue, maxValue);
  49. param->setDefaultValue(defaultValue);
  50. return param;
  51. }
  52. template <class TParamWidget>
  53. TParamWidget *createParamCentered(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) {
  54. TParamWidget *param = new TParamWidget();
  55. param->box.pos = pos.minus(param->box.size.div(2));
  56. param->module = module;
  57. param->paramId = paramId;
  58. param->setLimits(minValue, maxValue);
  59. param->setDefaultValue(defaultValue);
  60. return param;
  61. }
  62. template <class TPort>
  63. TPort *createInput(Vec pos, Module *module, int inputId) {
  64. TPort *port = new TPort();
  65. port->box.pos = pos;
  66. port->module = module;
  67. port->type = Port::INPUT;
  68. port->portId = inputId;
  69. return port;
  70. }
  71. template <class TPort>
  72. TPort *createInputCentered(Vec pos, Module *module, int inputId) {
  73. TPort *port = new TPort();
  74. port->box.pos = pos.minus(port->box.size.div(2));
  75. port->module = module;
  76. port->type = Port::INPUT;
  77. port->portId = inputId;
  78. return port;
  79. }
  80. template <class TPort>
  81. TPort *createOutput(Vec pos, Module *module, int outputId) {
  82. TPort *port = new TPort();
  83. port->box.pos = pos;
  84. port->module = module;
  85. port->type = Port::OUTPUT;
  86. port->portId = outputId;
  87. return port;
  88. }
  89. template <class TPort>
  90. TPort *createOutputCentered(Vec pos, Module *module, int outputId) {
  91. TPort *port = new TPort();
  92. port->box.pos = pos.minus(port->box.size.div(2));
  93. port->module = module;
  94. port->type = Port::OUTPUT;
  95. port->portId = outputId;
  96. return port;
  97. }
  98. template <class TModuleLightWidget>
  99. TModuleLightWidget *createLight(Vec pos, Module *module, int firstLightId) {
  100. TModuleLightWidget *light = new TModuleLightWidget();
  101. light->box.pos = pos;
  102. light->module = module;
  103. light->firstLightId = firstLightId;
  104. return light;
  105. }
  106. template <class TModuleLightWidget>
  107. TModuleLightWidget *createLightCentered(Vec pos, Module *module, int firstLightId) {
  108. TModuleLightWidget *light = new TModuleLightWidget();
  109. light->box.pos = pos.minus(light->box.size.div(2));
  110. light->module = module;
  111. light->firstLightId = firstLightId;
  112. return light;
  113. }
  114. } // namespace rack