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.

127 lines
4.0KB

  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 target value of the Engine's smoothing algorithm for a Param instead of the value directly.
  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. /** Deprecated. Use setValue() instead, which is identical since Rack 2.3.0. */
  58. DEPRECATED void setSmoothValue(float value);
  59. /** Deprecated. Use getValue() instead, which is identical since Rack 2.3.0. */
  60. DEPRECATED float getSmoothValue();
  61. /** Sets the Param value immediately without smoothing.
  62. If value is currently being smoothed by the engine, smoothing is canceled.
  63. */
  64. void setDirectValue(float value);
  65. /** Gets the Param value post-smoothing.
  66. If value is currently being smoothed by the engine, the return value is different than getValue().
  67. */
  68. float getDirectValue();
  69. /** Sets the Param's smoothing target value, or direct value if smoothing is disabled.
  70. Before Rack 2.3.0, this always set the Param's value directly.
  71. For this behavior, use `setDirectValue()` instead.
  72. */
  73. void setValue(float value) override;
  74. /** Gets the Param's smoothing target value, or direct value if smoothing is disabled.
  75. Before Rack 2.3.0, this always got the Param's value directly.
  76. For this behavior, use `getDirectValue()` instead.
  77. */
  78. float getValue() override;
  79. float getMinValue() override;
  80. float getMaxValue() override;
  81. float getDefaultValue() override;
  82. float getDisplayValue() override;
  83. void setDisplayValue(float displayValue) override;
  84. std::string getDisplayValueString() override;
  85. void setDisplayValueString(std::string s) override;
  86. int getDisplayPrecision() override;
  87. std::string getLabel() override;
  88. std::string getUnit() override;
  89. void reset() override;
  90. void randomize() override;
  91. virtual std::string getDescription();
  92. virtual json_t* toJson();
  93. virtual void fromJson(json_t* rootJ);
  94. };
  95. struct SwitchQuantity : ParamQuantity {
  96. std::vector<std::string> labels;
  97. std::string getDisplayValueString() override;
  98. void setDisplayValueString(std::string s) override;
  99. };
  100. } // namespace engine
  101. } // namespace rack