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.

rack.hpp 1.9KB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "asset.hpp"
  10. namespace rack {
  11. ////////////////////
  12. // helpers
  13. ////////////////////
  14. template <class TModuleWidget>
  15. Model *createModel(std::string manufacturerSlug, std::string manufacturerName, std::string slug, std::string name) {
  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->slug = slug;
  25. model->name = name;
  26. model->manufacturerSlug = manufacturerSlug;
  27. model->manufacturerName = manufacturerName;
  28. return model;
  29. }
  30. template <class TParam>
  31. ParamWidget *createParam(Vec pos, Module *module, int paramId, float minValue, float maxValue, float defaultValue) {
  32. ParamWidget *param = new TParam();
  33. param->box.pos = pos;
  34. param->module = module;
  35. param->paramId = paramId;
  36. param->setLimits(minValue, maxValue);
  37. param->setDefaultValue(defaultValue);
  38. return param;
  39. }
  40. template <class TPort>
  41. Port *createInput(Vec pos, Module *module, int inputId) {
  42. Port *port = new TPort();
  43. port->box.pos = pos;
  44. port->module = module;
  45. port->type = Port::INPUT;
  46. port->portId = inputId;
  47. return port;
  48. }
  49. template <class TPort>
  50. Port *createOutput(Vec pos, Module *module, int outputId) {
  51. Port *port = new TPort();
  52. port->box.pos = pos;
  53. port->module = module;
  54. port->type = Port::OUTPUT;
  55. port->portId = outputId;
  56. return port;
  57. }
  58. template <class TScrew>
  59. Widget *createScrew(Vec pos) {
  60. Widget *screw = new TScrew();
  61. screw->box.pos = pos;
  62. return screw;
  63. }
  64. template <class TLight>
  65. ValueLight *createValueLight(Vec pos, float *value) {
  66. ValueLight *light = new TLight();
  67. light->box.pos = pos;
  68. light->value = value;
  69. return light;
  70. }
  71. } // namespace rack