This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Context.cpp
74 lines (61 loc) · 1.84 KB
/
Context.cpp
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
64
65
66
67
68
69
70
71
72
73
74
/*****************************************************************//**
* \file Context.cpp
* \brief Directly Musical Data Access library for VST3 with JUCE.
*
* \author WuChang
* \email 31423836@qq.com
* \date July 2023
* \version 1.0.0
* \license MIT License
*********************************************************************/
#include "Context.h"
namespace DMDA {
Context::~Context() {
this->sendClosed();
}
void Context::addListener(Context::Listener* listener) {
if (!listener) { return; }
juce::GenericScopedLock locker(this->listeners.getLock());
this->listeners.addIfNotAlreadyThere(listener);
}
void Context::removeListener(Context::Listener* listener) {
if (!listener) { return; }
juce::GenericScopedLock locker(this->listeners.getLock());
this->listeners.removeAllInstancesOf(listener);
}
void Context::removeAllListeners() {
juce::GenericScopedLock locker(this->listeners.getLock());
this->listeners.clear();
}
void Context::sendClosed() const {
juce::GenericScopedLock locker(this->listeners.getLock());
for (auto i : this->listeners) {
i->closed(const_cast<Context*>(this));
}
}
void Context::sendDataChanged() const {
juce::GenericScopedLock locker(this->listeners.getLock());
for (auto i : this->listeners) {
i->dataChanged(const_cast<Context*>(this));
}
}
void Context::sendStateChanged(int32_t state) const {
juce::GenericScopedLock locker(this->listeners.getLock());
for (auto i : this->listeners) {
i->stateChanged(const_cast<Context*>(this), state);
}
}
void Context::handShake() {
JUCE_ASSERT_MESSAGE_THREAD;
this->handShaked = true;
this->handShakedStateChanged();
}
void Context::handWave() {
JUCE_ASSERT_MESSAGE_THREAD;
this->handShaked = false;
this->handShakedStateChanged();
}
bool Context::isHandShaked() const {
return this->handShaked;
}
}