lms-audio/src/olathread.h
snt 5915d4898e cambida señal dmx por llamada directa al método, reduce un 20% de cpu en
mi ordenador.
Restringida actualización de entry point como volumen, sigue cascando la
búsqueda en mp3, wav va fino.
2024-05-05 21:44:21 +02:00

97 lines
3 KiB
C++

#ifndef OLATHREAD_H
#define OLATHREAD_H
#include <QThread>
#include <ola/DmxBuffer.h>
#include <ola/Logging.h>
#include <ola/OlaClientWrapper.h>
#include <ola/client/OlaClient.h>
#include <ola/DmxBuffer.h>
#include <ola/client/ClientTypes.h>
#include <ola/Callback.h>
#include "dmxPersonality.h"
#include "settings.h"
#include "defines.h"
class olaThread : public QThread
{
Q_OBJECT
public:
QList<dmxSetting> m_dmxSettings;
int m_dmx[MAX_LAYERS][LAYER_CHANNELS];
ola::client::OlaClientWrapper *m_clientWrapper;
ola::client::OlaClient *m_client;
unsigned int m_counter;
struct timeval m_last_data; // Last DMX frame received
int m_layers;
olaThread(QObject *parent = 0, int layers = 0);
virtual ~olaThread();
void run ();
/** 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
*@return int the value
*/
inline int getValue(int layer, int channel) {
return m_dmx[layer][channel];
}
void resendDmx();
private:
/**
* @brief Callback from ola. Control de errores en el registro de Universos en OLA
* typedef SingleUseCallback1<void, const Result&> 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");
} else {
qCritical("Register command failed: %s", error.Error().c_str());
}
}
/**
* @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<void, const DMXMetadata&, const DmxBuffer&> ola::client::RepeatableDMXCallback
* 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();
void init();
public slots:
void stop();
inline void registerUniverse(int universe) {
qInfo("Registering universe %d", universe);
m_client->RegisterUniverse(universe,
ola::client::REGISTER,
ola::NewSingleCallback
(this, &olaThread::RegisterComplete));
}
inline void registerUniverse() {
QSet<int> unis = Settings::getInstance()->getUniverses();
foreach (const int &universe, unis) {
registerUniverse(universe);
}
}
signals:
void dmxOutput(int layer, int channel, int value);
void universeReceived(int uni);
};
#endif // OLATHREAD_H