Merge branch 'sfml'

Added Singleton to AudioWidget

Conflicts:
	lms-audio.xlm
	puredata/layer_audio.pd
	src/audiolayerwidget.cpp
	src/audiolayerwidget.h
	src/audiomasterwidget.cpp
	src/audiomasterwidget.h
	src/audiomotor.cpp
	src/audiomotor.h
	src/audiowidget.cpp
	src/defines.h
	src/libremediaserver-audio.cpp
	src/libremediaserver-audio.h
	src/libremediaserver-audio.pro
	src/libremediaserver-audio.ui
	src/medialibrary.cpp
	src/medialibrary.h
	src/olathread.cpp
	src/olathread.h
	src/settings.cpp
	src/settings.h
This commit is contained in:
santi 2014-10-03 13:17:00 +02:00
commit 2d16fb6af7
31 changed files with 1112 additions and 1296 deletions

View file

@ -1,27 +1,110 @@
#include "audiolayerwidget.h"
#include<iostream>
#include <QDebug>
#include <QVBoxLayout>
#include <QFile>
#include <QTime>
//#include <time.h> // nanosleep y la chapuza de liberar el buffer
AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name):
QGroupBox(parent)
, m_suspendResumeButton(0)
, m_watchDMX(new QTimer(this))
// , m_progressCounter(new QTime(0,0,0,1))
// , m_progressMs(0)
, m_currentMedia(" ")
, m_running(false)
{
Q_UNUSED(parent);
this->setTitle(name);
folder = new QLabel(this);
folder->setMaximumWidth(150);
file = new QLabel(this);
file->setMaximumWidth(150);
status = new QLabel(this);
vol = new QSlider(Qt::Horizontal, this);
vol->setMaximum(99);
vol->setMaximumWidth(150);
// mute = new QCheckBox(this);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(folder);
vbox->addWidget(file);
vbox->addWidget(status);
vbox->addWidget(vol);
// vbox->addWidget(mute);
this->setLayout(vbox);
this->setTitle(name);
QVBoxLayout *layout = new QVBoxLayout;
QHBoxLayout *status = new QHBoxLayout;
m_statusLabel = new QLabel;
m_statusLabel->setText(STATUS_LABEL);
m_statusValue = new QLabel;
// m_receiveDMX = new QCheckBox("Receiving DMX", this);
// m_receiveDMX->setChecked(false);
// status->addWidget(m_receiveDMX);
status->addWidget(m_statusLabel);
status->addWidget(m_statusValue);
layout->addLayout(status);
QHBoxLayout *folderLoaded = new QHBoxLayout;
m_folderLabel = new QLabel;
m_folderLabel->setText(FOLDER_LABEL);
m_folderValue = new QLabel;
m_folderValue->setMaximumWidth(150);
folderLoaded->addWidget(m_folderLabel);
folderLoaded->addWidget(m_folderValue);
layout->addLayout(folderLoaded);
QHBoxLayout *fileLoaded = new QHBoxLayout;
m_fileLabel = new QLabel;
m_fileLabel->setText(FILE_LABEL);
m_fileValue = new QLabel;
m_fileValue->setMaximumWidth(150);
fileLoaded->addWidget(m_fileLabel);
fileLoaded->addWidget(m_fileValue);
layout->addLayout(fileLoaded);
QHBoxLayout *volumeBox = new QHBoxLayout;
m_volumeLabel = new QLabel;
m_volumeLabel->setText(tr(VOLUME_LABEL));
m_volumeSlider = new QSlider(Qt::Horizontal);
m_volumeSlider->setMinimum(0);
m_volumeSlider->setMaximum(80);
m_volumeSlider->setSingleStep(1);
connect(m_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(volumeChanged(int)));
volumeBox->addWidget(m_volumeLabel);
volumeBox->addWidget(m_volumeSlider);
layout->addLayout(volumeBox);
QGridLayout *progressTime = new QGridLayout;
m_progressTimeLabel = new QLabel;
m_progressTimeLabel->setText(PROGRESS_TIME_LABEL);
m_progressTime = new QTimeEdit;
m_progressTime->text();
m_progressTime->setDisplayFormat("h:mm:ss:zzz");
m_progressTime->setReadOnly(true);
m_progressTime->setButtonSymbols(QAbstractSpinBox::NoButtons);
m_progressTime->setMaximumWidth(80);
progressTime->addWidget(m_progressTimeLabel, 0 ,0);
progressTime->addWidget(m_progressTime,0 ,1);
m_totalTimeLabel = new QLabel;
m_totalTimeLabel->setText(TOTAL_TIME_LABEL);
m_totalTimeValue = new QTimeEdit;
m_totalTimeValue->setDisplayFormat("h:mm:ss:zzz");
m_totalTimeValue->setReadOnly(true);
m_totalTimeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
m_totalTimeValue->setMaximumWidth(80);
progressTime->addWidget(m_totalTimeLabel,1 , 0);
progressTime->addWidget(m_totalTimeValue, 1 ,1);
layout->addLayout(progressTime);
QHBoxLayout *progressSlider = new QHBoxLayout;
m_progressLabel = new QLabel;
m_progressLabel->setText(PROGRESS_LABEL);
m_progressSlider = new QSlider(Qt::Horizontal);
progressSlider->addWidget(m_progressLabel);
progressSlider->addWidget(m_progressSlider);
layout->addLayout(progressSlider);
m_suspendResumeButton = new QPushButton(this);
m_suspendResumeButton->setText(tr(SUSPEND_LABEL));
connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspendResume()));
layout->addWidget(m_suspendResumeButton);
this->setLayout(layout);
connect(m_watchDMX, SIGNAL(timeout()),
this, SLOT(watchDMXExpired()));
m_watchDMX->start(243);
}
AudioLayerWidget::~AudioLayerWidget()
@ -29,3 +112,129 @@ AudioLayerWidget::~AudioLayerWidget()
}
void AudioLayerWidget::volumeChanged(int value)
{
m_music.setVolume(value);
}
// volume range 0 -100
void AudioLayerWidget::setVol(qreal vol)
{
m_music.setVolume(vol);
m_volumeSlider->blockSignals(true);
m_volumeSlider->setValue(vol);
m_volumeSlider->blockSignals(false);
}
void AudioLayerWidget::loadMedia(QString file)
{
if (m_currentMedia == file ) {
fileLoaded(file);
return;
}
if (!QFile::exists(file)) {
qWarning("Can not access to file %s", file.toLatin1().constData());
return;
}
// Load an ogg music file
if (!m_music.openFromFile(file.toStdString())) {
qWarning("Can not open file %s", file.toLatin1().constData());
return;
}
m_music.setAttenuation(0);
// m_progressCounter->restart();
durationChanged(m_music.getDuration().asMilliseconds());
fileLoaded(file);
// Display music informations
std::cout << "File loaded: " << file.toLatin1().constData() << " : " << std::endl;
std::cout << " " << m_music.getDuration().asSeconds() << " seconds";
std::cout << " " << m_music.getSampleRate() << " samples / sec";
std::cout << " " << m_music.getChannelCount() << " channels";
}
void AudioLayerWidget::fileLoaded(QString file)
{
QStringList list = file.split("/");
int size = list.size();
if (size >= 2) {
m_folderValue->setText(list.at(size - 2));
m_fileValue->setText(list.at(size - 1));
}
// m_progressMs = 0;
// m_progressTime->setTime(QTime::fromMSecsSinceStartOfDay(m_progressMs));
}
/*
void AudioLayerWidget::notified()
{
}
*/
// duration in miliseconds
void AudioLayerWidget::durationChanged(qint64 dur)
{
m_progressSlider->setMaximum(dur);
m_totalTimeValue->setTime(QTime::fromMSecsSinceStartOfDay(dur));
}
void AudioLayerWidget::play()
{
m_music.play();
// m_progressCounter->restart();
}
void AudioLayerWidget::pause()
{
m_music.pause();
// m_progressCounter->restart();
}
void AudioLayerWidget::stop()
{
m_music.stop();
}
void AudioLayerWidget::watchDMXExpired() {
// m_receiveDMX->setChecked(false);
int progress;
switch (m_music.getStatus()) {
case sf::SoundSource::Playing:
// m_progressMs += m_progressCounter->restart();
progress = m_music.getPlayingOffset().asMilliseconds();
m_progressSlider->setValue(progress);
m_progressTime->setTime(QTime::fromMSecsSinceStartOfDay(progress));
m_statusValue->setText(PLAY_LABEL);
m_suspendResumeButton->setText(tr(SUSPEND_LABEL));
break;
case sf::SoundSource::Paused:
m_statusValue->setText(PAUSE_LABEL);
m_suspendResumeButton->setText(tr(RESUME_LABEL));
break;
case sf::SoundSource::Stopped:
// m_progressCounter->restart();
// m_progressMs = 0;
m_progressTime->setTime(QTime::fromMSecsSinceStartOfDay(0));
m_statusValue->setText(STOP_LABEL);
m_suspendResumeButton->setText(tr(RESUME_LABEL));
m_progressSlider->setValue(0);
break;
}
}
/*
void AudioLayerWidget::updateWatchDMX(bool b)
{
// m_receiveDMX->setChecked(b);
}
*/
void AudioLayerWidget::toggleSuspendResume()
{
if (m_music.getStatus() == sf::SoundSource::Playing) {
m_music.pause();
// m_suspendResumeButton->setText(tr(SUSPEND_LABEL));
} else {
m_music.play();
// m_suspendResumeButton->setText(tr(PLAY_LABEL));
}
}