WE Core
Loading...
Searching...
No Matches
CustomParameter.h
Go to the documentation of this file.
1/*
2 * File: CustomParameter.h
3 *
4 * Version: 1.0.0
5 *
6 * Created: 18/08/2021
7 *
8 * This file is part of WECore.
9 *
10 * WECore is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * WECore is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with WECore. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25#pragma once
26
27#include "../JuceLibraryCode/JuceHeader.h"
28
29namespace WECore::JUCEPlugin {
41 public:
42 inline CustomParameter();
43 virtual ~CustomParameter() = default;
44
45 inline void setListener(juce::AudioProcessorParameter::Listener* listener);
46 inline void removeListener();
47
48 virtual void restoreFromXml(juce::XmlElement* element) = 0;
49 virtual void writeToXml(juce::XmlElement* element) = 0;
50
51 protected:
52 inline void _updateListener();
53
54 private:
55 std::mutex _listenerMutex;
56 juce::AudioProcessorParameter::Listener* _listener;
57 };
58
59 CustomParameter::CustomParameter() : _listener(nullptr) {
60 }
61
62 void CustomParameter::setListener(juce::AudioProcessorParameter::Listener* listener) {
63 std::scoped_lock lock(_listenerMutex);
64 _listener = listener;
65 }
66
68 std::scoped_lock lock(_listenerMutex);
69 _listener = nullptr;
70 }
71
73 std::scoped_lock lock(_listenerMutex);
74 if (_listener != nullptr) {
75 _listener->parameterValueChanged(0, 0);
76 }
77 }
78}
virtual void restoreFromXml(juce::XmlElement *element)=0
virtual void writeToXml(juce::XmlElement *element)=0
juce::AudioProcessorParameter::Listener * _listener
void setListener(juce::AudioProcessorParameter::Listener *listener)