2018-07-31 05:57:53 +02:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "audio_core/sink.h"
|
|
|
|
#include "audio_core/sink_details.h"
|
|
|
|
#include "core/core.h"
|
|
|
|
#include "core/settings.h"
|
|
|
|
#include "ui_configure_audio.h"
|
|
|
|
#include "yuzu/configuration/configure_audio.h"
|
|
|
|
|
|
|
|
ConfigureAudio::ConfigureAudio(QWidget* parent)
|
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureAudio>()) {
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
ui->output_sink_combo_box->clear();
|
2019-05-19 17:08:54 +02:00
|
|
|
ui->output_sink_combo_box->addItem(QString::fromUtf8(AudioCore::auto_device_name));
|
2018-12-13 22:23:31 +01:00
|
|
|
for (const char* id : AudioCore::GetSinkIDs()) {
|
2019-05-19 17:08:54 +02:00
|
|
|
ui->output_sink_combo_box->addItem(QString::fromUtf8(id));
|
2018-07-31 05:57:53 +02:00
|
|
|
}
|
|
|
|
|
2018-10-03 01:45:09 +02:00
|
|
|
connect(ui->volume_slider, &QSlider::valueChanged, this,
|
2019-05-26 06:39:23 +02:00
|
|
|
&ConfigureAudio::SetVolumeIndicatorText);
|
2018-07-31 05:57:53 +02:00
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
SetConfiguration();
|
2019-05-19 17:10:55 +02:00
|
|
|
connect(ui->output_sink_combo_box, qOverload<int>(&QComboBox::currentIndexChanged), this,
|
2019-05-26 06:39:23 +02:00
|
|
|
&ConfigureAudio::UpdateAudioDevices);
|
2018-07-31 05:57:53 +02:00
|
|
|
|
2019-05-19 17:12:29 +02:00
|
|
|
const bool is_powered_on = Core::System::GetInstance().IsPoweredOn();
|
|
|
|
ui->output_sink_combo_box->setEnabled(!is_powered_on);
|
|
|
|
ui->audio_device_combo_box->setEnabled(!is_powered_on);
|
2018-07-31 05:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigureAudio::~ConfigureAudio() = default;
|
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigureAudio::SetConfiguration() {
|
|
|
|
SetOutputSinkFromSinkID();
|
2018-10-03 02:17:14 +02:00
|
|
|
|
|
|
|
// The device list cannot be pre-populated (nor listed) until the output sink is known.
|
2019-05-26 06:39:23 +02:00
|
|
|
UpdateAudioDevices(ui->output_sink_combo_box->currentIndex());
|
2018-10-03 02:17:14 +02:00
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
SetAudioDeviceFromDeviceID();
|
2018-10-03 02:17:14 +02:00
|
|
|
|
|
|
|
ui->toggle_audio_stretching->setChecked(Settings::values.enable_audio_stretching);
|
|
|
|
ui->volume_slider->setValue(Settings::values.volume * ui->volume_slider->maximum());
|
2019-05-26 06:39:23 +02:00
|
|
|
SetVolumeIndicatorText(ui->volume_slider->sliderPosition());
|
2018-10-03 02:17:14 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigureAudio::SetOutputSinkFromSinkID() {
|
2018-07-31 05:57:53 +02:00
|
|
|
int new_sink_index = 0;
|
2018-10-03 02:17:14 +02:00
|
|
|
|
|
|
|
const QString sink_id = QString::fromStdString(Settings::values.sink_id);
|
2018-07-31 05:57:53 +02:00
|
|
|
for (int index = 0; index < ui->output_sink_combo_box->count(); index++) {
|
2018-10-03 02:17:14 +02:00
|
|
|
if (ui->output_sink_combo_box->itemText(index) == sink_id) {
|
2018-07-31 05:57:53 +02:00
|
|
|
new_sink_index = index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-03 02:17:14 +02:00
|
|
|
ui->output_sink_combo_box->setCurrentIndex(new_sink_index);
|
|
|
|
}
|
2018-07-31 05:57:53 +02:00
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigureAudio::SetAudioDeviceFromDeviceID() {
|
2018-07-31 05:57:53 +02:00
|
|
|
int new_device_index = -1;
|
2018-10-03 02:17:14 +02:00
|
|
|
|
|
|
|
const QString device_id = QString::fromStdString(Settings::values.audio_device_id);
|
2018-07-31 05:57:53 +02:00
|
|
|
for (int index = 0; index < ui->audio_device_combo_box->count(); index++) {
|
2018-10-03 02:17:14 +02:00
|
|
|
if (ui->audio_device_combo_box->itemText(index) == device_id) {
|
2018-07-31 05:57:53 +02:00
|
|
|
new_device_index = index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-03 02:17:14 +02:00
|
|
|
ui->audio_device_combo_box->setCurrentIndex(new_device_index);
|
2018-10-03 01:45:09 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigureAudio::SetVolumeIndicatorText(int percentage) {
|
2018-10-03 01:45:09 +02:00
|
|
|
ui->volume_indicator->setText(tr("%1%", "Volume percentage (e.g. 50%)").arg(percentage));
|
2018-07-31 05:57:53 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigureAudio::ApplyConfiguration() {
|
2018-07-31 05:57:53 +02:00
|
|
|
Settings::values.sink_id =
|
|
|
|
ui->output_sink_combo_box->itemText(ui->output_sink_combo_box->currentIndex())
|
|
|
|
.toStdString();
|
2018-08-23 14:33:03 +02:00
|
|
|
Settings::values.enable_audio_stretching = ui->toggle_audio_stretching->isChecked();
|
2018-07-31 05:57:53 +02:00
|
|
|
Settings::values.audio_device_id =
|
|
|
|
ui->audio_device_combo_box->itemText(ui->audio_device_combo_box->currentIndex())
|
|
|
|
.toStdString();
|
|
|
|
Settings::values.volume =
|
|
|
|
static_cast<float>(ui->volume_slider->sliderPosition()) / ui->volume_slider->maximum();
|
|
|
|
}
|
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigureAudio::UpdateAudioDevices(int sink_index) {
|
2018-07-31 05:57:53 +02:00
|
|
|
ui->audio_device_combo_box->clear();
|
2019-05-19 17:08:54 +02:00
|
|
|
ui->audio_device_combo_box->addItem(QString::fromUtf8(AudioCore::auto_device_name));
|
2018-07-31 05:57:53 +02:00
|
|
|
|
2018-10-03 01:50:48 +02:00
|
|
|
const std::string sink_id = ui->output_sink_combo_box->itemText(sink_index).toStdString();
|
2018-12-13 22:23:31 +01:00
|
|
|
for (const auto& device : AudioCore::GetDeviceListForSink(sink_id)) {
|
2018-10-03 01:50:48 +02:00
|
|
|
ui->audio_device_combo_box->addItem(QString::fromStdString(device));
|
2018-07-31 05:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 06:39:23 +02:00
|
|
|
void ConfigureAudio::RetranslateUI() {
|
2018-07-31 05:57:53 +02:00
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|