diff --git a/src/bitvis/bitvis.cpp b/src/bitvis/bitvis.cpp index d10eac1..3654631 100644 --- a/src/bitvis/bitvis.cpp +++ b/src/bitvis/bitvis.cpp @@ -64,6 +64,8 @@ CBitVis::CBitVis(int argc, char *argv[]) m_scrolloffset = 0; m_fontdisplay = 0; m_songupdatetime = GetTimeUs(); + m_volumetime = GetTimeUs(); + m_displayvolume = 0; const char* flags = "f:d:p:a:m:o:"; int c; @@ -375,7 +377,16 @@ void CBitVis::SendData(int64_t time) int nrlines; bool playingchanged; - if (m_mpdclient && m_mpdclient->IsPlaying(playingchanged)) + bool isplaying = false; + int volume = 0; + if (m_mpdclient) + { + isplaying = m_mpdclient->IsPlaying(playingchanged); + if (m_mpdclient->GetVolume(volume)) + m_volumetime = GetTimeUs(); + } + + if (isplaying) { if (m_fontdisplay < m_fontheight) m_fontdisplay++; @@ -390,40 +401,63 @@ void CBitVis::SendData(int64_t time) nrlines = m_nrlines - m_fontdisplay; } - for (int y = nrlines - 1; y >= 0; y--) + if (isplaying && GetTimeUs() - m_volumetime < 1000000) { - uint8_t line[m_nrcolumns / 4]; - for (int x = 0; x < m_nrcolumns / 4; x++) + for (int y = 0; y < nrlines; y++) { - uint8_t pixel = 0; - for (int i = 0; i < 4; i++) + uint8_t line[m_nrcolumns / 4]; + memset(line, 0, sizeof(line)); + int pixelcounter = 3; + for (int x = 0; x < m_nrcolumns; x++) { - int value = Round32(((log10(m_displaybuf[x * 4 + i]) * 20.0f) + 55.0f) / 48.0f * nrlines); - - peak& currpeak = m_peakholds[x * 4 + i]; - if (value >= Round32(currpeak.value)) - { - currpeak.value = value; - currpeak.time = time; - } - - pixel <<= 2; - - if (Round32(currpeak.value) == y || y == 0) - pixel |= 2; - else if (value > y) - pixel |= 1; - - if (time - currpeak.time > 500000 && Round32(currpeak.value) > 0) - { - currpeak.value += 0.01f; - if (currpeak.value >= nrlines) - currpeak.value = 0.0f; - } + if (y == nrlines - 1) + line[x / 4] |= 1 << (pixelcounter * 2 + 1); + else if (x < m_displayvolume) + line[x / 4] |= 1 << (pixelcounter * 2); + pixelcounter--; + if (pixelcounter == -1) + pixelcounter = 3; } - line[x] = pixel; + data.SetData(line, sizeof(line), true); + } + } + else + { + for (int y = nrlines - 1; y >= 0; y--) + { + uint8_t line[m_nrcolumns / 4]; + for (int x = 0; x < m_nrcolumns / 4; x++) + { + uint8_t pixel = 0; + for (int i = 0; i < 4; i++) + { + int value = Round32(((log10(m_displaybuf[x * 4 + i]) * 20.0f) + 55.0f) / 48.0f * nrlines); + + peak& currpeak = m_peakholds[x * 4 + i]; + if (value >= Round32(currpeak.value)) + { + currpeak.value = value; + currpeak.time = time; + } + + pixel <<= 2; + + if (Round32(currpeak.value) == y || y == 0) + pixel |= 2; + else if (value > y) + pixel |= 1; + + if (time - currpeak.time > 500000 && Round32(currpeak.value) > 0) + { + currpeak.value += 0.01f; + if (currpeak.value >= nrlines) + currpeak.value = 0.0f; + } + } + line[x] = pixel; + } + data.SetData(line, sizeof(line), true); } - data.SetData(line, sizeof(line), true); } uint8_t text[m_nrcolumns / 4 * m_fontheight]; @@ -453,6 +487,11 @@ void CBitVis::SendData(int64_t time) } m_debugwindow.DisplayFrame(data); + + if (volume > m_displayvolume) + m_displayvolume++; + else if (volume < m_displayvolume) + m_displayvolume--; } void CBitVis::SetText(uint8_t* buff, const char* str, int offset /*= 0*/) diff --git a/src/bitvis/bitvis.h b/src/bitvis/bitvis.h index 40d1ec7..96b0eb1 100644 --- a/src/bitvis/bitvis.h +++ b/src/bitvis/bitvis.h @@ -63,6 +63,8 @@ class CBitVis int m_scrolloffset; int64_t m_songupdatetime; CMpdClient* m_mpdclient; + int64_t m_volumetime; + int m_displayvolume; bool m_debug; int m_debugscale; diff --git a/src/bitvis/mpdclient.cpp b/src/bitvis/mpdclient.cpp index 413ac44..0d951f8 100644 --- a/src/bitvis/mpdclient.cpp +++ b/src/bitvis/mpdclient.cpp @@ -16,6 +16,8 @@ CMpdClient::CMpdClient(std::string address, int port) m_address = address; m_isplaying = false; m_playingchanged = false; + m_volume = 0; + m_volumechanged = false; } CMpdClient::~CMpdClient() @@ -39,7 +41,7 @@ void CMpdClient::Process() } else { - USleep(1000000); + USleep(30000); } } @@ -182,9 +184,19 @@ bool CMpdClient::GetPlayStatus() } else if (word == "volume:") { - if (GetWord(tmpline, word)) - if (word == "0") - muted = true; + int volume; + if (GetWord(tmpline, word) && StrToInt(word, volume)) + { + if (volume == 0) + volume = true; + + if (volume != m_volume) + { + CLock lock(m_condition); + m_volume = volume; + m_volumechanged = true; + } + } } } @@ -249,3 +261,12 @@ bool CMpdClient::IsPlaying(bool& playingchanged) m_playingchanged = false; return m_isplaying; } + +bool CMpdClient::GetVolume(int& volume) +{ + CLock lock(m_condition); + volume = m_volume; + bool changed = m_volumechanged; + m_volumechanged = false; + return changed; +} diff --git a/src/bitvis/mpdclient.h b/src/bitvis/mpdclient.h index 698a77c..53c7ce1 100644 --- a/src/bitvis/mpdclient.h +++ b/src/bitvis/mpdclient.h @@ -17,6 +17,7 @@ class CMpdClient : public CThread virtual void Process(); bool CurrentSong(std::string& song); bool IsPlaying(bool& playingchanged); + bool GetVolume(int& volume); private: bool OpenSocket(); @@ -33,6 +34,8 @@ class CMpdClient : public CThread bool m_songchanged; bool m_isplaying; bool m_playingchanged; + int m_volume; + bool m_volumechanged; };