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.

87 lines
1.9KB

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