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.

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