From 1d6a42a3aa247953ff580de1e2defc6c1f529331 Mon Sep 17 00:00:00 2001 From: santi Date: Wed, 2 Jul 2014 18:33:47 +0200 Subject: [PATCH] More verbose uotput in terminal --- lms-audio.xlm | 0 src/audiomotor.cpp | 24 ++++++------ src/audiomotor.h | 1 + src/libremediaserver-audio.cpp | 21 ++++++----- src/libremediaserver-audio.h | 7 +++- src/olainterface.cpp | 51 ------------------------- src/olainterface.h | 68 ---------------------------------- src/olathread.cpp | 10 ++--- src/olathread.h | 6 +-- 9 files changed, 38 insertions(+), 150 deletions(-) mode change 100755 => 100644 lms-audio.xlm delete mode 100755 src/olainterface.cpp delete mode 100755 src/olainterface.h diff --git a/lms-audio.xlm b/lms-audio.xlm old mode 100755 new mode 100644 diff --git a/src/audiomotor.cpp b/src/audiomotor.cpp index 37ba491..dbb1859 100644 --- a/src/audiomotor.cpp +++ b/src/audiomotor.cpp @@ -53,8 +53,6 @@ bool AudioMotor::init() connect(m_writePD, SIGNAL(connected()),this, SLOT(newConexion())); connect(m_writePD, SIGNAL(error(QAbstractSocket::SocketError)) , this, SLOT(errorWrite(QAbstractSocket::SocketError))); - - // Servidor para recibir feedback de Pure Data m_readPD = new QTcpServer(this); Q_CHECK_PTR(m_readPD); @@ -64,6 +62,7 @@ bool AudioMotor::init() qDebug(QString("AudioMotor| Listening to PD on TCP port %1").arg(PDPORT).toLatin1()); } else { qErrnoWarning(QString("AudioMotor::init() can not init TCP Server on port %1").arg(PDPORT).toLatin1()); + emit toTerminal(QString("AudioMotor::init() can not init TCP Server on port)" + PDPORT)); } // Start the pd process an set up PD @@ -77,16 +76,14 @@ bool AudioMotor::init() arguments.append("./puredata/pd -channels 2 -stderr -nostdpath -path ./puredata/externals/ -open ./puredata/lms-audio.pd "); if (!m_gui) arguments.append("-nogui"); - qDebug() << "PD starts with arguments: " << arguments; - m_pd_audio->start(arguments); - if (m_pd_audio->waitForStarted(3000)){ - qDebug("AudioMotor| PD started."); + qDebug("AudioMotor| PD started"); + emit toTerminal(QString("AudioMotor| PD started")); } else { - qWarning("AudioMotor| PD not started!"); + emit toTerminal("AudioMotor| Can not init PD"); qErrnoWarning("AudioMotor| Can not init PD"); return false; } @@ -154,11 +151,13 @@ bool AudioMotor::load(int layer, QString file) if (QAbstractSocket::ConnectedState != m_writePD->state()) { qErrnoWarning("AudioMotor::load(): Socket not conected: "); + emit toTerminal("AudioMotor::load(): Socket not connectedt"); return false; } if (message.size() != m_writePD->write(message.toAscii().constData(), message.size())) { qErrnoWarning("AudioMotor::load(): Can not write to socket"); + emit toTerminal("AudioMotor::load(): Can not write to socket"); return false; } return true; @@ -293,6 +292,7 @@ void AudioMotor::newMessage() if (m_connectedSocket == NULL) { qDebug()<<("AudioMotor::newMessage() Socket not connected. Trying open it..."); + emit toTerminal("AudioMotor::newMessage() Socket not connected. Trying open it..."); newPeer(); return; } @@ -302,7 +302,6 @@ void AudioMotor::newMessage() void AudioMotor::parse(QString message) { - int aux; QStringList list = message.split("\n", QString::SkipEmptyParts); for (int i = 0; i < list.size(); i ++) { if (list.at(i).size() > 0) { @@ -310,7 +309,8 @@ void AudioMotor::parse(QString message) QChar val = list.at(i).at(0); switch (val.digitValue()) { case 0: - qDebug() << "AudioMotor::newMessage() Loadbang from PD Audio received..."; + qDebug() << "AudioMotor::newMessage() Loadbang from PD Audio received"; + emit toTerminal("AudioMotor::newMessage() Loadbang from PD Audio received"); // Conectamos a Pure Data para escribir m_writePD->connectToHost(QHostAddress::LocalHost, SOCKET, QIODevice::WriteOnly); if (m_writePD->waitForConnected(30000)) @@ -334,10 +334,6 @@ void AudioMotor::parse(QString message) break; } - - - - } } } @@ -351,6 +347,7 @@ void AudioMotor::errorWrite(QAbstractSocket::SocketError error) // QString error = m_writePD->errorString(); qErrnoWarning(QString("AudioMotor::errorWrite() %1").arg(error).toLatin1()); + emit toTerminal(QString("AudioMotor::errorWrite() ") + error); } /** Sends packets to Pure Data audio @@ -376,5 +373,6 @@ bool AudioMotor::sendPacket(const char *buffer, int bufferLen) // Function error sending packets to PD audio void AudioMotor::errorSending() { qDebug() << "AudioMotor| Can not send packets to PD"; + emit toTerminal("AudioMotor| Can not send packets to PD"); } diff --git a/src/audiomotor.h b/src/audiomotor.h index 3fcb0d5..714ee31 100644 --- a/src/audiomotor.h +++ b/src/audiomotor.h @@ -114,6 +114,7 @@ signals: void newConnection(); void mediaLoaded(int layer, QString folder, QString file); void volChanged(int layer, int vol); + void toTerminal(QString message); private slots: diff --git a/src/libremediaserver-audio.cpp b/src/libremediaserver-audio.cpp index d2db36c..3b43582 100755 --- a/src/libremediaserver-audio.cpp +++ b/src/libremediaserver-audio.cpp @@ -25,8 +25,6 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) : QMainWindow(parent) { - ola = new olaThread(); - qDebug() << "********************************************************************************"; qDebug() << QDate::currentDate() << QTime::currentTime(); qDebug() << VERSION; @@ -36,13 +34,7 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) // Inicia el User Interface ui.setupUi(this); - // Inicia la lectura de dmx a través de ola - - ola->start(QThread::TimeCriticalPriority ); - ola->blockSignals(true); - // Inicia el widget Terminal - textEdit = new QTextEdit(this); textEdit->append(QString::fromAscii(VERSION)); textEdit->append(QString::fromAscii(LICENSE)); @@ -53,6 +45,14 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) bottomWidget->setWidget(textEdit); addDockWidget(Qt::BottomDockWidgetArea, bottomWidget); + // Inicia la lectura de dmx a través de ola + ola = new olaThread(); + Q_CHECK_PTR(ola); + connect(ola, SIGNAL(toTerminal(QString)), + this, SLOT(toTerminal(QString))); + ola->start(QThread::TimeCriticalPriority ); + ola->blockSignals(true); + // Inicia el widget central de audio aw = new AudioWidget(this); @@ -74,6 +74,9 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) textEdit->append("Pure Data GUI's will be shown"); } else { AudioMotor::getInstance()->setGui(false); } + connect(AudioMotor::getInstance(), SIGNAL(toTerminal(QString)), + this, SLOT(toTerminal(QString))); + if (args.contains("-log")) { textEdit->append("Log to file"); @@ -184,7 +187,7 @@ void libreMediaServerAudio::olasetup() } /** - * Parse the nes dmx information + * Parse the dmx information */ void libreMediaServerAudio::dmxInput(int layer, int channel, int value) { diff --git a/src/libremediaserver-audio.h b/src/libremediaserver-audio.h index 02803a2..caf2fe2 100755 --- a/src/libremediaserver-audio.h +++ b/src/libremediaserver-audio.h @@ -48,7 +48,7 @@ #define LICENSE "GPL 3 License. See LICENSE.txt and credits.txt for details" class QMenu; -class QProcess; +//class QProcess; class libreMediaServerAudio : public QMainWindow { @@ -86,6 +86,11 @@ private: public slots: + inline void toTerminal (QString message) + { + textEdit->append(message); + } + private slots: /** diff --git a/src/olainterface.cpp b/src/olainterface.cpp deleted file mode 100755 index 0cd4568..0000000 --- a/src/olainterface.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* olainterface.cpp - Santi Noreña 2013 - It includes two classes: - olaWorker is the threading class that reads raw DMX from ola daemon and save it into a buffer ordered in layers - olaInterface controls olaWorker and translates DMX values received from olaWorker into orders to RenderingManager and Source -*/ - -#include "olainterface.h" - -olaInterface::olaInterface() -{ - qDebug() << tr("olaInterface|") << "Starting"; - m_thread = NULL; - m_thread = new QThread; - Q_CHECK_PTR(m_thread); - worker = new olaWorker(); - Q_CHECK_PTR(worker); - connect (worker, SIGNAL(dmx(int,int,int)), this, SLOT(dmx(int,int,int)), Qt::QueuedConnection); // The DMX values. - worker->moveToThread(m_thread); - connect(m_thread, SIGNAL(started()), worker, SLOT(olastart())); - connect(m_thread, SIGNAL(finished()), m_thread, SLOT(deleteLater())); - m_thread->start(); -} - -olaInterface::~olaInterface() -{ - close(); -} - -// Close olaWorker and finish the thread -void olaInterface::close() -{ - worker->blockSignals(true); - worker->olastop(); - delete worker; -} - -//////////////////////////////////////////////////////////// -// -// Parse new DMX -// -//////////////////////////////////////////////////////////// - -//New dmx. Connected with signal newdmx from olaInterface->Worker -void olaInterface::dmx(int layer, int channel, int value) -{ - -} - - - diff --git a/src/olainterface.h b/src/olainterface.h deleted file mode 100755 index 02eb1ab..0000000 --- a/src/olainterface.h +++ /dev/null @@ -1,68 +0,0 @@ -/* olainterface.h - Santi Noreña 2013 - It includes two classes: - olaWorker is the threading class that reads raw DMX from ola daemon - olaInterface controls olaWorker and translates DMX values received from olaWorker into orders to RenderingManager and Source -*/ -#ifndef OLAINTERFACE_H -#define OLAINTERFACE_H - -//#define DMX_SOURCETYPE 7 - -#define LAYER_CHANNELS 15 // The numer of control channels per video layer -#define MAX_SOURCE_DMX 8 // Number of maximum Sources controlled by DMX. It should be equal to MAX_SOURCE_COUNT - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -// The OLA Library -#include -#include -//#include - - -#include "libremediaserver.h" - -using namespace ola; - -class olaInterface : public QObject -{ - Q_OBJECT - -public: - explicit olaInterface(); - virtual ~olaInterface(); - - void open(); // Starts the thread and open the connection with olad - void close(); // Close the connection with olad - - olaWorker *worker; // The thread of connection with ola. - -protected: - - QThread *m_thread; // The thread for olaWorker - -private: - - void readDataFromXML(); // Read the DMX configuration from the file dmx.xml - -public slots: - - void dmx(int layer, int channel, int value); // Connected with signal dmx from olaWorker. This is the horsepower of all this. Converts DMX orders - // into orders to RenderingManager and Source. Mantains updated the videolayer struct. -signals: - -}; - - -#endif // OLAINTERFACE_H - diff --git a/src/olathread.cpp b/src/olathread.cpp index d222b3f..42cb448 100644 --- a/src/olathread.cpp +++ b/src/olathread.cpp @@ -51,8 +51,9 @@ void olaThread::run() { if (!m_client->RegisterUniverse(m_universe, ola::REGISTER,ola::NewSingleCallback(&RegisterComplete))) { qDebug() << "Can not register universe %1".arg(m_universe); }*/ + qDebug() << tr("olaThread| Running"); + emit toTerminal("Reading DMX"); m_clientWrapper->GetSelectServer()->Run(); - qDebug()<< tr("olaThread|") << "Running"; } void olaThread::stop() @@ -111,19 +112,18 @@ bool olaThread::CheckDataLoss() { if (diff.tv_sec > 4 || (diff.tv_sec == 4 && diff.tv_usec > 4000000)) { // loss of data qDebug()<< "olaThread| Can not read one or several universes"; -// return false; // Retorna false para deshabilitar el callback + emit toTerminal("Can not read one universe"); + // return false; // Retorna false para deshabilitar el callback } } return true; } - - void olaThread::setLayersNumber(int layersNumber) { m_layersNumber = layersNumber; } - void olaThread::resendDmx() { + emit toTerminal("Resending DMX info"); for (int i = 0; i < m_layersNumber; i++) { // loop for reading the channels by layer. for (int j = 0; j < LAYER_CHANNELS; j++){ emit dmxOutput(i, j, m_dmx[i][j]); // Connected with dmx slot in olaInterface. diff --git a/src/olathread.h b/src/olathread.h index 1f6e9e1..ae44238 100644 --- a/src/olathread.h +++ b/src/olathread.h @@ -34,8 +34,6 @@ public: olaThread(QObject *parent = 0); virtual ~olaThread(); - - /** Retorna el valor de un canal *@param int layer the layer for we want the channel *@param int channel the channel for the value wanted @@ -54,7 +52,6 @@ public: private: - void run (); ola::client::OlaClientWrapper *m_clientWrapper; @@ -87,8 +84,10 @@ private: inline void RegisterComplete(const ola::client::Result &error) { if (error.Success()) { qDebug() << "Register Universe success"; + emit toTerminal("Register Universe success"); } else { qWarning() << "olaThread|" << "Register command failed" << QString::fromStdString(error.Error()); + emit toTerminal("olaThread| Register command failed " + QString::fromStdString(error.Error())); } } @@ -121,6 +120,7 @@ signals: void finished(); // Signal for closing. Not used now. void dmxOutput(int layer, int channel, int value); // Signal when a channel has changed + void toTerminal(QString message); }; #endif // OLATHREAD_H