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
/
Copy pathContext.h
119 lines (107 loc) · 2.86 KB
/
Context.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*****************************************************************//**
* \file Context.h
* \brief Directly Musical Data Access library for VST3 with JUCE.
*
* \author WuChang
* \email 31423836@qq.com
* \date Jan 2024
* \version 1.2.3
* \license MIT License
*********************************************************************/
#pragma once
#include <JuceHeader.h>
namespace DMDA {
/**
* The base class of all DMDA context types.
*
* You can inherit this to create your own context types.
*/
class DMDA_API Context {
public:
Context() = default;
virtual ~Context();
public:
/**
* The base class of context listeners.
*
* You can inhert this in DMDA host then pass the object pointer
* to Context::addListener() method to listen the change of the context.
*/
class DMDA_API Listener {
public:
virtual ~Listener() = default;
protected:
friend class Context;
/**
* This will be invoked when the DMDA plugin closed.
*/
virtual void closed(Context*) {};
/**
* This will be invoked when the Context::sendDataChanged() has been called.
*/
virtual void dataChanged(Context*) {};
/**
* This will be invoked with the state code
* when the Context::sendStateChanged() has been called.
*/
virtual void stateChanged(Context*, int32_t) {};
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Listener)
};
/**
* Add a listener to the context in DMDA host.
*
* You should ensure the listener object won't be deleted
* before the plugin instance closed.
* Or you can call removeListener() method before delete the listener object.
*/
void addListener(Listener* listener);
/**
* Remove a listener from the context in DMDA host.
*/
void removeListener(Listener* listener);
/**
* Remove all listeners added to the context in DMDA host.
*/
void removeAllListeners();
public:
/**
* For internal use.
*/
void sendClosed() const;
/**
* Send data changed signal to DMDA host in the plugin.
*
* This will invoke the Listener::dataChanged() method.
*/
void sendDataChanged() const;
/**
* Send state changed signal to DMDA host in the plugin.
*
* This will invoke the Listener::stateChanged() method.
*/
void sendStateChanged(int32_t state) const;
public:
/**
* Call this in the DMDA host to hand shake with the plugin.
*/
void handShake();
/**
* Call this in the DMDA host to hand wave with the plugin..
*/
void handWave();
/**
* Check the hand shake state.
*/
bool isHandShaked() const;
protected:
/**
* This will be invoked when the hand shake state has been changed.
*/
virtual void handShakedStateChanged() {};
private:
juce::Array<Listener*, juce::CriticalSection> listeners;
std::atomic_bool handShaked = false;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Context)
};
}