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 3.0KB

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