added: show the track progress by making the line between the visualizer and the now playing text increasingly orange

This commit is contained in:
Bob van Loosen 2013-04-02 20:52:24 +02:00
parent 0c826cbe7b
commit c5309c6ec9
3 changed files with 62 additions and 3 deletions

View file

@ -452,11 +452,15 @@ void CBitVis::SendData(int64_t time)
bool playingchanged;
bool isplaying = false;
int volume = 0;
int elapsed = 0;
if (m_mpdclient)
{
isplaying = m_mpdclient->IsPlaying(playingchanged);
if (m_mpdclient->GetVolume(volume))
m_volumetime = GetTimeUs();
if (isplaying)
elapsed = Round32(m_mpdclient->GetElapsedState() * m_nrcolumns);
}
if (isplaying)
@ -486,6 +490,8 @@ void CBitVis::SendData(int64_t time)
if (y == nrlines - 1)
{
line[x / 4] |= 1 << (pixelcounter * 2 + 1);
if (x < elapsed)
line[x / 4] |= 1 << (pixelcounter * 2);
}
else if (x < m_displayvolume * m_nrcolumns / 100)
{
@ -524,10 +530,20 @@ void CBitVis::SendData(int64_t time)
pixel <<= 2;
if (Round32(currpeak.value) == y || y == 0)
if (y == 0)
{
pixel |= 2;
if (x * 4 + i < elapsed)
pixel |= 1;
}
else if (Round32(currpeak.value) == y)
{
pixel |= 2;
}
else if (value > y)
{
pixel |= 1;
}
if (time - currpeak.time > 500000 && Round32(currpeak.value) > 0)
{

View file

@ -18,6 +18,7 @@ CMpdClient::CMpdClient(std::string address, int port)
m_playingchanged = false;
m_volume = 0;
m_volumechanged = false;
m_elapsedstate = 0.0;
}
CMpdClient::~CMpdClient()
@ -147,8 +148,10 @@ bool CMpdClient::GetPlayStatus()
}
data.Clear();
bool isplaying = false;
int volume = -1;
bool isplaying = false;
int volume = -1;
double elapsed = -1.0;
double total = 0.0;
while(1)
{
if (m_socket.Read(data) != SUCCESS)
@ -182,6 +185,33 @@ bool CMpdClient::GetPlayStatus()
if (GetWord(tmpline, word) && StrToInt(word, parsevolume))
volume = parsevolume;
}
else if (word == "time:")
{
if (GetWord(tmpline, word))
{
size_t colon = word.find(':');
if (colon != string::npos && colon > 0 && colon < word.size() - 1)
{
double tmpelapsed;
double tmptotal;
if (elapsed < 0.0 && StrToFloat(word.substr(0, colon), tmpelapsed))
elapsed = tmpelapsed;
if (StrToFloat(word.substr(colon + 1), tmptotal) && tmptotal > 0.0)
total = tmptotal;
}
}
}
else if (word == "elapsed:")
{
if (GetWord(tmpline, word))
{
double tmpelapsed;
if (StrToFloat(word, tmpelapsed))
elapsed = tmpelapsed;
}
}
}
if (line == "OK")
@ -201,6 +231,11 @@ bool CMpdClient::GetPlayStatus()
m_volumechanged = true;
}
if (total > 0.0 && elapsed >= 0.0)
m_elapsedstate = elapsed / total;
else
m_elapsedstate = 0.0;
return true;
}
}
@ -257,6 +292,12 @@ bool CMpdClient::GetVolume(int& volume)
return changed;
}
double CMpdClient::GetElapsedState()
{
CLock lock(m_condition);
return m_elapsedstate;
}
std::string CMpdClient::StripFilename(const std::string& filename)
{
//strip any preceding directories

View file

@ -18,6 +18,7 @@ class CMpdClient : public CThread
bool CurrentSong(std::string& song);
bool IsPlaying(bool& playingchanged);
bool GetVolume(int& volume);
double GetElapsedState();
private:
bool OpenSocket();
@ -37,6 +38,7 @@ class CMpdClient : public CThread
bool m_playingchanged;
int m_volume;
bool m_volumechanged;
double m_elapsedstate;
};