-
Notifications
You must be signed in to change notification settings - Fork 3
/
Player.h
119 lines (93 loc) · 1.91 KB
/
Player.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
#pragma once
class Player
{
public:
struct PlayerCue
{
float time;
uint8_t group;
uint8_t page;
uint8_t mode;
uint8_t lfo[4];
uint8_t intensity;
uint8_t h;
uint8_t s;
uint8_t v;
uint8_t speed;
uint8_t density;
uint8_t palette;
};
bool isPlaying;
bool isPaused;
bool loopAtFinish;
long timeAtPlay; //ms
long totalTime;
long currentTime;
long lastTime;
int currentCue;
int numCues;
void init()
{
loopAtFinish = false;
currentTime = 0;
currentCue = -1;
DBG("Player init.");
}
void update()
{
lastTime = millis();
if (!isPlaying) return;
if (isPlaying) currentTime += millis() - lastTime;
if(currentTime >= totalTime)
{
DBG("Finished !");
if(loopAtFinish)
{
DBG("Loop.");
currentTime = 0;
}else
{
DBG("Stop.");
stop();
}
}
}
void play(String filename)
{
File file = FileManager::openFile(filename);
DBG("File opened : "+String(file.name())+", size : "+String(file.size())+" bytes");
/*
totalTime = doc["totalTime"];
numCues = doc["cues"].size();
for(int i=0;i<numCues;i++)
{
cues[i].time = doc["cues"][i]["time"];
}
DBG("File total time : "+String(totalTime));
*/
currentTime = 0;
currentCue = -1;
isPlaying = true;
isPaused = false;
}
void stop()
{
isPlaying = false;
isPaused = false;
currentTime = 0;
}
void pause()
{
if (!isPlaying) return;
isPaused = true;
}
void seek(float toTime)
{
currentTime = toTime * 1000;
}
void resume()
{
isPlaying = true;
isPaused = false;
}
};