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.

152 lines
6.8KB

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