diff --git a/src/audiolayerwidget.cpp b/src/audiolayerwidget.cpp index 177dc33..eece14d 100644 --- a/src/audiolayerwidget.cpp +++ b/src/audiolayerwidget.cpp @@ -7,13 +7,14 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): QGroupBox(parent) - , m_pullTimer(new QTimer(this)) , m_suspendResumeButton(0) , m_deviceBox(0) - , m_output(0) + , m_pullTimer(new QTimer(this)) , m_device(QAudioDeviceInfo::defaultOutputDevice()) , m_audioOutput(0) + , m_output(0) , m_buffer(BufferSize, 0) + , m_decoder(0) { this->setTitle(name); @@ -110,6 +111,7 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): m_format = info.nearestFormat(m_format); } m_decoder = new AudioDecoder(m_format, this); + m_decoder->start(); connect(m_decoder, SIGNAL(totalTimeChanged(qint64)), this, SLOT(durationChanged(qint64))); connect(m_pullTimer, SIGNAL(timeout()), @@ -128,7 +130,8 @@ void AudioLayerWidget::createAudioOutput() m_audioOutput->setNotifyInterval(100); connect(m_audioOutput, SIGNAL(notify()), SLOT(notified())); connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(handleStateChanged(QAudio::State))); - m_decoder->start(); + m_output = m_audioOutput->start(); + toggleSuspendResume(); } void AudioLayerWidget::deviceChanged(int index) @@ -185,8 +188,8 @@ void AudioLayerWidget::pullTimerExpired() while (chunks) { const qint64 len = m_decoder->read(m_buffer.data(), m_audioOutput->periodSize()); if ( len == -1) { - qDebug() << "End of file"; stop(); + qDebug()<< this->title() << " End of file"; break; } if (len) { @@ -250,9 +253,9 @@ void AudioLayerWidget::fileLoaded(QString file) void AudioLayerWidget::play() { - m_decoder->setPos(0); - m_output = m_audioOutput->start(); +// m_decoder->setPos(0); m_pullTimer->start(20); + m_audioOutput->resume(); m_statusValue->setText(PLAY_LABEL); m_suspendResumeButton->setText(tr(SUSPEND_LABEL)); } @@ -264,10 +267,10 @@ void AudioLayerWidget::pause() void AudioLayerWidget::stop() { - m_pullTimer->stop(); m_audioOutput->suspend(); - m_audioOutput->reset(); - m_decoder->setPos(0); + m_pullTimer->stop(); +// m_audioOutput->reset(); + m_decoder->setPos(44); m_statusValue->setText(STOP_LABEL); m_suspendResumeButton->setText(tr(RESUME_LABEL)); } diff --git a/src/defines.h b/src/defines.h index df8f3a4..d46e749 100644 --- a/src/defines.h +++ b/src/defines.h @@ -2,7 +2,7 @@ #define DEFINES_H -#define VERSION "LibreMediaServer-Audio 0.1.0" +#define VERSION "Libre Media Server Audio 0.1.0" #define COPYRIGHT "(C) 2014 Santi Norena libremediaserver@gmail.com" #define LICENSE "GPL 3 License. See LICENSE.txt and credits.txt for details" @@ -25,7 +25,7 @@ const int BufferSize = 32768; #define PROGRESS_LABEL "Progress: " #define PROGRESS_TIME_LABEL "Current Time: " #define REMAINING_TIME "Remaining Time: " -#define TOTAL_TIME_LABEL "Track Time: " +#define TOTAL_TIME_LABEL "Total Time: " #define FILE_LABEL "File: " #define FOLDER_LABEL "Folder: " #define STATUS_LABEL "Status: " diff --git a/src/libremediaserver-audio.cpp b/src/libremediaserver-audio.cpp index d4ed8cf..9c6ba60 100755 --- a/src/libremediaserver-audio.cpp +++ b/src/libremediaserver-audio.cpp @@ -18,6 +18,11 @@ */ #include "libremediaserver-audio.h" +QTextEdit * libreMediaServerAudio::textEdit = 0; + + + + /** / Constructor */ @@ -25,25 +30,24 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) : QMainWindow(parent) { - qDebug() << "********************************************************************************"; - qDebug() << QDate::currentDate().toString() << " "<< QTime::currentTime().toString(); - qDebug() << VERSION; - qDebug() << COPYRIGHT; - qDebug() << LICENSE; - + Q_UNUSED(args); ui.setupUi(this); - this->setWindowTitle(VERSION); // Inicia el widget Terminal - textEdit = new QTextEdit(this); - textEdit->append(QString::fromLatin1(VERSION)); - textEdit->append(QString::fromLatin1(LICENSE)); - textEdit->append(QString::fromLatin1(COPYRIGHT)); + textEdit = new QTextEdit; + textEdit->setReadOnly(true); QDockWidget *bottomWidget = new QDockWidget(tr("Terminal"), this); bottomWidget->setAllowedAreas(Qt::BottomDockWidgetArea); bottomWidget->setWidget(textEdit); addDockWidget(Qt::BottomDockWidgetArea, bottomWidget); + this->setWindowTitle(VERSION); + +// qDebug() << QDate::currentDate().toString() << " "<< QTime::currentTime().toString(); + qDebug() << VERSION; + qDebug() << COPYRIGHT; + qDebug() << LICENSE; + // Inicia el widget central de audio aw = new AudioWidget(this); setCentralWidget(aw); @@ -51,11 +55,19 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) // 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); + connect(ola, SIGNAL(toTerminal(QString)), + textEdit, SLOT(append(QString)), Qt::QueuedConnection); + + ola->blockSignals(true); + ola->start(QThread::TimeCriticalPriority ); + +/* connect(MediaLibrary::getInstance(), SIGNAL(debug(QString)), + textEdit, SLOT(append(QString)), Qt::QueuedConnection); + + connect(MediaLibrary::getInstance(), SIGNAL(warning(QString)), + textEdit, SLOT(append(QString)), Qt::QueuedConnection); +*/ // Inicia el widget Master. No implementado todavía /* amw = new AudioMasterWidget(this); @@ -64,11 +76,6 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) topWidget->setWidget(amw); addDockWidget(Qt::TopDockWidgetArea, topWidget); */ - if (args.contains("-log")) - { - textEdit->append("Log to file"); - } - // Conectamos los menus connect(ui.actionOpen_conf, SIGNAL(triggered()), this, SLOT(openFile())); connect(ui.actionSave_conf, SIGNAL(triggered()), this, SLOT(saveFile())); @@ -98,11 +105,11 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) libreMediaServerAudio::~libreMediaServerAudio() { // save_finish(); - delete MediaLibrary::getInstance(); - ola->stop(); - qDebug() << QDate::currentDate().toString() << " " << QTime::currentTime().toString(); - qDebug() << "********************************************************************************"; - return; +// delete MediaLibrary::getInstance(); +// ola->stop(); +// qDebug() << QDate::currentDate().toString() << " " << QTime::currentTime().toString(); +// qDebug() << "********************************************************************************"; +// return; } /////////////////////////////////////////////////////////////////// diff --git a/src/libremediaserver-audio.h b/src/libremediaserver-audio.h index a9973d2..a05e21b 100755 --- a/src/libremediaserver-audio.h +++ b/src/libremediaserver-audio.h @@ -51,13 +51,15 @@ public: Ui::LibreMediaServerAudio ui; + static QTextEdit *textEdit; // Terminal de feedback + protected: QString m_pathmedia; // Path to Medias private: - QTextEdit *textEdit; // Terminal de feedback +// void MessageHandler(QtMsgType type, const QMessageLogContext &logcontext, const QString &msg); AudioMasterWidget *amw; AudioWidget *aw; olaThread *ola; @@ -68,11 +70,7 @@ private: void save(QFile *file); public slots: - - inline void toTerminal (QString message) - { - textEdit->append(message); - } +// inline void toTerminal(QString msg) { textEdit->append(msg); } private slots: diff --git a/src/libremediaserver-audio.pro b/src/libremediaserver-audio.pro index d28775f..037f010 100755 --- a/src/libremediaserver-audio.pro +++ b/src/libremediaserver-audio.pro @@ -32,7 +32,8 @@ FORMS += \ #INCLUDEPATH += ./ -LIBS += -L./debug -lola -lolacommon +LIBS += -lola -lolacommon +# -L./debug #win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../debug/release/ -lcitp #else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../debug/debug/ -lcitp @@ -43,7 +44,6 @@ LIBS += -L./debug -lola -lolacommon RESOURCES = - OTHER_FILES += \ ../LICENSE.txt \ ../instalacion.txt \ diff --git a/src/main.cpp b/src/main.cpp index e95dd0c..d00acb0 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,36 +19,22 @@ */ #include +#include +#include #include "libremediaserver-audio.h" -// Handler for pipe the stderr to a log file +// Handler for pipe the stderr to a log file and texEdit bool initMessageHandler = false; QFile outFile; +QMutex mutex; +//QMutexLocker mutexLocker(mutex); -void MessageHandler(QtMsgType type, const QMessageLogContext &logcontext, const QString &msg) +void MessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { - Q_UNUSED(logcontext); - QString txt; - switch (type) { - case QtDebugMsg: - txt.append("Debug: "); - txt.append(msg); - break; - case QtWarningMsg: - txt.append("Warning: "); - txt.append(msg); - break; - case QtCriticalMsg: - txt.append("Critical: "); - txt.append(msg); - break; - case QtFatalMsg: - txt.append("Fatal: "); - txt.append(msg); - abort(); - } + Q_UNUSED(context); +// mutex.lock(); // Create the log dir and log file - if (!initMessageHandler) { +/* if (!initMessageHandler) { QDir dir; if (!dir.exists("log")) { if (!dir.mkdir("log")) { @@ -69,13 +55,74 @@ void MessageHandler(QtMsgType type, const QMessageLogContext &logcontext, const } initMessageHandler = true; } - QTextStream ts(&outFile); - ts << txt << endl; + QTextStream ts(&outFile);*/ + if (libreMediaServerAudio::textEdit == 0) + { + QByteArray localMsg = msg.toLocal8Bit(); + switch (type) { + case QtDebugMsg: + fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); + break; + case QtWarningMsg: + fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); + break; + case QtCriticalMsg: + fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); + break; + case QtFatalMsg: + fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); + abort(); + } + } + else + { + QString txt; + switch (type) { + case QtDebugMsg: + txt.append("Debug: "); + txt.append(context.file); + txt.append(context.line); + txt.append(context.function); + txt.append(msg); +// libreMediaServerAudio::textEdit->append(msg);, context.file, context.line, context.function); + libreMediaServerAudio::textEdit->append(txt); + break; + case QtWarningMsg: +// txt.append("Warning: "); +// txt.append(msg); + libreMediaServerAudio::textEdit->append(msg); + break; + case QtCriticalMsg: +// txt.append("Critical: "); +// txt.append(msg); + libreMediaServerAudio::textEdit->append(msg); + break; + case QtFatalMsg: +// txt.append("Fatal: "); +// txt.append(msg); + libreMediaServerAudio::textEdit->append(msg); +// ts << txt << endl; + abort(); + } +// outFile.write(txt.toLatin1().constData(), txt.size()); +// ts << txt << endl; +// libreMediaServerAudio::textEdit->append(txt); + } +// mutex.unlock(); } int main(int argc, char *argv[]) { + + // ToDo: discriminar niveles de log y log a fichero segúna argumentos + /* + if (args.contains("-log")) + { + qInstallMessageHandler(MessageHandler); + }*/ + QApplication app(argc, argv); + qInstallMessageHandler(MessageHandler); QStringList args = app.arguments(); // parse the command line if (args.size() > 1) @@ -98,10 +145,6 @@ int main(int argc, char *argv[]) qDebug() << "-h this help"; return 0; } - if (args.contains("-log")) - { - qInstallMessageHandler(MessageHandler); - } } libreMediaServerAudio libreMediaServerAudio(args); libreMediaServerAudio.show(); diff --git a/src/olathread.cpp b/src/olathread.cpp index b19bef2..366a644 100644 --- a/src/olathread.cpp +++ b/src/olathread.cpp @@ -2,6 +2,7 @@ olaThread::olaThread(QObject *parent) { + Q_UNUSED(parent); m_universe = new QList(); m_counter = 0; gettimeofday(&m_last_data, NULL); @@ -27,7 +28,7 @@ olaThread::olaThread(QObject *parent) ola::InitLogging(ola::OLA_LOG_INFO , ola::OLA_LOG_STDERR); m_client->SetDMXCallback(ola::NewCallback(this, &olaThread::NewDmx)); m_clientWrapper->GetSelectServer()->RegisterRepeatingTimeout(4000, ola::NewCallback(this, &olaThread::CheckDataLoss)); - qDebug() << "Init olaThread"; +// qDebug() << "Init olaThread"; } // --- DECONSTRUCTOR --- @@ -40,7 +41,7 @@ olaThread::~olaThread() { void olaThread::run() { - qDebug() << tr("olaThread| Running"); +// qDebug() << tr("olaThread| Running"); emit toTerminal("Reading DMX"); m_clientWrapper->GetSelectServer()->Run(); } @@ -72,7 +73,7 @@ void olaThread::NewDmx(const ola::client::DMXMetadata &data, { m_counter++; gettimeofday(&m_last_data, NULL); - int universe = data.universe; + uint universe = data.universe; for (int i = 0; i < m_layersNumber; i++) { // loop for reading the channels by layer. if((m_settings.at(i).universe == universe) && ( m_settings.at(i).address > -1 )) { // Compare if the layer is from this universe @@ -99,8 +100,8 @@ bool olaThread::CheckDataLoss() { timersub(&now, &m_last_data, &diff); 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"; - emit toTerminal("Can not read one universe"); +// qDebug()<< "olaThread| Can not read one or several universes"; + emit toTerminal("olaThread: Can not read one universe"); // return false; // Retorna false para deshabilitar el callback } } @@ -111,14 +112,13 @@ void olaThread::setLayersNumber(int layersNumber) { m_layersNumber = layersNumbe void olaThread::resendDmx() { - emit toTerminal("Resending DMX info"); +// qDebug() << "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. } } } - ////////////////////////////////////////////////////////////////////////////////////////////