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.

ParamQuantity.hpp 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #pragma once
  2. #include <vector>
  3. #include <jansson.h>
  4. #include <Quantity.hpp>
  5. #include <engine/Param.hpp>
  6. namespace rack {
  7. namespace engine {
  8. struct Module;
  9. /** A Quantity that wraps an engine::Param.
  10. If `smoothEnabled` is true, all methods access/modify the Param's target value of the Engine's per-sample smoothing algorithm instead of the immediate value.
  11. */
  12. struct ParamQuantity : Quantity {
  13. Module* module = NULL;
  14. int paramId = -1;
  15. /** The minimum allowed value. */
  16. float minValue = 0.f;
  17. /** The maximum allowed value. Must be greater than minValue. */
  18. float maxValue = 1.f;
  19. /** The initial value. */
  20. float defaultValue = 0.f;
  21. /** The name of the parameter, using sentence capitalization.
  22. e.g. "Frequency", "Pulse width", "Alternative mode"
  23. */
  24. std::string name;
  25. /** The numerical unit of measurement appended to the value.
  26. Unit words and abbreviations should have a space to separate the numerical value from the number (e.g. " semitones", " V", " ms").
  27. Unit symbols should have no space (e.g. "%", "ยบ").
  28. */
  29. std::string unit;
  30. /** Set to 0 for linear, positive for exponential, negative for logarithmic.
  31. The formula is \f$displayValue = f(value) * displayMultiplier + displayOffset\f$ where \f$f(value)\f$ is
  32. - \f$value\f$ for \f$displayBase = 0\f$.
  33. - \f$\log_{-displayBase}(value)\f$ for \f$displayBase < 0\f$.
  34. - \f$displayBase^{value}\f$ for \f$displayBase > 0\f$.
  35. */
  36. float displayBase = 0.f;
  37. float displayMultiplier = 1.f;
  38. float displayOffset = 0.f;
  39. /** Number of digits of precision to display.
  40. With displayPrecision = 5 for example, numbers will print as 12.345, 0.12345, 1.2345e6, or 1.2345e-6.
  41. */
  42. int displayPrecision = 5;
  43. /** An optional one-sentence description of the parameter. */
  44. std::string description;
  45. /** Enables parameter resetting when the module or parameter itself is reset.
  46. */
  47. bool resetEnabled = true;
  48. /** Enables parameter randomization when the module is randomized.
  49. Unbounded (infinite) parameters are not randomizable, regardless of this setting.
  50. */
  51. bool randomizeEnabled = true;
  52. /** Enables per-sample Engine parameter smoothing when setSmoothValue() is called. */
  53. bool smoothEnabled = false;
  54. /** Rounds values to the nearest integer. */
  55. bool snapEnabled = false;
  56. Param* getParam();
  57. /** Sets the target value of the Engine's smoothing algorithm, or immediate value if smoothing is disabled.
  58. Before Rack 2.3.0, this always set the Param's immediate value.
  59. For this behavior, use `setImmediateValue()` instead.
  60. */
  61. void setValue(float value) override;
  62. /** Gets the Param's smoothing target value, or immediate value if smoothing is disabled.
  63. Before Rack 2.3.0, this always got the Param's immediate value.
  64. For this behavior, use `getImmediateValue()` instead.
  65. */
  66. float getValue() override;
  67. /** Sets the Param's value immediately without smoothing.
  68. If the Param's value is currently being smoothed by the Engine, smoothing is canceled.
  69. */
  70. void setImmediateValue(float value);
  71. /** Gets the Param's value post-smoothing.
  72. If (and only if) the Param's value is currently being smoothed by the Engine, the return value is different than getValue().
  73. */
  74. float getImmediateValue();
  75. float getMinValue() override;
  76. float getMaxValue() override;
  77. float getDefaultValue() override;
  78. float getDisplayValue() override;
  79. /** Always sets immediate value. */
  80. void setDisplayValue(float displayValue) override;
  81. std::string getDisplayValueString() override;
  82. /** Always sets immediate value. */
  83. void setDisplayValueString(std::string s) override;
  84. int getDisplayPrecision() override;
  85. std::string getLabel() override;
  86. std::string getUnit() override;
  87. void reset() override;
  88. void randomize() override;
  89. virtual std::string getDescription();
  90. virtual json_t* toJson();
  91. virtual void fromJson(json_t* rootJ);
  92. /** Deprecated. Use setValue() instead, which is identical since Rack 2.3.0. */
  93. DEPRECATED void setSmoothValue(float value);
  94. /** Deprecated. Use getValue() instead, which is identical since Rack 2.3.0. */
  95. DEPRECATED float getSmoothValue();
  96. };
  97. struct SwitchQuantity : ParamQuantity {
  98. std::vector<std::string> labels;
  99. std::string getDisplayValueString() override;
  100. void setDisplayValueString(std::string s) override;
  101. };
  102. } // namespace engine
  103. } // namespace rack