From b59cc92c5f16198a11ac1214583b93fd69b6c48d Mon Sep 17 00:00:00 2001 From: snt Date: Tue, 23 Apr 2024 01:16:52 +0200 Subject: [PATCH] funcionando controles ui --- src/audiolayerwidget.cpp | 34 +++++--------------- src/audiolayerwidget.h | 3 +- src/audiowidget.cpp | 14 ++++---- src/audiowidget.h | 3 +- src/defines.h | 5 +-- src/libremediaserver-audio.cpp | 3 +- src/libremediaserver-audio.ui | 10 ++++-- src/olathread.cpp | 39 +++++++---------------- src/olathread.h | 58 ++++++---------------------------- src/settings.cpp | 6 ---- 10 files changed, 50 insertions(+), 125 deletions(-) diff --git a/src/audiolayerwidget.cpp b/src/audiolayerwidget.cpp index 1eb4364..3c58b2c 100644 --- a/src/audiolayerwidget.cpp +++ b/src/audiolayerwidget.cpp @@ -13,23 +13,14 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name, int layer): QVBoxLayout *layout = new QVBoxLayout; QGridLayout *status = new QGridLayout; - m_statusLabel = new QLabel; - m_statusLabel->setText(STATUS_LABEL); m_statusValue = new QLabel; - status->addWidget(m_statusLabel, 0, 0); - status->addWidget(m_statusValue, 0, 2); - m_folderLabel = new QLabel; - m_folderLabel->setText(FOLDER_LABEL); + status->addWidget(m_statusValue, 1, 1); m_folderValue = new QLabel; - m_folderValue->setMaximumWidth(200); - status->addWidget(m_folderLabel, 1, 0); - status->addWidget(m_folderValue, 1, 1); - m_fileLabel = new QLabel; - m_fileLabel->setText(FILE_LABEL); + m_folderValue->setMaximumWidth(100); + status->addWidget(m_folderValue, 0, 0); m_fileValue = new QLabel; - m_fileValue->setMaximumWidth(200); - status->addWidget(m_fileLabel, 1, 2); - status->addWidget(m_fileValue, 1, 3); + m_fileValue->setMaximumWidth(100); + status->addWidget(m_fileValue, 0, 2); layout->addLayout(status); QGridLayout *volumeBox = new QGridLayout; @@ -126,26 +117,17 @@ AudioLayerWidget::~AudioLayerWidget() // From UI. void AudioLayerWidget::volumeChanged(int value) { - (void)value; - // ToDo: call the audio engine + emit(uiSliderChanged(m_layer, Slider::Volume, value)); } void AudioLayerWidget::panChanged(int value) { - (void)value; - // ToDo: call the audio engine + emit(uiSliderChanged(m_layer, Slider::Pan, value)); } void AudioLayerWidget::pitchChanged(int value) { - (void)value; - // ToDo: call the audio engine -} - -void AudioLayerWidget::loopChanged(int value) -{ - (void)value; - // ToDo: call the audio engine + emit(uiSliderChanged(m_layer, Slider::Pitch, value)); } void AudioLayerWidget::toggleSuspendResume() diff --git a/src/audiolayerwidget.h b/src/audiolayerwidget.h index 78d0b4a..f91858f 100644 --- a/src/audiolayerwidget.h +++ b/src/audiolayerwidget.h @@ -65,14 +65,13 @@ public slots: void volumeChanged(int vol); void panChanged(int vol); void pitchChanged(int vol); - void loopChanged(int vol); void fileLoaded(QString file); void durationChanged(qint64 dur); void refreshUi(float progress); signals: void uiPlaybackChanged(int layer, Status s); - void uiSliderChanged(int layer, Slider s, Status status); + void uiSliderChanged(int layer, Slider s, int value); }; diff --git a/src/audiowidget.cpp b/src/audiowidget.cpp index 700b846..d1274d6 100644 --- a/src/audiowidget.cpp +++ b/src/audiowidget.cpp @@ -8,7 +8,7 @@ AudioWidget::AudioWidget() : for (int i= 0; i < Settings::getInstance()->getLayersNumber(); i++ ) { AudioLayerWidget *alw = new AudioLayerWidget(this, tr("Layer %1").arg(i + 1), i); m_layout->insertWidget(i, alw); - connect(alw, SIGNAL(uiSliderAction(int, Slider, qreal)), this, SLOT(uiSliderAction(int, Status))); + connect(alw, SIGNAL(uiSliderChanged(int, Slider, int)), this, SLOT(uiSliderAction(int, Slider, int))); connect(alw, SIGNAL(uiPlaybackChanged(int, Status)), this, SLOT(uiChangePlaybackStatus(int, Status))); } setLayout(m_layout); @@ -92,20 +92,22 @@ void AudioWidget::refreshUi() { } } -void AudioWidget::uiSliderAction(int layer, Slider s, qreal value) +void AudioWidget::uiSliderAction(int layer, Slider s, int value) { switch (s){ case Slider::Volume: - this->volChanged(layer, value); + m_mae.volChanged(layer, value); + break; case Slider::Pan: - this->panChanged(layer, value); + m_mae.panChanged(layer, value); + break; case Slider::Pitch: - this->pitchChanged(layer, value); + m_mae.pitchChanged(layer, value); + break; } } void AudioWidget::uiChangePlaybackStatus(int layer, Status s) { - qDebug("changing playback %i %i", layer, s); m_mae.playbackChanged(layer, s); } diff --git a/src/audiowidget.h b/src/audiowidget.h index 48f2b4b..26f63b1 100644 --- a/src/audiowidget.h +++ b/src/audiowidget.h @@ -3,7 +3,6 @@ #include #include -#include #include #include "audiomasterwidget.h" @@ -40,7 +39,7 @@ private: QTimer *m_refreshUi; public slots: - void uiSliderAction(int layer, Slider s, qreal value); + void uiSliderAction(int layer, Slider s, int value); void uiChangePlaybackStatus(int layer, Status s); private slots: diff --git a/src/defines.h b/src/defines.h index 50fe3ec..ca94591 100644 --- a/src/defines.h +++ b/src/defines.h @@ -15,14 +15,11 @@ #define STOP_LABEL "Stop" #define PAUSE_LABEL "Pause" #define IDDLE_LABEL "Iddle playback" -#define VOLUME_LABEL "Volume" +#define VOLUME_LABEL "Vol" #define PROGRESS_LABEL "Progress" #define PROGRESS_TIME_LABEL "Current" #define REMAINING_TIME "Remaining" #define TOTAL_TIME_LABEL "Total" -#define FILE_LABEL "File: " -#define FOLDER_LABEL "Folder: " -#define STATUS_LABEL "Status: " #define NOTIFY_INTERVAL 150 #define PULL_TIMER_INTERVAL 10 #define MAX_DEVICES 16 diff --git a/src/libremediaserver-audio.cpp b/src/libremediaserver-audio.cpp index a458db6..f8193e7 100644 --- a/src/libremediaserver-audio.cpp +++ b/src/libremediaserver-audio.cpp @@ -66,7 +66,7 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) topWidget->setWidget(amw); addDockWidget(Qt::TopDockWidgetArea, topWidget); // ola setup - ola = new olaThread(); + ola = new olaThread(this, set->getLayersNumber()); Q_CHECK_PTR(ola); ola->blockSignals(true); connect(set, SIGNAL(registerUniverse(int)), ola, SLOT(registerUniverse(int))); @@ -82,6 +82,7 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent) aw->startEngine(); qDebug("Init Complete."); ola->blockSignals(false); + ola->resendDmx(); } /////////////////////////////////////////////////////////////////// diff --git a/src/libremediaserver-audio.ui b/src/libremediaserver-audio.ui index 3256e49..2090b50 100644 --- a/src/libremediaserver-audio.ui +++ b/src/libremediaserver-audio.ui @@ -7,7 +7,7 @@ 0 0 - 199 + 114 218 @@ -20,7 +20,7 @@ 0 0 - 199 + 114 22 @@ -33,7 +33,13 @@ + + + Help + + + diff --git a/src/olathread.cpp b/src/olathread.cpp index 5808cb5..1453e2d 100644 --- a/src/olathread.cpp +++ b/src/olathread.cpp @@ -1,10 +1,11 @@ #include "olathread.h" -olaThread::olaThread(QObject *parent) +olaThread::olaThread(QObject *parent, int layers) : + m_counter(0) + , m_layers(layers) { Q_UNUSED(parent); - m_counter = 0; gettimeofday(&m_last_data, NULL); for (int i=0; i < MAX_LAYERS; i++) { @@ -41,7 +42,6 @@ void olaThread::init() void olaThread::run() { - emit toTerminal("Start reading DMX"); m_clientWrapper->GetSelectServer()->Run(); } @@ -64,15 +64,13 @@ void olaThread::NewDmx(const ola::client::DMXMetadata &data, { m_counter++; gettimeofday(&m_last_data, NULL); - uint universe = data.universe; - emit layerReceived(); - foreach (const dmxSetting &i, Settings::getInstance()->getDmxSettings()) { // loop for reading the channels by layer. - if(i.universe == universe && i.address > -1) { // Compare if the layer is from this universe AND if the DMX address is 0 or greater, process this layer. - for (int j = 0; j < MAX_LAYERS; j++){ - int value = buffer.Get((i.address) + j); // Get the value for this channel. - if (m_dmx[i.layer][j] != value) { // Compare the new value with the old value. - emit dmxOutput(i.layer,j,value); + foreach (const dmxSetting &i, Settings::getInstance()->getDmxSettings()) { + if(i.universe == data.universe && i.address > -1) { + for (int j = 0; j < LAYER_CHANNELS; j++){ + int value = buffer.Get((i.address) + j); + if (m_dmx[i.layer][j] != value) { m_dmx[i.layer][j] = value; + emit dmxOutput(i.layer,j,value); } } } @@ -82,17 +80,13 @@ void olaThread::NewDmx(const ola::client::DMXMetadata &data, /** * Check for data loss each 4 seconds. */ - bool olaThread::CheckDataLoss() { struct timeval now, diff; if (timerisset(&m_last_data)) { gettimeofday(&now, NULL); 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("olaThread: Can not read one universe"); - // return false; // Retorna false para deshabilitar el callback + qInfo()<< "olaThread| Can not read one or several universes"; } } return true; @@ -100,8 +94,7 @@ bool olaThread::CheckDataLoss() { void olaThread::resendDmx() { -// qDebug() << "Resending DMX info"; - for (int i = 0; i < MAX_LAYERS; i++) { // loop for reading the channels by layer. + for (int i = 0; i < m_layers; i++) { for (int j = 0; j < LAYER_CHANNELS; j++){ emit dmxOutput(i, j, m_dmx[i][j]); } @@ -110,19 +103,11 @@ void olaThread::resendDmx() void olaThread::socketClosed() { - qWarning("ola close the connection. Trying reopening it... "); - emit toTerminal("OLA closed the connection. Tryin reopening it... "); - + qWarning("ola closed connection. Try reopening it... "); m_clientWrapper->GetSelectServer()->Terminate(); m_client = NULL; m_clientWrapper = NULL; - - // setup ola connection init(); - - // register universes registerUniverse(); - - // start thread run(); } diff --git a/src/olathread.h b/src/olathread.h index 070922e..9692d9e 100644 --- a/src/olathread.h +++ b/src/olathread.h @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -25,7 +24,7 @@ class olaThread : public QThread public: - olaThread(QObject *parent = 0); + olaThread(QObject *parent = 0, int layers = 0); virtual ~olaThread(); /** Retorna el valor de un canal @@ -37,9 +36,6 @@ public: return m_dmx[layer][channel]; } - /** - * @brief resendDMX emite todo el buffer DMX - */ void resendDmx(); private: @@ -49,78 +45,49 @@ private: ola::client::OlaClient *m_client; unsigned int m_counter; struct timeval m_last_data; // Last DMX frame received - - int m_dmx[MAX_LAYERS][LAYER_CHANNELS]; // DMX Buffer. HabrĂ­a que cambiarlo si queremos hacer las capas dinĂ¡micas + int m_layers; + int m_dmx[MAX_LAYERS][LAYER_CHANNELS]; /** * @brief Callback from ola. Control de errores en el registro de Universos en OLA * typedef SingleUseCallback1 ola::client::SetCallback * @param ola::client::Result &error * @return void - * - * */ inline void RegisterComplete(const ola::client::Result &error) { if (error.Success()) { qDebug("Register Universe success"); - emit toTerminal("Register Universe success"); } else { qWarning("Register command failed: %s", error.Error().c_str()); - emit toTerminal("olaThread| Register command failed " + QString::fromStdString(error.Error())); } } - /** * @brief Check if the dmx info is arriving each 4 seconds * @return bool */ bool CheckDataLoss(); - /** * @brief RepeteableDMXCallBack from ola called when arrives a new dmx frame * typedef Callback2 ola::client::RepeatableDMXCallback - * This is called one for second if there is not updated in the DMX frame. We need emit only the channels that - * has changed to save resources. - * - * + * This is called one for second if there is not updated in the DMX frame. + * emit only the channels that has been changed. */ void NewDmx(const ola::client::DMXMetadata &dmx_meta, const ola::DmxBuffer &buffer); // - /** * @brief Sometimes the ola server closes the connection. This is a callback to handle this event an reconect to ola - * - * */ void socketClosed(); - - /** - * @brief Open the connection with olad and start processing data. - * - * - */ - void init(); + void init(); public slots: - - void stop(); // Close the connection with olad. - - /** - * @brief register one Universe - * void ola::client::OlaClient::RegisterUniverse(unsigned int universe,RegisterAction register_action,SetCallback * callback - * @param universe - */ + void stop(); inline void registerUniverse(int universe) { - qDebug("Registering universe %d", universe); + qInfo("Registering universe %d", universe); m_client->RegisterUniverse(universe, ola::client::REGISTER, ola::NewSingleCallback (this, &olaThread::RegisterComplete)); } - - /** - * @brief Register all the universes again - * - */ inline void registerUniverse() { QSet unis = Settings::getInstance()->getUniverses(); foreach (const int &universe, unis) { @@ -128,15 +95,8 @@ public slots: } } -protected slots: - 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 universeReceived(uint universe); - void layerReceived(); + void dmxOutput(int layer, int channel, int value); }; using namespace ola; diff --git a/src/settings.cpp b/src/settings.cpp index 4dc7bff..510685f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -73,27 +73,22 @@ void Settings::readFromFile(QString file) { m_settings.append(temp); if (!m_universe.contains(temp.universe)) { m_universe.insert(temp.universe); -// emit registerUniverse(temp.universe); } counter++; } } } - if(xmlReader->hasError()) { QMessageBox::critical(NULL,"File xml Parse Error ", xmlReader->errorString(), QMessageBox::Ok); qWarning("File xml Parse Error %s", xmlReader->errorString().toLatin1().constData()); return; } - //close reader and flush file xmlReader->clear(); xmlFile->close(); - delete xmlReader; delete xmlFile; } - /** Read the default file * */ @@ -110,7 +105,6 @@ void Settings::changeLayerSetup(int layer, int universe, int address) m_settings.replace(layer, temp); if (!m_universe.contains(temp.universe)) { m_universe.insert(temp.universe); -// emit registerUniverse(temp.universe); } }