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.

100 lines
4.0KB

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