added: now playing
This commit is contained in:
parent
61b42c1e8f
commit
e91398d77b
4 changed files with 31 additions and 121 deletions
|
@ -54,6 +54,9 @@ CBitVis::CBitVis(int argc, char *argv[])
|
|||
|
||||
m_nrlines = 48 - m_fontheight - 1;
|
||||
m_scrolloffset = 0;
|
||||
|
||||
m_mpdclient = new CMpdClient("music.bitlair", 6600);
|
||||
m_mpdclient->StartThread();
|
||||
}
|
||||
|
||||
CBitVis::~CBitVis()
|
||||
|
@ -331,7 +334,7 @@ void CBitVis::SendData(int64_t time)
|
|||
//add an empty line
|
||||
data.SetData(text, m_nrcolumns / 4, true);
|
||||
|
||||
SetText(text, "Wat? No money? Hier! Suck a cock!");
|
||||
SetText(text, m_mpdclient->CurrentSong().c_str());
|
||||
data.SetData(text, sizeof(text), true);
|
||||
|
||||
uint8_t end[10];
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "jackclient.h"
|
||||
#include "fft.h"
|
||||
#include "util/tcpsocket.h"
|
||||
#include "mpdclient.h"
|
||||
|
||||
class CBitVis
|
||||
{
|
||||
|
@ -53,6 +54,7 @@ class CBitVis
|
|||
float m_decay;
|
||||
int m_fontheight;
|
||||
int m_scrolloffset;
|
||||
CMpdClient* m_mpdclient;
|
||||
|
||||
struct peak
|
||||
{
|
||||
|
|
|
@ -27,35 +27,18 @@ void CMpdClient::Process()
|
|||
{
|
||||
if (!OpenSocket())
|
||||
{
|
||||
CLock lock(m_condition);
|
||||
m_commands.clear();
|
||||
m_currentsong.clear();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
CLock lock(m_condition);
|
||||
if (m_commands.empty())
|
||||
{
|
||||
if (!m_condition.Wait(10000000))
|
||||
{
|
||||
lock.Leave();
|
||||
if (!Ping())
|
||||
{
|
||||
m_socket.Close();
|
||||
lock.Enter();
|
||||
m_commands.clear();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
lock.Leave();
|
||||
|
||||
if (!ProcessCommands())
|
||||
if (!GetCurrentSong())
|
||||
{
|
||||
m_currentsong.clear();
|
||||
m_socket.Close();
|
||||
lock.Enter();
|
||||
m_commands.clear();
|
||||
}
|
||||
|
||||
USleep(1000000);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,72 +64,18 @@ bool CMpdClient::OpenSocket()
|
|||
}
|
||||
}
|
||||
|
||||
bool CMpdClient::ProcessCommands()
|
||||
{
|
||||
CLock lock(m_condition);
|
||||
while (!m_commands.empty())
|
||||
{
|
||||
ECMD cmd = m_commands.front();
|
||||
m_commands.pop_front();
|
||||
lock.Leave();
|
||||
|
||||
int volume;
|
||||
if (!GetVolume(volume))
|
||||
return false;
|
||||
|
||||
int newvolume = volume;
|
||||
if (cmd == CMD_VOLUP)
|
||||
newvolume += 5;
|
||||
else if (cmd == CMD_VOLDOWN)
|
||||
newvolume -= 5;
|
||||
|
||||
newvolume = Clamp(newvolume, 0, 100);
|
||||
printf("Setting volume from %i to %i\n", volume, newvolume);
|
||||
|
||||
if (!SetVolume(newvolume))
|
||||
return false;
|
||||
|
||||
lock.Enter();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CMpdClient::Ping()
|
||||
bool CMpdClient::GetCurrentSong()
|
||||
{
|
||||
CTcpData data;
|
||||
data.SetData("ping\n");
|
||||
|
||||
data.SetData("currentsong\n");
|
||||
if (m_socket.Write(data) != SUCCESS)
|
||||
{
|
||||
printf("Error writing socket: %s\n", m_socket.GetError().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_socket.SetTimeout(0);
|
||||
int returnv;
|
||||
while((returnv = m_socket.Read(data)) == SUCCESS);
|
||||
|
||||
m_socket.SetTimeout(10000000);
|
||||
|
||||
if (returnv == FAIL)
|
||||
{
|
||||
printf("Error reading socket: %s\n", m_socket.GetError().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CMpdClient::GetVolume(int& volume)
|
||||
{
|
||||
CTcpData data;
|
||||
data.SetData("status\n");
|
||||
if (m_socket.Write(data) != SUCCESS)
|
||||
{
|
||||
printf("Error writing socket: %s\n", m_socket.GetError().c_str());
|
||||
return false;
|
||||
}
|
||||
string artist;
|
||||
string title;
|
||||
|
||||
data.Clear();
|
||||
while(1)
|
||||
|
@ -166,10 +95,18 @@ bool CMpdClient::GetVolume(int& volume)
|
|||
break;
|
||||
|
||||
string word;
|
||||
if (GetWord(line, word) && word == "volume:")
|
||||
if (GetWord(line, word))
|
||||
{
|
||||
if (GetWord(line, word) && StrToInt(word, volume) && volume >= 0 && volume <= 100)
|
||||
return true;
|
||||
if (word == "Artist:")
|
||||
artist = line.substr(1);
|
||||
else if (word == "Title:")
|
||||
title = line.substr(1);
|
||||
}
|
||||
|
||||
if (!artist.empty() && !title.empty())
|
||||
{
|
||||
m_currentsong = artist + " - " + title;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,31 +114,9 @@ bool CMpdClient::GetVolume(int& volume)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool CMpdClient::SetVolume(int volume)
|
||||
{
|
||||
CTcpData data;
|
||||
data.SetData(string("setvol ") + ToString(volume) + "\n");
|
||||
|
||||
if (m_socket.Write(data) != SUCCESS)
|
||||
{
|
||||
printf("Error writing socket: %s\n", m_socket.GetError().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMpdClient::VolumeUp()
|
||||
std::string CMpdClient::CurrentSong()
|
||||
{
|
||||
CLock lock(m_condition);
|
||||
m_commands.push_back(CMD_VOLUP);
|
||||
m_condition.Signal();
|
||||
}
|
||||
|
||||
void CMpdClient::VolumeDown()
|
||||
{
|
||||
CLock lock(m_condition);
|
||||
m_commands.push_back(CMD_VOLDOWN);
|
||||
m_condition.Signal();
|
||||
return m_currentsong;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,6 @@
|
|||
#include "util/condition.h"
|
||||
#include "util/tcpsocket.h"
|
||||
|
||||
enum ECMD
|
||||
{
|
||||
CMD_VOLUP,
|
||||
CMD_VOLDOWN
|
||||
};
|
||||
|
||||
class CMpdClient : public CThread
|
||||
{
|
||||
public:
|
||||
|
@ -21,21 +15,17 @@ class CMpdClient : public CThread
|
|||
~CMpdClient();
|
||||
|
||||
virtual void Process();
|
||||
void VolumeUp();
|
||||
void VolumeDown();
|
||||
std::string CurrentSong();
|
||||
|
||||
private:
|
||||
bool OpenSocket();
|
||||
bool Ping();
|
||||
bool ProcessCommands();
|
||||
bool GetVolume(int& volume);
|
||||
bool SetVolume(int volume);
|
||||
bool GetCurrentSong();
|
||||
|
||||
int m_port;
|
||||
std::string m_address;
|
||||
CTcpClientSocket m_socket;
|
||||
std::deque<ECMD> m_commands;
|
||||
CCondition m_condition;
|
||||
std::string m_currentsong;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue