LMMS
Loading...
Searching...
No Matches
juce_AudioProcessorValueTreeState.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
37{
42
43public:
45 JUCE_NODISCARD auto withStringFromValueFunction (StringFromValue x) const { return withMember (*this, &This::attributes, attributes.withStringFromValueFunction (std::move (x))); }
47 JUCE_NODISCARD auto withValueFromStringFunction (ValueFromString x) const { return withMember (*this, &This::attributes, attributes.withValueFromStringFunction (std::move (x))); }
49 JUCE_NODISCARD auto withLabel (String x) const { return withMember (*this, &This::attributes, attributes.withLabel (std::move (x))); }
51 JUCE_NODISCARD auto withCategory (Category x) const { return withMember (*this, &This::attributes, attributes.withCategory (std::move (x))); }
53 JUCE_NODISCARD auto withMeta (bool x) const { return withMember (*this, &This::attributes, attributes.withMeta (std::move (x))); }
55 JUCE_NODISCARD auto withAutomatable (bool x) const { return withMember (*this, &This::attributes, attributes.withAutomatable (std::move (x))); }
57 JUCE_NODISCARD auto withInverted (bool x) const { return withMember (*this, &This::attributes, attributes.withInverted (std::move (x))); }
58
63 JUCE_NODISCARD auto withDiscrete (bool x) const { return withMember (*this, &This::discrete, std::move (x)); }
64
69 JUCE_NODISCARD auto withBoolean (bool x) const { return withMember (*this, &This::boolean, std::move (x)); }
70
74 JUCE_NODISCARD const auto& getDiscrete() const { return discrete; }
76 JUCE_NODISCARD const auto& getBoolean() const { return boolean; }
77
78private:
80 bool discrete = false, boolean = false;
81};
82
109 private ValueTree::Listener
110{
111public:
112 //==============================================================================
120 {
121 private:
122 //==============================================================================
123 template <typename It>
124 using ValidIfIterator = decltype (std::next (std::declval<It>()));
125
126 public:
127 //==============================================================================
128 template <typename... Items>
129 ParameterLayout (std::unique_ptr<Items>... items) { add (std::move (items)...); }
130
131 template <typename It, typename = ValidIfIterator<It>>
133
134 template <typename... Items>
135 void add (std::unique_ptr<Items>... items)
136 {
137 parameters.reserve (parameters.size() + sizeof... (items));
138
139 // We can replace this with some nicer code once generic lambdas become available. A
140 // sequential context like an array initialiser is required to ensure we get the correct
141 // order from the parameter pack.
142 int unused[] { (parameters.emplace_back (MakeContents() (std::move (items))), 0)... };
143 ignoreUnused (unused);
144 }
145
146 template <typename It, typename = ValidIfIterator<It>>
147 void add (It begin, It end)
148 {
149 parameters.reserve (parameters.size() + std::size_t (std::distance (begin, end)));
150 std::transform (std::make_move_iterator (begin),
151 std::make_move_iterator (end),
152 std::back_inserter (parameters),
153 MakeContents());
154 }
155
156 ParameterLayout (const ParameterLayout& other) = delete;
157 ParameterLayout (ParameterLayout&& other) noexcept { swap (other); }
158
159 ParameterLayout& operator= (const ParameterLayout& other) = delete;
160 ParameterLayout& operator= (ParameterLayout&& other) noexcept { swap (other); return *this; }
161
162 void swap (ParameterLayout& other) noexcept { std::swap (other.parameters, parameters); }
163
164 private:
165 //==============================================================================
166 struct Visitor
167 {
168 virtual ~Visitor() = default;
169
170 // If you have a compiler error telling you that there is no matching
171 // member function to call for 'visit', then you are probably attempting
172 // to add a parameter that is not derived from RangedAudioParameter to
173 // the AudioProcessorValueTreeState.
174 virtual void visit (std::unique_ptr<RangedAudioParameter>) const = 0;
175 virtual void visit (std::unique_ptr<AudioProcessorParameterGroup>) const = 0;
176 };
177
179 {
180 virtual ~ParameterStorageBase() = default;
181 virtual void accept (const Visitor& visitor) = 0;
182 };
183
184 template <typename Contents>
186 {
187 explicit ParameterStorage (std::unique_ptr<Contents> input) : contents (std::move (input)) {}
188
189 void accept (const Visitor& visitor) override { visitor.visit (std::move (contents)); }
190
191 std::unique_ptr<Contents> contents;
192 };
193
195 {
196 template <typename Item>
197 std::unique_ptr<ParameterStorageBase> operator() (std::unique_ptr<Item> item) const
198 {
199 return std::unique_ptr<ParameterStorageBase> (new ParameterStorage<Item> (std::move (item)));
200 }
201 };
202
203 void add() {}
204
206
207 std::vector<std::unique_ptr<ParameterStorageBase>> parameters;
208 };
209
210 //==============================================================================
258 AudioProcessorValueTreeState (AudioProcessor& processorToConnectTo,
259 UndoManager* undoManagerToUse,
260 const Identifier& valueTreeType,
261 ParameterLayout parameterLayout);
262
273 AudioProcessorValueTreeState (AudioProcessor& processorToConnectTo, UndoManager* undoManagerToUse);
274
277
278 //==============================================================================
279 #ifndef DOXYGEN
312 [[deprecated ("This function is deprecated and will be removed in a future version of JUCE! "
313 "See the method docs for a code example of the replacement methods.")]]
315 const String& parameterName,
316 const String& labelText,
317 NormalisableRange<float> valueRange,
318 float defaultValue,
319 std::function<String (float)> valueToTextFunction,
320 std::function<float (const String&)> textToValueFunction,
321 bool isMetaParameter = false,
322 bool isAutomatableParameter = true,
323 bool isDiscrete = false,
325 bool isBoolean = false);
326 #endif
327
331 RangedAudioParameter* createAndAddParameter (std::unique_ptr<RangedAudioParameter> parameter);
332
333 //==============================================================================
335 RangedAudioParameter* getParameter (StringRef parameterID) const noexcept;
336
343 std::atomic<float>* getRawParameterValue (StringRef parameterID) const noexcept;
344
345 //==============================================================================
350 {
351 virtual ~Listener() = default;
352
359 virtual void parameterChanged (const String& parameterID, float newValue) = 0;
360 };
361
363 void addParameterListener (StringRef parameterID, Listener* listener);
364
366 void removeParameterListener (StringRef parameterID, Listener* listener);
367
368 //==============================================================================
370 Value getParameterAsValue (StringRef parameterID) const;
371
373 NormalisableRange<float> getParameterRange (StringRef parameterID) const noexcept;
374
375 //==============================================================================
389
401 void replaceState (const ValueTree& newState);
402
403 //==============================================================================
406
415
418
419private:
420 //==============================================================================
421 class ParameterAdapter;
422
423public:
424 //==============================================================================
453 {
454 public:
477 Parameter (const ParameterID& parameterID,
478 const String& parameterName,
479 NormalisableRange<float> valueRange,
480 float defaultValue,
482
483 [[deprecated ("Prefer the signature taking an Attributes argument")]]
484 Parameter (const ParameterID& parameterID,
485 const String& parameterName,
486 const String& labelText,
487 NormalisableRange<float> valueRange,
488 float defaultParameterValue,
489 std::function<String (float)> valueToTextFunction,
490 std::function<float (const String&)> textToValueFunction,
491 bool isMetaParameter = false,
492 bool isAutomatableParameter = true,
493 bool isDiscrete = false,
495 bool isBoolean = false)
496 : Parameter (parameterID,
497 parameterName,
498 valueRange,
499 defaultParameterValue,
501 .withStringFromValueFunction ([valueToTextFunction] (float v, int) { return valueToTextFunction (v); })
502 .withValueFromStringFunction (std::move (textToValueFunction))
503 .withMeta (isMetaParameter)
504 .withAutomatable (isAutomatableParameter)
505 .withDiscrete (isDiscrete)
506 .withCategory (parameterCategory)
507 .withBoolean (isBoolean))
508 {
509 }
510
511 float getDefaultValue() const override;
512 int getNumSteps() const override;
513
514 bool isDiscrete() const override;
515 bool isBoolean() const override;
516
517 private:
518 void valueChanged (float) override;
519
520 std::function<void()> onValueChanged;
521
522 const float unsnappedDefault;
523 const bool discrete, boolean;
524 std::atomic<float> lastValue { -1.0f };
525
527 };
528
529 #if ! JUCE_AUDIOPROCESSOR_NO_GUI
530 //==============================================================================
540 {
541 public:
543 const String& parameterID,
544 Slider& slider);
545
546 private:
547 std::unique_ptr<SliderParameterAttachment> attachment;
549 };
550
551 //==============================================================================
566 {
567 public:
569 const String& parameterID,
570 ComboBox& combo);
571
572 private:
573 std::unique_ptr<ComboBoxParameterAttachment> attachment;
575 };
576
577 //==============================================================================
587 {
588 public:
590 const String& parameterID,
591 Button& button);
592
593 private:
594 std::unique_ptr<ButtonParameterAttachment> attachment;
596 };
597 #endif
598
599private:
600 //==============================================================================
622 [[deprecated ("This method was introduced to allow you to use AudioProcessorValueTreeState parameters in "
623 "an AudioProcessorParameterGroup, but there is now a much nicer way to achieve this. See the "
624 "method docs for a code example.")]]
625 std::unique_ptr<RangedAudioParameter> createParameter (const String&, const String&, const String&, NormalisableRange<float>,
626 float, std::function<String (float)>, std::function<float (const String&)>,
627 bool, bool, bool, AudioProcessorParameter::Category, bool);
628
629 //==============================================================================
630 #if JUCE_UNIT_TESTS
631 friend struct ParameterAdapterTests;
632 #endif
633
636
638 void setNewState (ValueTree);
639 void timerCallback() override;
640
641 void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
642 void valueTreeChildAdded (ValueTree&, ValueTree&) override;
643 void valueTreeRedirected (ValueTree&) override;
645
646 const Identifier valueType { "PARAM" }, valuePropertyID { "value" }, idPropertyID { "id" };
647
649 {
650 bool operator() (StringRef a, StringRef b) const noexcept { return a.text.compare (b.text) < 0; }
651 };
652
653 std::map<StringRef, std::unique_ptr<ParameterAdapter>, StringRefLessThan> adapterTable;
654
656
658};
659
660} // namespace juce
#define final
Definition DistrhoDefines.h:74
uint8_t a
Definition Spc_Cpu.h:141
Definition juce_AudioParameterFloat.h:33
AudioParameterFloat(const ParameterID &parameterID, const String &parameterName, NormalisableRange< float > normalisableRange, float defaultValue, const AudioParameterFloatAttributes &attributes={})
Definition juce_AudioParameterFloat.cpp:29
Definition juce_AudioProcessor.h:46
Category
Definition juce_AudioProcessorParameter.h:231
@ genericParameter
Definition juce_AudioProcessorParameter.h:232
bool isMetaParameter() const override
Definition juce_AudioProcessorParameterWithID.h:177
std::unique_ptr< ButtonParameterAttachment > attachment
Definition juce_AudioProcessorValueTreeState.h:594
ButtonAttachment(AudioProcessorValueTreeState &stateToUse, const String &parameterID, Button &button)
Definition juce_AudioProcessorValueTreeState.cpp:503
std::unique_ptr< ComboBoxParameterAttachment > attachment
Definition juce_AudioProcessorValueTreeState.h:573
ComboBoxAttachment(AudioProcessorValueTreeState &stateToUse, const String &parameterID, ComboBox &combo)
Definition juce_AudioProcessorValueTreeState.cpp:496
Definition juce_AudioProcessorValueTreeState.cpp:66
bool isBoolean() const override
Definition juce_AudioProcessorValueTreeState.cpp:51
Parameter(const ParameterID &parameterID, const String &parameterName, const String &labelText, NormalisableRange< float > valueRange, float defaultParameterValue, std::function< String(float)> valueToTextFunction, std::function< float(const String &)> textToValueFunction, bool isMetaParameter=false, bool isAutomatableParameter=true, bool isDiscrete=false, AudioProcessorParameter::Category parameterCategory=AudioProcessorParameter::genericParameter, bool isBoolean=false)
Definition juce_AudioProcessorValueTreeState.h:484
bool isDiscrete() const override
Definition juce_AudioProcessorValueTreeState.cpp:50
const bool discrete
Definition juce_AudioProcessorValueTreeState.h:523
std::atomic< float > lastValue
Definition juce_AudioProcessorValueTreeState.h:524
Parameter(const ParameterID &parameterID, const String &parameterName, NormalisableRange< float > valueRange, float defaultValue, const AudioProcessorValueTreeStateParameterAttributes &attributes={})
Definition juce_AudioProcessorValueTreeState.cpp:31
std::function< void()> onValueChanged
Definition juce_AudioProcessorValueTreeState.h:520
const float unsnappedDefault
Definition juce_AudioProcessorValueTreeState.h:522
const bool boolean
Definition juce_AudioProcessorValueTreeState.h:523
Definition juce_AudioProcessorValueTreeState.h:120
void add(It begin, It end)
Definition juce_AudioProcessorValueTreeState.h:147
decltype(std::next(std::declval< It >())) ValidIfIterator
Definition juce_AudioProcessorValueTreeState.h:124
ParameterLayout(ParameterLayout &&other) noexcept
Definition juce_AudioProcessorValueTreeState.h:157
void add(std::unique_ptr< Items >... items)
Definition juce_AudioProcessorValueTreeState.h:135
std::vector< std::unique_ptr< ParameterStorageBase > > parameters
Definition juce_AudioProcessorValueTreeState.h:207
friend class AudioProcessorValueTreeState
Definition juce_AudioProcessorValueTreeState.h:205
ParameterLayout(std::unique_ptr< Items >... items)
Definition juce_AudioProcessorValueTreeState.h:129
void swap(ParameterLayout &other) noexcept
Definition juce_AudioProcessorValueTreeState.h:162
void add()
Definition juce_AudioProcessorValueTreeState.h:203
ParameterLayout(It begin, It end)
Definition juce_AudioProcessorValueTreeState.h:132
ParameterLayout(const ParameterLayout &other)=delete
SliderAttachment(AudioProcessorValueTreeState &stateToUse, const String &parameterID, Slider &slider)
Definition juce_AudioProcessorValueTreeState.cpp:489
std::unique_ptr< SliderParameterAttachment > attachment
Definition juce_AudioProcessorValueTreeState.h:547
void valueTreePropertyChanged(ValueTree &, const Identifier &) override
Definition juce_AudioProcessorValueTreeState.cpp:437
Value getParameterAsValue(StringRef parameterID) const
Definition juce_AudioProcessorValueTreeState.cpp:351
UndoManager *const undoManager
Definition juce_AudioProcessorValueTreeState.h:417
RangedAudioParameter * getParameter(StringRef parameterID) const noexcept
Definition juce_AudioProcessorValueTreeState.cpp:368
void updateParameterConnectionsToChildTrees()
Definition juce_AudioProcessorValueTreeState.cpp:412
void addParameterAdapter(RangedAudioParameter &)
Definition juce_AudioProcessorValueTreeState.cpp:328
AudioProcessor & processor
Definition juce_AudioProcessorValueTreeState.h:405
RangedAudioParameter * createAndAddParameter(const String &parameterID, const String &parameterName, const String &labelText, NormalisableRange< float > valueRange, float defaultValue, std::function< String(float)> valueToTextFunction, std::function< float(const String &)> textToValueFunction, bool isMetaParameter=false, bool isAutomatableParameter=true, bool isDiscrete=false, AudioProcessorParameter::Category parameterCategory=AudioProcessorParameter::genericParameter, bool isBoolean=false)
Definition juce_AudioProcessorValueTreeState.cpp:279
void addParameterListener(StringRef parameterID, Listener *listener)
Definition juce_AudioProcessorValueTreeState.cpp:339
NormalisableRange< float > getParameterRange(StringRef parameterID) const noexcept
Definition juce_AudioProcessorValueTreeState.cpp:360
AudioProcessorValueTreeState(AudioProcessor &processorToConnectTo, UndoManager *undoManagerToUse, const Identifier &valueTreeType, ParameterLayout parameterLayout)
Definition juce_AudioProcessorValueTreeState.cpp:209
void valueTreeRedirected(ValueTree &) override
Definition juce_AudioProcessorValueTreeState.cpp:449
void setNewState(ValueTree)
Definition juce_AudioProcessorValueTreeState.cpp:401
void replaceState(const ValueTree &newState)
Definition juce_AudioProcessorValueTreeState.cpp:391
bool flushParameterValuesToValueTree()
Definition juce_AudioProcessorValueTreeState.cpp:455
void removeParameterListener(StringRef parameterID, Listener *listener)
Definition juce_AudioProcessorValueTreeState.cpp:345
std::unique_ptr< RangedAudioParameter > createParameter(const String &, const String &, const String &, NormalisableRange< float >, float, std::function< String(float)>, std::function< float(const String &)>, bool, bool, bool, AudioProcessorParameter::Category, bool)
void valueTreeChildAdded(ValueTree &, ValueTree &) override
Definition juce_AudioProcessorValueTreeState.cpp:443
std::map< StringRef, std::unique_ptr< ParameterAdapter >, StringRefLessThan > adapterTable
Definition juce_AudioProcessorValueTreeState.h:653
void timerCallback() override
Definition juce_AudioProcessorValueTreeState.cpp:467
CriticalSection valueTreeChanging
Definition juce_AudioProcessorValueTreeState.h:655
ValueTree copyState()
Definition juce_AudioProcessorValueTreeState.cpp:384
const Identifier valueType
Definition juce_AudioProcessorValueTreeState.h:646
ValueTree state
Definition juce_AudioProcessorValueTreeState.h:414
ParameterAdapter * getParameterAdapter(StringRef) const
Definition juce_AudioProcessorValueTreeState.cpp:333
std::atomic< float > * getRawParameterValue(StringRef parameterID) const noexcept
Definition juce_AudioProcessorValueTreeState.cpp:376
Definition juce_AudioProcessorValueTreeState.h:37
AudioParameterFloatAttributes::Category Category
Definition juce_AudioProcessorValueTreeState.h:41
AudioParameterFloatAttributes attributes
Definition juce_AudioProcessorValueTreeState.h:79
JUCE_NODISCARD auto withLabel(String x) const
Definition juce_AudioProcessorValueTreeState.h:49
bool boolean
Definition juce_AudioProcessorValueTreeState.h:80
JUCE_NODISCARD const auto & getAudioParameterFloatAttributes() const
Definition juce_AudioProcessorValueTreeState.h:72
JUCE_NODISCARD auto withDiscrete(bool x) const
Definition juce_AudioProcessorValueTreeState.h:63
JUCE_NODISCARD auto withMeta(bool x) const
Definition juce_AudioProcessorValueTreeState.h:53
bool discrete
Definition juce_AudioProcessorValueTreeState.h:80
JUCE_NODISCARD auto withCategory(Category x) const
Definition juce_AudioProcessorValueTreeState.h:51
JUCE_NODISCARD const auto & getDiscrete() const
Definition juce_AudioProcessorValueTreeState.h:74
JUCE_NODISCARD const auto & getBoolean() const
Definition juce_AudioProcessorValueTreeState.h:76
JUCE_NODISCARD auto withInverted(bool x) const
Definition juce_AudioProcessorValueTreeState.h:57
JUCE_NODISCARD auto withValueFromStringFunction(ValueFromString x) const
Definition juce_AudioProcessorValueTreeState.h:47
JUCE_NODISCARD auto withAutomatable(bool x) const
Definition juce_AudioProcessorValueTreeState.h:55
AudioProcessorValueTreeStateParameterAttributes This
Definition juce_AudioProcessorValueTreeState.h:38
JUCE_NODISCARD auto withStringFromValueFunction(StringFromValue x) const
Definition juce_AudioProcessorValueTreeState.h:45
AudioParameterFloatAttributes::ValueFromString ValueFromString
Definition juce_AudioProcessorValueTreeState.h:40
JUCE_NODISCARD auto withBoolean(bool x) const
Definition juce_AudioProcessorValueTreeState.h:69
AudioParameterFloatAttributes::StringFromValue StringFromValue
Definition juce_AudioProcessorValueTreeState.h:39
Definition juce_Button.h:43
Definition juce_ComboBox.h:49
Definition juce_CriticalSection.h:43
Definition juce_Identifier.h:39
Definition juce_NormalisableRange.h:40
Definition juce_AudioProcessorParameterWithID.h:33
std::function< float(const String &)> ValueFromString
Definition juce_RangedAudioParameter.h:49
AudioProcessorParameter::Category Category
Definition juce_RangedAudioParameter.h:46
std::function< String(float, int)> StringFromValue
Definition juce_RangedAudioParameter.h:48
Definition juce_RangedAudioParameter.h:98
Definition juce_Slider.h:54
Definition juce_String.h:53
Definition juce_StringRef.h:62
Timer() noexcept
Definition juce_Timer.cpp:316
Definition juce_UndoManager.h:52
Definition juce_Value.h:51
Definition juce_ValueTree.h:479
Definition juce_ValueTree.h:72
unsigned v[N_MAX]
Definition inflate.c:1584
unsigned x[BMAX+1]
Definition inflate.c:1586
#define JUCE_NODISCARD
Definition juce_CompilerSupport.h:108
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
Object withMember(Object copy, Member OtherObject::*member, Member &&value)
Definition juce_Functional.h:89
RangedDirectoryIterator end(const RangedDirectoryIterator &)
Definition juce_RangedDirectoryIterator.h:184
@ valueChanged
Definition juce_AccessibilityEvent.h:44
void ignoreUnused(Types &&...) noexcept
Definition juce_MathsFunctions.h:333
@ slider
Definition juce_AccessibilityRole.h:43
@ button
Definition juce_AccessibilityRole.h:38
RangedDirectoryIterator begin(const RangedDirectoryIterator &it)
Definition juce_RangedDirectoryIterator.h:179
Definition juce_Uuid.h:141
Definition juce_AudioProcessorValueTreeState.h:350
virtual void parameterChanged(const String &parameterID, float newValue)=0
Definition juce_AudioProcessorValueTreeState.h:195
Definition juce_AudioProcessorValueTreeState.h:179
Definition juce_AudioProcessorValueTreeState.h:186
ParameterStorage(std::unique_ptr< Contents > input)
Definition juce_AudioProcessorValueTreeState.h:187
std::unique_ptr< Contents > contents
Definition juce_AudioProcessorValueTreeState.h:191
void accept(const Visitor &visitor) override
Definition juce_AudioProcessorValueTreeState.h:189
Definition juce_AudioProcessorValueTreeState.h:167
virtual void visit(std::unique_ptr< RangedAudioParameter >) const =0
virtual void visit(std::unique_ptr< AudioProcessorParameterGroup >) const =0
Definition juce_AudioProcessorValueTreeState.h:649
b
Definition crypt.c:628
typedef int(UZ_EXP MsgFn)()
#define void
Definition unzip.h:396