diff --git a/include/adapters/mpd.hpp b/include/adapters/mpd.hpp index e3dcb79b..aac390d5 100644 --- a/include/adapters/mpd.hpp +++ b/include/adapters/mpd.hpp @@ -139,6 +139,7 @@ namespace mpd { bool match_state(mpdstate state) const; int get_songid() const; + int get_queuelen() const; unsigned get_total_time() const; unsigned get_elapsed_time() const; unsigned get_elapsed_percentage(); @@ -157,6 +158,7 @@ namespace mpd { bool m_single = false; int m_songid; + int m_queuelen; unsigned long m_total_time; unsigned long m_elapsed_time; diff --git a/include/modules/mpd.hpp b/include/modules/mpd.hpp index c5d242b9..c7309484 100644 --- a/include/modules/mpd.hpp +++ b/include/modules/mpd.hpp @@ -25,14 +25,12 @@ namespace modules { bool has_event(); bool update(); string get_format() const; + string get_output(); bool build(builder* builder, string tag) const; bool handle_event(string cmd); bool receive_events() const; private: - // static const int PROGRESSBAR_THREAD_SYNC_COUNT = 10; - // const chrono::duration PROGRESSBAR_THREAD_INTERVAL = 1s; - static constexpr auto FORMAT_ONLINE = "format-online"; static constexpr auto TAG_BAR_PROGRESS = ""; static constexpr auto TAG_TOGGLE = ""; diff --git a/src/adapters/mpd.cpp b/src/adapters/mpd.cpp index c18901cf..d9312b92 100644 --- a/src/adapters/mpd.cpp +++ b/src/adapters/mpd.cpp @@ -315,6 +315,7 @@ namespace mpd { m_status.reset(mpd_run_status(*conn)); m_updated_at = chrono::system_clock::now(); m_songid = mpd_status_get_song_id(m_status.get()); + m_queuelen = mpd_status_get_queue_length(m_status.get()); m_random = mpd_status_get_random(m_status.get()); m_repeat = mpd_status_get_repeat(m_status.get()); m_single = mpd_status_get_single(m_status.get()); @@ -323,7 +324,7 @@ namespace mpd { } void mpdstatus::update(int event, mpdconnection* connection) { - if (connection == nullptr || (event & (MPD_IDLE_PLAYER | MPD_IDLE_OPTIONS)) == false) + if (connection == nullptr || (event & (MPD_IDLE_PLAYER | MPD_IDLE_OPTIONS | MPD_IDLE_PLAYLIST)) == false) return; fetch_data(connection); @@ -375,6 +376,10 @@ namespace mpd { return m_songid; } + int mpdstatus::get_queuelen() const { + return m_queuelen; + } + unsigned mpdstatus::get_total_time() const { return m_total_time; } diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp index 53e35608..777ae8d8 100644 --- a/src/modules/mpd.cpp +++ b/src/modules/mpd.cpp @@ -215,6 +215,15 @@ namespace modules { return connected() ? FORMAT_ONLINE : FORMAT_OFFLINE; } + string mpd_module::get_output() { + if (m_status && m_status->get_queuelen() == 0) { + m_log.info("%s: Hiding module since queue is empty", name()); + return ""; + } else { + return event_module::get_output(); + } + } + bool mpd_module::build(builder* builder, string tag) const { bool is_playing = false; bool is_paused = false;