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.

192 lines
7.8KB

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