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.

121 lines
3.7KB

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