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.

146 lines
6.3KB

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