206 lines
6.5 KiB
C++
206 lines
6.5 KiB
C++
/*
|
|
|
|
Libre Media Server Audio - An Open source Media Server for arts and performing.
|
|
(c) Criptomart - Santiago Noreña 2012-2024 <lms@criptomart.net>
|
|
https://git.criptomart.net/libremediaserver
|
|
|
|
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"
|
|
|
|
|
|
libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent)
|
|
: QMainWindow(parent)
|
|
{
|
|
Q_UNUSED(args);
|
|
ui.setupUi(this);
|
|
this->setWindowTitle(VERSION);
|
|
|
|
Settings *set = Settings::getInstance();
|
|
set->readFile();
|
|
connect(set, SIGNAL(audioDeviceChanged(int)), this, SLOT(audioDeviceChanged(int)));
|
|
/*
|
|
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);
|
|
}*/
|
|
|
|
/* connect(MediaLibrary::getInstance(), SIGNAL(debug(QString)),
|
|
textEdit, SLOT(append(QString)), Qt::QueuedConnection);
|
|
|
|
connect(MediaLibrary::getInstance(), SIGNAL(warning(QString)),
|
|
textEdit, SLOT(append(QString)), Qt::QueuedConnection);
|
|
*/
|
|
|
|
this->setWindowTitle(VERSION);
|
|
qDebug() << VERSION;
|
|
qDebug() << COPYRIGHT;
|
|
qDebug() << LICENSE;
|
|
|
|
// start audio engine
|
|
MediaLibrary::getInstance()->initMediaLibrary();
|
|
aw = new AudioWidget;
|
|
setCentralWidget(aw);
|
|
amw = new AudioMasterWidget(this);
|
|
QDockWidget *topWidget = new QDockWidget(tr("Master"), this);
|
|
topWidget->setAllowedAreas(Qt::TopDockWidgetArea);
|
|
topWidget->setWidget(amw);
|
|
addDockWidget(Qt::TopDockWidgetArea, topWidget);
|
|
// ola setup
|
|
ola = new olaThread(this, set->getLayersNumber());
|
|
Q_CHECK_PTR(ola);
|
|
ola->blockSignals(true);
|
|
connect(set, SIGNAL(registerUniverse(int)), ola, SLOT(registerUniverse(int)));
|
|
connect(ola, SIGNAL (layerReceived()), amw, SLOT(updateWatchDMX()));
|
|
connect(ola, SIGNAL(dmxOutput(int, int, int)), this, SLOT(dmxInput(int, int, int)));
|
|
connect(ui.actionLaunch_OLA_Setup, SIGNAL(triggered()), this, SLOT(olasetup()));
|
|
ola->registerUniverse();
|
|
ola->start(QThread::TimeCriticalPriority );
|
|
// menus
|
|
connect(ui.actionOpen_conf, SIGNAL(triggered()), this, SLOT(openFile()));
|
|
connect(ui.actionSave_conf, SIGNAL(triggered()), this, SLOT(saveFile()));
|
|
connect(ui.action_Settings, SIGNAL(triggered()), this, SLOT(settings()));
|
|
aw->startEngine();
|
|
qDebug("Init Complete.");
|
|
ola->blockSignals(false);
|
|
ola->resendDmx();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
// Destructor
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
libreMediaServerAudio::~libreMediaServerAudio()
|
|
{
|
|
ola->stop();
|
|
aw->stopEngine();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
// 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);
|
|
}
|
|
|
|
void libreMediaServerAudio::settings()
|
|
{
|
|
SettingsDialog *sd = new SettingsDialog();
|
|
sd->show();
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
// OLA Stuff
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
void libreMediaServerAudio::olasetup()
|
|
{
|
|
QWebView *view = new QWebView();
|
|
view->load(QUrl("http://localhost:9090/ola.html"));
|
|
view->show();
|
|
}
|
|
|
|
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;
|
|
switch(channel){
|
|
case DMX_FOLDER:// Folder
|
|
aux = ola->getValue(layer, DMX_FILE);
|
|
mediaFile = MediaLibrary::getInstance()->requestNewFile(value, aux);
|
|
if (QFile::exists(mediaFile))
|
|
aw->mediaLoaded(layer, mediaFile);
|
|
break;
|
|
case DMX_FILE:// File
|
|
aux = ola->getValue(layer, DMX_FOLDER);
|
|
mediaFile = MediaLibrary::getInstance()->requestNewFile(aux, value);
|
|
if (QFile::exists(mediaFile))
|
|
aw->mediaLoaded(layer, mediaFile);
|
|
break;
|
|
case VOLUME_COARSE:
|
|
f = ( value * 0x100 ) + ola->getValue(layer, VOLUME_FINE);
|
|
aw->volChanged(layer, (f / 655.35));
|
|
break;
|
|
case VOLUME_FINE:
|
|
f = ( ola->getValue(layer, VOLUME_COARSE) * 0x100 ) + value;
|
|
aw->volChanged(layer, (f / 655.35));
|
|
break;
|
|
case PAN:
|
|
aw->panChanged(layer, value);
|
|
break;
|
|
case PITCH:
|
|
aw->pitchChanged(layer, value);
|
|
break;
|
|
case PLAYBACK:
|
|
if (value == 0)
|
|
break;
|
|
aux = value / 25;
|
|
switch (aux) {
|
|
case 0 :
|
|
aw->playbackChanged(layer, PlayingOnce);
|
|
break;
|
|
case 1 :
|
|
aw->playbackChanged(layer, Stopped);
|
|
break;
|
|
case 2 :
|
|
aw->playbackChanged(layer, Paused);
|
|
break;
|
|
case 3 :
|
|
aw->playbackChanged(layer, PlayingLoop);
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void libreMediaServerAudio::audioDeviceChanged(int id)
|
|
{
|
|
aw->stopEngine();
|
|
aw->startEngine(id);
|
|
}
|