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_AudioParameterInt.h 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-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. /** Properties of an AudioParameterInt.
  21. @see AudioParameterInt(), RangedAudioParameterAttributes()
  22. */
  23. class AudioParameterIntAttributes : public RangedAudioParameterAttributes<AudioParameterIntAttributes, int> {};
  24. //==============================================================================
  25. /**
  26. Provides a class of AudioProcessorParameter that can be used as an
  27. integer value with a given range.
  28. @see AudioParameterFloat, AudioParameterBool, AudioParameterChoice
  29. @tags{Audio}
  30. */
  31. class JUCE_API AudioParameterInt : public RangedAudioParameter
  32. {
  33. public:
  34. /** Creates a AudioParameterInt with the specified parameters.
  35. Note that the attributes argument is optional and only needs to be
  36. supplied if you want to change options from their default values.
  37. Example usage:
  38. @code
  39. auto attributes = AudioParameterIntAttributes().withStringFromValueFunction ([] (auto x, auto) { return String (x); })
  40. .withLabel ("things");
  41. auto param = std::make_unique<AudioParameterInt> ("paramID", "Parameter Name", 0, 100, 50, attributes);
  42. @endcode
  43. @param parameterID The parameter ID to use
  44. @param parameterName The parameter name to use
  45. @param minValue The minimum parameter value
  46. @param maxValue The maximum parameter value
  47. @param defaultValue The default value
  48. @param attributes Optional characteristics
  49. */
  50. AudioParameterInt (const ParameterID& parameterID,
  51. const String& parameterName,
  52. int minValue,
  53. int maxValue,
  54. int defaultValue,
  55. const AudioParameterIntAttributes& attributes = {});
  56. /** Creates a AudioParameterInt with the specified parameters.
  57. @param parameterID The parameter ID to use
  58. @param parameterName The parameter name to use
  59. @param minValue The minimum parameter value
  60. @param maxValue The maximum parameter value
  61. @param defaultValueIn The default value
  62. @param parameterLabel An optional label for the parameter's value
  63. @param stringFromInt An optional lambda function that converts a int
  64. value to a string with a maximum length. This may
  65. be used by hosts to display the parameter's value.
  66. @param intFromString An optional lambda function that parses a string
  67. and converts it into an int. Some hosts use this
  68. to allow users to type in parameter values.
  69. */
  70. [[deprecated ("Prefer the signature taking an Attributes argument")]]
  71. AudioParameterInt (const ParameterID& parameterID,
  72. const String& parameterName,
  73. int minValue,
  74. int maxValue,
  75. int defaultValueIn,
  76. const String& parameterLabel,
  77. std::function<String (int value, int maximumStringLength)> stringFromInt = nullptr,
  78. std::function<int (const String& text)> intFromString = nullptr)
  79. : AudioParameterInt (parameterID,
  80. parameterName,
  81. minValue,
  82. maxValue,
  83. defaultValueIn,
  84. AudioParameterIntAttributes().withLabel (parameterLabel)
  85. .withStringFromValueFunction (std::move (stringFromInt))
  86. .withValueFromStringFunction (std::move (intFromString)))
  87. {
  88. }
  89. /** Destructor. */
  90. ~AudioParameterInt() override;
  91. /** Returns the parameter's current value as an integer. */
  92. int get() const noexcept { return roundToInt (value.load()); }
  93. /** Returns the parameter's current value as an integer. */
  94. operator int() const noexcept { return get(); }
  95. /** Changes the parameter's current value to a new integer.
  96. The value passed in will be snapped to the permitted range before being used.
  97. */
  98. AudioParameterInt& operator= (int newValue);
  99. /** Returns the parameter's range. */
  100. Range<int> getRange() const noexcept { return { (int) getNormalisableRange().start, (int) getNormalisableRange().end }; }
  101. /** Returns the range of values that the parameter can take. */
  102. const NormalisableRange<float>& getNormalisableRange() const override { return range; }
  103. protected:
  104. /** Override this method if you are interested in receiving callbacks
  105. when the parameter value changes.
  106. */
  107. virtual void valueChanged (int newValue);
  108. private:
  109. //==============================================================================
  110. float getValue() const override;
  111. void setValue (float newValue) override;
  112. float getDefaultValue() const override;
  113. int getNumSteps() const override;
  114. String getText (float, int) const override;
  115. float getValueForText (const String&) const override;
  116. const NormalisableRange<float> range;
  117. std::atomic<float> value;
  118. const float defaultValue;
  119. std::function<String (int, int)> stringFromIntFunction;
  120. std::function<int (const String&)> intFromStringFunction;
  121. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioParameterInt)
  122. };
  123. } // namespace juce