JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_AudioParameterChoice.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
35class AudioParameterChoiceAttributes : public RangedAudioParameterAttributes<AudioParameterChoiceAttributes, int> {};
36
37//==============================================================================
47{
48public:
66 AudioParameterChoice (const ParameterID& parameterID,
67 const String& parameterName,
68 const StringArray& choices,
69 int defaultItemIndex,
70 const AudioParameterChoiceAttributes& attributes = {});
71
86 [[deprecated ("Prefer the signature taking an Attributes argument")]]
87 AudioParameterChoice (const ParameterID& parameterID,
88 const String& parameterName,
89 const StringArray& choicesToUse,
90 int defaultItemIndex,
91 const String& parameterLabel,
92 std::function<String (int index, int maximumStringLength)> stringFromIndex = nullptr,
93 std::function<int (const String& text)> indexFromString = nullptr)
94 : AudioParameterChoice (parameterID,
95 parameterName,
96 choicesToUse,
97 defaultItemIndex,
98 AudioParameterChoiceAttributes().withLabel (parameterLabel)
99 .withStringFromValueFunction (std::move (stringFromIndex))
100 .withValueFromStringFunction (std::move (indexFromString)))
101 {
102 }
103
105 ~AudioParameterChoice() override;
106
108 int getIndex() const noexcept { return roundToInt (value.load()); }
109
111 operator int() const noexcept { return getIndex(); }
112
114 String getCurrentChoiceName() const noexcept { return choices[getIndex()]; }
115
117 operator String() const noexcept { return getCurrentChoiceName(); }
118
120 AudioParameterChoice& operator= (int newValue);
121
123 const NormalisableRange<float>& getNormalisableRange() const override { return range; }
124
127
128protected:
132 virtual void valueChanged (int newValue);
133
134private:
135 //==============================================================================
136 float getValue() const override;
137 void setValue (float newValue) override;
138 float getDefaultValue() const override;
139 int getNumSteps() const override;
140 bool isDiscrete() const override;
141 String getText (float, int) const override;
142 float getValueForText (const String&) const override;
143
144 const NormalisableRange<float> range;
145 std::atomic<float> value;
146 const float defaultValue;
147 std::function<String (int, int)> stringFromIndexFunction;
148 std::function<int (const String&)> indexFromStringFunction;
149
151};
152
153} // namespace juce
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.
const NormalisableRange< float > & getNormalisableRange() const override
Returns the range of values that the parameter can take.
String getCurrentChoiceName() const noexcept
Returns the name of the currently selected item.
int getIndex() const noexcept
Returns the current index of the selected item.
AudioParameterChoice(const ParameterID &parameterID, const String &parameterName, const StringArray &choicesToUse, int defaultItemIndex, const String &parameterLabel, std::function< String(int index, int maximumStringLength)> stringFromIndex=nullptr, std::function< int(const String &text)> indexFromString=nullptr)
Creates a AudioParameterChoice with the specified 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.
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:53
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
typedef int
JUCE Namespace.
@ valueChanged
Indicates that the UI element's value has changed.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.