added: display bar when volume changes
This commit is contained in:
parent
c7bc599c56
commit
a67afebb0c
4 changed files with 99 additions and 34 deletions
|
@ -64,6 +64,8 @@ CBitVis::CBitVis(int argc, char *argv[])
|
||||||
m_scrolloffset = 0;
|
m_scrolloffset = 0;
|
||||||
m_fontdisplay = 0;
|
m_fontdisplay = 0;
|
||||||
m_songupdatetime = GetTimeUs();
|
m_songupdatetime = GetTimeUs();
|
||||||
|
m_volumetime = GetTimeUs();
|
||||||
|
m_displayvolume = 0;
|
||||||
|
|
||||||
const char* flags = "f:d:p:a:m:o:";
|
const char* flags = "f:d:p:a:m:o:";
|
||||||
int c;
|
int c;
|
||||||
|
@ -375,7 +377,16 @@ void CBitVis::SendData(int64_t time)
|
||||||
|
|
||||||
int nrlines;
|
int nrlines;
|
||||||
bool playingchanged;
|
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)
|
if (m_fontdisplay < m_fontheight)
|
||||||
m_fontdisplay++;
|
m_fontdisplay++;
|
||||||
|
@ -390,40 +401,63 @@ void CBitVis::SendData(int64_t time)
|
||||||
nrlines = m_nrlines - m_fontdisplay;
|
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 y = 0; y < nrlines; y++)
|
||||||
for (int x = 0; x < m_nrcolumns / 4; x++)
|
|
||||||
{
|
{
|
||||||
uint8_t pixel = 0;
|
uint8_t line[m_nrcolumns / 4];
|
||||||
for (int i = 0; i < 4; i++)
|
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);
|
if (y == nrlines - 1)
|
||||||
|
line[x / 4] |= 1 << (pixelcounter * 2 + 1);
|
||||||
peak& currpeak = m_peakholds[x * 4 + i];
|
else if (x < m_displayvolume)
|
||||||
if (value >= Round32(currpeak.value))
|
line[x / 4] |= 1 << (pixelcounter * 2);
|
||||||
{
|
pixelcounter--;
|
||||||
currpeak.value = value;
|
if (pixelcounter == -1)
|
||||||
currpeak.time = time;
|
pixelcounter = 3;
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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];
|
uint8_t text[m_nrcolumns / 4 * m_fontheight];
|
||||||
|
@ -453,6 +487,11 @@ void CBitVis::SendData(int64_t time)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_debugwindow.DisplayFrame(data);
|
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*/)
|
void CBitVis::SetText(uint8_t* buff, const char* str, int offset /*= 0*/)
|
||||||
|
|
|
@ -63,6 +63,8 @@ class CBitVis
|
||||||
int m_scrolloffset;
|
int m_scrolloffset;
|
||||||
int64_t m_songupdatetime;
|
int64_t m_songupdatetime;
|
||||||
CMpdClient* m_mpdclient;
|
CMpdClient* m_mpdclient;
|
||||||
|
int64_t m_volumetime;
|
||||||
|
int m_displayvolume;
|
||||||
|
|
||||||
bool m_debug;
|
bool m_debug;
|
||||||
int m_debugscale;
|
int m_debugscale;
|
||||||
|
|
|
@ -16,6 +16,8 @@ CMpdClient::CMpdClient(std::string address, int port)
|
||||||
m_address = address;
|
m_address = address;
|
||||||
m_isplaying = false;
|
m_isplaying = false;
|
||||||
m_playingchanged = false;
|
m_playingchanged = false;
|
||||||
|
m_volume = 0;
|
||||||
|
m_volumechanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMpdClient::~CMpdClient()
|
CMpdClient::~CMpdClient()
|
||||||
|
@ -39,7 +41,7 @@ void CMpdClient::Process()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USleep(1000000);
|
USleep(30000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,9 +184,19 @@ bool CMpdClient::GetPlayStatus()
|
||||||
}
|
}
|
||||||
else if (word == "volume:")
|
else if (word == "volume:")
|
||||||
{
|
{
|
||||||
if (GetWord(tmpline, word))
|
int volume;
|
||||||
if (word == "0")
|
if (GetWord(tmpline, word) && StrToInt(word, volume))
|
||||||
muted = true;
|
{
|
||||||
|
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;
|
m_playingchanged = false;
|
||||||
return m_isplaying;
|
return m_isplaying;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CMpdClient::GetVolume(int& volume)
|
||||||
|
{
|
||||||
|
CLock lock(m_condition);
|
||||||
|
volume = m_volume;
|
||||||
|
bool changed = m_volumechanged;
|
||||||
|
m_volumechanged = false;
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ class CMpdClient : public CThread
|
||||||
virtual void Process();
|
virtual void Process();
|
||||||
bool CurrentSong(std::string& song);
|
bool CurrentSong(std::string& song);
|
||||||
bool IsPlaying(bool& playingchanged);
|
bool IsPlaying(bool& playingchanged);
|
||||||
|
bool GetVolume(int& volume);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool OpenSocket();
|
bool OpenSocket();
|
||||||
|
@ -33,6 +34,8 @@ class CMpdClient : public CThread
|
||||||
bool m_songchanged;
|
bool m_songchanged;
|
||||||
bool m_isplaying;
|
bool m_isplaying;
|
||||||
bool m_playingchanged;
|
bool m_playingchanged;
|
||||||
|
int m_volume;
|
||||||
|
bool m_volumechanged;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue