added: hide text when mpd is not playing
This commit is contained in:
parent
b775565689
commit
88913326d5
4 changed files with 102 additions and 6 deletions
|
@ -52,8 +52,9 @@ CBitVis::CBitVis(int argc, char *argv[])
|
|||
m_fontheight = 0;
|
||||
InitChars();
|
||||
|
||||
m_nrlines = 48 - m_fontheight - 1;
|
||||
m_nrlines = 48;
|
||||
m_scrolloffset = 0;
|
||||
m_fontdisplay = 0;
|
||||
m_songupdatetime = GetTimeUs();
|
||||
|
||||
m_mpdclient = new CMpdClient("music.bitlair", 6600);
|
||||
|
@ -291,7 +292,24 @@ void CBitVis::SendData(int64_t time)
|
|||
CTcpData data;
|
||||
data.SetData(":00");
|
||||
|
||||
for (int y = m_nrlines - 1; y >= 0; y--)
|
||||
int nrlines;
|
||||
bool playingchanged;
|
||||
if (m_mpdclient->IsPlaying(playingchanged))
|
||||
{
|
||||
if (m_fontdisplay < m_fontheight)
|
||||
m_fontdisplay++;
|
||||
|
||||
nrlines = m_nrlines - m_fontdisplay;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_fontdisplay > 0)
|
||||
m_fontdisplay--;
|
||||
|
||||
nrlines = m_nrlines - m_fontdisplay;
|
||||
}
|
||||
|
||||
for (int y = nrlines - 1; y >= 0; y--)
|
||||
{
|
||||
uint8_t line[m_nrcolumns / 4];
|
||||
for (int x = 0; x < m_nrcolumns / 4; x++)
|
||||
|
@ -300,7 +318,7 @@ void CBitVis::SendData(int64_t time)
|
|||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
pixel <<= 2;
|
||||
int value = Round32(((log10(m_displaybuf[x * 4 + i]) * 20.0f) + 55.0f) / 48.0f * m_nrlines);
|
||||
int value = Round32(((log10(m_displaybuf[x * 4 + i]) * 20.0f) + 55.0f) / 48.0f * nrlines);
|
||||
if (value > y)
|
||||
pixel |= 1;
|
||||
|
||||
|
@ -317,7 +335,7 @@ void CBitVis::SendData(int64_t time)
|
|||
if (time - currpeak.time > 500000 && Round32(currpeak.value) > 0)
|
||||
{
|
||||
currpeak.value += 0.01f;
|
||||
if (currpeak.value >= m_nrlines)
|
||||
if (currpeak.value >= nrlines)
|
||||
currpeak.value = 0.0f;
|
||||
}
|
||||
}
|
||||
|
@ -333,7 +351,7 @@ void CBitVis::SendData(int64_t time)
|
|||
data.SetData(text, m_nrcolumns / 4, true);
|
||||
|
||||
string currentsong;
|
||||
if (m_mpdclient->CurrentSong(currentsong))
|
||||
if (m_mpdclient->CurrentSong(currentsong) || playingchanged)
|
||||
{
|
||||
m_scrolloffset = 0;
|
||||
m_songupdatetime = GetTimeUs();
|
||||
|
|
|
@ -51,6 +51,7 @@ class CBitVis
|
|||
int m_nrbins;
|
||||
int m_nrcolumns;
|
||||
int m_nrlines;
|
||||
int m_fontdisplay;
|
||||
float m_decay;
|
||||
int m_fontheight;
|
||||
int m_scrolloffset;
|
||||
|
|
|
@ -14,6 +14,8 @@ CMpdClient::CMpdClient(std::string address, int port)
|
|||
{
|
||||
m_port = port;
|
||||
m_address = address;
|
||||
m_isplaying = false;
|
||||
m_playingchanged = false;
|
||||
}
|
||||
|
||||
CMpdClient::~CMpdClient()
|
||||
|
@ -30,7 +32,7 @@ void CMpdClient::Process()
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!GetCurrentSong())
|
||||
if (!GetCurrentSong() || !GetPlayStatus())
|
||||
{
|
||||
m_socket.Close();
|
||||
USleep(10000000);
|
||||
|
@ -126,6 +128,70 @@ bool CMpdClient::GetCurrentSong()
|
|||
return false;
|
||||
}
|
||||
|
||||
bool CMpdClient::GetPlayStatus()
|
||||
{
|
||||
CTcpData data;
|
||||
data.SetData("status\n");
|
||||
if (m_socket.Write(data) != SUCCESS)
|
||||
{
|
||||
SetSockError();
|
||||
LogError("Writing socket: %s", m_socket.GetError().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
data.Clear();
|
||||
bool isplaying = false;
|
||||
while(1)
|
||||
{
|
||||
if (m_socket.Read(data) != SUCCESS)
|
||||
{
|
||||
SetSockError();
|
||||
LogError("Reading socket: %s", m_socket.GetError().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
stringstream datastream(data.GetData());
|
||||
string line;
|
||||
while (1)
|
||||
{
|
||||
getline(datastream, line);
|
||||
if (datastream.fail())
|
||||
break;
|
||||
|
||||
string tmpline = line;
|
||||
string word;
|
||||
if (GetWord(tmpline, word))
|
||||
{
|
||||
if (word == "state:" && GetWord(tmpline, word))
|
||||
{
|
||||
if (word == "play")
|
||||
isplaying = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (line == "OK")
|
||||
{
|
||||
CLock lock(m_condition);
|
||||
if (m_isplaying == false && isplaying == true)
|
||||
m_playingchanged = true;
|
||||
|
||||
m_isplaying = isplaying;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetCurrentSong("Unable to get play status");
|
||||
|
||||
CLock lock(m_condition);
|
||||
if (m_isplaying != false)
|
||||
m_playingchanged = true;
|
||||
|
||||
m_isplaying = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CMpdClient::SetCurrentSong(const std::string& song)
|
||||
{
|
||||
CLock lock(m_condition);
|
||||
|
@ -154,3 +220,10 @@ bool CMpdClient::CurrentSong(std::string& song)
|
|||
return songchanged;
|
||||
}
|
||||
|
||||
bool CMpdClient::IsPlaying(bool& playingchanged)
|
||||
{
|
||||
CLock lock(m_condition);
|
||||
playingchanged = m_playingchanged;
|
||||
m_playingchanged = false;
|
||||
return m_isplaying;
|
||||
}
|
||||
|
|
|
@ -16,10 +16,12 @@ class CMpdClient : public CThread
|
|||
|
||||
virtual void Process();
|
||||
bool CurrentSong(std::string& song);
|
||||
bool IsPlaying(bool& playingchanged);
|
||||
|
||||
private:
|
||||
bool OpenSocket();
|
||||
bool GetCurrentSong();
|
||||
bool GetPlayStatus();
|
||||
void SetCurrentSong(const std::string& song);
|
||||
void SetSockError();
|
||||
|
||||
|
@ -29,6 +31,8 @@ class CMpdClient : public CThread
|
|||
CCondition m_condition;
|
||||
std::string m_currentsong;
|
||||
bool m_songchanged;
|
||||
bool m_isplaying;
|
||||
bool m_playingchanged;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue