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.

88 lines
2.4KB

  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. float displayBase = 0.f;
  29. float displayMultiplier = 1.f;
  30. float displayOffset = 0.f;
  31. int displayPrecision = 5;
  32. /** An optional one-sentence description of the parameter. */
  33. std::string description;
  34. /** Enables parameter resetting when the module or parameter itself is reset.
  35. */
  36. bool resetEnabled = true;
  37. /** Enables parameter randomization when the module is randomized.
  38. Unbounded (infinite) parameters are not randomizable, regardless of this setting.
  39. */
  40. bool randomizeEnabled = true;
  41. /** Rounds values to the nearest integer. */
  42. bool snapEnabled = false;
  43. Param* getParam();
  44. /** Request to the engine to smoothly set the value */
  45. void setSmoothValue(float smoothValue);
  46. float getSmoothValue();
  47. void setValue(float value) override;
  48. float getValue() override;
  49. float getMinValue() override;
  50. float getMaxValue() override;
  51. float getDefaultValue() override;
  52. float getDisplayValue() override;
  53. void setDisplayValue(float displayValue) override;
  54. std::string getDisplayValueString() override;
  55. void setDisplayValueString(std::string s) override;
  56. int getDisplayPrecision() override;
  57. std::string getLabel() override;
  58. std::string getUnit() override;
  59. virtual std::string getDescription();
  60. };
  61. struct SwitchQuantity : ParamQuantity {
  62. std::vector<std::string> labels;
  63. void setLabels(const std::vector<std::string>& labels) {
  64. this->labels = labels;
  65. }
  66. std::string getDisplayValueString() override;
  67. void setDisplayValueString(std::string s) override;
  68. };
  69. } // namespace engine
  70. } // namespace rack