-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParameterListener.h
More file actions
63 lines (54 loc) · 1.97 KB
/
ParameterListener.h
File metadata and controls
63 lines (54 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include <juce_core/juce_core.h>
#include <juce_audio_processors/juce_audio_processors.h>
namespace moiraesoftware
{
struct ParameterListener : juce::AudioProcessorValueTreeState::Listener
{
explicit ParameterListener (std::atomic<bool>& needsUpdate) : updateNeeded (needsUpdate) {}
void parameterChanged (const juce::String& parameterID, float newValue) override
{
//TODO: check its not a param that doesnt need a re-calc of something in channel
// is there anything that doesnt need an update in the params?
//possibly if the speaker had changed but the mic was still set to none
updateNeeded.store (true);
}
std::atomic<bool>& updateNeeded;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ParameterListener)
};
template <std::size_t N>
class ParameterListenerManager
{
public:
ParameterListenerManager (juce::AudioProcessorValueTreeState& state,
const std::array<const juce::ParameterID*, N>& channelParameterIds,
std::atomic<bool>& update)
: apvts_ (state),
parameterIds (channelParameterIds),
listener (update)
{
for (const auto& param : parameterIds)
{
if (param)
{
apvts_.addParameterListener (param->getParamID(), &listener);
}
}
}
~ParameterListenerManager()
{
for (const auto param : parameterIds)
{
if (param)
{
apvts_.removeParameterListener (param->getParamID(), &listener);
}
}
}
private:
juce::AudioProcessorValueTreeState& apvts_;
const std::array<const juce::ParameterID*, N>& parameterIds;
ParameterListener listener;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ParameterListenerManager)
};
}