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.

110 lines
4.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - 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 this technical preview, this file is not subject to commercial licensing.
  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. A subclass of AudioProcessorParameter that provides an easy way to create a
  17. parameter which maps onto a given NormalisableRange.
  18. @see AudioParameterInt, AudioParameterBool, AudioParameterChoice
  19. @tags{Audio}
  20. */
  21. class JUCE_API AudioParameterFloat : public RangedAudioParameter
  22. {
  23. public:
  24. /** Creates a AudioParameterFloat with the specified parameters.
  25. @param parameterID The parameter ID to use
  26. @param parameterName The parameter name to use
  27. @param normalisableRange The NormalisableRange to use
  28. @param defaultValue The non-normalised default value
  29. @param parameterLabel An optional label for the parameter's value
  30. @param parameterCategory An optional parameter category
  31. @param stringFromValue An optional lambda function that converts a non-normalised
  32. value to a string with a maximum length. This may
  33. be used by hosts to display the parameter's value.
  34. @param valueFromString An optional lambda function that parses a string and
  35. converts it into a non-normalised value. Some hosts use
  36. this to allow users to type in parameter values.
  37. */
  38. AudioParameterFloat (const String& parameterID,
  39. const String& parameterName,
  40. NormalisableRange<float> normalisableRange,
  41. float defaultValue,
  42. const String& parameterLabel = String(),
  43. Category parameterCategory = AudioProcessorParameter::genericParameter,
  44. std::function<String(float value, int maximumStringLength)> stringFromValue = nullptr,
  45. std::function<float(const String& text)> valueFromString = nullptr);
  46. /** Creates a AudioParameterFloat with an ID, name, and range.
  47. On creation, its value is set to the default value.
  48. For control over skew factors, you can use the other
  49. constructor and provide a NormalisableRange.
  50. */
  51. AudioParameterFloat (String parameterID,
  52. String parameterName,
  53. float minValue,
  54. float maxValue,
  55. float defaultValue);
  56. /** Destructor. */
  57. ~AudioParameterFloat() override;
  58. /** Returns the parameter's current value. */
  59. float get() const noexcept { return value; }
  60. /** Returns the parameter's current value. */
  61. operator float() const noexcept { return value; }
  62. /** Changes the parameter's current value. */
  63. AudioParameterFloat& operator= (float newValue);
  64. /** Returns the range of values that the parameter can take. */
  65. const NormalisableRange<float>& getNormalisableRange() const override { return range; }
  66. /** Provides access to the parameter's range. */
  67. NormalisableRange<float> range;
  68. protected:
  69. /** Override this method if you are interested in receiving callbacks
  70. when the parameter value changes.
  71. */
  72. virtual void valueChanged (float newValue);
  73. private:
  74. //==============================================================================
  75. float getValue() const override;
  76. void setValue (float newValue) override;
  77. float getDefaultValue() const override;
  78. int getNumSteps() const override;
  79. String getText (float, int) const override;
  80. float getValueForText (const String&) const override;
  81. std::atomic<float> value;
  82. const float defaultValue;
  83. std::function<String(float, int)> stringFromValueFunction;
  84. std::function<float(const String&)> valueFromStringFunction;
  85. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioParameterFloat)
  86. };
  87. } // namespace juce