Audio plugin host https://kx.studio/carla
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.

216 lines
7.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For the technical preview this file cannot be licensed commercially.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. /** An abstract interface representing the value of an accessibility element.
  16. Values should be used when information needs to be conveyed which cannot
  17. be represented by the accessibility element's label alone. For example, a
  18. gain slider with the label "Gain" needs to also provide a value for its
  19. position whereas a "Save" button does not.
  20. This class allows for full control over the value text/numeric conversion,
  21. ranged, and read-only properties but in most cases you'll want to use one
  22. of the derived classes below which handle some of this for you.
  23. @see AccessibilityTextValueInterface, AccessibilityNumericValueInterface,
  24. AccessibilityRangedNumericValueInterface
  25. @tags{Accessibility}
  26. */
  27. class JUCE_API AccessibilityValueInterface
  28. {
  29. public:
  30. /** Destructor. */
  31. virtual ~AccessibilityValueInterface() = default;
  32. /** Returns true if the value is read-only and cannot be modified by an
  33. accessibility client.
  34. @see setValue, setValueAsString
  35. */
  36. virtual bool isReadOnly() const = 0;
  37. /** Returns the current value as a double. */
  38. virtual double getCurrentValue() const = 0;
  39. /** Returns the current value as a String. */
  40. virtual String getCurrentValueAsString() const = 0;
  41. /** Sets the current value to a new double value. */
  42. virtual void setValue (double newValue) = 0;
  43. /** Sets the current value to a new String value. */
  44. virtual void setValueAsString (const String& newValue) = 0;
  45. /** Represents the range of this value, if supported.
  46. Return one of these from the `getRange()` method, providing a minimum,
  47. maximum, and interval value for the range to indicate that this is a
  48. ranged value.
  49. The default state is an "invalid" range, indicating that the accessibility
  50. element does not support ranged values.
  51. @see AccessibilityRangedNumericValueInterface
  52. @tags{Accessibility}
  53. */
  54. class JUCE_API AccessibleValueRange
  55. {
  56. public:
  57. /** Constructor.
  58. Creates a default, "invalid" range that can be returned from
  59. `AccessibilityValueInterface::getRange()` to indicate that the value
  60. interface does not support ranged values.
  61. */
  62. AccessibleValueRange() = default;
  63. /** The minimum and maximum values for this range, inclusive. */
  64. struct JUCE_API MinAndMax { double min, max; };
  65. /** Constructor.
  66. Creates a valid AccessibleValueRange with the provided minimum, maximum,
  67. and interval values.
  68. */
  69. AccessibleValueRange (MinAndMax valueRange, double interval)
  70. : valid (true),
  71. range (valueRange),
  72. stepSize (interval)
  73. {
  74. jassert (range.min < range.max);
  75. }
  76. /** Returns true if this represents a valid range. */
  77. bool isValid() const noexcept { return valid; }
  78. /** Returns the minimum value for this range. */
  79. double getMinimumValue() const noexcept { return range.min; }
  80. /** Returns the maximum value for this range. */
  81. double getMaximumValue() const noexcept { return range.max; }
  82. /** Returns the interval for this range. */
  83. double getInterval() const noexcept { return stepSize; }
  84. private:
  85. bool valid = false;
  86. MinAndMax range {};
  87. double stepSize = 0.0;
  88. };
  89. /** If this is a ranged value, this should return a valid AccessibleValueRange
  90. object representing the supported numerical range.
  91. */
  92. virtual AccessibleValueRange getRange() const = 0;
  93. };
  94. //==============================================================================
  95. /** A value interface that represents a text value.
  96. @tags{Accessibility}
  97. */
  98. class JUCE_API AccessibilityTextValueInterface : public AccessibilityValueInterface
  99. {
  100. public:
  101. /** Returns true if the value is read-only and cannot be modified by an
  102. accessibility client.
  103. @see setValueAsString
  104. */
  105. bool isReadOnly() const override = 0;
  106. /** Returns the current value. */
  107. String getCurrentValueAsString() const override = 0;
  108. /** Sets the current value to a new value. */
  109. void setValueAsString (const String& newValue) override = 0;
  110. /** @internal */
  111. double getCurrentValue() const final { return getCurrentValueAsString().getDoubleValue(); }
  112. /** @internal */
  113. void setValue (double newValue) final { setValueAsString (String (newValue)); }
  114. /** @internal */
  115. AccessibleValueRange getRange() const final { return {}; }
  116. };
  117. //==============================================================================
  118. /** A value interface that represents a non-ranged numeric value.
  119. @tags{Accessibility}
  120. */
  121. class JUCE_API AccessibilityNumericValueInterface : public AccessibilityValueInterface
  122. {
  123. public:
  124. /** Returns true if the value is read-only and cannot be modified by an
  125. accessibility client.
  126. @see setValue
  127. */
  128. bool isReadOnly() const override = 0;
  129. /** Returns the current value. */
  130. double getCurrentValue() const override = 0;
  131. /** Sets the current value to a new value. */
  132. void setValue (double newValue) override = 0;
  133. /** @internal */
  134. String getCurrentValueAsString() const final { return String (getCurrentValue()); }
  135. /** @internal */
  136. void setValueAsString (const String& newValue) final { setValue (newValue.getDoubleValue()); }
  137. /** @internal */
  138. AccessibleValueRange getRange() const final { return {}; }
  139. };
  140. //==============================================================================
  141. /** A value interface that represents a ranged numeric value.
  142. @tags{Accessibility}
  143. */
  144. class JUCE_API AccessibilityRangedNumericValueInterface : public AccessibilityValueInterface
  145. {
  146. public:
  147. /** Returns true if the value is read-only and cannot be modified by an
  148. accessibility client.
  149. @see setValueAsString
  150. */
  151. bool isReadOnly() const override = 0;
  152. /** Returns the current value. */
  153. double getCurrentValue() const override = 0;
  154. /** Sets the current value to a new value. */
  155. void setValue (double newValue) override = 0;
  156. /** Returns the range. */
  157. AccessibleValueRange getRange() const override = 0;
  158. /** @internal */
  159. String getCurrentValueAsString() const final { return String (getCurrentValue()); }
  160. /** @internal */
  161. void setValueAsString (const String& newValue) final { setValue (newValue.getDoubleValue()); }
  162. };
  163. } // namespace juce