91 lines
2.8 KiB
C++
91 lines
2.8 KiB
C++
#include "audiowidget.h"
|
|
|
|
|
|
AudioWidget::AudioWidget() :
|
|
m_layout(new QHBoxLayout())
|
|
, m_refreshUi(new QTimer(this))
|
|
{
|
|
|
|
for (int i= 0; i < Settings::getInstance()->getLayersNumber(); i++ ) {
|
|
m_layout->insertWidget(i, new AudioLayerWidget(this, tr("Layer %1").arg(i + 1)));
|
|
}
|
|
setLayout(m_layout);
|
|
connect(m_refreshUi, SIGNAL(timeout()), this, SLOT(refreshUi()));
|
|
m_refreshUi->start(UI_REFRESH_TIME);
|
|
}
|
|
|
|
bool AudioWidget::startEngine(int id)
|
|
{
|
|
return (m_mae.startEngine(id));
|
|
}
|
|
|
|
bool AudioWidget::startEngine()
|
|
{
|
|
return (m_mae.startEngine(Settings::getInstance()->getAudioDeviceId()));
|
|
}
|
|
|
|
void AudioWidget::stopEngine()
|
|
{
|
|
m_mae.stopEngine();
|
|
}
|
|
|
|
void AudioWidget::mediaLoaded(int layer, QString file)
|
|
{
|
|
ma_result result;
|
|
|
|
if (m_currentMedia[layer].compare(file) == 0 ) {
|
|
return;
|
|
}
|
|
if (!QFile::exists(file)) {
|
|
qWarning("Can not access to file %s", file.toLatin1().constData());
|
|
return;
|
|
}
|
|
result = m_mae.loadMedia(layer, file.toLatin1().data());
|
|
if (result != MA_SUCCESS) {
|
|
qWarning("can not open file %s", file.toLatin1().constData());
|
|
return;
|
|
}
|
|
m_currentMedia[layer] = file;
|
|
float pLength = m_mae.getDuration(layer);
|
|
qInfo("File loaded: %s - Duration: %f secs", file.toLatin1().constData(), pLength);
|
|
m_mae.printFormatInfo(layer);
|
|
QLayoutItem * const item = m_layout->itemAt(layer);
|
|
dynamic_cast<AudioLayerWidget *>(item->widget())->fileLoaded(file);
|
|
dynamic_cast<AudioLayerWidget *>(item->widget())->durationChanged(pLength);
|
|
}
|
|
|
|
void AudioWidget::volChanged(int layer, qreal vol) {
|
|
m_mae.volChanged(layer, vol);
|
|
QLayoutItem * const item = m_layout->itemAt(layer);
|
|
dynamic_cast<AudioLayerWidget *>(item->widget())->setVol(vol);
|
|
}
|
|
|
|
void AudioWidget::panChanged(int layer, qreal pan) {
|
|
m_mae.panChanged(layer, pan);
|
|
QLayoutItem * const item = m_layout->itemAt(layer);
|
|
dynamic_cast<AudioLayerWidget *>(item->widget())->setPan(pan);
|
|
}
|
|
|
|
void AudioWidget::pitchChanged(int layer, qreal pitch) {
|
|
m_mae.pitchChanged(layer, pitch);
|
|
QLayoutItem * const item = m_layout->itemAt(layer);
|
|
dynamic_cast<AudioLayerWidget *>(item->widget())->setPitch(pitch);
|
|
}
|
|
|
|
void AudioWidget::playbackChanged(int layer, Status status)
|
|
{
|
|
m_mae.playbackChanged(layer, status);
|
|
QLayoutItem * const item = m_layout->itemAt(layer);
|
|
dynamic_cast<AudioLayerWidget *>(item->widget())->setPlaybackStatus(status);
|
|
}
|
|
|
|
void AudioWidget::refreshUi() {
|
|
for (int i= 0; i < Settings::getInstance()->getLayersNumber(); i++ ) {
|
|
QLayoutItem * const item = m_layout->itemAt(i);
|
|
AudioLayerWidget *aw = dynamic_cast<AudioLayerWidget *>(item->widget());
|
|
Status s = aw->getPlaybackStatus();
|
|
if (s == Status::PlayingOnce || s == Status::PlayingLoop) {
|
|
aw->refreshUi(m_mae.getCursor(i));
|
|
}
|
|
}
|
|
}
|