255 lines
8.1 KiB
C++
Executable file
255 lines
8.1 KiB
C++
Executable file
/*
|
|
Pure Media Server - A Media Server Sotfware for stage and performing
|
|
|
|
Copyright (C) 2012-2013 Santi Noreña libremediaserver@gmail.com
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include "libremediaserver-audio.h"
|
|
|
|
/**
|
|
/ Constructor
|
|
*/
|
|
|
|
libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent)
|
|
: QMainWindow(parent)
|
|
{
|
|
qDebug() << "********************************************************************************";
|
|
qDebug() << QDate::currentDate() << QTime::currentTime();
|
|
qDebug() << VERSION;
|
|
qDebug() << COPYRIGHT;
|
|
qDebug() << LICENSE;
|
|
|
|
// Inicia el User Interface
|
|
ui.setupUi(this);
|
|
this->setWindowTitle(VERSION);
|
|
|
|
// Inicia el widget Terminal
|
|
textEdit = new QTextEdit(this);
|
|
textEdit->append(QString::fromAscii(VERSION));
|
|
textEdit->append(QString::fromAscii(LICENSE));
|
|
textEdit->append(QString::fromAscii(COPYRIGHT));
|
|
|
|
QDockWidget *bottomWidget = new QDockWidget(tr("Terminal"), this);
|
|
bottomWidget->setAllowedAreas(Qt::BottomDockWidgetArea);
|
|
bottomWidget->setWidget(textEdit);
|
|
addDockWidget(Qt::BottomDockWidgetArea, bottomWidget);
|
|
|
|
// Inicia el widget central de audio
|
|
aw = new AudioWidget(this);
|
|
setCentralWidget(aw);
|
|
|
|
// Inicia el widget Master.
|
|
amw = new AudioMasterWidget(this);
|
|
QDockWidget *topWidget = new QDockWidget(tr("Master"), this);
|
|
topWidget->setAllowedAreas(Qt::TopDockWidgetArea);
|
|
topWidget->setWidget(amw);
|
|
addDockWidget(Qt::TopDockWidgetArea, topWidget);
|
|
|
|
// Conectamos los menus
|
|
connect(ui.actionOpen_conf, SIGNAL(triggered()), this, SLOT(openFile()));
|
|
connect(ui.actionSave_conf, SIGNAL(triggered()), this, SLOT(saveFile()));
|
|
connect(ui.actionChange_Media_Path, SIGNAL(triggered()), this, SLOT(ChangeMediaPath()));
|
|
connect(ui.actionLaunch_OLA_Setup, SIGNAL(triggered()), this, SLOT(olasetup()));
|
|
|
|
Settings *set = new Settings();
|
|
|
|
// 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(set, SIGNAL( layersNumber(int)),
|
|
ola, SLOT( setLayersNumber(int)));
|
|
|
|
connect(set, SIGNAL( DMXConf(dmxSetting ) ),
|
|
ola, SLOT( setDMXConf(dmxSetting) ) );
|
|
|
|
// Lee la configuración por defecto
|
|
if (!set->readDefaultFile()) {
|
|
// Dar la oportunidad de cargar otro fichero de configuración
|
|
// Crear el fichero por defecto.
|
|
}
|
|
|
|
// Parse the command line options
|
|
if (args.contains("-gui"))
|
|
{
|
|
qDebug()<< "libremediaserver Constructor option GUI detected";
|
|
AudioMotor::getInstance()->setGui(true);
|
|
textEdit->append("Pure Data GUI's will be shown");
|
|
} else { AudioMotor::getInstance()->setGui(false); }
|
|
|
|
connect(AudioMotor::getInstance(), SIGNAL(toTerminal(QString)),
|
|
this, SLOT(toTerminal(QString)));
|
|
|
|
if (args.contains("-log"))
|
|
{
|
|
textEdit->append("Logging to file");
|
|
}
|
|
|
|
// Iniciamos Pure Data
|
|
connect(AudioMotor::getInstance(), SIGNAL(loadbang()),
|
|
this, SLOT (loadbang()));
|
|
|
|
AudioMotor::getInstance()->init();
|
|
|
|
connect(AudioMotor::getInstance(), SIGNAL(mediaLoaded(int, QString, QString)),
|
|
aw, SLOT(mediaLoaded(int, QString, QString)));
|
|
|
|
connect(AudioMotor::getInstance(), SIGNAL(volChanged(int, int)),
|
|
aw, SLOT(volChanged(int, int)));
|
|
|
|
connect(ola, SIGNAL( dmxOutput(int, int, int) ),
|
|
this, SLOT( dmxInput(int, int, int) ) );
|
|
|
|
connect(ola, SIGNAL(universeReceived(uint)),
|
|
amw, SLOT(updateWatchDMX()));
|
|
|
|
ola->blockSignals(false);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
// Destructor
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
libreMediaServerAudio::~libreMediaServerAudio()
|
|
{
|
|
// save_finish();
|
|
// delete MediaLibrary::getInstance();
|
|
ola->stop();
|
|
AudioMotor::getInstance()->close();
|
|
// qDebug() << "PD Audio restarts: " << m_startaudio;
|
|
qDebug() << QDate::currentDate() << QTime::currentTime();
|
|
qDebug() << "********************************************************************************";
|
|
// return;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
// Menu File
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Open a configuration File
|
|
void libreMediaServerAudio::openFile()
|
|
{
|
|
QFileDialog dialog(this);
|
|
if (!dialog.exec())
|
|
return;
|
|
QStringList fileNames;
|
|
fileNames = dialog.selectedFiles();
|
|
QFile file(fileNames.at(0));
|
|
// open(&file);
|
|
}
|
|
// Save configuration File
|
|
void libreMediaServerAudio::saveFile()
|
|
{
|
|
QFileDialog dialog(this);
|
|
if (!dialog.exec())
|
|
return;
|
|
QStringList fileNames;
|
|
fileNames = dialog.selectedFiles();
|
|
QFile file(fileNames.at(0));
|
|
// save(&file);
|
|
}
|
|
|
|
// Change Media path
|
|
void libreMediaServerAudio::ChangeMediaPath()
|
|
{
|
|
QFileDialog dialog(this);
|
|
dialog.setFileMode(QFileDialog::Directory);
|
|
QStringList fileNames;
|
|
if (!dialog.exec())
|
|
return;
|
|
fileNames = dialog.selectedFiles();
|
|
QString file = fileNames.at(0);
|
|
MediaLibrary::getInstance()->setPath(file);
|
|
QString desc = tr("Media Path Changed to: %1").arg(m_pathmedia);
|
|
textEdit->append(desc.toAscii());
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
// OLA Stuff
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
void libreMediaServerAudio::olasetup()
|
|
{
|
|
QWebView *view = new QWebView();
|
|
view->load(QUrl("http://localhost:9090/ola.html"));
|
|
view->show();
|
|
}
|
|
|
|
/**
|
|
* Parse the dmx information
|
|
*/
|
|
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;
|
|
QString mediaFile = NULL;
|
|
int aux;
|
|
float f;
|
|
switch(channel){
|
|
case DMX_FOLDER:// Folder
|
|
aux = ola->getValue(layer, DMX_FILE);
|
|
mediaFile = MediaLibrary::getInstance()->requestNewFile(value, aux);
|
|
if (QFile::exists(mediaFile))
|
|
AudioMotor::getInstance()->load(layer, mediaFile);
|
|
break;
|
|
case DMX_FILE:// File
|
|
aux = ola->getValue(layer, DMX_FOLDER);
|
|
mediaFile = MediaLibrary::getInstance()->requestNewFile(aux, value);
|
|
if (QFile::exists(mediaFile))
|
|
AudioMotor::getInstance()->load(layer, mediaFile);
|
|
break;
|
|
case VOLUME_COARSE:
|
|
f = ( value * 0x100 ) + ola->getValue(layer, VOLUME_FINE);
|
|
AudioMotor::getInstance()->setLayerVolume(layer, f/655.35);
|
|
break;
|
|
case VOLUME_FINE:
|
|
f = ( ola->getValue(layer, VOLUME_COARSE) * 0x100 ) + value;
|
|
AudioMotor::getInstance()->setLayerVolume(layer, f/655.35);
|
|
break;
|
|
case PAN:
|
|
f = (float)value / 255;
|
|
AudioMotor::getInstance()->setLayerPan(layer, f );
|
|
break;
|
|
case PLAYBACK:
|
|
aux = value / 25;
|
|
switch (aux) {
|
|
case 0 :
|
|
AudioMotor::getInstance()->play(layer);
|
|
break;
|
|
case 1 :
|
|
AudioMotor::getInstance()->stop(layer);
|
|
break;
|
|
case 2 :
|
|
AudioMotor::getInstance()->pause(layer);
|
|
break;
|
|
}
|
|
default:
|
|
// emit dmxInput(layer, channel, value);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Send the DMX info to Pure Data in init
|
|
*
|
|
*/
|
|
void libreMediaServerAudio::loadbang() {
|
|
ola->resendDmx();
|
|
}
|