feature/test #9

Merged
njohnson merged 318 commits from feature/test into main 2025-09-07 12:35:21 -04:00
Showing only changes of commit 1739a4686e - Show all commits

View File

@ -1,80 +1,80 @@
#include "soundviewer.h" #include "soundviewer.h"
#include "ui_soundviewer.h" #include "ui_soundviewer.h"
SoundViewer::SoundViewer(QWidget *parent) SoundViewer::SoundViewer(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::SoundViewer) , ui(new Ui::SoundViewer)
, player(new QMediaPlayer()) , player(new QMediaPlayer())
, buffer(new QBuffer()) , buffer(new QBuffer())
{ {
ui->setupUi(this); ui->setupUi(this);
connect(ui->pushButton_Play, &QPushButton::clicked, player, &QMediaPlayer::play); connect(ui->pushButton_Play, &QPushButton::clicked, player, &QMediaPlayer::play);
connect(ui->pushButton_Pause, &QPushButton::clicked, player, &QMediaPlayer::pause); connect(ui->pushButton_Pause, &QPushButton::clicked, player, &QMediaPlayer::pause);
connect(ui->pushButton_Stop, &QPushButton::clicked, this, [this]() { connect(ui->pushButton_Stop, &QPushButton::clicked, this, [this]() {
if (player->isPlaying()) { if (player->isPlaying()) {
player->stop(); player->stop();
} }
}); });
connect(ui->pushButton_SkipForward, &QPushButton::clicked, this, [this]() { connect(ui->pushButton_SkipForward, &QPushButton::clicked, this, [this]() {
player->setPosition(player->position() + 30); player->setPosition(player->position() + 30);
}); });
connect(ui->pushButton_SkipBack, &QPushButton::clicked, this, [this]() { connect(ui->pushButton_SkipBack, &QPushButton::clicked, this, [this]() {
player->setPosition(player->position() - 30); player->setPosition(player->position() - 30);
}); });
connect(player, &QMediaPlayer::positionChanged, player, [this](qint64 position) { connect(player, &QMediaPlayer::positionChanged, player, [this](qint64 position) {
ui->horizontalSlider->setSliderPosition(position); ui->horizontalSlider->setSliderPosition(position);
ui->label_Time->setText(QString("%1:%2:%3") ui->label_Time->setText(QString("%1:%2:%3")
.arg(position / 60000) .arg(position / 60000)
.arg((position % 60000) / 1000) .arg((position % 60000) / 1000)
.arg(position % 1000)); .arg(position % 1000));
}); });
connect(player, &QMediaPlayer::durationChanged, player, [this](qint64 duration) { connect(player, &QMediaPlayer::durationChanged, player, [this](qint64 duration) {
ui->horizontalSlider->setMaximum(duration); ui->horizontalSlider->setMaximum(duration);
ui->label_TimeMax->setText(QString("%1:%2:%3") ui->label_TimeMax->setText(QString("%1:%2:%3")
.arg(duration / 60000) .arg(duration / 60000)
.arg((duration % 60000) / 1000) .arg((duration % 60000) / 1000)
.arg(duration % 1000)); .arg(duration % 1000));
}); });
connect(ui->horizontalSlider, &QSlider::sliderMoved, this, [this](int position) { connect(ui->horizontalSlider, &QSlider::sliderMoved, this, [this](int position) {
player->setPosition(position); player->setPosition(position);
}); });
for (auto outputDevice : QMediaDevices::audioOutputs()) { for (auto outputDevice : QMediaDevices::audioOutputs()) {
ui->comboBox_Output->addItem(outputDevice.description()); ui->comboBox_Output->addItem(outputDevice.description());
} }
connect(ui->comboBox_Output, &QComboBox::currentIndexChanged, this, [this](int index) { connect(ui->comboBox_Output, &QComboBox::currentIndexChanged, this, [this](int index) {
auto outputDevice = QMediaDevices::audioOutputs()[index]; auto outputDevice = QMediaDevices::audioOutputs()[index];
QAudioOutput *audioOutput = new QAudioOutput(outputDevice); QAudioOutput *audioOutput = new QAudioOutput(outputDevice);
player->setAudioOutput(audioOutput); player->setAudioOutput(audioOutput);
}); });
auto outputDevice = QMediaDevices::defaultAudioOutput(); auto outputDevice = QMediaDevices::defaultAudioOutput();
QAudioOutput *audioOutput = new QAudioOutput(outputDevice); QAudioOutput *audioOutput = new QAudioOutput(outputDevice);
player->setAudioOutput(audioOutput); player->setAudioOutput(audioOutput);
} }
SoundViewer::~SoundViewer() SoundViewer::~SoundViewer()
{ {
delete buffer; delete buffer;
delete player; delete player;
delete ui; delete ui;
} }
// void SoundViewer::SetSound(std::shared_ptr<Sound> aSound) // void SoundViewer::SetSound(std::shared_ptr<Sound> aSound)
// { // {
// buffer->setData(aSound->data); // buffer->setData(aSound->data);
// if (!buffer->open(QIODevice::ReadOnly)) { // if (!buffer->open(QIODevice::ReadOnly)) {
// qWarning() << "Failed to open QBuffer."; // qWarning() << "Failed to open QBuffer.";
// return; // return;
// } // }
// ui->groupBox->setTitle(aSound->path); // ui->groupBox->setTitle(aSound->path);
// player->setSourceDevice(buffer); // player->setSourceDevice(buffer);
// } // }
void SoundViewer::SetOutput(QAudioOutput *aOutput) { void SoundViewer::SetOutput(QAudioOutput *aOutput) {
if (!aOutput) { return; } if (!aOutput) { return; }
player->setAudioOutput(aOutput); player->setAudioOutput(aOutput);
} }