forked from xfjx/TonUINO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerMode.h
131 lines (113 loc) · 2.86 KB
/
PlayerMode.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
#ifndef PLAYER_MODE_H
#define PLAYER_MODE_H
#include "Tonuino.h"
#include <DFMiniMp3.h>
/*
* Player modes.
* The are presented in audio menu with names starting from mp3/0311_*.mp3.
*/
// No mode configured (invalid)
#define MODE_INVALID 0
// Random mode: Play random track from folder
#define MODE_RANDOM 1
// Album mode: Play complete folder in numbered order
#define MODE_ALBUM 2
// Hörbuch mode: Play complete folder and save position
#define MODE_AUDIO_BOOK 3
// Admin mode: Admin functions
#define MODE_ADMIN_MENU 4
#define MODE_ADMIN 255
/**
* Active player mode.
*/
class PlayerMode;
PlayerMode* activeMode = NULL;
/**
* Player Mode.
*/
class PlayerMode {
public:
PlayerMode(uint16_t num_tracks) : n_tracks(num_tracks), curr_track(1) {};
virtual ~PlayerMode() {};
virtual bool handleNextTrack() = 0;
virtual bool handlePreviousTrack() = 0;
virtual bool handlePlay() = 0;
virtual bool handleStop() = 0;
/* Object members */
uint16_t n_tracks;
uint8_t curr_track;
/* Class member functions for MP3 event handling */
static void OnError(DfMp3& mp3, uint16_t errorCode) {
// see DfMp3_Error for code meaning
DEBUG_PRINT("COM error: ");
DEBUG_PRINTLN(errorCode);
return;
}
static void OnPlayFinished(DfMp3& mp3, DfMp3_PlaySources source, uint16_t track) {
PrintlnSourceAction(source, "finished playing");
if (activeMode) activeMode->handleNextTrack();
}
static void OnPlaySourceOnline(DfMp3& mp3, DfMp3_PlaySources source) {
PrintlnSourceAction(source, "online");
}
static void OnPlaySourceInserted(DfMp3& mp3, DfMp3_PlaySources source) {
PrintlnSourceAction(source, "ready");
}
static void OnPlaySourceRemoved(DfMp3& mp3, DfMp3_PlaySources source) {
PrintlnSourceAction(source, "removed");
}
private:
/* Class helper function for debugging */
static void PrintlnSourceAction(DfMp3_PlaySources source, const char *action) {
if (source & DfMp3_PlaySources_Sd) {
DEBUG_PRINT("SD card ");
} else {
DEBUG_PRINT("Unsupported source ");
}
DEBUG_PRINTLN(action);
}
};
/**
* AlbumMode.
*/
class AlbumMode: public PlayerMode {
public:
AlbumMode(uint16_t num_tracks) : PlayerMode(num_tracks) {}
~AlbumMode() {};
bool handleNextTrack();
bool handlePreviousTrack();
bool handlePlay();
bool handleStop();
};
/**
* AudiobookMode.
*/
class AudiobookMode: public PlayerMode {
public:
AudiobookMode(uint16_t num_tracks) : PlayerMode(num_tracks) {}
~AudiobookMode() {};
bool handleNextTrack();
bool handlePreviousTrack();
bool handlePlay();
bool handleStop();
};
/**
* RandomMode.
*/
class RandomMode: public PlayerMode {
public:
RandomMode(uint16_t num_tracks) : PlayerMode(num_tracks) {
this->queue = new byte[num_tracks];
}
~RandomMode() {
delete this->queue;
};
bool handleNextTrack();
bool handlePreviousTrack();
bool handlePlay();
bool handleStop();
private:
byte* queue;
void shuffleQueue();
};
#endif // PLAYER_MODE_H