added: CDebugWindow support for bitvis

added: parse commandline argument to set ip:port of bitpanel and mpd
This commit is contained in:
Bob van Loosen 2013-02-19 18:53:47 +01:00
parent e14a8da618
commit ef067a0e14
4 changed files with 107 additions and 35 deletions

View file

@ -36,6 +36,12 @@ using namespace std;
CBitVis::CBitVis(int argc, char *argv[]) CBitVis::CBitVis(int argc, char *argv[])
{ {
m_debug = false;
m_debugscale = 2;
m_address = NULL;
m_port = 1337;
m_mpdaddress = NULL;
m_mpdport = 6600;
g_printdebuglevel = true; g_printdebuglevel = true;
m_stop = false; m_stop = false;
m_buf = NULL; m_buf = NULL;
@ -49,6 +55,7 @@ CBitVis::CBitVis(int argc, char *argv[])
m_nrcolumns = 120; m_nrcolumns = 120;
m_decay = 0.5; m_decay = 0.5;
m_fps = 30; m_fps = 30;
m_mpdclient = NULL;
m_fontheight = 0; m_fontheight = 0;
InitChars(); InitChars();
@ -58,7 +65,7 @@ CBitVis::CBitVis(int argc, char *argv[])
m_fontdisplay = 0; m_fontdisplay = 0;
m_songupdatetime = GetTimeUs(); m_songupdatetime = GetTimeUs();
const char* flags = "f:"; const char* flags = "f:d:p:a:m:o:";
int c; int c;
while ((c = getopt(argc, argv, flags)) != -1) while ((c = getopt(argc, argv, flags)) != -1)
{ {
@ -73,10 +80,52 @@ CBitVis::CBitVis(int argc, char *argv[])
m_fps = fps; m_fps = fps;
} }
else if (c == 'd') //debug
{
int scale;
if (!StrToInt(string(optarg), scale) || scale <= 0)
{
LogError("Wrong argument \"%s\" for debug", optarg);
exit(1);
}
m_debugscale = scale;
m_debug = true;
}
else if (c == 'p') //port
{
int port;
if (!StrToInt(string(optarg), port) || port <= 0 || port > 65535)
{
LogError("Wrong argument \"%s\" for port", optarg);
exit(1);
}
m_port = port;
}
else if (c == 'a') //address
{
m_address = optarg;
}
else if (c == 'm') //mpd address
{
m_mpdaddress = optarg;
}
else if (c == 'o') //mpd port
{
int port;
if (!StrToInt(string(optarg), port) || port <= 0 || port > 65535)
{
LogError("Wrong argument \"%s\" for mpd port", optarg);
exit(1);
}
m_mpdport = port;
}
} }
m_mpdclient = new CMpdClient("music.bitlair", 6600); if (!m_address)
m_mpdclient->StartThread(); m_debug = true;
} }
CBitVis::~CBitVis() CBitVis::~CBitVis()
@ -103,6 +152,14 @@ void CBitVis::Setup()
m_peakholds = new peak[m_nrcolumns]; m_peakholds = new peak[m_nrcolumns];
memset(m_peakholds, 0, m_nrcolumns * sizeof(peak)); memset(m_peakholds, 0, m_nrcolumns * sizeof(peak));
m_debugwindow.Enable(m_nrcolumns, m_nrlines, m_debugscale);
if (m_mpdaddress)
{
m_mpdclient = new CMpdClient(m_mpdaddress, m_mpdport);
m_mpdclient->StartThread();
}
} }
void CBitVis::SetupSignals() void CBitVis::SetupSignals()
@ -183,9 +240,9 @@ void CBitVis::Process()
while ((msg = m_jackclient.GetMessage()) != MsgNone) while ((msg = m_jackclient.GetMessage()) != MsgNone)
LogDebug("got message %s from jack client", MsgToString(msg)); LogDebug("got message %s from jack client", MsgToString(msg));
if (!m_socket.IsOpen() && GetTimeUs() - lastconnect > CONNECTINTERVAL) if (!m_socket.IsOpen() && m_address && GetTimeUs() - lastconnect > CONNECTINTERVAL)
{ {
if (m_socket.Open("192.168.88.117", 1337, 10000000) != SUCCESS) if (m_socket.Open(m_address, m_port, 10000000) != SUCCESS)
{ {
LogError("Failed to connect: %s", m_socket.GetError().c_str()); LogError("Failed to connect: %s", m_socket.GetError().c_str());
m_socket.Close(); m_socket.Close();
@ -209,9 +266,13 @@ void CBitVis::Process()
} }
m_jackclient.Disconnect(); m_jackclient.Disconnect();
m_mpdclient->StopThread();
delete m_mpdclient; if (m_mpdclient)
m_mpdclient = NULL; {
m_mpdclient->StopThread();
delete m_mpdclient;
m_mpdclient = NULL;
}
} }
void CBitVis::ProcessSignalfd() void CBitVis::ProcessSignalfd()
@ -248,9 +309,6 @@ void CBitVis::ProcessAudio()
int64_t audiotime; int64_t audiotime;
if ((samples = m_jackclient.GetAudio(m_buf, m_bufsize, samplerate, audiotime)) > 0) if ((samples = m_jackclient.GetAudio(m_buf, m_bufsize, samplerate, audiotime)) > 0)
{ {
if (!m_socket.IsOpen())
return;
int additions = 0; int additions = 0;
for (int i = 1; i < m_nrcolumns; i++) for (int i = 1; i < m_nrcolumns; i++)
additions += i; additions += i;
@ -306,6 +364,7 @@ void CBitVis::ProcessAudio()
void CBitVis::Cleanup() void CBitVis::Cleanup()
{ {
m_jackclient.Disconnect(); m_jackclient.Disconnect();
m_debugwindow.Disable();
} }
void CBitVis::SendData(int64_t time) void CBitVis::SendData(int64_t time)
@ -315,7 +374,7 @@ void CBitVis::SendData(int64_t time)
int nrlines; int nrlines;
bool playingchanged; bool playingchanged;
if (m_mpdclient->IsPlaying(playingchanged)) if (m_mpdclient && m_mpdclient->IsPlaying(playingchanged))
{ {
if (m_fontdisplay < m_fontheight) if (m_fontdisplay < m_fontheight)
m_fontdisplay++; m_fontdisplay++;
@ -370,7 +429,7 @@ void CBitVis::SendData(int64_t time)
memset(text, 0, sizeof(text)); memset(text, 0, sizeof(text));
string currentsong; string currentsong;
if (m_mpdclient->CurrentSong(currentsong) || playingchanged) if ((m_mpdclient && m_mpdclient->CurrentSong(currentsong)) || playingchanged)
{ {
m_scrolloffset = 0; m_scrolloffset = 0;
m_songupdatetime = GetTimeUs(); m_songupdatetime = GetTimeUs();
@ -386,11 +445,13 @@ void CBitVis::SendData(int64_t time)
USleep(time - GetTimeUs()); USleep(time - GetTimeUs());
if (m_socket.Write(data) != SUCCESS) if (m_socket.IsOpen() && m_socket.Write(data) != SUCCESS)
{ {
LogError("%s", m_socket.GetError().c_str()); LogError("%s", m_socket.GetError().c_str());
m_socket.Close(); m_socket.Close();
} }
m_debugwindow.DisplayFrame(data);
} }
void CBitVis::SetText(uint8_t* buff, const char* str, int offset /*= 0*/) void CBitVis::SetText(uint8_t* buff, const char* str, int offset /*= 0*/)

View file

@ -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 "util/debugwindow.h"
#include "mpdclient.h" #include "mpdclient.h"
class CBitVis class CBitVis
@ -38,26 +39,34 @@ class CBitVis
void Cleanup(); void Cleanup();
private: private:
bool m_stop; bool m_stop;
CJackClient m_jackclient; char* m_address;
int m_signalfd; int m_port;
Cfft m_fft; char* m_mpdaddress;
float* m_buf; int m_mpdport;
int m_bufsize; CJackClient m_jackclient;
float* m_fftbuf; int m_signalfd;
float* m_displaybuf; Cfft m_fft;
int m_samplecounter; float* m_buf;
int m_nrffts; int m_bufsize;
int m_nrbins; float* m_fftbuf;
int m_nrcolumns; float* m_displaybuf;
int m_nrlines; int m_samplecounter;
int m_fontdisplay; int m_nrffts;
float m_decay; int m_nrbins;
int m_fps; int m_nrcolumns;
int m_fontheight; int m_nrlines;
int m_scrolloffset; int m_fontdisplay;
int64_t m_songupdatetime; float m_decay;
CMpdClient* m_mpdclient; int m_fps;
int m_fontheight;
int m_scrolloffset;
int64_t m_songupdatetime;
CMpdClient* m_mpdclient;
bool m_debug;
int m_debugscale;
CDebugWindow m_debugwindow;
struct peak struct peak
{ {

View file

@ -47,6 +47,7 @@ CDebugWindow::CDebugWindow()
CDebugWindow::~CDebugWindow() CDebugWindow::~CDebugWindow()
{ {
Disable();
} }
void CDebugWindow::Enable(int width, int height, int scale) void CDebugWindow::Enable(int width, int height, int scale)

View file

@ -49,6 +49,7 @@ def build(bld):
src/bitvis/jackclient.cpp\ src/bitvis/jackclient.cpp\
src/bitvis/mpdclient.cpp\ src/bitvis/mpdclient.cpp\
src/bitvis/fft.cpp\ src/bitvis/fft.cpp\
src/util/debugwindow.cpp\
src/util/log.cpp\ src/util/log.cpp\
src/util/misc.cpp\ src/util/misc.cpp\
src/util/mutex.cpp\ src/util/mutex.cpp\
@ -56,7 +57,7 @@ def build(bld):
src/util/condition.cpp\ src/util/condition.cpp\
src/util/tcpsocket.cpp\ src/util/tcpsocket.cpp\
src/util/thread.cpp', src/util/thread.cpp',
use=['m','pthread','rt', 'jack', 'fftw3', 'fftw3f', 'samplerate'], use=['m','pthread','rt', 'jack', 'fftw3', 'fftw3f', 'samplerate', 'X11', 'Xrender'],
includes='./src', includes='./src',
cxxflags='-Wall -g -DUTILNAMESPACE=BitVisUtil', cxxflags='-Wall -g -DUTILNAMESPACE=BitVisUtil',
target='bitvis') target='bitvis')