30 int minValue,
int maxValue,
int def,
33 range ([minValue, maxValue]
36 [] (
float start,
float end,
float v) {
return jlimit (start,
end, v * (
end - start) + start); },
37 [] (
float start,
float end,
float v) {
return jlimit (0.0f, 1.0f, (v - start) / (
end - start)); },
43 defaultValue (convertTo0to1 ((
float)
def)),
44 stringFromIntFunction (attributes.getStringFromValueFunction() !=
nullptr
45 ? attributes.getStringFromValueFunction()
47 intFromStringFunction (attributes.getValueFromStringFunction() !=
nullptr
48 ? attributes.getValueFromStringFunction()
49 : [] (
const String& text) {
return text.getIntValue(); })
56 #if __cpp_lib_atomic_is_always_lock_free
58 "AudioParameterInt requires a lock-free std::atomic<float>");
62float AudioParameterInt::getValue()
const {
return convertTo0to1 (value); }
64float AudioParameterInt::getDefaultValue()
const {
return defaultValue; }
66float AudioParameterInt::getValueForText (
const String& text)
const {
return convertTo0to1 ((
float) intFromStringFunction (text)); }
67String AudioParameterInt::getText (
float v,
int length)
const {
return stringFromIntFunction ((
int)
convertFrom0to1 (v), length); }
72 if (
get() != newValue)
89 void runTest()
override
91 beginTest (
"Three options switches at the correct points");
93 AudioParameterInt
intParam ({}, {}, 1, 3, 1);
95 intParam.setValueNotifyingHost (0.0f);
98 intParam.setValueNotifyingHost (0.2f);
101 intParam.setValueNotifyingHost (0.3f);
104 intParam.setValueNotifyingHost (0.7f);
107 intParam.setValueNotifyingHost (0.8f);
110 intParam.setValueNotifyingHost (1.0f);
114 beginTest (
"Out-of-bounds input");
116 AudioParameterInt
intParam ({}, {}, -1, 2, 0);
118 intParam.setValueNotifyingHost (-0.5f);
121 intParam.setValueNotifyingHost (1.5f);
Properties of an AudioParameterInt.
Provides a class of AudioProcessorParameter that can be used as an integer value with a given range.
AudioParameterInt(const ParameterID ¶meterID, const String ¶meterName, int minValue, int maxValue, int defaultValue, const AudioParameterIntAttributes &attributes={})
Creates a AudioParameterInt with the specified parameters.
AudioParameterInt & operator=(int newValue)
Changes the parameter's current value to a new integer.
int get() const noexcept
Returns the parameter's current value as an integer.
const NormalisableRange< float > & getNormalisableRange() const override
Returns the range of values that the parameter can take.
~AudioParameterInt() override
Destructor.
virtual void valueChanged(int newValue)
Override this method if you are interested in receiving callbacks when the parameter value changes.
Range< int > getRange() const noexcept
Returns the parameter's range.
void setValueNotifyingHost(float newValue)
A processor should call this when it needs to change one of its parameters.
Represents a mapping between an arbitrary range of values and a normalised 0->1 range.
Combines a parameter ID and a version hint.
This abstract base class is used by some AudioProcessorParameter helper classes.
float convertTo0to1(float v) const noexcept
Normalises and snaps a value based on the normalisable range.
float convertFrom0to1(float v) const noexcept
Denormalises and snaps a value based on the normalisable range.
This is a base class for classes that perform a unit test.
RangedDirectoryIterator end(const RangedDirectoryIterator &)
Returns a default-constructed sentinel value.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
@ valueChanged
Indicates that the UI element's value has changed.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.