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.

154 lines
3.6KB

  1. #include "plugin.hpp"
  2. #include "engine.hpp"
  3. #include "app.hpp"
  4. #include "event.hpp"
  5. namespace rack {
  6. template <class TModule, class TModuleWidget, typename... Tags>
  7. Model *createModel(std::string author, std::string slug, std::string name, Tags... tags) {
  8. struct TModel : Model {
  9. Module *createModule() override {
  10. TModule *o = new TModule;
  11. return o;
  12. }
  13. ModuleWidget *createModuleWidget() override {
  14. TModule *module = new TModule;
  15. TModuleWidget *o = new TModuleWidget(module);
  16. o->model = this;
  17. return o;
  18. }
  19. ModuleWidget *createModuleWidgetNull() override {
  20. TModuleWidget *o = new TModuleWidget(NULL);
  21. o->model = this;
  22. return o;
  23. }
  24. };
  25. Model *o = new TModel;
  26. o->author = author;
  27. o->slug = slug;
  28. o->name = name;
  29. o->tags = {tags...};
  30. return o;
  31. }
  32. template <class TWidget>
  33. TWidget *createWidget(Vec pos) {
  34. TWidget *o = new TWidget;
  35. o->box.pos = pos;
  36. return o;
  37. }
  38. template <class TParamWidget>
  39. TParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) {
  40. TParamWidget *o = new TParamWidget;
  41. o->box.pos = pos;
  42. o->quantity->module = module;
  43. o->quantity->paramId = paramId;
  44. o->setLimits(minValue, maxValue);
  45. o->setDefaultValue(defaultValue);
  46. return o;
  47. }
  48. template <class TParamWidget>
  49. TParamWidget *createParamCentered(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) {
  50. TParamWidget *o = new TParamWidget;
  51. o->box.pos = pos.minus(o->box.size.div(2));
  52. o->quantity->module = module;
  53. o->quantity->paramId = paramId;
  54. o->setLimits(minValue, maxValue);
  55. o->setDefaultValue(defaultValue);
  56. return o;
  57. }
  58. template <class TPort>
  59. TPort *createInput(Vec pos, Module *module, int inputId) {
  60. TPort *o = new TPort;
  61. o->box.pos = pos;
  62. o->module = module;
  63. o->type = Port::INPUT;
  64. o->portId = inputId;
  65. return o;
  66. }
  67. template <class TPort>
  68. TPort *createInputCentered(Vec pos, Module *module, int inputId) {
  69. TPort *o = new TPort;
  70. o->box.pos = pos.minus(o->box.size.div(2));
  71. o->module = module;
  72. o->type = Port::INPUT;
  73. o->portId = inputId;
  74. return o;
  75. }
  76. template <class TPort>
  77. TPort *createOutput(Vec pos, Module *module, int outputId) {
  78. TPort *o = new TPort;
  79. o->box.pos = pos;
  80. o->module = module;
  81. o->type = Port::OUTPUT;
  82. o->portId = outputId;
  83. return o;
  84. }
  85. template <class TPort>
  86. TPort *createOutputCentered(Vec pos, Module *module, int outputId) {
  87. TPort *o = new TPort;
  88. o->box.pos = pos.minus(o->box.size.div(2));
  89. o->module = module;
  90. o->type = Port::OUTPUT;
  91. o->portId = outputId;
  92. return o;
  93. }
  94. template <class TModuleLightWidget>
  95. TModuleLightWidget *createLight(Vec pos, Module *module, int firstLightId) {
  96. TModuleLightWidget *o = new TModuleLightWidget;
  97. o->box.pos = pos;
  98. o->module = module;
  99. o->firstLightId = firstLightId;
  100. return o;
  101. }
  102. template <class TModuleLightWidget>
  103. TModuleLightWidget *createLightCentered(Vec pos, Module *module, int firstLightId) {
  104. TModuleLightWidget *o = new TModuleLightWidget;
  105. o->box.pos = pos.minus(o->box.size.div(2));
  106. o->module = module;
  107. o->firstLightId = firstLightId;
  108. return o;
  109. }
  110. template <class TMenuLabel = MenuLabel>
  111. TMenuLabel *createMenuLabel(std::string text) {
  112. TMenuLabel *o = new TMenuLabel;
  113. o->text = text;
  114. return o;
  115. }
  116. template <class TMenuItem = MenuItem>
  117. TMenuItem *createMenuItem(std::string text, std::string rightText = "") {
  118. TMenuItem *o = new TMenuItem;
  119. o->text = text;
  120. o->rightText = rightText;
  121. return o;
  122. }
  123. // TODO Reevaluate this. Does it belong here?
  124. inline Menu *createMenu() {
  125. Menu *o = new Menu;
  126. o->box.pos = gMousePos;
  127. MenuOverlay *menuOverlay = new MenuOverlay;
  128. menuOverlay->addChild(o);
  129. event::gContext->rootWidget->addChild(menuOverlay);
  130. return o;
  131. }
  132. } // namespace rack