Merge pull request #1431 from lioncash/audio

configure_audio: Minor cleanup-related changes
This commit is contained in:
bunnei 2018-10-03 19:14:22 -04:00 committed by GitHub
commit 839dbd9710
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 17 deletions

View file

@ -21,9 +21,8 @@ ConfigureAudio::ConfigureAudio(QWidget* parent)
ui->output_sink_combo_box->addItem(sink_detail.id); ui->output_sink_combo_box->addItem(sink_detail.id);
} }
connect(ui->volume_slider, &QSlider::valueChanged, [this] { connect(ui->volume_slider, &QSlider::valueChanged, this,
ui->volume_indicator->setText(tr("%1 %").arg(ui->volume_slider->sliderPosition())); &ConfigureAudio::setVolumeIndicatorText);
});
this->setConfiguration(); this->setConfiguration();
connect(ui->output_sink_combo_box, connect(ui->output_sink_combo_box,
@ -37,32 +36,48 @@ ConfigureAudio::ConfigureAudio(QWidget* parent)
ConfigureAudio::~ConfigureAudio() = default; ConfigureAudio::~ConfigureAudio() = default;
void ConfigureAudio::setConfiguration() { void ConfigureAudio::setConfiguration() {
setOutputSinkFromSinkID();
// The device list cannot be pre-populated (nor listed) until the output sink is known.
updateAudioDevices(ui->output_sink_combo_box->currentIndex());
setAudioDeviceFromDeviceID();
ui->toggle_audio_stretching->setChecked(Settings::values.enable_audio_stretching);
ui->volume_slider->setValue(Settings::values.volume * ui->volume_slider->maximum());
setVolumeIndicatorText(ui->volume_slider->sliderPosition());
}
void ConfigureAudio::setOutputSinkFromSinkID() {
int new_sink_index = 0; int new_sink_index = 0;
const QString sink_id = QString::fromStdString(Settings::values.sink_id);
for (int index = 0; index < ui->output_sink_combo_box->count(); index++) { for (int index = 0; index < ui->output_sink_combo_box->count(); index++) {
if (ui->output_sink_combo_box->itemText(index).toStdString() == Settings::values.sink_id) { if (ui->output_sink_combo_box->itemText(index) == sink_id) {
new_sink_index = index; new_sink_index = index;
break; break;
} }
} }
ui->output_sink_combo_box->setCurrentIndex(new_sink_index); ui->output_sink_combo_box->setCurrentIndex(new_sink_index);
}
ui->toggle_audio_stretching->setChecked(Settings::values.enable_audio_stretching); void ConfigureAudio::setAudioDeviceFromDeviceID() {
// The device list cannot be pre-populated (nor listed) until the output sink is known.
updateAudioDevices(new_sink_index);
int new_device_index = -1; int new_device_index = -1;
const QString device_id = QString::fromStdString(Settings::values.audio_device_id);
for (int index = 0; index < ui->audio_device_combo_box->count(); index++) { for (int index = 0; index < ui->audio_device_combo_box->count(); index++) {
if (ui->audio_device_combo_box->itemText(index).toStdString() == if (ui->audio_device_combo_box->itemText(index) == device_id) {
Settings::values.audio_device_id) {
new_device_index = index; new_device_index = index;
break; break;
} }
} }
ui->audio_device_combo_box->setCurrentIndex(new_device_index);
ui->volume_slider->setValue(Settings::values.volume * ui->volume_slider->maximum()); ui->audio_device_combo_box->setCurrentIndex(new_device_index);
ui->volume_indicator->setText(tr("%1 %").arg(ui->volume_slider->sliderPosition())); }
void ConfigureAudio::setVolumeIndicatorText(int percentage) {
ui->volume_indicator->setText(tr("%1%", "Volume percentage (e.g. 50%)").arg(percentage));
} }
void ConfigureAudio::applyConfiguration() { void ConfigureAudio::applyConfiguration() {
@ -81,10 +96,10 @@ void ConfigureAudio::updateAudioDevices(int sink_index) {
ui->audio_device_combo_box->clear(); ui->audio_device_combo_box->clear();
ui->audio_device_combo_box->addItem(AudioCore::auto_device_name); ui->audio_device_combo_box->addItem(AudioCore::auto_device_name);
std::string sink_id = ui->output_sink_combo_box->itemText(sink_index).toStdString(); const std::string sink_id = ui->output_sink_combo_box->itemText(sink_index).toStdString();
std::vector<std::string> device_list = AudioCore::GetSinkDetails(sink_id).list_devices(); const std::vector<std::string> device_list = AudioCore::GetSinkDetails(sink_id).list_devices();
for (const auto& device : device_list) { for (const auto& device : device_list) {
ui->audio_device_combo_box->addItem(device.c_str()); ui->audio_device_combo_box->addItem(QString::fromStdString(device));
} }
} }

View file

@ -26,6 +26,9 @@ public slots:
private: private:
void setConfiguration(); void setConfiguration();
void setOutputSinkFromSinkID();
void setAudioDeviceFromDeviceID();
void setVolumeIndicatorText(int percentage);
std::unique_ptr<Ui::ConfigureAudio> ui; std::unique_ptr<Ui::ConfigureAudio> ui;
}; };