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.

159 lines
7.0KB

  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. /** Properties of an AudioParameterFloat.
  21. @see AudioParameterFloat(), RangedAudioParameterAttributes()
  22. */
  23. class AudioParameterFloatAttributes : public RangedAudioParameterAttributes<AudioParameterFloatAttributes, float> {};
  24. //==============================================================================
  25. /**
  26. A subclass of AudioProcessorParameter that provides an easy way to create a
  27. parameter which maps onto a given NormalisableRange.
  28. @see AudioParameterInt, AudioParameterBool, AudioParameterChoice
  29. @tags{Audio}
  30. */
  31. class JUCE_API AudioParameterFloat : public RangedAudioParameter
  32. {
  33. public:
  34. /** Creates a AudioParameterFloat with the specified parameters.
  35. Note that the attributes argument is optional and only needs to be
  36. supplied if you want to change options from their default values.
  37. Example usage:
  38. @code
  39. auto attributes = AudioParameterFloatAttributes().withStringFromValueFunction ([] (auto x, auto) { return String (x * 100); })
  40. .withLabel ("%");
  41. auto param = std::make_unique<AudioParameterFloat> ("paramID", "Parameter Name", NormalisableRange<float>(), 0.5f, attributes);
  42. @endcode
  43. @param parameterID The parameter ID to use
  44. @param parameterName The parameter name to use
  45. @param normalisableRange The NormalisableRange to use
  46. @param defaultValue The non-normalised default value
  47. @param attributes Optional characteristics
  48. */
  49. AudioParameterFloat (const ParameterID& parameterID,
  50. const String& parameterName,
  51. NormalisableRange<float> normalisableRange,
  52. float defaultValue,
  53. const AudioParameterFloatAttributes& attributes = {});
  54. /** Creates a AudioParameterFloat with the specified parameters.
  55. @param parameterID The parameter ID to use
  56. @param parameterName The parameter name to use
  57. @param normalisableRange The NormalisableRange to use
  58. @param defaultValue The non-normalised default value
  59. @param parameterLabel An optional label for the parameter's value
  60. @param parameterCategory An optional parameter category
  61. @param stringFromValue An optional lambda function that converts a non-normalised
  62. value to a string with a maximum length. This may
  63. be used by hosts to display the parameter's value.
  64. @param valueFromString An optional lambda function that parses a string and
  65. converts it into a non-normalised value. Some hosts use
  66. this to allow users to type in parameter values.
  67. */
  68. [[deprecated ("Prefer the signature taking an Attributes argument")]]
  69. AudioParameterFloat (const ParameterID& parameterID,
  70. const String& parameterName,
  71. NormalisableRange<float> normalisableRange,
  72. float defaultValue,
  73. const String& parameterLabel,
  74. Category parameterCategory = AudioProcessorParameter::genericParameter,
  75. std::function<String (float value, int maximumStringLength)> stringFromValue = nullptr,
  76. std::function<float (const String& text)> valueFromString = nullptr)
  77. : AudioParameterFloat (parameterID,
  78. parameterName,
  79. std::move (normalisableRange),
  80. defaultValue,
  81. AudioParameterFloatAttributes().withLabel (parameterLabel)
  82. .withCategory (parameterCategory)
  83. .withStringFromValueFunction (std::move (stringFromValue))
  84. .withValueFromStringFunction (std::move (valueFromString)))
  85. {
  86. }
  87. /** Creates a AudioParameterFloat with an ID, name, and range.
  88. On creation, its value is set to the default value.
  89. For control over skew factors, you can use the other
  90. constructor and provide a NormalisableRange.
  91. */
  92. AudioParameterFloat (const ParameterID& parameterID,
  93. const String& parameterName,
  94. float minValue,
  95. float maxValue,
  96. float defaultValue);
  97. /** Destructor. */
  98. ~AudioParameterFloat() override;
  99. /** Returns the parameter's current value. */
  100. float get() const noexcept { return value; }
  101. /** Returns the parameter's current value. */
  102. operator float() const noexcept { return value; }
  103. /** Changes the parameter's current value. */
  104. AudioParameterFloat& operator= (float newValue);
  105. /** Returns the range of values that the parameter can take. */
  106. const NormalisableRange<float>& getNormalisableRange() const override { return range; }
  107. /** Provides access to the parameter's range. */
  108. NormalisableRange<float> range;
  109. protected:
  110. /** Override this method if you are interested in receiving callbacks
  111. when the parameter value changes.
  112. */
  113. virtual void valueChanged (float newValue);
  114. private:
  115. //==============================================================================
  116. float getValue() const override;
  117. void setValue (float newValue) override;
  118. float getDefaultValue() const override;
  119. int getNumSteps() const override;
  120. String getText (float, int) const override;
  121. float getValueForText (const String&) const override;
  122. std::atomic<float> value;
  123. const float valueDefault;
  124. std::function<String (float, int)> stringFromValueFunction;
  125. std::function<float (const String&)> valueFromStringFunction;
  126. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioParameterFloat)
  127. };
  128. } // namespace juce