-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDL_playlist.h
108 lines (87 loc) · 2.58 KB
/
SDL_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
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
#ifndef SDL_PLAYLIST_H_
#define SDL_PLAYLIST_H_
#include <iostream>
#include <string>
#include <map>
#include <SDL_mixer.h>
struct SDL_playlist_files {
std::string Directory;
std::string Pattern;
std::string Path() {
return Directory + Pattern;
}
};
struct SDL_playlist_options {
int FadeTime = 1000;
SDL_playlist_files Files;
bool Shuffle = true;
//TODO
// OnSongChange - bool callback to determine if song change should continue
// OnShuffle - bool callback to determine if shuffle should continue
// OnStatusChange - callback that is passed the new status
};
struct SDL_playlist_track {
Mix_Music* Stream = NULL;
std::string Title = "Unknown Title";
std::string Author = "Unknown Author";
std::string Path;
SDL_playlist_track(std::string filename) : Details(this) {
Path = filename;
}
~SDL_playlist_track() {
Unload();
}
void Load() {
if (!Stream) {
Stream = Mix_LoadMUS(Path.c_str());
if (!Stream) {
std::cerr << "Could not load music file \"" << Path << "\": " << Mix_GetError() << std::endl;
}
}
}
void Unload() {
if (Stream) {
Mix_FreeMusic(Stream);
Stream = NULL;
}
}
struct Details {
SDL_playlist_track* parent;
Details(SDL_playlist_track* parent) : parent(parent) {}
std::string Text() { return parent->Title + " - " + parent->Author + " (" + parent->Path + ")"; }
// TODO option to render text to a renderer
};
// Expose inner structs
Details Details;
};
enum SDL_playlist_status {
Loading,
Playing,
Paused,
Stopped
};
class SDL_playlist {
private:
static SDL_playlist_options mOptions;
static std::map<unsigned, SDL_playlist_track*> mTracks;
static SDL_playlist_status mStatus;
static unsigned mCurrentTrack;
static Uint32 mSongStart;
static void mPlay();
static void mSongEnd();
static void mSetStatus(SDL_playlist_status status);
public:
static void Initialize(SDL_playlist_options options);
static void Destroy();
static void Start();
static void Pause();
static void Resume();
static void Stop();
static void TogglePause();
static void Next();
static void Prev();
static void Shuffle();
static SDL_playlist_track* CurrentTrack() { return mTracks[mCurrentTrack]; }
static SDL_playlist_status Status() { return mStatus; }
};
#endif;