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_AudioParameterBool.cpp
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
30 const String& nameToUse,
31 bool def,
32 const AudioParameterBoolAttributes& attributes)
33 : RangedAudioParameter (idToUse, nameToUse, attributes.getAudioProcessorParameterWithIDAttributes()),
34 value (def ? 1.0f : 0.0f),
35 valueDefault (def),
36 stringFromBoolFunction (attributes.getStringFromValueFunction() != nullptr
37 ? attributes.getStringFromValueFunction()
38 : [] (bool v, int) { return v ? TRANS ("On") : TRANS ("Off"); }),
39 boolFromStringFunction (attributes.getValueFromStringFunction() != nullptr
40 ? attributes.getValueFromStringFunction()
41 : [] (const String& text)
42 {
43 static const StringArray onStrings { TRANS ("on"), TRANS ("yes"), TRANS ("true") };
44 static const StringArray offStrings { TRANS ("off"), TRANS ("no"), TRANS ("false") };
45
46 String lowercaseText (text.toLowerCase());
47
48 for (auto& testText : onStrings)
51
52 for (auto& testText : offStrings)
55
56 return text.getIntValue() != 0;
57 })
58{
59}
60
62{
63 #if __cpp_lib_atomic_is_always_lock_free
65 "AudioParameterBool requires a lock-free std::atomic<float>");
66 #endif
67}
68
69float AudioParameterBool::getValue() const { return value; }
70void AudioParameterBool::setValue (float newValue) { value = newValue; valueChanged (get()); }
71float AudioParameterBool::getDefaultValue() const { return valueDefault; }
72int AudioParameterBool::getNumSteps() const { return 2; }
73bool AudioParameterBool::isDiscrete() const { return true; }
74bool AudioParameterBool::isBoolean() const { return true; }
76
77float AudioParameterBool::getValueForText (const String& text) const
78{
79 return boolFromStringFunction (text) ? 1.0f : 0.0f;
80}
81
82String AudioParameterBool::getText (float v, int maximumLength) const
83{
84 return stringFromBoolFunction (v >= 0.5f, maximumLength);
85}
86
88{
89 if (get() != newValue)
90 setValueNotifyingHost (newValue ? 1.0f : 0.0f);
91
92 return *this;
93}
94
95} // namespace juce
Properties of an AudioParameterBool.
Provides a class of AudioProcessorParameter that can be used as a boolean value.
bool get() const noexcept
Returns the parameter's current boolean value.
AudioParameterBool & operator=(bool newValue)
Changes the parameter's current value to a new boolean.
virtual void valueChanged(bool newValue)
Override this method if you are interested in receiving callbacks when the parameter value changes.
AudioParameterBool(const ParameterID &parameterID, const String &parameterName, bool defaultValue, const AudioParameterBoolAttributes &attributes={})
Creates a AudioParameterBool with the specified parameters.
~AudioParameterBool() override
Destructor.
void setValueNotifyingHost(float newValue)
A processor should call this when it needs to change one of its parameters.
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 TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
typedef int
JUCE Namespace.
@ 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...
Definition juce_Memory.h:88