forked from xLightsSequencer/xLights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyncManager.h
118 lines (102 loc) · 3.63 KB
/
SyncManager.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
#pragma once
/***************************************************************
* This source files comes from the xLights project
* https://www.xlights.org
* https://github.com/smeighan/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/smeighan/xLights/blob/master/License.txt
**************************************************************/
#include <list>
#include <memory>
#include <string>
class ScheduleOptions;
class ScheduleManager;
enum class TIMECODEFORMAT
{
F24,
F25,
F2997,
F30
};
// These are or-ed together
enum class SYNCMODE
{
STANDALONE = 0,
FPPBROADCASTMASTER = 1,
FPPUNICASTMASTER = 2,
ARTNETMASTER = 4,
OSCMASTER = 8,
MIDIMASTER = 16,
FPPMULTICASTMASTER = 32,
FPPUNICASTCSVMASTER = 64,
SMPTEMASTER = 128 // not currently useable
};
enum class REMOTEMODE
{
DISABLED,
FPPBROADCASTSLAVE,
FPPUNICASTSLAVE,
ARTNETSLAVE,
OSCSLAVE,
MIDISLAVE,
FPPSLAVE,
FPPCSVSLAVE,
SMPTESLAVE
};
class SyncBase
{
protected:
bool _supportsStepMMSSFormat = false;
uint32_t _ms = 0;
std::string _song = "";
SYNCMODE _mode = SYNCMODE::STANDALONE;
REMOTEMODE _remoteMode = REMOTEMODE::DISABLED;
bool _useStepMMSSFormat = false;
uint32_t GetHours(uint32_t ms, uint32_t step) const {
if (_useStepMMSSFormat && _supportsStepMMSSFormat) {
return step;
}
return ms / 3600000;
}
uint32_t GetMinutes(uint32_t ms) const { return (ms % 3600000) / 60000; }
uint32_t GetSeconds(uint32_t ms) const { return (ms % 60000) / 1000; }
public:
SyncBase(SYNCMODE mode, REMOTEMODE remoteMode, const ScheduleOptions& options);
virtual ~SyncBase() {}
virtual void 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 = 0;
virtual std::string GetType() const = 0;
virtual void SendStop() const = 0;
uint32_t GetMS() const { return _ms; }
std::string GetSong() const { return _song; }
bool IsMode(SYNCMODE mode) const { return _mode == mode; }
bool IsRemoteMode(REMOTEMODE mode) const { return _remoteMode == mode; }
virtual bool IsReactive() const { return true; }
};
class SyncManager
{
std::list<std::unique_ptr<SyncBase>> _masters;
std::unique_ptr<SyncBase> _remote = nullptr;
ScheduleManager* _scheduleManager = nullptr;
std::unique_ptr<SyncBase> CreateSync(SYNCMODE sm, REMOTEMODE rm) const;
public:
SyncManager(ScheduleManager* scheduleManager);
virtual ~SyncManager() {
_remote = nullptr;
ClearMasters();
}
void AddMaster(SYNCMODE sm);
void RemoveMaster(SYNCMODE sm);
void SetRemote(REMOTEMODE rm);
void ClearRemote();
void ClearMasters();
void 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; // send out to all masters
void Start(int mode, REMOTEMODE remoteMode, const std::string& localIP);
void Stop(const std::string& localIP);
bool IsSlave() const { return _remote != nullptr; }
bool IsTimecodeSlave() const;
bool IsFPPRemoteOrMaster() const;
bool IsMaster(SYNCMODE mode) const;
void SendStop() const;
};