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.

75 lines
1.5KB

  1. #pragma once
  2. #include "common.hpp"
  3. #include <jansson.h>
  4. namespace rack {
  5. struct ParamQuantity;
  6. struct ParamQuantityFactory {
  7. virtual ~ParamQuantityFactory() {}
  8. virtual ParamQuantity *create() = 0;
  9. };
  10. struct Param {
  11. float value = 0.f;
  12. float minValue = 0.f;
  13. float maxValue = 1.f;
  14. float defaultValue = 0.f;
  15. std::string label;
  16. std::string unit;
  17. /** Set to 0 for linear, nonzero for exponential */
  18. float displayBase = 0.f;
  19. float displayMultiplier = 1.f;
  20. std::string description;
  21. ParamQuantityFactory *paramQuantityFactory = NULL;
  22. ~Param() {
  23. if (paramQuantityFactory)
  24. delete paramQuantityFactory;
  25. }
  26. template<class TParamQuantity = ParamQuantity>
  27. void config(float minValue, float maxValue, float defaultValue, std::string label = "", std::string unit = "", float displayBase = 0.f, float displayMultiplier = 1.f) {
  28. this->value = defaultValue;
  29. this->minValue = minValue;
  30. this->maxValue = maxValue;
  31. this->defaultValue = defaultValue;
  32. if (!label.empty())
  33. this->label = label;
  34. this->unit = unit;
  35. this->displayBase = displayBase;
  36. this->displayMultiplier = displayMultiplier;
  37. struct TParamQuantityFactory : ParamQuantityFactory {
  38. ParamQuantity *create() override {return new TParamQuantity;}
  39. };
  40. if (paramQuantityFactory)
  41. delete paramQuantityFactory;
  42. paramQuantityFactory = new TParamQuantityFactory;
  43. }
  44. float getValue() {
  45. return value;
  46. }
  47. void setValue(float value) {
  48. this->value = value;
  49. }
  50. bool isBounded();
  51. json_t *toJson();
  52. void fromJson(json_t *rootJ);
  53. void reset();
  54. void randomize();
  55. };
  56. } // namespace rack