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.

96 lines
2.8KB

  1. #pragma once
  2. #include <vector>
  3. #include <Quantity.hpp>
  4. #include <engine/Param.hpp>
  5. namespace rack {
  6. namespace engine {
  7. struct Module;
  8. /** A Quantity that wraps an engine::Param. */
  9. struct ParamQuantity : Quantity {
  10. Module* module = NULL;
  11. int paramId;
  12. /** The minimum allowed value. */
  13. float minValue = 0.f;
  14. /** The maximum allowed value. Must be greater than minValue. */
  15. float maxValue = 1.f;
  16. /** The initial value. */
  17. float defaultValue = 0.f;
  18. /** The name of the parameter, using sentence capitalization.
  19. e.g. "Frequency", "Pulse width", "Alternative mode"
  20. */
  21. std::string name;
  22. /** The numerical unit of measurement appended to the value.
  23. Unit words and abbreviations should have a space to separate the numerical value from the number (e.g. " semitones", " V", " ms").
  24. Unit symbols should have no space (e.g. "%", "ยบ").
  25. */
  26. std::string unit;
  27. /** Set to 0 for linear, positive for exponential, negative for logarithmic.
  28. The formula is \f$displayValue = f(value) * displayMultiplier + displayOffset\f$ where \f$f(value)\f$ is
  29. - \f$value\f$ for \f$displayBase = 0\f$.
  30. - \f$\log_{-displayBase}(value)\f$ for \f$displayBase < 0\f$.
  31. - \f$displayBase^{value}\f$ for \f$displayBase > 0\f$.
  32. */
  33. float displayBase = 0.f;
  34. float displayMultiplier = 1.f;
  35. float displayOffset = 0.f;
  36. /** Number of digits of precision to display.
  37. With displayPrecision = 5 for example, numbers will print as 12.345, 0.12345, 1.2345e6, or 1.2345e-6.
  38. */
  39. int displayPrecision = 5;
  40. /** An optional one-sentence description of the parameter. */
  41. std::string description;
  42. /** Enables parameter resetting when the module or parameter itself is reset.
  43. */
  44. bool resetEnabled = true;
  45. /** Enables parameter randomization when the module is randomized.
  46. Unbounded (infinite) parameters are not randomizable, regardless of this setting.
  47. */
  48. bool randomizeEnabled = true;
  49. /** Rounds values to the nearest integer. */
  50. bool snapEnabled = false;
  51. Param* getParam();
  52. /** Request to the engine to smoothly set the value */
  53. void setSmoothValue(float smoothValue);
  54. float getSmoothValue();
  55. void setValue(float value) override;
  56. float getValue() override;
  57. float getMinValue() override;
  58. float getMaxValue() override;
  59. float getDefaultValue() override;
  60. float getDisplayValue() override;
  61. void setDisplayValue(float displayValue) override;
  62. std::string getDisplayValueString() override;
  63. void setDisplayValueString(std::string s) override;
  64. int getDisplayPrecision() override;
  65. std::string getLabel() override;
  66. std::string getUnit() override;
  67. void reset() override;
  68. void randomize() override;
  69. virtual std::string getDescription();
  70. };
  71. struct SwitchQuantity : ParamQuantity {
  72. std::vector<std::string> labels;
  73. std::string getDisplayValueString() override;
  74. void setDisplayValueString(std::string s) override;
  75. };
  76. } // namespace engine
  77. } // namespace rack