-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrapper.cpp
More file actions
123 lines (101 loc) · 2.53 KB
/
wrapper.cpp
File metadata and controls
123 lines (101 loc) · 2.53 KB
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
#include "wrapper.h"
#include <assert.h>
#include <stdio.h>
#include <QString>
MPD::Connection Mpd;
MPD::Connection::Connection() :
itsConnection(0)
,itsHost("localhost")
,itsPort(6600)
,itsCurrentStatus(0)
,isIdle(0) { }
MPD::Connection::~Connection() {
if (itsConnection)
mpd_connection_free(itsConnection);
if (itsCurrentStatus)
mpd_status_free(itsCurrentStatus);
}
bool MPD::Connection::Connect() {
if (itsConnection)
return true;
itsConnection = mpd_connection_new(itsHost.c_str(), itsPort, 30000);
return true;
}
bool MPD::Connection::Connected() const {
return itsConnection;
}
void MPD::Connection::Disconnect() {
if (itsConnection)
mpd_connection_free(itsConnection);
if (itsCurrentStatus)
mpd_status_free(itsCurrentStatus);
itsConnection = 0;
itsCurrentStatus = 0;
isIdle = 0;
}
void MPD::Connection::Play() {
if (itsConnection) {
mpd_send_play(itsConnection);
mpd_recv_idle(itsConnection, 15000);
}
}
void MPD::Connection::Play(int pos) {
if (itsConnection) {
mpd_send_play_pos(itsConnection, pos);
mpd_recv_idle(itsConnection, 15000);
}
}
void MPD::Connection::PlayById(int id) {
if (itsConnection) {
mpd_send_play_pos(itsConnection, id);
mpd_recv_idle(itsConnection, 15000);
}
}
void MPD::Connection::Pause(bool state) {
if (itsConnection) {
mpd_send_pause(itsConnection, state);
mpd_recv_idle(itsConnection, 15000);
}
}
void MPD::Connection::Toggle() {
if (itsConnection) {
if (isPlaying()) {
mpd_run_toggle_pause(itsConnection);
mpd_recv_idle(itsConnection, 15000);
} else {
mpd_send_play(itsConnection);
mpd_recv_idle(itsConnection, 15000);
}
}
}
void MPD::Connection::Stop() {
if (itsConnection) {
mpd_send_stop(itsConnection);
mpd_recv_idle(itsConnection, 15000);
}
}
void MPD::Connection::Prev() {
if (itsConnection) {
mpd_send_previous(itsConnection);
mpd_recv_idle(itsConnection, 15000);
}
}
void MPD::Connection::Next() {
if (itsConnection) {
mpd_send_next(itsConnection);
mpd_recv_idle(itsConnection, 15000);
}
}
void MPD::Connection::GetDirectoryRecursive(const std::string &path, mpdSongList &v) {
if (!itsConnection)
return;
//mpd_send_list_all_meta(itsConnection, path.c_str());
mpd_send_list_queue_meta(itsConnection);
while (mpd_song *s = mpd_recv_song(itsConnection)) {
v.push_back(new Song(s));
}
mpd_response_finish(itsConnection);
}
void MPD::Connection::Delete(int pos) {
mpd_run_delete(itsConnection, pos);
}