diff --git a/src/audiodecoder.cpp b/src/audiodecoder.cpp index 41542ae..bff8f2c 100644 --- a/src/audiodecoder.cpp +++ b/src/audiodecoder.cpp @@ -106,16 +106,16 @@ void AudioDecoder::errorDecoding(QAudioDecoder::Error msg) case QAudioDecoder::NoError: break; case QAudioDecoder::ResourceError: - qWarning() << "A media resource couldn't be resolved: " << m_decoder->sourceFilename(); + qWarning("A media resource couldn't be resolved: %s", m_decoder->sourceFilename().toLatin1().constData()); break; case QAudioDecoder::FormatError: - qWarning() << "The format of a media resource isn't supported: " << m_decoder->sourceFilename();; + qWarning("The format of a media resource isn't supported: %s", m_decoder->sourceFilename().toLatin1().constData()); break; case QAudioDecoder::AccessDeniedError: - qWarning() << "There are not the appropriate permissions to play a media resource" << m_decoder->sourceFilename();; + qWarning("There are not the appropriate permissions to play a media resource %s", m_decoder->sourceFilename().toLatin1().constData()); break; case QAudioDecoder::ServiceMissingError: - qWarning() << "A valid playback service was not found, playback cannot proceed."; + qWarning("A valid playback service was not found, playback cannot proceed"); break; } } @@ -127,7 +127,6 @@ qint64 AudioDecoder::readData(char *data, qint64 len) qint64 total = 0; while (len - total > 0) { const qint64 chunk = qMin((m_buffer.size() - m_pos), len - total); -// qWarning() << "Buffer Size: " << m_buffer.size() << "m_pos: " << m_pos; memcpy(data + total, m_buffer.constData() + m_pos, chunk); // Controla Final del track if ( (m_pos + chunk ) >= ( m_buffer.size() ) @@ -153,7 +152,7 @@ qint64 AudioDecoder::bytesAvailable() const void AudioDecoder::decoderFinished() { - qDebug() << "AudioDecoder: Decoding file finished; " << m_decoder->sourceFilename(); + qDebug("Decoding file finished %s ", m_decoder->sourceFilename().toLatin1().constData()); emit fileLoaded(m_decoder->sourceFilename()); } diff --git a/src/audiolayerwidget.cpp b/src/audiolayerwidget.cpp index eece14d..ed57bbc 100644 --- a/src/audiolayerwidget.cpp +++ b/src/audiolayerwidget.cpp @@ -9,16 +9,22 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): QGroupBox(parent) , m_suspendResumeButton(0) , m_deviceBox(0) + , m_watchDMX(new QTimer(this)) , m_pullTimer(new QTimer(this)) , m_device(QAudioDeviceInfo::defaultOutputDevice()) , m_audioOutput(0) , m_output(0) , m_buffer(BufferSize, 0) , m_decoder(0) + , m_progressCounter(new QTime(0,0,0,1)) + , m_progressMs(0) + , m_currentMedia(" ") + { this->setTitle(name); QVBoxLayout *layout = new QVBoxLayout; + m_deviceBox = new QComboBox(this); const QAudioDeviceInfo &defaultDeviceInfo = QAudioDeviceInfo::defaultOutputDevice(); m_deviceBox->addItem(defaultDeviceInfo.deviceName(), qVariantFromValue(defaultDeviceInfo)); @@ -26,6 +32,7 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): if (deviceInfo != defaultDeviceInfo) m_deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); } + m_deviceBox->setMaximumWidth(250); connect(m_deviceBox,SIGNAL(activated(int)), this, SLOT(deviceChanged(int))); layout->addWidget(m_deviceBox); @@ -34,6 +41,10 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): m_statusLabel = new QLabel; m_statusLabel->setText(STATUS_LABEL); m_statusValue = new QLabel; + m_receiveDMX = new QCheckBox("Receiving DMX", this); +// m_receiveDMX->setCheckable(false); + m_receiveDMX->setChecked(false); + status->addWidget(m_receiveDMX); status->addWidget(m_statusLabel); status->addWidget(m_statusValue); layout->addLayout(status); @@ -54,23 +65,43 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): fileLoaded->addWidget(m_fileValue); layout->addLayout(fileLoaded); - m_suspendResumeButton = new QPushButton(this); - m_suspendResumeButton->setText(tr(SUSPEND_LABEL)); - connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspendResume())); - layout->addWidget(m_suspendResumeButton); - QHBoxLayout *volumeBox = new QHBoxLayout; m_volumeLabel = new QLabel; m_volumeLabel->setText(tr(VOLUME_LABEL)); m_volumeSlider = new QSlider(Qt::Horizontal); m_volumeSlider->setMinimum(0); - m_volumeSlider->setMaximum(100); + m_volumeSlider->setMaximum(80); m_volumeSlider->setSingleStep(1); connect(m_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(volumeChanged(int))); volumeBox->addWidget(m_volumeLabel); volumeBox->addWidget(m_volumeSlider); layout->addLayout(volumeBox); + QHBoxLayout *progressTime = new QHBoxLayout; + m_progressTimeLabel = new QLabel; + m_progressTimeLabel->setText(PROGRESS_TIME_LABEL); + m_progressTime = new QTimeEdit; + m_progressTime->setDisplayFormat("h:mm:ss:zzz"); + m_progressTime->setReadOnly(true); + m_progressTime->setButtonSymbols(QAbstractSpinBox::NoButtons); + m_progressTime->setMaximumWidth(90); + progressTime->addWidget(m_progressTimeLabel); + progressTime->addWidget(m_progressTime); + + +// QHBoxLayout *totalTime = new QHBoxLayout; + m_totalTimeLabel = new QLabel; + m_totalTimeLabel->setText(TOTAL_TIME_LABEL); + m_totalTimeValue = new QTimeEdit; + m_totalTimeValue->setDisplayFormat("h:mm:ss:zzz"); + m_totalTimeValue->setReadOnly(true); + m_totalTimeValue->setButtonSymbols(QAbstractSpinBox::NoButtons); + m_totalTimeValue->setMaximumWidth(90); + progressTime->addWidget(m_totalTimeLabel); + progressTime->addWidget(m_totalTimeValue); +// layout->addLayout(totalTime); + layout->addLayout(progressTime); + QHBoxLayout *progressSlider = new QHBoxLayout; m_progressLabel = new QLabel; m_progressLabel->setText(PROGRESS_LABEL); @@ -79,22 +110,10 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): progressSlider->addWidget(m_progressSlider); layout->addLayout(progressSlider); - QHBoxLayout *progressTime = new QHBoxLayout; - m_progressTimeLabel = new QLabel; - m_progressTimeLabel->setText(PROGRESS_TIME_LABEL); - m_progressTimeValue = new QLabel; - m_progressTimeValue->setText("0:00:00:000"); - progressTime->addWidget(m_progressTimeLabel); - progressTime->addWidget(m_progressTimeValue); - layout->addLayout(progressTime); - - QHBoxLayout *totalTime = new QHBoxLayout; - m_totalTimeLabel = new QLabel; - m_totalTimeLabel->setText(TOTAL_TIME_LABEL); - m_totalTimeValue = new QLabel; - totalTime->addWidget(m_totalTimeLabel); - totalTime->addWidget(m_totalTimeValue); - layout->addLayout(totalTime); + m_suspendResumeButton = new QPushButton(this); + m_suspendResumeButton->setText(tr(SUSPEND_LABEL)); + connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspendResume())); + layout->addWidget(m_suspendResumeButton); this->setLayout(layout); @@ -107,7 +126,7 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(m_format)) { - qWarning() << "Default format not supported - trying to use nearest"; + qWarning("Default format not supported - trying to use nearest"); m_format = info.nearestFormat(m_format); } m_decoder = new AudioDecoder(m_format, this); @@ -116,6 +135,10 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name): this, SLOT(durationChanged(qint64))); connect(m_pullTimer, SIGNAL(timeout()), this, SLOT(pullTimerExpired())); + + connect(m_watchDMX, SIGNAL(timeout()), + this, SLOT(watchDMXExpired())); + m_watchDMX->start(1000); createAudioOutput(); } @@ -127,17 +150,17 @@ AudioLayerWidget::~AudioLayerWidget() void AudioLayerWidget::createAudioOutput() { m_audioOutput = new QAudioOutput(m_device, m_format, this); - m_audioOutput->setNotifyInterval(100); + Q_CHECK_PTR(m_audioOutput); + m_audioOutput->setNotifyInterval(NOTIFY_INTERVAL); connect(m_audioOutput, SIGNAL(notify()), SLOT(notified())); + reset(); + m_statusValue->setText(PAUSE_LABEL); connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(handleStateChanged(QAudio::State))); - m_output = m_audioOutput->start(); - toggleSuspendResume(); } void AudioLayerWidget::deviceChanged(int index) { m_pullTimer->stop(); - m_decoder->stop(); m_audioOutput->stop(); m_audioOutput->disconnect(this); m_device = m_deviceBox->itemData(index).value(); @@ -161,20 +184,31 @@ void AudioLayerWidget::setVol(qreal vol) void AudioLayerWidget::loadMedia(QString file) { - stop(); + if (m_currentMedia == file) + return; + reset(); if (QFile::exists(file)){ m_decoder->loadMedia(file); + m_currentMedia = file; fileLoaded(file); } } +void AudioLayerWidget::fileLoaded(QString file) +{ + QStringList list = file.split("/"); + int size = list.size(); + if (size >= 2) { + m_folderValue->setText(list.at(size - 2)); + m_fileValue->setText(list.at(size - 1)); + } +} + void AudioLayerWidget::notified() { - QTime real(0,0,0,0); - qint64 ms = m_audioOutput->processedUSecs() / 1000 ; - real = real.addMSecs(ms); - m_progressTimeValue->setText(real.toString("h:mm:ss:zzz")); - m_progressSlider->setValue(ms); + m_progressMs += m_progressCounter->restart(); + m_progressTime->setTime(QTime::fromMSecsSinceStartOfDay(m_progressMs)); + m_progressSlider->setValue(m_progressMs); /* qDebug() << "bytesFree = " << m_audioOutput->bytesFree() << ", " << "elapsedUSecs = " << m_audioOutput->elapsedUSecs() << ", " << "processedUSecs = " << m_audioOutput->processedUSecs(); @@ -189,7 +223,7 @@ void AudioLayerWidget::pullTimerExpired() const qint64 len = m_decoder->read(m_buffer.data(), m_audioOutput->periodSize()); if ( len == -1) { stop(); - qDebug()<< this->title() << " End of file"; + qDebug("End of file %s", this->title().toLatin1().constData()); break; } if (len) { @@ -205,72 +239,92 @@ void AudioLayerWidget::pullTimerExpired() void AudioLayerWidget::toggleSuspendResume() { if (m_audioOutput->state() == QAudio::SuspendedState) { -// qDebug() << "status: Suspended, resume()"; - m_audioOutput->resume(); - m_pullTimer->start(20); - m_suspendResumeButton->setText(tr(SUSPEND_LABEL)); - m_statusValue->setText(PLAY_LABEL); + resume(); } else if (m_audioOutput->state() == QAudio::ActiveState) { -// qDebug() << "status: Active, suspend()"; - m_audioOutput->suspend(); - m_pullTimer->stop(); - m_suspendResumeButton->setText(tr(RESUME_LABEL)); - m_statusValue->setText(PAUSE_LABEL); + pause(); } else if (m_audioOutput->state() == QAudio::StoppedState) { -// qDebug() << "status: Stopped, resume()"; play(); } else if (m_audioOutput->state() == QAudio::IdleState) { -// qDebug() << "status: IdleState"; - m_statusValue->setText(IDDLE_LABEL); + qWarning("%s: IdleState", this->title().toLatin1().constData()); + play(); } } void AudioLayerWidget::handleStateChanged(QAudio::State state) { - qDebug() << this->title() << " state = " << state; + if (state == QAudio::SuspendedState) { + m_statusValue->setText(PAUSE_LABEL); + } else if (state == QAudio::ActiveState) { + m_statusValue->setText(PLAY_LABEL); + } else if (m_audioOutput->state() == QAudio::StoppedState) { + m_statusValue->setText(STOP_LABEL); + } else if (state == QAudio::IdleState) { + m_statusValue->setText(IDDLE_LABEL); + } } void AudioLayerWidget::durationChanged(qint64 dur) { if (dur == -1) return; - QTime temp(0,0,0,0); - QTime real = temp.addMSecs(dur); - m_totalTimeValue->setText(real.toString("h:mm:ss:zzz")); + m_totalTimeValue->setTime(QTime::fromMSecsSinceStartOfDay(dur)); m_progressSlider->setMaximum(dur); - qDebug() << this->title() << " Duration Changed: " << dur; -} - -void AudioLayerWidget::fileLoaded(QString file) -{ - QStringList list = file.split("/"); - int size = list.size(); - if (size >= 2) { - m_folderValue->setText(list.at(size - 2)); - m_fileValue->setText(list.at(size - 1)); - } } void AudioLayerWidget::play() { -// m_decoder->setPos(0); - m_pullTimer->start(20); + setInitPosition(); + m_pullTimer->start(PULL_TIMER_INTERVAL); m_audioOutput->resume(); - m_statusValue->setText(PLAY_LABEL); + pullTimerExpired(); + m_progressCounter->start(); m_suspendResumeButton->setText(tr(SUSPEND_LABEL)); } void AudioLayerWidget::pause() { - toggleSuspendResume(); + m_audioOutput->suspend(); + m_pullTimer->stop(); + m_suspendResumeButton->setText(tr(RESUME_LABEL)); +} + +void AudioLayerWidget::resume() +{ + m_pullTimer->start(PULL_TIMER_INTERVAL); + m_audioOutput->resume(); + pullTimerExpired(); + m_progressCounter->start(); + m_suspendResumeButton->setText(tr(SUSPEND_LABEL)); } void AudioLayerWidget::stop() { - m_audioOutput->suspend(); - m_pullTimer->stop(); -// m_audioOutput->reset(); - m_decoder->setPos(44); - m_statusValue->setText(STOP_LABEL); - m_suspendResumeButton->setText(tr(RESUME_LABEL)); + reset(); + setInitPosition(); +} + +void AudioLayerWidget::reset() +{ + m_pullTimer->stop(); + m_audioOutput->reset(); + m_output = m_audioOutput->start(); + Q_CHECK_PTR(m_output); + pause(); +} + +void AudioLayerWidget::setInitPosition() +{ + m_decoder->setPos(0); + m_progressMs = 0; + m_progressTime->setTime(QTime::fromMSecsSinceStartOfDay(m_progressMs)); + m_progressSlider->setValue(m_progressMs); +} + +void AudioLayerWidget::watchDMXExpired() { + m_receiveDMX->setChecked(false); +} + +void AudioLayerWidget::updateWatchDMX(bool b) +{ + m_receiveDMX->setChecked(b); } diff --git a/src/audiolayerwidget.h b/src/audiolayerwidget.h index d380b5b..14eed99 100644 --- a/src/audiolayerwidget.h +++ b/src/audiolayerwidget.h @@ -8,7 +8,10 @@ #include #include #include +#include +#include #include +#include #include "audiodecoder.h" #include "defines.h" @@ -27,7 +30,9 @@ public: void stop(); void pause(); void setVol(qreal vol); + void resume(); + void updateWatchDMX(bool b); public slots: void toggleSuspendResume(); @@ -47,10 +52,10 @@ private: QSlider *m_progressSlider; QLabel *m_progressTimeLabel; - QLabel *m_progressTimeValue; + QTimeEdit *m_progressTime; QLabel *m_totalTimeLabel; - QLabel *m_totalTimeValue; + QTimeEdit *m_totalTimeValue; QLabel *m_fileLabel; QLabel *m_fileValue; @@ -58,6 +63,9 @@ private: QLabel * m_folderLabel; QLabel * m_folderValue; + QCheckBox *m_receiveDMX; + QTimer *m_watchDMX; + QTimer *m_pullTimer; QAudioDeviceInfo m_device; QAudioOutput *m_audioOutput; @@ -66,8 +74,16 @@ private: QByteArray m_buffer; AudioDecoder *m_decoder; + QTime *m_progressCounter; + quint64 m_progressMs; + + QString m_currentMedia; + void createAudioOutput(); + void reset(); + void setInitPosition(); + private slots: void notified(); void pullTimerExpired(); @@ -75,7 +91,7 @@ private slots: void handleStateChanged(QAudio::State state); void deviceChanged(int index); void durationChanged(qint64 dur); - + void watchDMXExpired(); }; diff --git a/src/audiowidget.cpp b/src/audiowidget.cpp index 05004e2..51a4be9 100644 --- a/src/audiowidget.cpp +++ b/src/audiowidget.cpp @@ -35,11 +35,17 @@ void AudioWidget::playbackChanged(int layer, QAudio::State state) dynamic_cast(item->widget())->play(); break; case QAudio::StoppedState: - dynamic_cast(item->widget())->stop(); + dynamic_cast(item->widget())->pause(); break; case QAudio::SuspendedState: - dynamic_cast(item->widget())->toggleSuspendResume(); + dynamic_cast(item->widget())->resume(); case QAudio::IdleState: break; } } + +void AudioWidget::layerReceived(int layer) +{ + QLayoutItem * const item = layout->itemAt(layer); + dynamic_cast(item->widget())->updateWatchDMX(true); +} diff --git a/src/audiowidget.h b/src/audiowidget.h index 6ac58b5..6654fae 100644 --- a/src/audiowidget.h +++ b/src/audiowidget.h @@ -24,6 +24,7 @@ public slots: void mediaLoaded(int layer, QString media); void volChanged(int layer, qreal vol); void playbackChanged(int layer, QAudio::State state); + void layerReceived(int layer); }; #endif // AUDIOWIDGET_H diff --git a/src/defines.h b/src/defines.h index d46e749..648734a 100644 --- a/src/defines.h +++ b/src/defines.h @@ -1,7 +1,6 @@ #ifndef DEFINES_H #define DEFINES_H - #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" @@ -13,22 +12,27 @@ const int DurationSeconds = 1; const int ToneSampleRateHz = 600; const int DataSampleRateHz = 44100; -const int BufferSize = 32768; +const int BufferSize = 262144; -#define SUSPEND_LABEL "Suspend playback" -#define RESUME_LABEL "Resume playback" -#define PLAY_LABEL "Playing" -#define STOP_LABEL "Stopped" -#define PAUSE_LABEL "Pause" -#define IDDLE_LABEL "Iddle playback" -#define VOLUME_LABEL "Volume:" -#define PROGRESS_LABEL "Progress: " -#define PROGRESS_TIME_LABEL "Current Time: " +#define SUSPEND_LABEL "Pause playback" +#define RESUME_LABEL "Resume playback" + +#define PLAY_LABEL "Playing" +#define STOP_LABEL "Stopped" +#define PAUSE_LABEL "Pause" +#define IDDLE_LABEL "Iddle playback" + +#define VOLUME_LABEL "Volume" +#define PROGRESS_LABEL "Progress" +#define PROGRESS_TIME_LABEL "Current" #define REMAINING_TIME "Remaining Time: " -#define TOTAL_TIME_LABEL "Total Time: " +#define TOTAL_TIME_LABEL "Total" #define FILE_LABEL "File: " #define FOLDER_LABEL "Folder: " -#define STATUS_LABEL "Status: " +#define STATUS_LABEL " Status: " + +#define NOTIFY_INTERVAL 150 +#define PULL_TIMER_INTERVAL 10 // struct where save the DMX settings for each layer struct dmxSetting { diff --git a/src/libremediaserver-audio.cpp b/src/libremediaserver-audio.cpp index 9c6ba60..b71822a 100755 --- a/src/libremediaserver-audio.cpp +++ b/src/libremediaserver-audio.cpp @@ -33,14 +33,21 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) Q_UNUSED(args); ui.setupUi(this); - // Inicia el widget Terminal - textEdit = new QTextEdit; - textEdit->setReadOnly(true); - QDockWidget *bottomWidget = new QDockWidget(tr("Terminal"), this); - bottomWidget->setAllowedAreas(Qt::BottomDockWidgetArea); - bottomWidget->setWidget(textEdit); - addDockWidget(Qt::BottomDockWidgetArea, bottomWidget); + // Inicia la lectura de dmx a través de ola + ola = new olaThread(); + Q_CHECK_PTR(ola); + if (args.contains("-log")) { + // Inicia el widget Terminal + textEdit = new QTextEdit; + textEdit->setReadOnly(true); + QDockWidget *bottomWidget = new QDockWidget(tr("Terminal"), this); + bottomWidget->setAllowedAreas(Qt::BottomDockWidgetArea); + bottomWidget->setWidget(textEdit); + addDockWidget(Qt::BottomDockWidgetArea, bottomWidget); + connect(ola, SIGNAL(toTerminal(QString)), + textEdit, SLOT(append(QString)), Qt::QueuedConnection); + } this->setWindowTitle(VERSION); // qDebug() << QDate::currentDate().toString() << " "<< QTime::currentTime().toString(); @@ -52,13 +59,7 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) aw = new AudioWidget(this); setCentralWidget(aw); - // Inicia la lectura de dmx a través de ola - ola = new olaThread(); - Q_CHECK_PTR(ola); - - connect(ola, SIGNAL(toTerminal(QString)), - textEdit, SLOT(append(QString)), Qt::QueuedConnection); - + // Inicia la lectur de datos DMX ola->blockSignals(true); ola->start(QThread::TimeCriticalPriority ); @@ -88,13 +89,14 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) ola, SLOT( setLayersNumber(int))); connect(set, SIGNAL( DMXConf(dmxSetting ) ), ola, SLOT( setDMXConf(dmxSetting) ) ); - - connect(ola, SIGNAL( dmxOutput(int, int, int) ), - this, SLOT( dmxInput(int, int, int) ) ); + connect(ola, SIGNAL (layerReceived(int)), + aw, SLOT(layerReceived(int))); // Lee la configuración por defecto set->readDefaultFile(); ola->blockSignals(false); + connect(ola, SIGNAL( dmxOutput(int, int, int) ), + this, SLOT( dmxInput(int, int, int) ) ); ola->resendDmx(); } @@ -173,6 +175,8 @@ void libreMediaServerAudio::dmxInput(int layer, int channel, int value) { // This qDebug slows all the program. Uncomment only for debugging purpouse and comment again in normal use // qDebug() << tr("olaInterface|") << "newdmx layer" << layer << "channel" << channel << "value" << value; + if (layer > LAYER_CHANNELS) + return; QString mediaFile = NULL; int aux; qreal f; @@ -201,6 +205,8 @@ void libreMediaServerAudio::dmxInput(int layer, int channel, int value) f = (float)value / 255; break; case PLAYBACK: + if (value == 0) + break; aux = value / 25; switch (aux) { case 0 : diff --git a/src/libremediaserver-audio.h b/src/libremediaserver-audio.h index a05e21b..d59d7d1 100755 --- a/src/libremediaserver-audio.h +++ b/src/libremediaserver-audio.h @@ -16,8 +16,8 @@ along with this program. If not, see . */ -#ifndef LIBREMEDIASERVER_H -#define LIBREMEDIASERVER_H +#ifndef LIBREMEDIASERVERAUDIO_H +#define LIBREMEDIASERVERAUDIO_H #include #include @@ -59,7 +59,7 @@ protected: private: -// void MessageHandler(QtMsgType type, const QMessageLogContext &logcontext, const QString &msg); + // void MessageHandler(QtMsgType type, const QMessageLogContext &logcontext, const QString &msg); AudioMasterWidget *amw; AudioWidget *aw; olaThread *ola; @@ -88,4 +88,4 @@ private slots: void ChangeMediaPath();// Change the path to medias }; -#endif // LIBREMEDIASERVER_H +#endif // LIBREMEDIASERVERAUDIO_H diff --git a/src/main.cpp b/src/main.cpp index d00acb0..89fa504 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,29 +79,54 @@ void MessageHandler(QtMsgType type, const QMessageLogContext &context, const QSt QString txt; switch (type) { case QtDebugMsg: - txt.append("Debug: "); + txt.append("Debug from File: "); txt.append(context.file); - txt.append(context.line); + txt.append(" Line: "); + txt.append(QString::number(context.line)); + txt.append(" Function: "); txt.append(context.function); + txt.append(" Message: "); 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); + txt.append("Warning from File: "); + txt.append(context.file); + txt.append(" Line: "); + txt.append(QString::number(context.line)); + txt.append(" Function: "); + txt.append(context.function); + txt.append(" Message: "); + txt.append(msg); +// libreMediaServerAudio::textEdit->append(msg);, context.file, context.line, context.function); + libreMediaServerAudio::textEdit->append(txt); + abort(); break; case QtCriticalMsg: -// txt.append("Critical: "); -// txt.append(msg); - libreMediaServerAudio::textEdit->append(msg); +// txt.append("Critical from File: "); + txt.append(context.file); + txt.append(" Line: "); + txt.append(QString::number(context.line)); + txt.append(" Function: "); + txt.append(context.function); + txt.append(" Message "); + txt.append(msg); +// libreMediaServerAudio::textEdit->append(msg);, context.file, context.line, context.function); + libreMediaServerAudio::textEdit->append(txt); + abort(); break; case QtFatalMsg: -// txt.append("Fatal: "); -// txt.append(msg); - libreMediaServerAudio::textEdit->append(msg); -// ts << txt << endl; +// txt.append("Fatal from File: "); + txt.append(context.file); + txt.append(" Line: "); + txt.append(QString::number(context.line)); + txt.append(" Function: "); + txt.append(context.function); + txt.append(" Message: "); + txt.append(msg); +// libreMediaServerAudio::textEdit->append(msg);, context.file, context.line, context.function); + libreMediaServerAudio::textEdit->append(txt);// ts << txt << endl; abort(); } // outFile.write(txt.toLatin1().constData(), txt.size()); @@ -120,9 +145,9 @@ int main(int argc, char *argv[]) { qInstallMessageHandler(MessageHandler); }*/ - - QApplication app(argc, argv); qInstallMessageHandler(MessageHandler); + QApplication app(argc, argv); + QStringList args = app.arguments(); // parse the command line if (args.size() > 1) diff --git a/src/medialibrary.cpp b/src/medialibrary.cpp index 9299b51..d884d38 100644 --- a/src/medialibrary.cpp +++ b/src/medialibrary.cpp @@ -27,7 +27,7 @@ MediaLibrary::MediaLibrary(QObject *parent) : void MediaLibrary::initMediaLibrary() { QDir dir; if (!dir.cd(m_pathmedia)) { - qWarning() << "olaInterface::initMediaLibrary| Can not cd to the path: " << m_pathmedia.toLatin1().constData(); + qWarning("Can not cd to the path: %s", m_pathmedia.toLatin1().constData()); return; } m_media = new QList; diff --git a/src/olathread.cpp b/src/olathread.cpp index 366a644..52388f4 100644 --- a/src/olathread.cpp +++ b/src/olathread.cpp @@ -75,18 +75,19 @@ void olaThread::NewDmx(const ola::client::DMXMetadata &data, gettimeofday(&m_last_data, NULL); 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 - // AND if the DMX address is 0 or greater, process this layer. + if(m_settings.at(i).universe == universe) { // Compare if the layer is from this universe + if ( m_settings.at(i).address > -1 ) { // AND if the DMX address is 0 or greater, process this layer. + emit layerReceived(i); for (int j = 0; j < LAYER_CHANNELS; j++){ - int value = buffer.Get((m_settings.at(i).address) + j); // Get the value for this channel. - if (m_dmx[i][j] != value) { // Compare the new value with the old value. - emit dmxOutput(i,j,value); // Connected with dmx slot in olaInterface. - m_dmx[i][j] = value; - } + int value = buffer.Get((m_settings.at(i).address) + j); // Get the value for this channel. + if (m_dmx[i][j] != value) { // Compare the new value with the old value. + emit dmxOutput(i,j,value); + m_dmx[i][j] = value; } + } } - } + } + } } /** @@ -108,7 +109,13 @@ bool olaThread::CheckDataLoss() { return true; } -void olaThread::setLayersNumber(int layersNumber) { m_layersNumber = layersNumber; } +void olaThread::setLayersNumber(int layersNumber) +{ + if (layersNumber <= LAYERS_NUMBER) + m_layersNumber = layersNumber; + else + m_layersNumber = LAYERS_NUMBER; +} void olaThread::resendDmx() { @@ -119,6 +126,17 @@ void olaThread::resendDmx() } } } + +void olaThread::setDMXConf(dmxSetting set) +{ + if (set.layer >= m_layersNumber) { return; } + m_settings.replace(set.layer, set); + // ToDo: registro del nuevo universo si no está registrado ya + if (!m_universe->contains(set.universe)) { + registerUniverse(set.universe); + m_universe->append(set.universe); + } +} //////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/olathread.h b/src/olathread.h index c91998f..3e0d589 100644 --- a/src/olathread.h +++ b/src/olathread.h @@ -67,10 +67,10 @@ private: // typedef SingleUseCallback1 ola::client::SetCallback inline void RegisterComplete(const ola::client::Result &error) { if (error.Success()) { - qDebug() << "Register Universe success"; +// qDebug("Register Universe success"); emit toTerminal("Register Universe success"); } else { - qWarning() << "olaThread|" << "Register command failed" << QString::fromStdString(error.Error()); +// qWarning("Register command failed: %s", error.Error().c_str()); emit toTerminal("olaThread| Register command failed " + QString::fromStdString(error.Error())); } } @@ -84,15 +84,7 @@ public slots: void stop(); // Close the connection with olad. void setLayersNumber(int layersNumber); - inline void setDMXConf(dmxSetting set) { - if (set.layer >= m_layersNumber) { return; } - m_settings.replace(set.layer, set); - // ToDo: registro del nuevo universo si no está registrado ya - if (!m_universe->contains(set.universe)) { - registerUniverse(set.universe); - m_universe->append(set.universe); - } - } + void setDMXConf(dmxSetting set); protected slots: @@ -101,6 +93,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); + void layerReceived(int i); }; #endif // OLATHREAD_H diff --git a/src/settings.cpp b/src/settings.cpp index 85a2f49..ff2bc10 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -23,7 +23,7 @@ void Settings::readFromFile(QString file) { QXmlStreamReader* xmlReader = new QXmlStreamReader(xmlFile); int counter = 0; //Parse the XML until we reach end of it - while(!xmlReader->atEnd() && !xmlReader->hasError()) { + while(!xmlReader->atEnd() && !xmlReader->hasError() && counter < LAYERS_NUMBER) { // Read next element QXmlStreamReader::TokenType token = xmlReader->readNext(); //If token is just StartDocument - go to next