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;
|
m_fontheight = 0;
|
||||||
InitChars();
|
InitChars();
|
||||||
|
|
||||||
m_nrlines = 48 - m_fontheight - 1;
|
m_nrlines = 48;
|
||||||
m_scrolloffset = 0;
|
m_scrolloffset = 0;
|
||||||
|
m_fontdisplay = 0;
|
||||||
m_songupdatetime = GetTimeUs();
|
m_songupdatetime = GetTimeUs();
|
||||||
|
|
||||||
m_mpdclient = new CMpdClient("music.bitlair", 6600);
|
m_mpdclient = new CMpdClient("music.bitlair", 6600);
|
||||||
|
@ -291,7 +292,24 @@ void CBitVis::SendData(int64_t time)
|
||||||
CTcpData data;
|
CTcpData data;
|
||||||
data.SetData(":00");
|
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];
|
uint8_t line[m_nrcolumns / 4];
|
||||||
for (int x = 0; x < m_nrcolumns / 4; x++)
|
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++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
pixel <<= 2;
|
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)
|
if (value > y)
|
||||||
pixel |= 1;
|
pixel |= 1;
|
||||||
|
|
||||||
|
@ -317,7 +335,7 @@ void CBitVis::SendData(int64_t time)
|
||||||
if (time - currpeak.time > 500000 && Round32(currpeak.value) > 0)
|
if (time - currpeak.time > 500000 && Round32(currpeak.value) > 0)
|
||||||
{
|
{
|
||||||
currpeak.value += 0.01f;
|
currpeak.value += 0.01f;
|
||||||
if (currpeak.value >= m_nrlines)
|
if (currpeak.value >= nrlines)
|
||||||
currpeak.value = 0.0f;
|
currpeak.value = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -333,7 +351,7 @@ void CBitVis::SendData(int64_t time)
|
||||||
data.SetData(text, m_nrcolumns / 4, true);
|
data.SetData(text, m_nrcolumns / 4, true);
|
||||||
|
|
||||||
string currentsong;
|
string currentsong;
|
||||||
if (m_mpdclient->CurrentSong(currentsong))
|
if (m_mpdclient->CurrentSong(currentsong) || playingchanged)
|
||||||
{
|
{
|
||||||
m_scrolloffset = 0;
|
m_scrolloffset = 0;
|
||||||
m_songupdatetime = GetTimeUs();
|
m_songupdatetime = GetTimeUs();
|
||||||
|
|
|
@ -51,6 +51,7 @@ class CBitVis
|
||||||
int m_nrbins;
|
int m_nrbins;
|
||||||
int m_nrcolumns;
|
int m_nrcolumns;
|
||||||
int m_nrlines;
|
int m_nrlines;
|
||||||
|
int m_fontdisplay;
|
||||||
float m_decay;
|
float m_decay;
|
||||||
int m_fontheight;
|
int m_fontheight;
|
||||||
int m_scrolloffset;
|
int m_scrolloffset;
|
||||||
|
|
|
@ -14,6 +14,8 @@ CMpdClient::CMpdClient(std::string address, int port)
|
||||||
{
|
{
|
||||||
m_port = port;
|
m_port = port;
|
||||||
m_address = address;
|
m_address = address;
|
||||||
|
m_isplaying = false;
|
||||||
|
m_playingchanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMpdClient::~CMpdClient()
|
CMpdClient::~CMpdClient()
|
||||||
|
@ -30,7 +32,7 @@ void CMpdClient::Process()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetCurrentSong())
|
if (!GetCurrentSong() || !GetPlayStatus())
|
||||||
{
|
{
|
||||||
m_socket.Close();
|
m_socket.Close();
|
||||||
USleep(10000000);
|
USleep(10000000);
|
||||||
|
@ -126,6 +128,70 @@ bool CMpdClient::GetCurrentSong()
|
||||||
return false;
|
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)
|
void CMpdClient::SetCurrentSong(const std::string& song)
|
||||||
{
|
{
|
||||||
CLock lock(m_condition);
|
CLock lock(m_condition);
|
||||||
|
@ -154,3 +220,10 @@ bool CMpdClient::CurrentSong(std::string& song)
|
||||||
return songchanged;
|
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();
|
virtual void Process();
|
||||||
bool CurrentSong(std::string& song);
|
bool CurrentSong(std::string& song);
|
||||||
|
bool IsPlaying(bool& playingchanged);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool OpenSocket();
|
bool OpenSocket();
|
||||||
bool GetCurrentSong();
|
bool GetCurrentSong();
|
||||||
|
bool GetPlayStatus();
|
||||||
void SetCurrentSong(const std::string& song);
|
void SetCurrentSong(const std::string& song);
|
||||||
void SetSockError();
|
void SetSockError();
|
||||||
|
|
||||||
|
@ -29,6 +31,8 @@ class CMpdClient : public CThread
|
||||||
CCondition m_condition;
|
CCondition m_condition;
|
||||||
std::string m_currentsong;
|
std::string m_currentsong;
|
||||||
bool m_songchanged;
|
bool m_songchanged;
|
||||||
|
bool m_isplaying;
|
||||||
|
bool m_playingchanged;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue