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.

181 lines
7.5KB

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