-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayList.h
65 lines (57 loc) · 1.41 KB
/
playList.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
#ifndef __PLAYLIST_H
#define __PLAYLIST_H
#include <Arduino.h>
#include <vector>
#include "presets.h"
#define PLAYLIST_MAX_ITEMS 100
enum streamType { HTTP_FILE,
HTTP_STREAM,
HTTP_FAVORITE,
HTTP_PRESET,
SDCARD_FILE };
static const char* typeStr[] = { "FILE", "STREAM", "FAVO", "PRESET", "SDCARD" };
struct playListItem {
streamType type;
String name;
String url;
uint32_t index;
};
class playList_t {
public:
playList_t() {
ESP_LOGD(TAG, "allocating %i items", PLAYLIST_MAX_ITEMS);
list.reserve(PLAYLIST_MAX_ITEMS);
}
~playList_t() {
list.clear();
}
int size() {
return list.size();
}
bool isUpdated{ false };
void get(const uint32_t index, playListItem& item) {
item = (index < list.size()) ? list[index] : (playListItem){};
}
void add(const playListItem& item) {
if (list.size() < PLAYLIST_MAX_ITEMS) {
list.push_back(item);
isUpdated = true;
}
}
void remove(const uint32_t index) {
if (list.size() > index) {
list.erase(list.begin() + index);
isUpdated = true;
}
}
void clear() {
if (list.size()) {
list.clear();
isUpdated = true;
}
}
String& toString(String& s);
private:
std::vector<playListItem> list;
};
#endif