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_nrlines = 48 - m_fontheight - 1;
|
||||||
m_scrolloffset = 0;
|
m_scrolloffset = 0;
|
||||||
|
|
||||||
|
m_mpdclient = new CMpdClient("music.bitlair", 6600);
|
||||||
|
m_mpdclient->StartThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
CBitVis::~CBitVis()
|
CBitVis::~CBitVis()
|
||||||
|
@ -331,7 +334,7 @@ void CBitVis::SendData(int64_t time)
|
||||||
//add an empty line
|
//add an empty line
|
||||||
data.SetData(text, m_nrcolumns / 4, true);
|
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);
|
data.SetData(text, sizeof(text), true);
|
||||||
|
|
||||||
uint8_t end[10];
|
uint8_t end[10];
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "jackclient.h"
|
#include "jackclient.h"
|
||||||
#include "fft.h"
|
#include "fft.h"
|
||||||
#include "util/tcpsocket.h"
|
#include "util/tcpsocket.h"
|
||||||
|
#include "mpdclient.h"
|
||||||
|
|
||||||
class CBitVis
|
class CBitVis
|
||||||
{
|
{
|
||||||
|
@ -53,6 +54,7 @@ class CBitVis
|
||||||
float m_decay;
|
float m_decay;
|
||||||
int m_fontheight;
|
int m_fontheight;
|
||||||
int m_scrolloffset;
|
int m_scrolloffset;
|
||||||
|
CMpdClient* m_mpdclient;
|
||||||
|
|
||||||
struct peak
|
struct peak
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,35 +27,18 @@ void CMpdClient::Process()
|
||||||
{
|
{
|
||||||
if (!OpenSocket())
|
if (!OpenSocket())
|
||||||
{
|
{
|
||||||
CLock lock(m_condition);
|
m_currentsong.clear();
|
||||||
m_commands.clear();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CLock lock(m_condition);
|
if (!GetCurrentSong())
|
||||||
if (m_commands.empty())
|
|
||||||
{
|
|
||||||
if (!m_condition.Wait(10000000))
|
|
||||||
{
|
|
||||||
lock.Leave();
|
|
||||||
if (!Ping())
|
|
||||||
{
|
{
|
||||||
|
m_currentsong.clear();
|
||||||
m_socket.Close();
|
m_socket.Close();
|
||||||
lock.Enter();
|
|
||||||
m_commands.clear();
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
lock.Leave();
|
|
||||||
|
|
||||||
if (!ProcessCommands())
|
USleep(1000000);
|
||||||
{
|
|
||||||
m_socket.Close();
|
|
||||||
lock.Enter();
|
|
||||||
m_commands.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,72 +64,18 @@ bool CMpdClient::OpenSocket()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMpdClient::ProcessCommands()
|
bool CMpdClient::GetCurrentSong()
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
CTcpData data;
|
CTcpData data;
|
||||||
data.SetData("ping\n");
|
data.SetData("currentsong\n");
|
||||||
|
|
||||||
if (m_socket.Write(data) != SUCCESS)
|
if (m_socket.Write(data) != SUCCESS)
|
||||||
{
|
{
|
||||||
printf("Error writing socket: %s\n", m_socket.GetError().c_str());
|
printf("Error writing socket: %s\n", m_socket.GetError().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_socket.SetTimeout(0);
|
string artist;
|
||||||
int returnv;
|
string title;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Clear();
|
data.Clear();
|
||||||
while(1)
|
while(1)
|
||||||
|
@ -166,9 +95,17 @@ bool CMpdClient::GetVolume(int& volume)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
string word;
|
string word;
|
||||||
if (GetWord(line, word) && word == "volume:")
|
if (GetWord(line, word))
|
||||||
{
|
{
|
||||||
if (GetWord(line, word) && StrToInt(word, volume) && volume >= 0 && volume <= 100)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,31 +114,9 @@ bool CMpdClient::GetVolume(int& volume)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMpdClient::SetVolume(int volume)
|
std::string CMpdClient::CurrentSong()
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
CLock lock(m_condition);
|
CLock lock(m_condition);
|
||||||
m_commands.push_back(CMD_VOLUP);
|
return m_currentsong;
|
||||||
m_condition.Signal();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMpdClient::VolumeDown()
|
|
||||||
{
|
|
||||||
CLock lock(m_condition);
|
|
||||||
m_commands.push_back(CMD_VOLDOWN);
|
|
||||||
m_condition.Signal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,6 @@
|
||||||
#include "util/condition.h"
|
#include "util/condition.h"
|
||||||
#include "util/tcpsocket.h"
|
#include "util/tcpsocket.h"
|
||||||
|
|
||||||
enum ECMD
|
|
||||||
{
|
|
||||||
CMD_VOLUP,
|
|
||||||
CMD_VOLDOWN
|
|
||||||
};
|
|
||||||
|
|
||||||
class CMpdClient : public CThread
|
class CMpdClient : public CThread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -21,21 +15,17 @@ class CMpdClient : public CThread
|
||||||
~CMpdClient();
|
~CMpdClient();
|
||||||
|
|
||||||
virtual void Process();
|
virtual void Process();
|
||||||
void VolumeUp();
|
std::string CurrentSong();
|
||||||
void VolumeDown();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool OpenSocket();
|
bool OpenSocket();
|
||||||
bool Ping();
|
bool GetCurrentSong();
|
||||||
bool ProcessCommands();
|
|
||||||
bool GetVolume(int& volume);
|
|
||||||
bool SetVolume(int volume);
|
|
||||||
|
|
||||||
int m_port;
|
int m_port;
|
||||||
std::string m_address;
|
std::string m_address;
|
||||||
CTcpClientSocket m_socket;
|
CTcpClientSocket m_socket;
|
||||||
std::deque<ECMD> m_commands;
|
|
||||||
CCondition m_condition;
|
CCondition m_condition;
|
||||||
|
std::string m_currentsong;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue