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.

49 lines
1.1KB

  1. #pragma once
  2. #include "common.hpp"
  3. namespace rack {
  4. struct ParamQuantity;
  5. struct ParamQuantityFactory {
  6. virtual ~ParamQuantityFactory() {}
  7. virtual ParamQuantity *create() = 0;
  8. };
  9. struct ParamInfo {
  10. std::string label;
  11. std::string unit;
  12. /** Set to 0 for linear, nonzero for exponential */
  13. float displayBase = 0.f;
  14. float displayMultiplier = 1.f;
  15. std::string description;
  16. ParamQuantityFactory *paramQuantityFactory = NULL;
  17. ~ParamInfo() {
  18. if (paramQuantityFactory)
  19. delete paramQuantityFactory;
  20. }
  21. template<class TParamQuantity = ParamQuantity>
  22. void config(std::string label = "", std::string unit = "", float displayBase = 0.f, float displayMultiplier = 1.f) {
  23. this->label = label;
  24. this->unit = unit;
  25. this->displayBase = displayBase;
  26. this->displayMultiplier = displayMultiplier;
  27. struct TParamQuantityFactory : ParamQuantityFactory {
  28. ParamQuantity *create() override {return new TParamQuantity;}
  29. };
  30. if (paramQuantityFactory)
  31. delete paramQuantityFactory;
  32. paramQuantityFactory = new TParamQuantityFactory;
  33. }
  34. };
  35. } // namespace rack