From 1c819b3b414753a71765562be8967b8a8b1a3f76 Mon Sep 17 00:00:00 2001 From: Bob van Loosen Date: Wed, 19 Dec 2012 23:29:41 +0100 Subject: [PATCH] fixed: reset scroll offset when song changed --- src/bitvis.cpp | 6 +++++- src/mpdclient.cpp | 15 ++++++++++++--- src/mpdclient.h | 3 ++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/bitvis.cpp b/src/bitvis.cpp index 43bfea8..423d60d 100644 --- a/src/bitvis.cpp +++ b/src/bitvis.cpp @@ -334,7 +334,11 @@ void CBitVis::SendData(int64_t time) //add an empty line data.SetData(text, m_nrcolumns / 4, true); - SetText(text, m_mpdclient->CurrentSong().c_str()); + string currentsong; + if (m_mpdclient->CurrentSong(currentsong)) + m_scrolloffset = m_nrcolumns; + + SetText(text, currentsong.c_str()); data.SetData(text, sizeof(text), true); uint8_t end[10]; diff --git a/src/mpdclient.cpp b/src/mpdclient.cpp index 85697ce..bbb47ae 100644 --- a/src/mpdclient.cpp +++ b/src/mpdclient.cpp @@ -105,7 +105,13 @@ bool CMpdClient::GetCurrentSong() if (!artist.empty() && !title.empty()) { - m_currentsong = artist + " - " + title; + string song = artist + " - " + title; + CLock lock(m_condition); + if (song != m_currentsong) + { + m_currentsong = song; + m_songchanged = true; + } return true; } } @@ -114,9 +120,12 @@ bool CMpdClient::GetCurrentSong() return false; } -std::string CMpdClient::CurrentSong() +bool CMpdClient::CurrentSong(std::string& song) { CLock lock(m_condition); - return m_currentsong; + song = m_currentsong; + bool songchanged = m_songchanged; + m_songchanged = false; + return songchanged; } diff --git a/src/mpdclient.h b/src/mpdclient.h index b9df02d..9481fb1 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -15,7 +15,7 @@ class CMpdClient : public CThread ~CMpdClient(); virtual void Process(); - std::string CurrentSong(); + bool CurrentSong(std::string& song); private: bool OpenSocket(); @@ -26,6 +26,7 @@ class CMpdClient : public CThread CTcpClientSocket m_socket; CCondition m_condition; std::string m_currentsong; + bool m_songchanged; };