-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpd.cpp
97 lines (73 loc) · 2.54 KB
/
mpd.cpp
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
/* global function definitions */
bool initMpd() {
mpd = &_mpd;
mpd->update(MPD_TAG_UNKNOWN, "");
return true;
}
bool loopMpd()
{ return true; }
void termMpd() {
}
/* main functions */
Mpd::Mpd(): mode(MODE_NORMAL), limit(false) {
conn = mpd_connection_new(NULL, 0, 30000);
}
Mpd::~Mpd() {
/* */
}
void Mpd::err()
{ /* */ }
bool Mpd::isErr()
{ return errStatus; }
/* music functions */
/* album functions */
/* filter functions */
/* grid functions */
/* mpd functions */
bool Mpd::update(mpd_tag_type type, const char *value) {
mpd_pair *pair;
album.clear();
if (!mpd_search_db_tags(conn, MPD_TAG_ALBUM)) { err(); return false; }
if (strcmp(value, "") != 0)
if (!mpd_search_add_tag_constraint(conn, MPD_OPERATOR_DEFAULT, type, value)) { err(); return false; }
if (!mpd_search_commit(conn)) { err(); return false; }
while ((pair = mpd_recv_pair_tag(conn, MPD_TAG_ALBUM)) != NULL) {
album.push_back(Album(pair->value));
mpd_return_pair(conn, pair);
}
if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { err(); return false; }
if (!mpd_response_finish(conn)) { err(); return false; }
cout << "Successful Update" << endl;
for (std::vector<Album>::iterator i = album.begin(); i != album.end(); ++i)
i->buildTags();
sys->sortAlbums(MPD_TAG_UNKNOWN);
for (std::vector<Album>::iterator i = album.begin(); i != album.end(); ++i)
i->build();
return true;
}
std::string Mpd::getTag(const char *_album, mpd_tag_type type) {
std::string tagRet = "";
mpd_song *song;
if (!mpd_search_db_songs(conn, false)) { err(); return NULL; }
if (!mpd_search_add_tag_constraint(conn, MPD_OPERATOR_DEFAULT, MPD_TAG_ALBUM, _album)) { err(); return NULL; }
if (!mpd_search_commit(conn)) { err(); return NULL; }
if (type == MPD_TAG_UNKNOWN) {
if ((song = mpd_recv_song(conn)) != NULL) {
if (mpd_song_get_uri(song) != NULL)
tagRet = mpd_song_get_uri(song);
else
tagRet = "";
}
} else if ((song = mpd_recv_song(conn)) != NULL) {
if (mpd_song_get_tag(song, type, 0) != NULL)
tagRet = mpd_song_get_tag(song, type, 0);
else
tagRet = "";
}
mpd_song_free(song);
if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { err(); return NULL; }
if (!mpd_response_finish(conn)) { err(); return NULL; }
return tagRet;
}
std::string Mpd::getDir(std::string _album)
{ return getTag(_album.c_str(), MPD_TAG_UNKNOWN); }