The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

188 lines
7.7KB

  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. /**
  21. Combines a parameter ID and a version hint.
  22. */
  23. class ParameterID
  24. {
  25. public:
  26. ParameterID() = default;
  27. /** Constructs an instance.
  28. Note that this constructor implicitly converts from Strings and string-like types.
  29. @param identifier A string that uniquely identifies a single parameter
  30. @param versionHint Influences parameter ordering in Audio Unit plugins.
  31. Used to provide backwards compatibility of Audio Unit plugins in
  32. Logic and GarageBand.
  33. @see AudioProcessorParameter(int)
  34. */
  35. template <typename StringLike, typename = DisableIfSameOrDerived<ParameterID, StringLike>>
  36. ParameterID (StringLike&& identifier, int versionHint = 0)
  37. : paramID (std::forward<StringLike> (identifier)), version (versionHint) {}
  38. /** @see AudioProcessorParameterWithID::paramID */
  39. auto getParamID() const { return paramID; }
  40. /** @see AudioProcessorParameter(int) */
  41. auto getVersionHint() const { return version; }
  42. private:
  43. String paramID;
  44. int version = 0;
  45. };
  46. /**
  47. An instance of this class may be passed to the constructor of an AudioProcessorParameterWithID
  48. to set optional characteristics of that parameter.
  49. */
  50. class AudioProcessorParameterWithIDAttributes
  51. {
  52. using This = AudioProcessorParameterWithIDAttributes;
  53. public:
  54. using Category = AudioProcessorParameter::Category;
  55. /** An optional label for the parameter's value */
  56. JUCE_NODISCARD auto withLabel (String x) const { return withMember (*this, &This::label, std::move (x)); }
  57. /** The semantics of this parameter */
  58. JUCE_NODISCARD auto withCategory (Category x) const { return withMember (*this, &This::category, std::move (x)); }
  59. /** @see AudioProcessorParameter::isMetaParameter() */
  60. JUCE_NODISCARD auto withMeta (bool x) const { return withMember (*this, &This::meta, std::move (x)); }
  61. /** @see AudioProcessorParameter::isAutomatable() */
  62. JUCE_NODISCARD auto withAutomatable (bool x) const { return withMember (*this, &This::automatable, std::move (x)); }
  63. /** @see AudioProcessorParameter::isOrientationInverted() */
  64. JUCE_NODISCARD auto withInverted (bool x) const { return withMember (*this, &This::inverted, std::move (x)); }
  65. /** An optional label for the parameter's value */
  66. JUCE_NODISCARD auto getLabel() const { return label; }
  67. /** The semantics of this parameter */
  68. JUCE_NODISCARD auto getCategory() const { return category; }
  69. /** @see AudioProcessorParameter::isMetaParameter() */
  70. JUCE_NODISCARD auto getMeta() const { return meta; }
  71. /** @see AudioProcessorParameter::isAutomatable() */
  72. JUCE_NODISCARD auto getAutomatable() const { return automatable; }
  73. /** @see AudioProcessorParameter::isOrientationInverted() */
  74. JUCE_NODISCARD auto getInverted() const { return inverted; }
  75. private:
  76. String label;
  77. Category category = AudioProcessorParameter::genericParameter;
  78. bool meta = false, automatable = true, inverted = false;
  79. };
  80. //==============================================================================
  81. /**
  82. This abstract base class is used by some AudioProcessorParameter helper classes.
  83. @see AudioParameterFloat, AudioParameterInt, AudioParameterBool, AudioParameterChoice
  84. @tags{Audio}
  85. */
  86. class JUCE_API AudioProcessorParameterWithID : public HostedAudioProcessorParameter
  87. {
  88. public:
  89. /** The creation of this object requires providing a name and ID which will be constant for its lifetime.
  90. Given that AudioProcessorParameterWithID is abstract, you'll probably call this constructor
  91. from a derived class constructor, e.g.
  92. @code
  93. MyParameterType (String paramID, String name, String label, bool automatable)
  94. : AudioProcessorParameterWithID (paramID, name, AudioProcessorParameterWithIDAttributes().withLabel (label)
  95. .withAutomatable (automatable))
  96. {
  97. }
  98. @endcode
  99. @param parameterID Specifies the identifier, and optionally the parameter's version hint.
  100. @param parameterName The user-facing parameter name.
  101. @param attributes Other parameter properties.
  102. */
  103. AudioProcessorParameterWithID (const ParameterID& parameterID,
  104. const String& parameterName,
  105. const AudioProcessorParameterWithIDAttributes& attributes = {});
  106. /** The creation of this object requires providing a name and ID which will be
  107. constant for its lifetime.
  108. @param parameterID Used to uniquely identify the parameter
  109. @param parameterName The user-facing name of the parameter
  110. @param parameterLabel An optional label for the parameter's value
  111. @param parameterCategory The semantics of this parameter
  112. */
  113. [[deprecated ("Prefer the signature taking an Attributes argument")]]
  114. AudioProcessorParameterWithID (const ParameterID& parameterID,
  115. const String& parameterName,
  116. const String& parameterLabel,
  117. Category parameterCategory = AudioProcessorParameter::genericParameter)
  118. : AudioProcessorParameterWithID (parameterID,
  119. parameterName,
  120. AudioProcessorParameterWithIDAttributes().withLabel (parameterLabel)
  121. .withCategory (parameterCategory))
  122. {
  123. }
  124. /** Provides access to the parameter's ID string. */
  125. const String paramID;
  126. /** Provides access to the parameter's name. */
  127. const String name;
  128. /** Provides access to the parameter's label. */
  129. const String label;
  130. /** Provides access to the parameter's category. */
  131. const Category category;
  132. String getName (int) const override;
  133. String getLabel() const override;
  134. Category getCategory() const override;
  135. String getParameterID() const override { return paramID; }
  136. bool isMetaParameter() const override { return meta; }
  137. bool isAutomatable() const override { return automatable; }
  138. bool isOrientationInverted() const override { return inverted; }
  139. private:
  140. bool meta = false, automatable = true, inverted = false;
  141. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioProcessorParameterWithID)
  142. };
  143. } // namespace juce