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.

66 lines
1.4KB

  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. this->label = label;
  33. this->unit = unit;
  34. this->displayBase = displayBase;
  35. this->displayMultiplier = displayMultiplier;
  36. struct TParamQuantityFactory : ParamQuantityFactory {
  37. ParamQuantity *create() override {return new TParamQuantity;}
  38. };
  39. if (paramQuantityFactory)
  40. delete paramQuantityFactory;
  41. paramQuantityFactory = new TParamQuantityFactory;
  42. }
  43. bool isBounded();
  44. json_t *toJson();
  45. void fromJson(json_t *rootJ);
  46. void reset();
  47. void randomize();
  48. };
  49. } // namespace rack