46 defaultValue (convertTo0to1 ((
float)
def)),
47 stringFromIndexFunction (attributes.getStringFromValueFunction() !=
nullptr
48 ? attributes.getStringFromValueFunction()
49 : [
this] (
int index,
int) {
return choices [index]; }),
50 indexFromStringFunction (attributes.getValueFromStringFunction() !=
nullptr
51 ? attributes.getValueFromStringFunction()
52 : [
this] (
const String& text) {
return choices.indexOf (text); })
59 #if __cpp_lib_atomic_is_always_lock_free
61 "AudioParameterChoice requires a lock-free std::atomic<float>");
65float AudioParameterChoice::getValue()
const {
return convertTo0to1 (value); }
67float AudioParameterChoice::getDefaultValue()
const {
return defaultValue; }
68int AudioParameterChoice::getNumSteps()
const {
return choices.
size(); }
69bool AudioParameterChoice::isDiscrete()
const {
return true; }
70float AudioParameterChoice::getValueForText (
const String& text)
const {
return convertTo0to1 ((
float) indexFromStringFunction (text)); }
71String AudioParameterChoice::getText (
float v,
int length)
const {
return stringFromIndexFunction ((
int)
convertFrom0to1 (v), length); }
93 void runTest()
override
95 beginTest (
"Three options switches at the correct points");
97 AudioParameterChoice
choice ({}, {}, {
"a",
"b",
"c" }, {});
99 choice.setValueNotifyingHost (0.0f);
100 expectEquals (
choice.getIndex(), 0);
102 choice.setValueNotifyingHost (0.2f);
103 expectEquals (
choice.getIndex(), 0);
105 choice.setValueNotifyingHost (0.3f);
106 expectEquals (
choice.getIndex(), 1);
108 choice.setValueNotifyingHost (0.7f);
109 expectEquals (
choice.getIndex(), 1);
111 choice.setValueNotifyingHost (0.8f);
112 expectEquals (
choice.getIndex(), 2);
114 choice.setValueNotifyingHost (1.0f);
115 expectEquals (
choice.getIndex(), 2);
118 beginTest (
"Out-of-bounds input");
120 AudioParameterChoice
choiceParam ({}, {}, {
"a",
"b",
"c" }, {});
Properties of an AudioParameterChoice.
Provides a class of AudioProcessorParameter that can be used to select an indexed,...
const StringArray choices
Provides access to the list of choices that this parameter is working with.
AudioParameterChoice(const ParameterID ¶meterID, const String ¶meterName, const StringArray &choices, int defaultItemIndex, const AudioParameterChoiceAttributes &attributes={})
Creates a AudioParameterChoice with the specified parameters.
~AudioParameterChoice() override
Destructor.
int getIndex() const noexcept
Returns the current index of the selected item.
virtual void valueChanged(int newValue)
Override this method if you are interested in receiving callbacks when the parameter value changes.
AudioParameterChoice & operator=(int newValue)
Changes the selected item to a new index.
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.
A special array for holding a list of strings.
int size() const noexcept
Returns the number of strings in the array.
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.