|
a/upmpd/mpdcli.cxx |
|
b/upmpd/mpdcli.cxx |
|
... |
|
... |
33 |
using namespace std;
|
33 |
using namespace std;
|
34 |
|
34 |
|
35 |
#define M_CONN ((struct mpd_connection *)m_conn)
|
35 |
#define M_CONN ((struct mpd_connection *)m_conn)
|
36 |
|
36 |
|
37 |
MPDCli::MPDCli(const string& host, int port, const string& pass)
|
37 |
MPDCli::MPDCli(const string& host, int port, const string& pass)
|
38 |
: m_conn(0), m_premutevolume(0),
|
38 |
: m_conn(0), m_premutevolume(0), m_cachedvolume(50),
|
39 |
m_host(host), m_port(port), m_password(pass)
|
39 |
m_host(host), m_port(port), m_password(pass)
|
40 |
{
|
40 |
{
|
41 |
if (!openconn()) {
|
41 |
if (!openconn()) {
|
42 |
return;
|
42 |
return;
|
43 |
}
|
43 |
}
|
|
... |
|
... |
130 |
}
|
130 |
}
|
131 |
return false;
|
131 |
return false;
|
132 |
}
|
132 |
}
|
133 |
|
133 |
|
134 |
m_stat.volume = mpd_status_get_volume(mpds);
|
134 |
m_stat.volume = mpd_status_get_volume(mpds);
|
|
|
135 |
if (m_stat.volume >= 0) {
|
|
|
136 |
m_cachedvolume = m_stat.volume;
|
|
|
137 |
} else {
|
|
|
138 |
m_stat.volume = m_cachedvolume;
|
|
|
139 |
}
|
|
|
140 |
|
135 |
m_stat.rept = mpd_status_get_repeat(mpds);
|
141 |
m_stat.rept = mpd_status_get_repeat(mpds);
|
136 |
m_stat.random = mpd_status_get_random(mpds);
|
142 |
m_stat.random = mpd_status_get_random(mpds);
|
137 |
m_stat.single = mpd_status_get_single(mpds);
|
143 |
m_stat.single = mpd_status_get_single(mpds);
|
138 |
m_stat.consume = mpd_status_get_consume(mpds);
|
144 |
m_stat.consume = mpd_status_get_consume(mpds);
|
139 |
m_stat.qlen = mpd_status_get_queue_length(mpds);
|
145 |
m_stat.qlen = mpd_status_get_queue_length(mpds);
|
140 |
m_stat.qvers = mpd_status_get_queue_version(mpds);
|
146 |
m_stat.qvers = mpd_status_get_queue_version(mpds);
|
|
|
147 |
|
141 |
switch (mpd_status_get_state(mpds)) {
|
148 |
switch (mpd_status_get_state(mpds)) {
|
142 |
case MPD_STATE_UNKNOWN: m_stat.state = MpdStatus::MPDS_UNK;break;
|
|
|
143 |
case MPD_STATE_STOP: m_stat.state = MpdStatus::MPDS_STOP;break;
|
149 |
case MPD_STATE_STOP: m_stat.state = MpdStatus::MPDS_STOP;break;
|
144 |
case MPD_STATE_PLAY: m_stat.state = MpdStatus::MPDS_PLAY;break;
|
150 |
case MPD_STATE_PLAY: m_stat.state = MpdStatus::MPDS_PLAY;break;
|
145 |
case MPD_STATE_PAUSE: m_stat.state = MpdStatus::MPDS_PAUSE;break;
|
151 |
case MPD_STATE_PAUSE: m_stat.state = MpdStatus::MPDS_PAUSE;break;
|
|
|
152 |
case MPD_STATE_UNKNOWN:
|
|
|
153 |
default:
|
|
|
154 |
m_stat.state = MpdStatus::MPDS_UNK;
|
|
|
155 |
break;
|
146 |
}
|
156 |
}
|
147 |
|
|
|
148 |
|
157 |
|
149 |
m_stat.crossfade = mpd_status_get_crossfade(mpds);
|
158 |
m_stat.crossfade = mpd_status_get_crossfade(mpds);
|
150 |
m_stat.mixrampdb = mpd_status_get_mixrampdb(mpds);
|
159 |
m_stat.mixrampdb = mpd_status_get_mixrampdb(mpds);
|
151 |
m_stat.mixrampdelay = mpd_status_get_mixrampdelay(mpds);
|
160 |
m_stat.mixrampdelay = mpd_status_get_mixrampdelay(mpds);
|
152 |
m_stat.songpos = mpd_status_get_song_pos(mpds);
|
161 |
m_stat.songpos = mpd_status_get_song_pos(mpds);
|
|
... |
|
... |
222 |
if (!ok()) {
|
231 |
if (!ok()) {
|
223 |
return false;
|
232 |
return false;
|
224 |
}
|
233 |
}
|
225 |
|
234 |
|
226 |
// MPD does not want to set the volume if not active.
|
235 |
// MPD does not want to set the volume if not active.
|
227 |
if (!(m_stat.state== MpdStatus::MPDS_PLAY) &&
|
236 |
if (!(m_stat.state == MpdStatus::MPDS_PLAY) &&
|
228 |
!(m_stat.state == MpdStatus::MPDS_PAUSE)) {
|
237 |
!(m_stat.state == MpdStatus::MPDS_PAUSE)) {
|
229 |
LOGINF("MPDCli::setVolume: not active" << endl);
|
238 |
LOGINF("MPDCli::setVolume: not active" << endl);
|
230 |
return true;
|
239 |
return true;
|
231 |
}
|
240 |
}
|
232 |
|
241 |
|
|
... |
|
... |
236 |
if (volume) {
|
245 |
if (volume) {
|
237 |
// Restore premute volume
|
246 |
// Restore premute volume
|
238 |
LOGDEB("MPDCli::setVolume: restoring premute " << m_premutevolume
|
247 |
LOGDEB("MPDCli::setVolume: restoring premute " << m_premutevolume
|
239 |
<< endl);
|
248 |
<< endl);
|
240 |
volume = m_stat.volume = m_premutevolume;
|
249 |
volume = m_stat.volume = m_premutevolume;
|
|
|
250 |
m_premutevolume = 0;
|
241 |
} else {
|
251 |
} else {
|
242 |
if (m_stat.volume != 0) {
|
252 |
if (m_cachedvolume > 0) {
|
243 |
cerr << "Saving premute: " << m_stat.volume << endl;
|
|
|
244 |
m_premutevolume = m_stat.volume;
|
253 |
m_premutevolume = m_cachedvolume;
|
245 |
}
|
254 |
}
|
246 |
}
|
255 |
}
|
247 |
}
|
256 |
}
|
248 |
|
257 |
|
249 |
if (volume < 0)
|
258 |
if (volume < 0)
|
|
... |
|
... |
251 |
else if (volume > 100)
|
260 |
else if (volume > 100)
|
252 |
volume = 100;
|
261 |
volume = 100;
|
253 |
|
262 |
|
254 |
RETRY_CMD(mpd_run_set_volume(M_CONN, volume));
|
263 |
RETRY_CMD(mpd_run_set_volume(M_CONN, volume));
|
255 |
m_stat.volume = volume;
|
264 |
m_stat.volume = volume;
|
|
|
265 |
m_cachedvolume = volume;
|
256 |
return true;
|
266 |
return true;
|
257 |
}
|
267 |
}
|
258 |
|
268 |
|
259 |
int MPDCli::getVolume()
|
269 |
int MPDCli::getVolume()
|
260 |
{
|
270 |
{
|
261 |
return m_stat.volume == -1 ? 0: m_stat.volume;
|
271 |
return m_stat.volume >= 0 ? m_stat.volume : m_cachedvolume;
|
262 |
}
|
272 |
}
|
263 |
|
273 |
|
264 |
bool MPDCli::togglePause()
|
274 |
bool MPDCli::togglePause()
|
265 |
{
|
275 |
{
|
266 |
LOGDEB("MPDCli::togglePause" << endl);
|
276 |
LOGDEB("MPDCli::togglePause" << endl);
|