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.

118 lines
4.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. /**
  22. A subclass of AudioProcessorParameter that provides an easy way to create a
  23. parameter which maps onto a given NormalisableRange.
  24. @see AudioParameterInt, AudioParameterBool, AudioParameterChoice
  25. @tags{Audio}
  26. */
  27. class JUCE_API AudioParameterFloat : public RangedAudioParameter
  28. {
  29. public:
  30. /** Creates a AudioParameterFloat with the specified parameters.
  31. @param parameterID The parameter ID to use
  32. @param name The parameter name to use
  33. @param normalisableRange The NormalisableRange to use
  34. @param defaultValue The non-normalised default value
  35. @param label An optional label for the parameter's value
  36. @param category An optional parameter category
  37. @param stringFromValue An optional lambda function that converts a non-normalised
  38. value to a string with a maximum length. This may
  39. be used by hosts to display the parameter's value.
  40. @param valueFromString An optional lambda function that parses a string and
  41. converts it into a non-normalised value. Some hosts use
  42. this to allow users to type in parameter values.
  43. */
  44. AudioParameterFloat (const String& parameterID,
  45. const String& name,
  46. NormalisableRange<float> normalisableRange,
  47. float defaultValue,
  48. const String& label = String(),
  49. Category category = AudioProcessorParameter::genericParameter,
  50. std::function<String (float value, int maximumStringLength)> stringFromValue = nullptr,
  51. std::function<float (const String& text)> valueFromString = nullptr);
  52. /** Creates a AudioParameterFloat with an ID, name, and range.
  53. On creation, its value is set to the default value.
  54. For control over skew factors, you can use the other
  55. constructor and provide a NormalisableRange.
  56. */
  57. AudioParameterFloat (String parameterID,
  58. String name,
  59. float minValue,
  60. float maxValue,
  61. float defaultValue);
  62. /** Destructor. */
  63. ~AudioParameterFloat() override;
  64. /** Returns the parameter's current value. */
  65. float get() const noexcept { return value; }
  66. /** Returns the parameter's current value. */
  67. operator float() const noexcept { return value; }
  68. /** Changes the parameter's current value. */
  69. AudioParameterFloat& operator= (float newValue);
  70. /** Returns the range of values that the parameter can take. */
  71. const NormalisableRange<float>& getNormalisableRange() const override { return range; }
  72. /** Provides access to the parameter's range. */
  73. NormalisableRange<float> range;
  74. protected:
  75. /** Override this method if you are interested in receiving callbacks
  76. when the parameter value changes.
  77. */
  78. virtual void valueChanged (float newValue);
  79. private:
  80. //==============================================================================
  81. float getValue() const override;
  82. void setValue (float newValue) override;
  83. float getDefaultValue() const override;
  84. int getNumSteps() const override;
  85. String getText (float, int) const override;
  86. float getValueForText (const String&) const override;
  87. float value;
  88. const float defaultValue;
  89. std::function<String (float, int)> stringFromValueFunction;
  90. std::function<float (const String&)> valueFromStringFunction;
  91. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioParameterFloat)
  92. };
  93. } // namespace juce