--- a/upmpd/mpdcli.cxx
+++ b/upmpd/mpdcli.cxx
@@ -35,7 +35,7 @@
#define M_CONN ((struct mpd_connection *)m_conn)
MPDCli::MPDCli(const string& host, int port, const string& pass)
- : m_conn(0), m_premutevolume(0),
+ : m_conn(0), m_premutevolume(0), m_cachedvolume(50),
m_host(host), m_port(port), m_password(pass)
{
if (!openconn()) {
@@ -132,19 +132,28 @@
}
m_stat.volume = mpd_status_get_volume(mpds);
+ if (m_stat.volume >= 0) {
+ m_cachedvolume = m_stat.volume;
+ } else {
+ m_stat.volume = m_cachedvolume;
+ }
+
m_stat.rept = mpd_status_get_repeat(mpds);
m_stat.random = mpd_status_get_random(mpds);
m_stat.single = mpd_status_get_single(mpds);
m_stat.consume = mpd_status_get_consume(mpds);
m_stat.qlen = mpd_status_get_queue_length(mpds);
m_stat.qvers = mpd_status_get_queue_version(mpds);
+
switch (mpd_status_get_state(mpds)) {
- case MPD_STATE_UNKNOWN: m_stat.state = MpdStatus::MPDS_UNK;break;
case MPD_STATE_STOP: m_stat.state = MpdStatus::MPDS_STOP;break;
case MPD_STATE_PLAY: m_stat.state = MpdStatus::MPDS_PLAY;break;
case MPD_STATE_PAUSE: m_stat.state = MpdStatus::MPDS_PAUSE;break;
- }
-
+ case MPD_STATE_UNKNOWN:
+ default:
+ m_stat.state = MpdStatus::MPDS_UNK;
+ break;
+ }
m_stat.crossfade = mpd_status_get_crossfade(mpds);
m_stat.mixrampdb = mpd_status_get_mixrampdb(mpds);
@@ -224,7 +233,7 @@
}
// MPD does not want to set the volume if not active.
- if (!(m_stat.state== MpdStatus::MPDS_PLAY) &&
+ if (!(m_stat.state == MpdStatus::MPDS_PLAY) &&
!(m_stat.state == MpdStatus::MPDS_PAUSE)) {
LOGINF("MPDCli::setVolume: not active" << endl);
return true;
@@ -238,10 +247,10 @@
LOGDEB("MPDCli::setVolume: restoring premute " << m_premutevolume
<< endl);
volume = m_stat.volume = m_premutevolume;
+ m_premutevolume = 0;
} else {
- if (m_stat.volume != 0) {
- cerr << "Saving premute: " << m_stat.volume << endl;
- m_premutevolume = m_stat.volume;
+ if (m_cachedvolume > 0) {
+ m_premutevolume = m_cachedvolume;
}
}
}
@@ -253,12 +262,13 @@
RETRY_CMD(mpd_run_set_volume(M_CONN, volume));
m_stat.volume = volume;
+ m_cachedvolume = volume;
return true;
}
int MPDCli::getVolume()
{
- return m_stat.volume == -1 ? 0: m_stat.volume;
+ return m_stat.volume >= 0 ? m_stat.volume : m_cachedvolume;
}
bool MPDCli::togglePause()