forked from xLightsSequencer/xLights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyncManager.cpp
265 lines (235 loc) · 8.35 KB
/
SyncManager.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/***************************************************************
* This source files comes from the xLights project
* https://www.xlights.org
* https://github.com/xLightsSequencer/xLights
* See the github commit history for a record of contributing
* developers.
* Copyright claimed based on commit dates recorded in Github
* License: https://github.com/xLightsSequencer/xLights/blob/master/License.txt
**************************************************************/
#include "SyncManager.h"
#include "ScheduleOptions.h"
#include "ScheduleManager.h"
#include "events/ListenerManager.h"
#include "../xLights/UtilFunctions.h"
#include "SyncOSC.h"
#include "SyncFPP.h"
#include "SyncMIDI.h"
#include "SyncArtNet.h"
#include "SyncSMPTE.h"
#include <log4cpp/Category.hh>
std::unique_ptr<SyncBase> SyncManager::CreateSync(SYNCMODE sm, REMOTEMODE rm) const
{
wxASSERT(_scheduleManager != nullptr);
if (sm == SYNCMODE::OSCMASTER || rm == REMOTEMODE::OSCSLAVE)
{
return std::make_unique<SyncOSC>(SyncOSC(sm, rm, *_scheduleManager->GetOptions(), _scheduleManager->GetListenerManager(), _scheduleManager->GetForceLocalIP()));
}
else if (sm == SYNCMODE::ARTNETMASTER || rm == REMOTEMODE::ARTNETSLAVE)
{
return std::make_unique<SyncArtNet>(SyncArtNet(sm, rm, *_scheduleManager->GetOptions(), _scheduleManager->GetListenerManager(), _scheduleManager->GetForceLocalIP()));
}
else if (sm == SYNCMODE::FPPBROADCASTMASTER)
{
return std::make_unique<SyncBroadcastFPP>(SyncBroadcastFPP(sm, rm, *_scheduleManager->GetOptions(), _scheduleManager->GetListenerManager(), _scheduleManager->GetForceLocalIP()));
}
else if (sm == SYNCMODE::FPPUNICASTMASTER)
{
return std::make_unique<SyncUnicastFPP>(SyncUnicastFPP(sm, rm, *_scheduleManager->GetOptions(), _scheduleManager->GetListenerManager(), _scheduleManager->GetForceLocalIP()));
}
else if (sm == SYNCMODE::FPPUNICASTCSVMASTER || rm == REMOTEMODE::FPPCSVSLAVE)
{
return std::make_unique<SyncUnicastCSVFPP>(SyncUnicastCSVFPP(sm, rm, *_scheduleManager->GetOptions(), _scheduleManager->GetListenerManager(), _scheduleManager->GetForceLocalIP()));
}
else if (sm == SYNCMODE::FPPMULTICASTMASTER)
{
return std::make_unique<SyncMulticastFPP>(SyncMulticastFPP(sm, rm, *_scheduleManager->GetOptions(), _scheduleManager->GetListenerManager(), _scheduleManager->GetForceLocalIP()));
}
else if (rm == REMOTEMODE::FPPSLAVE || rm == REMOTEMODE::FPPBROADCASTSLAVE || rm == REMOTEMODE::FPPUNICASTSLAVE)
{
// really doesnt matter which FPP I create
return std::make_unique<SyncMulticastFPP>(SyncMulticastFPP(sm, REMOTEMODE::FPPSLAVE, *_scheduleManager->GetOptions(), _scheduleManager->GetListenerManager(), _scheduleManager->GetForceLocalIP()));
}
else if (sm == SYNCMODE::MIDIMASTER || rm == REMOTEMODE::MIDISLAVE)
{
return std::make_unique<SyncMIDI>(SyncMIDI(sm, rm, *_scheduleManager->GetOptions(), _scheduleManager->GetListenerManager()));
}
else if (rm == REMOTEMODE::SMPTESLAVE)
{
return std::make_unique<SyncSMPTE>(SyncSMPTE(sm, rm, *_scheduleManager->GetOptions(), _scheduleManager->GetListenerManager()));
}
else if (rm == REMOTEMODE::DISABLED){
return nullptr;
}
else
{
wxASSERT(false);
}
return nullptr;
}
SyncManager::SyncManager(ScheduleManager* scheduleManager) : _scheduleManager(scheduleManager) {
static log4cpp::Category& logger_base = log4cpp::Category::getInstance(std::string("log_base"));
if (scheduleManager == nullptr) {
logger_base.crit("SyncManager::SyncManager created with nullptr to scheduleManager ... this will not end well.");
}
else {
logger_base.debug("SyncManager::SyncManager created ok.");
}
}
void SyncManager::AddMaster(SYNCMODE sm)
{
RemoveMaster(sm);
_masters.emplace_back(std::move(CreateSync(sm, REMOTEMODE::DISABLED)));
}
void SyncManager::RemoveMaster(SYNCMODE sm)
{
for (auto it = begin(_masters); it != end(_masters); ++it)
{
if ((*it)->IsMode(sm))
{
_masters.erase(it);
return;
}
}
}
void SyncManager::SetRemote(REMOTEMODE rm)
{
_remote = CreateSync(SYNCMODE::STANDALONE, rm);
}
void SyncManager::ClearRemote()
{
if (_scheduleManager->GetListenerManager() != nullptr)
{
_scheduleManager->GetListenerManager()->SetRemoteNone();
}
_remote = nullptr;
}
void SyncManager::ClearMasters()
{
while (_masters.size() > 0)
{
_masters.remove(_masters.front());
}
}
void SyncManager::SendSync(uint32_t frameMS, uint32_t stepLengthMS, uint32_t stepMS, uint32_t playlistMS, const std::string& fseq, const std::string& media, const std::string& step, const std::string& timeItem, uint32_t stepno) const
{
for (auto& it : _masters)
{
if (it->IsReactive())
{
it->SendSync(frameMS, stepLengthMS, stepMS, playlistMS, fseq, media, step, timeItem, stepno);
}
}
}
void SyncManager::Start(int mode, REMOTEMODE remoteMode, const std::string& localIP)
{
if (mode & static_cast<int>(SYNCMODE::FPPBROADCASTMASTER)) {
AddMaster(SYNCMODE::FPPBROADCASTMASTER);
}
else {
RemoveMaster(SYNCMODE::FPPBROADCASTMASTER);
}
if (mode & static_cast<int>(SYNCMODE::FPPUNICASTMASTER)) {
AddMaster(SYNCMODE::FPPUNICASTMASTER);
}
else {
RemoveMaster(SYNCMODE::FPPUNICASTMASTER);
}
if (mode & static_cast<int>(SYNCMODE::FPPUNICASTCSVMASTER)) {
AddMaster(SYNCMODE::FPPUNICASTCSVMASTER);
}
else {
RemoveMaster(SYNCMODE::FPPUNICASTCSVMASTER);
}
if (mode & static_cast<int>(SYNCMODE::FPPMULTICASTMASTER)) {
AddMaster(SYNCMODE::FPPMULTICASTMASTER);
}
else {
RemoveMaster(SYNCMODE::FPPMULTICASTMASTER);
}
if (mode & static_cast<int>(SYNCMODE::OSCMASTER)) {
AddMaster(SYNCMODE::OSCMASTER);
}
else {
RemoveMaster(SYNCMODE::OSCMASTER);
}
if (mode & static_cast<int>(SYNCMODE::MIDIMASTER)) {
AddMaster(SYNCMODE::MIDIMASTER);
}
else {
RemoveMaster(SYNCMODE::MIDIMASTER);
}
if (mode & static_cast<int>(SYNCMODE::ARTNETMASTER)) {
AddMaster(SYNCMODE::ARTNETMASTER);
}
else {
RemoveMaster(SYNCMODE::ARTNETMASTER);
}
if (remoteMode == REMOTEMODE::MIDISLAVE) {
SetRemote(REMOTEMODE::MIDISLAVE);
}
else if (remoteMode == REMOTEMODE::FPPBROADCASTSLAVE) {
SetRemote(REMOTEMODE::FPPSLAVE);
}
else if (remoteMode == REMOTEMODE::OSCSLAVE) {
SetRemote(REMOTEMODE::OSCSLAVE);
}
else if (remoteMode == REMOTEMODE::FPPUNICASTSLAVE) {
SetRemote(REMOTEMODE::FPPSLAVE);
}
else if (remoteMode == REMOTEMODE::FPPCSVSLAVE) {
SetRemote(REMOTEMODE::FPPCSVSLAVE);
}
else if (remoteMode == REMOTEMODE::FPPSLAVE) {
SetRemote(REMOTEMODE::FPPSLAVE);
}
else if (remoteMode == REMOTEMODE::DISABLED) {
ClearRemote();
}
else if (remoteMode == REMOTEMODE::ARTNETSLAVE) {
SetRemote(REMOTEMODE::ARTNETSLAVE);
}
else if (remoteMode == REMOTEMODE::SMPTESLAVE) {
SetRemote(REMOTEMODE::SMPTESLAVE);
}
_scheduleManager->GetListenerManager()->StartListeners(localIP);
}
void SyncManager::Stop(const std::string& localIP)
{
SetRemote(REMOTEMODE::DISABLED);
ClearMasters();
_scheduleManager->GetListenerManager()->StartListeners(localIP);
}
bool SyncManager::IsTimecodeSlave() const
{
return _remote != nullptr && (_remote->IsRemoteMode(REMOTEMODE::ARTNETSLAVE) || _remote->IsRemoteMode(REMOTEMODE::OSCSLAVE) || _remote->IsRemoteMode(REMOTEMODE::MIDISLAVE) || _remote->IsRemoteMode(REMOTEMODE::SMPTESLAVE));
}
bool SyncManager::IsFPPRemoteOrMaster() const
{
if (_remote != nullptr && Contains(_remote->GetType(), "FPP")) { return true; }
for (auto& it : _masters)
{
if (Contains(it->GetType(), "FPP")) { return true; }
}
return false;
}
bool SyncManager::IsMaster(SYNCMODE mode) const
{
bool res = false;
for (auto& it: _masters)
{
res |= it->IsMode(mode);
}
return res;
}
void SyncManager::SendStop() const
{
for (auto& it : _masters)
{
it->SendStop();
}
}
SyncBase::SyncBase(SYNCMODE mode, REMOTEMODE remoteMode, const ScheduleOptions& options) : _mode(mode), _remoteMode(remoteMode)
{
_useStepMMSSFormat = options.IsUseStepMMSSTimecodeFormat();
}