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.

107 lines
4.3KB

  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. Provides a class of AudioProcessorParameter that can be used as an
  22. integer value with a given range.
  23. @see AudioParameterFloat, AudioParameterBool, AudioParameterChoice
  24. @tags{Audio}
  25. */
  26. class JUCE_API AudioParameterInt : public RangedAudioParameter
  27. {
  28. public:
  29. /** Creates a AudioParameterInt with the specified parameters.
  30. @param parameterID The parameter ID to use
  31. @param parameterName The parameter name to use
  32. @param minValue The minimum parameter value
  33. @param maxValue The maximum parameter value
  34. @param defaultValue The default value
  35. @param parameterLabel An optional label for the parameter's value
  36. @param stringFromInt An optional lambda function that converts a int
  37. value to a string with a maximum length. This may
  38. be used by hosts to display the parameter's value.
  39. @param intFromString An optional lambda function that parses a string
  40. and converts it into an int. Some hosts use this
  41. to allow users to type in parameter values.
  42. */
  43. AudioParameterInt (const String& parameterID, const String& parameterName,
  44. int minValue, int maxValue,
  45. int defaultValue,
  46. const String& parameterLabel = String(),
  47. std::function<String (int value, int maximumStringLength)> stringFromInt = nullptr,
  48. std::function<int (const String& text)> intFromString = nullptr);
  49. /** Destructor. */
  50. ~AudioParameterInt() override;
  51. /** Returns the parameter's current value as an integer. */
  52. int get() const noexcept { return roundToInt (value.load()); }
  53. /** Returns the parameter's current value as an integer. */
  54. operator int() const noexcept { return get(); }
  55. /** Changes the parameter's current value to a new integer.
  56. The value passed in will be snapped to the permitted range before being used.
  57. */
  58. AudioParameterInt& operator= (int newValue);
  59. /** Returns the parameter's range. */
  60. Range<int> getRange() const noexcept { return { (int) getNormalisableRange().start, (int) getNormalisableRange().end }; }
  61. /** Returns the range of values that the parameter can take. */
  62. const NormalisableRange<float>& getNormalisableRange() const override { return range; }
  63. protected:
  64. /** Override this method if you are interested in receiving callbacks
  65. when the parameter value changes.
  66. */
  67. virtual void valueChanged (int newValue);
  68. private:
  69. //==============================================================================
  70. float getValue() const override;
  71. void setValue (float newValue) override;
  72. float getDefaultValue() const override;
  73. int getNumSteps() const override;
  74. String getText (float, int) const override;
  75. float getValueForText (const String&) const override;
  76. const NormalisableRange<float> range;
  77. std::atomic<float> value;
  78. const float defaultValue;
  79. std::function<String (int, int)> stringFromIntFunction;
  80. std::function<int (const String&)> intFromStringFunction;
  81. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioParameterInt)
  82. };
  83. } // namespace juce