171 lines
5.8 KiB
C++
171 lines
5.8 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(bool gui)
|
|
{
|
|
m_ui = gui;
|
|
Settings *set = Settings::getInstance();
|
|
set->readFile();
|
|
m_mediaLibrary = new MediaLibrary;
|
|
m_mediaLibrary->initMediaLibrary();
|
|
for (int i = 0; i < MAX_LAYERS; i++) {
|
|
m_currentMedia[i] = Status::Iddle;
|
|
m_updateUi[i][0] = -1;
|
|
m_updateUi[i][1] = -1;
|
|
m_updateUi[i][2] = -1;
|
|
}
|
|
m_ola = new olaThread(this, set->getLayersNumber());
|
|
Q_CHECK_PTR(m_ola);
|
|
m_ola->blockSignals(true);
|
|
connect(m_ola, SIGNAL(dmxOutput(int, int, int)), this, SLOT(dmxInput(int, int, int)));
|
|
m_ola->registerUniverse();
|
|
m_mae.startEngine(set->getAudioDeviceId());
|
|
qDebug("Core init Complete. Start reading DMX.");
|
|
m_ola->blockSignals(false);
|
|
m_ola->start(QThread::TimeCriticalPriority );
|
|
}
|
|
|
|
libreMediaServerAudio::~libreMediaServerAudio()
|
|
{
|
|
m_ola->stop();
|
|
m_mae.stopEngine();
|
|
}
|
|
|
|
void libreMediaServerAudio::dmxInput(int layer, int channel, int value)
|
|
{
|
|
if (layer >= MAX_LAYERS || channel >= LAYER_CHANNELS)
|
|
return;
|
|
QString mediaFile = NULL;
|
|
int aux;
|
|
if (channel == DMX_FOLDER || channel == DMX_FILE){
|
|
int folder = (value >> 8) & 0x000000FF;
|
|
int file = value & 0x000000FF;
|
|
mediaFile = m_mediaLibrary->requestNewFile(folder, file);
|
|
if (strcmp(mediaFile.toLatin1().constData(), m_currentMedia[layer].toLatin1().constData()) == 0)
|
|
return;
|
|
if (QFile::exists(mediaFile)){
|
|
m_mae.loadMedia(layer, mediaFile.toLatin1().data());
|
|
m_currentMedia[layer] = mediaFile;
|
|
#ifndef NOGUI
|
|
if (m_ui)
|
|
m_lmsUi->m_aw->mediaLoaded(layer, mediaFile, m_mae.getDuration(layer));
|
|
#endif
|
|
}
|
|
return;
|
|
} else if (channel == VOLUME_COARSE || channel == VOLUME_FINE) {
|
|
float tmp = value / 65025.0f;
|
|
m_mae.volChanged(layer, tmp);
|
|
m_updateUi[layer][0] = tmp * 100.0f;
|
|
} else if (channel == PAN) {
|
|
m_mae.panChanged(layer, value);
|
|
m_updateUi[layer][1] = value;
|
|
} else if (channel == PITCH) {
|
|
m_mae.pitchChanged(layer, value);
|
|
m_updateUi[layer][2] = value;
|
|
} else if (channel == ENTRY_POINT_COARSE || channel == ENTRY_POINT_FINE) {
|
|
m_mae.setCursor(layer, value);
|
|
#ifndef NOGUI
|
|
m_lmsUi->m_aw->cursorChanged(layer, m_mae.getCursor(layer));
|
|
#endif
|
|
return;
|
|
} else if (channel == PLAYBACK && value > 0) {
|
|
aux = value / 25;
|
|
Status s = m_currentStatus[layer];
|
|
if (aux == 0)
|
|
s = Status::PlayingOnce;
|
|
else if (aux == 1)
|
|
s = Status::Stopped;
|
|
else if (aux == 2)
|
|
s = Status::Paused;
|
|
else if (aux == 3)
|
|
s = Status::PlayingLoop;
|
|
m_mae.playbackChanged(layer, s);
|
|
m_currentStatus[layer] = s;
|
|
#ifndef NOGUI
|
|
if (m_ui) m_lmsUi->m_aw->playbackChanged(layer, s);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
#ifndef NOGUI
|
|
void libreMediaServerAudio::refreshUi() {
|
|
if (!m_ui) return;
|
|
for (int i= 0; i < Settings::getInstance()->getLayersNumber(); i++ ) {
|
|
Status s = m_currentStatus[i];
|
|
if (s == Status::PlayingOnce || s == Status::PlayingLoop) {
|
|
m_lmsUi->m_aw->cursorChanged(i, m_mae.getCursor(i));
|
|
}
|
|
if (m_updateUi[i][0] >= 0) {
|
|
m_lmsUi->m_aw->volChanged(i, m_updateUi[i][0]);
|
|
m_updateUi[i][0] = -1;
|
|
}
|
|
if (m_updateUi[i][1] >= 0) {
|
|
m_lmsUi->m_aw->panChanged(i, m_updateUi[i][1]);
|
|
m_updateUi[i][1] = -1;
|
|
}
|
|
if (m_updateUi[i][2] >= 0) {
|
|
m_lmsUi->m_aw->pitchChanged(i, m_updateUi[i][2]);
|
|
m_updateUi[i][2] = -1;
|
|
}
|
|
//m_lmsUi->m_aw->playbackChanged(i, m_currentStatus[i]);
|
|
}
|
|
}
|
|
|
|
void libreMediaServerAudio::setUi(libreMediaServerAudioUi *lmsUi)
|
|
{
|
|
m_lmsUi = lmsUi;
|
|
connect(m_ola, SIGNAL(universeReceived(int)), m_lmsUi->m_dmxWidget, SLOT(updateWatchDMX(int)));
|
|
connect(m_lmsUi->m_aw, SIGNAL(uiSliderChanged(int, Slider, int)), this, SLOT(uiSliderChanged(int, Slider, int)));
|
|
connect(m_lmsUi->m_aw, SIGNAL(uiPlaybackChanged(int, Status)), this, SLOT(uiPlaybackChanged(int, Status)));
|
|
connect(m_lmsUi->m_aw, SIGNAL(uiLoadMedia(int, QString)), this, SLOT(uiLoadMedia(int, QString)));
|
|
m_refreshUi = new QTimer(this);
|
|
connect(m_refreshUi, SIGNAL(timeout()), this, SLOT(refreshUi()));
|
|
m_refreshUi->start(UI_REFRESH_TIME);
|
|
};
|
|
|
|
void libreMediaServerAudio::uiSliderChanged(int layer, Slider s, int value)
|
|
{
|
|
switch (s){
|
|
case Slider::Volume:
|
|
m_mae.volChanged(layer, float((value / 100.0f)));
|
|
break;
|
|
case Slider::Pan:
|
|
m_mae.panChanged(layer, value);
|
|
break;
|
|
case Slider::Pitch:
|
|
m_mae.pitchChanged(layer, value);
|
|
break;
|
|
}
|
|
}
|
|
|
|
void libreMediaServerAudio::uiPlaybackChanged(int layer, Status s)
|
|
{
|
|
m_mae.playbackChanged(layer, s);
|
|
m_currentStatus[layer] = s;
|
|
}
|
|
|
|
void libreMediaServerAudio::uiLoadMedia(int layer, QString s)
|
|
{
|
|
m_mae.loadMedia(layer, s.toLatin1().data());
|
|
}
|
|
#endif
|