171 lines
5.1 KiB
C++
171 lines
5.1 KiB
C++
#include "audiolayerwidget.h"
|
|
|
|
|
|
AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name, int layer):
|
|
QGroupBox(parent)
|
|
, m_layer(layer)
|
|
, m_suspendResumeButton(0)
|
|
{
|
|
this->setTitle(name);
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
|
|
|
QHBoxLayout *progressTime = new QHBoxLayout;
|
|
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(90);
|
|
m_progressTime->setFocusPolicy(Qt::NoFocus);
|
|
progressTime->addWidget(m_progressTime);
|
|
m_totalTimeValue = new QTimeEdit;
|
|
m_totalTimeValue->setDisplayFormat("h:mm:ss:zzz");
|
|
m_totalTimeValue->setReadOnly(true);
|
|
m_totalTimeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
|
|
m_totalTimeValue->setMaximumWidth(90);
|
|
m_totalTimeValue->setFocusPolicy(Qt::NoFocus);
|
|
progressTime->addWidget(m_totalTimeValue);
|
|
layout->addLayout(progressTime);
|
|
|
|
m_progressSlider = new QSlider(Qt::Horizontal);
|
|
m_progressSlider->setFocusPolicy(Qt::NoFocus);
|
|
layout->addWidget(m_progressSlider);
|
|
|
|
QGridLayout *status = new QGridLayout;
|
|
m_statusValue = new QLabel;
|
|
status->addWidget(m_statusValue, 0, 0);
|
|
m_folderValue = new QLabel;
|
|
m_folderValue->setMaximumWidth(200);
|
|
status->addWidget(m_folderValue, 1, 0);
|
|
m_fileValue = new QLabel;
|
|
m_fileValue->setMaximumWidth(200);
|
|
status->addWidget(m_fileValue, 2, 0);
|
|
layout->addLayout(status);
|
|
|
|
QHBoxLayout *volumeBox = new QHBoxLayout;
|
|
m_volume = new SliderGroup("Vol", 0 , 100, 2, NULL);
|
|
volumeBox->addWidget(m_volume);
|
|
connect(m_volume, SIGNAL(valueChanged(float)), this, SLOT(volumeChanged(float)));
|
|
m_pan = new SliderGroup("Pan", 0 , 255, 0, NULL);
|
|
volumeBox->addWidget(m_pan);
|
|
connect(m_pan, SIGNAL(valueChanged(float)), this, SLOT(panChanged(float)));
|
|
m_pitch = new SliderGroup("Pitch", 0 , 255, 0, NULL);
|
|
volumeBox->addWidget(m_pitch);
|
|
connect(m_pitch, SIGNAL(valueChanged(float)), this, SLOT(pitchChanged(float)));
|
|
layout->addLayout(volumeBox);
|
|
|
|
m_suspendResumeButton = new QPushButton(this);
|
|
m_suspendResumeButton->setText(StatusStr[Status::Stopped]);
|
|
connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspendResume()));
|
|
layout->addWidget(m_suspendResumeButton);
|
|
|
|
this->setLayout(layout);
|
|
}
|
|
|
|
AudioLayerWidget::~AudioLayerWidget()
|
|
{
|
|
|
|
}
|
|
|
|
// From UI.
|
|
void AudioLayerWidget::volumeChanged(float value)
|
|
{
|
|
emit(uiSliderChanged(m_layer, Slider::Volume, value));
|
|
}
|
|
|
|
void AudioLayerWidget::panChanged(float value)
|
|
{
|
|
emit(uiSliderChanged(m_layer, Slider::Pan, value));
|
|
}
|
|
|
|
void AudioLayerWidget::pitchChanged(float value)
|
|
{
|
|
emit(uiSliderChanged(m_layer, Slider::Pitch, value));
|
|
}
|
|
|
|
void AudioLayerWidget::toggleSuspendResume()
|
|
{
|
|
switch (m_status) {
|
|
case Status::PlayingLoop:
|
|
case Status::PlayingOnce:
|
|
this->setPlaybackStatus(Status::Paused);
|
|
emit uiPlaybackChanged(m_layer, Status::Paused);
|
|
break;
|
|
case Status::Paused:
|
|
case Status::Stopped:
|
|
this->setPlaybackStatus(Status::PlayingOnce);
|
|
emit uiPlaybackChanged(m_layer, Status::PlayingOnce);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// from DMX signals
|
|
void AudioLayerWidget::setVol(float vol)
|
|
{
|
|
m_volume->blockSignals(true);
|
|
m_volume->setValue(vol);
|
|
m_volume->blockSignals(false);
|
|
}
|
|
|
|
void AudioLayerWidget::setPan(int pan)
|
|
{
|
|
m_pan->blockSignals(true);
|
|
m_pan->setValue(pan);
|
|
m_pan->blockSignals(false);
|
|
}
|
|
|
|
void AudioLayerWidget::setPitch(int pitch)
|
|
{
|
|
m_pitch->blockSignals(true);
|
|
m_pitch->setValue(pitch);
|
|
m_pitch->blockSignals(false);
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|
|
|
|
void AudioLayerWidget::setPlaybackStatus(Status status)
|
|
{
|
|
m_status = status;
|
|
if (status == Status::Stopped)
|
|
m_progressTime->setTime(QTime::fromMSecsSinceStartOfDay(0));
|
|
m_statusValue->blockSignals(true);
|
|
m_suspendResumeButton->blockSignals(true);
|
|
m_statusValue->setText(StatusStr[status]);
|
|
m_suspendResumeButton->setText(StatusStr[status]);
|
|
switch (m_status) {
|
|
case Status::Paused:
|
|
m_statusValue->setStyleSheet("QLabel { color : red; }");
|
|
break;
|
|
case Status::PlayingLoop:
|
|
case Status::PlayingOnce:
|
|
m_statusValue->setStyleSheet("QLabel { color : green; }");
|
|
break;
|
|
case Status::Stopped:
|
|
m_statusValue->setStyleSheet("QLabel { color : red; }");
|
|
break;
|
|
}
|
|
m_statusValue->blockSignals(false);
|
|
m_suspendResumeButton->blockSignals(false);
|
|
}
|
|
|
|
void AudioLayerWidget::durationChanged(float dur)
|
|
{
|
|
dur *= 1000;
|
|
m_progressSlider->setMaximum(dur);
|
|
m_totalTimeValue->setTime(QTime::fromMSecsSinceStartOfDay(dur));
|
|
}
|
|
|
|
void AudioLayerWidget::refreshUi(float progress)
|
|
{
|
|
progress *= 1000;
|
|
m_progressSlider->setValue(progress);
|
|
m_progressTime->setTime(QTime::fromMSecsSinceStartOfDay(progress));
|
|
}
|