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.

88 lines
1.9KB

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