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.

juce_AccessibilityValueInterface.h 7.5KB

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