-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPlaylist_Static.h
266 lines (202 loc) · 6.1 KB
/
Playlist_Static.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
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
266
#ifndef Platlist_Static_H
#define Platlist_Static_H
//#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
//#include "Vector.h"
//#include "Boid.h"
//#include "Attractor.h"
// these are work in progress
#include "PatternStatic_A_Worms.h"
#include "PatternStatic_M_SpiralLines.h"
#include "PatternStatic_M_Flock.h"
#include "PatternStatic_M_FlowField.h"
#include "PatternStatic_M_Attract.h"
#include "PatternStatic_M_Bounce.h"
#include "PatternStatic_X_Atom.h"
#include "PatternStatic_X_SimpleStars.h"
#include "PatternStatic_X_Swirl.h"
// theses are all just proof of concept from aurora demo,
#include "PatternTest.h"
#include "PatternXIncrementalDrift.h"
#include "PatternXSpiro.h"
#include "PatternXSpin.h"
#include "PatternXRadar.h"
#include "PatternXWave.h"
#include "PatternStatic_X_SpiralingCurves.h"
//#include "PatternStatic_L_LianLi120.h"
class Platlist_Static : public Playlist {
private:
PatternStaticWorms staticWorms;
PatternStaticSimpleStars staticSimpleStars;
PatternStaticAtom staticAtom;
PatternTest patternTest;
PatternSpiralLines spiralLines;
PatternIncrementalDrift incrementalDrift;
PatternFlock flock;
PatternFlowField flowField;
PatternSpiro spiro;
PatternAttract attract;
PatternSpin spin;
PatternStaticBounce staticBounce;
PatternRadar radar;
PatternWave wave;
PatternStaticSpiralingCurves spiralingCurves;
PatternStaticSwirl staticSwirl;
//PatternStaticLianLi120 staticLianLi;
int currentIndex = 0;
Drawable* currentItem;
int getCurrentIndex() {
return currentIndex;
}
const static int PATTERN_COUNT = 12;
Drawable* shuffledItems[PATTERN_COUNT];
Drawable* items[PATTERN_COUNT] = {
//&staticLianLi,
&staticWorms,
&spiralLines, // spiraling lines
&flock,
&attract,
&flowField,
&staticBounce,
&spiralingCurves,
&staticSwirl,
&radar,
&wave,
&incrementalDrift,
&spiro,
//&staticSimpleStars, // don't work
//&staticAtom, // don't work
//&spin, // BAD freezes randomly
//&patternTest,
};
public:
Platlist_Static() {
// add the items to the shuffledItems array
for (int a = 0; a < PATTERN_COUNT; a++) {
shuffledItems[a] = items[a];
}
shuffleItems();
this->currentItem = items[0];
for (int i=0; i < maxPlaylistsStatic; i++)
{
this->currentItem->start(i);
}
}
//char* Drawable::name = (char *)"Patterns";
// Auroradrop:
// Auroradrop:
char* getItemName(int _id) {
return items[_id]->name;
}
int getPatternCount() {
return PATTERN_COUNT;
}
bool getItemEnabled(int _id) {
return items[_id]->isEnabled();
}
void setItemEnabled(int _id, int value) {
//items[_id]->enabled == (bool)value;
items[_id]->setEnabled((bool)value);
Serial.print("pattern id "); Serial.print(id); Serial.print(" changed to "); Serial.println(value);
}
bool getCurrentItemEnabled() {
return this->currentItem->isEnabled();
}
// Auroradrop:
// Auroradrop:
void stop() {
if (currentItem)
currentItem->stop();
}
void start(uint8_t _pattern) {
if (currentItem)
currentItem->start(_pattern);
}
void move(int step, uint8_t _pattern) {
currentIndex += step;
if (currentIndex >= PATTERN_COUNT) currentIndex = 0;
else if (currentIndex < 0) currentIndex = PATTERN_COUNT - 1;
if (effects.paletteIndex == effects.RandomPaletteIndex)
effects.RandomPalette();
moveTo(currentIndex, _pattern);
//if (!isTimeAvailable && currentItem == &analogClock)
// move(step);
}
void moveRandom(int step, uint8_t _pattern) {
currentIndex += step;
if (currentIndex >= PATTERN_COUNT) currentIndex = 0;
else if (currentIndex < 0) currentIndex = PATTERN_COUNT - 1;
if (effects.paletteIndex == effects.RandomPaletteIndex)
effects.RandomPalette();
if (currentItem)
currentItem->stop();
currentItem = shuffledItems[currentIndex];
if (currentItem)
currentItem->start(_pattern);
// if (!isTimeAvailable && currentItem == &analogClock)
// moveRandom(step);
}
void shuffleItems() {
//return; // TEMP
for (int a = 0; a < PATTERN_COUNT; a++)
{
int r = random(a, PATTERN_COUNT);
Drawable* temp = shuffledItems[a];
shuffledItems[a] = shuffledItems[r];
shuffledItems[r] = temp;
}
}
unsigned int drawFrame(uint8_t _pattern, uint8_t _total) {
return currentItem->drawFrame(_pattern, _total);
}
void listPatterns() {
Serial.println(F("{"));
Serial.print(F(" \"count\": "));
Serial.print(PATTERN_COUNT);
Serial.println(",");
Serial.println(F(" \"results\": ["));
for (int i = 0; i < PATTERN_COUNT; i++) {
Serial.print(F(" \""));
Serial.print(i, DEC);
Serial.print(F(": "));
Serial.print(items[i]->name);
if (i == PATTERN_COUNT - 1)
Serial.println(F("\""));
else
Serial.println(F("\","));
}
Serial.println(" ]");
Serial.println("}");
}
char * getCurrentPatternName()
{
return currentItem->name;
}
char * getCurrentPatternId()
{
return currentItem->id;
}
void moveTo(int index, uint8_t _pattern) {
if (currentItem)
currentItem->stop();
currentIndex = index;
currentItem = items[currentIndex];
if (currentItem)
currentItem->start(_pattern);
}
bool setPattern(String name, uint8_t _pattern) {
for (int i = 0; i < PATTERN_COUNT; i++) {
if (name.compareTo(items[i]->name) == 0) {
moveTo(i, _pattern);
return true;
}
}
return false;
}
bool setPattern(int index, uint8_t _pattern) {
if (index >= PATTERN_COUNT || index < 0)
return false;
moveTo(index, _pattern);
return true;
}
};
#endif