143 lines
2.9 KiB
C++
143 lines
2.9 KiB
C++
#ifndef AUDIOMOTOR_H
|
|
#define AUDIOMOTOR_H
|
|
|
|
#include <QObject>
|
|
#include <QtDebug>
|
|
#include <QtNetwork>
|
|
#include <QTcpServer>
|
|
#include <QLocalSocket>
|
|
#include <QTcpSocket>
|
|
#include <QChar>
|
|
|
|
#include "dmxPersonality.h"
|
|
|
|
#define PDPORT 9198
|
|
#define SOCKET 9197 // "/tmp/socket"
|
|
|
|
class AudioMotor : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static AudioMotor *getInstance();
|
|
|
|
/** Init the engine
|
|
*/
|
|
bool init();
|
|
|
|
/** Close the engine
|
|
*/
|
|
void close();
|
|
|
|
/** Set the numbers of layers
|
|
*/
|
|
void setLayers (int layers);
|
|
|
|
/** Get the number of layers
|
|
*/
|
|
int getlayers();
|
|
|
|
/** Load a file in memory
|
|
*
|
|
*/
|
|
bool load(int layer, QString file);
|
|
|
|
/** Starts the playback at start position
|
|
*
|
|
*/
|
|
bool play(int layer);
|
|
|
|
/** Pause/unpause the playback
|
|
*/
|
|
bool pause(int layer);
|
|
|
|
/** Stops the playback and reset the media to the start position
|
|
*
|
|
*/
|
|
bool stop(int layer);
|
|
|
|
/** Sets the start playback position
|
|
*
|
|
*/
|
|
void setEntryPoint(int layer, int entry);
|
|
|
|
/** Sets the final playback position
|
|
*
|
|
*/
|
|
void setExitPoint(int layer, int exit);
|
|
|
|
/** Set the volumen in one layer
|
|
*
|
|
*/
|
|
void setLayerVolume(int layer, float vol);
|
|
|
|
/** Set pan in one layer
|
|
*/
|
|
void setLayerPan(int layer, float pan);
|
|
|
|
/** Set Volumen master.
|
|
* All layers are limited by this master
|
|
* 0 will mute all the outputs
|
|
*/
|
|
void setMasterVolume(int vol);
|
|
|
|
/** Set pan master
|
|
* Will pan the master output of sound
|
|
*/
|
|
void setMasterPan(int pan);
|
|
|
|
inline void setGui(bool gui) { m_gui = gui; }
|
|
|
|
private:
|
|
|
|
AudioMotor(QObject *parent = 0);
|
|
virtual ~AudioMotor();
|
|
static AudioMotor *_instance;
|
|
|
|
bool m_gui;
|
|
int m_layersNumber;
|
|
QProcess *m_pd_audio; // Pure Data process for audio
|
|
|
|
// Audio TCP Sockets
|
|
QTcpSocket *m_writePD;
|
|
QTcpServer *m_readPD;
|
|
QTcpSocket *m_connectedSocket; // connected socket to server
|
|
int m_startaudio; // Counter starts audio engine. Debugging purpose
|
|
|
|
bool sendPacket(const char *buffer, int bufferLen);
|
|
void errorSending();
|
|
void parse(QString message);
|
|
|
|
signals:
|
|
void loadbang();
|
|
void newConnection();
|
|
void mediaLoaded(int layer, QString folder, QString file);
|
|
void volChanged(int layer, int vol);
|
|
void toTerminal(QString message);
|
|
|
|
private slots:
|
|
|
|
void newPeer();
|
|
inline void newConexion() { qDebug() << "AudioMotor write socket connected to PD"; }
|
|
void restartAudio();
|
|
void newMessage();
|
|
void errorWrite(QAbstractSocket::SocketError error);
|
|
/**
|
|
*
|
|
* Listen the terminal exit of PD
|
|
*
|
|
*/
|
|
|
|
// Sacamos la salida de Pure Data Audio en la terminal
|
|
inline void stdout() {
|
|
QString out = m_pd_audio->readAllStandardError();
|
|
out.chop(1);
|
|
if (!out.isEmpty())
|
|
{
|
|
qDebug() << "AudioMotor from PD: " << out;
|
|
}
|
|
}
|
|
};
|
|
|
|
#endif // AUDIOMOTOR_H
|