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.

juce_AudioParameterFloat.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-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. 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. @param parameterID The parameter ID to use
  31. @param parameterName The parameter name to use
  32. @param normalisableRange The NormalisableRange to use
  33. @param defaultValue The non-normalised default value
  34. @param parameterLabel An optional label for the parameter's value
  35. @param parameterCategory An optional parameter category
  36. @param stringFromValue An optional lambda function that converts a non-normalised
  37. value to a string with a maximum length. This may
  38. be used by hosts to display the parameter's value.
  39. @param valueFromString An optional lambda function that parses a string and
  40. converts it into a non-normalised value. Some hosts use
  41. this to allow users to type in parameter values.
  42. */
  43. AudioParameterFloat (const String& parameterID,
  44. const String& parameterName,
  45. NormalisableRange<float> normalisableRange,
  46. float defaultValue,
  47. const String& parameterLabel = String(),
  48. Category parameterCategory = AudioProcessorParameter::genericParameter,
  49. std::function<String (float value, int maximumStringLength)> stringFromValue = nullptr,
  50. std::function<float (const String& text)> valueFromString = nullptr);
  51. /** Creates a AudioParameterFloat with an ID, name, and range.
  52. On creation, its value is set to the default value.
  53. For control over skew factors, you can use the other
  54. constructor and provide a NormalisableRange.
  55. */
  56. AudioParameterFloat (String parameterID,
  57. String parameterName,
  58. float minValue,
  59. float maxValue,
  60. float defaultValue);
  61. /** Destructor. */
  62. ~AudioParameterFloat() override;
  63. /** Returns the parameter's current value. */
  64. float get() const noexcept { return value; }
  65. /** Returns the parameter's current value. */
  66. operator float() const noexcept { return value; }
  67. /** Changes the parameter's current value. */
  68. AudioParameterFloat& operator= (float newValue);
  69. /** Returns the range of values that the parameter can take. */
  70. const NormalisableRange<float>& getNormalisableRange() const override { return range; }
  71. /** Provides access to the parameter's range. */
  72. NormalisableRange<float> range;
  73. protected:
  74. /** Override this method if you are interested in receiving callbacks
  75. when the parameter value changes.
  76. */
  77. virtual void valueChanged (float newValue);
  78. private:
  79. //==============================================================================
  80. float getValue() const override;
  81. void setValue (float newValue) override;
  82. float getDefaultValue() const override;
  83. int getNumSteps() const override;
  84. String getText (float, int) const override;
  85. float getValueForText (const String&) const override;
  86. std::atomic<float> value;
  87. const float defaultValue;
  88. std::function<String (float, int)> stringFromValueFunction;
  89. std::function<float (const String&)> valueFromStringFunction;
  90. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioParameterFloat)
  91. };
  92. } // namespace juce