From 837c0d369e4f6ea1613e3ad127b4e1271581cd32 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 21 Feb 2025 13:43:07 -0500 Subject: [PATCH] A few cleanups in qt_settingssound.cpp --- src/qt/qt_settingssound.cpp | 88 +++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 29 deletions(-) diff --git a/src/qt/qt_settingssound.cpp b/src/qt/qt_settingssound.cpp index e0572c3d8..cca903076 100644 --- a/src/qt/qt_settingssound.cpp +++ b/src/qt/qt_settingssound.cpp @@ -50,13 +50,15 @@ void SettingsSound::save() { for (uint8_t i = 0; i < SOUND_CARD_MAX; ++i) { - auto *cbox = findChild(QString("comboBoxSoundCard%1").arg(i + 1)); - sound_card_current[i] = cbox->currentData().toInt(); + QComboBox *cbox = findChild(QString("comboBoxSoundCard%1").arg(i + 1)); + sound_card_current[i] = cbox->currentData().toInt(); } midi_output_device_current = ui->comboBoxMidiOut->currentData().toInt(); - midi_input_device_current = ui->comboBoxMidiIn->currentData().toInt(); - mpu401_standalone_enable = ui->checkBoxMPU401->isChecked() ? 1 : 0; + + midi_input_device_current = ui->comboBoxMidiIn->currentData().toInt(); + + mpu401_standalone_enable = ui->checkBoxMPU401->isChecked() ? 1 : 0; sound_is_float = ui->checkBoxFloat32->isChecked() ? 1 : 0; @@ -74,12 +76,13 @@ SettingsSound::onCurrentMachineChanged(const int machineId) int c; int selectedRow; + // Sound Card for (uint8_t i = 0; i < SOUND_CARD_MAX; ++i) { - auto * cbox = findChild(QString("comboBoxSoundCard%1").arg(i + 1)); - auto * model = cbox->model(); - const auto removeRows = model->rowCount(); - c = 0; - selectedRow = 0; + QComboBox *cbox = findChild(QString("comboBoxSoundCard%1").arg(i + 1)); + c = 0; + auto model = cbox->model(); + auto removeRows = model->rowCount(); + selectedRow = 0; while (true) { /* Skip "internal" if machine doesn't have it or this is not the primary card. */ @@ -88,17 +91,21 @@ SettingsSound::onCurrentMachineChanged(const int machineId) continue; } - auto name = DeviceConfig::DeviceName(sound_card_getdevice(c), sound_card_get_internal_name(c), 1); + const QString name = DeviceConfig::DeviceName(sound_card_getdevice(c), sound_card_get_internal_name(c), 1); if (name.isEmpty()) { break; } - if (sound_card_available(c) && device_is_valid(sound_card_getdevice(c), machineId)) { - int row = Models::AddEntry(model, name, c); - if (c == sound_card_current[i]) { - selectedRow = row - removeRows; + if (sound_card_available(c)) { + const device_t *sound_dev = sound_card_getdevice(c); + if (device_is_valid(sound_dev, machineId)) { + int row = Models::AddEntry(model, name, c); + if (c == sound_card_current[i]) { + selectedRow = row - removeRows; + } } } + c++; } @@ -108,12 +115,14 @@ SettingsSound::onCurrentMachineChanged(const int machineId) cbox->setCurrentIndex(selectedRow); } - auto model = ui->comboBoxMidiOut->model(); - auto removeRows = model->rowCount(); - c = 0; - selectedRow = 0; + // Midi Out + c = 0; + auto model = ui->comboBoxMidiOut->model(); + auto removeRows = model->rowCount(); + selectedRow = 0; + while (true) { - QString name = DeviceConfig::DeviceName(midi_out_device_getdevice(c), midi_out_device_get_internal_name(c), 0); + const QString name = DeviceConfig::DeviceName(midi_out_device_getdevice(c), midi_out_device_get_internal_name(c), 0); if (name.isEmpty()) { break; } @@ -124,19 +133,23 @@ SettingsSound::onCurrentMachineChanged(const int machineId) selectedRow = row - removeRows; } } + c++; } + model->removeRows(0, removeRows); ui->comboBoxMidiOut->setEnabled(model->rowCount() > 0); ui->comboBoxMidiOut->setCurrentIndex(-1); ui->comboBoxMidiOut->setCurrentIndex(selectedRow); + // Midi In + c = 0; model = ui->comboBoxMidiIn->model(); removeRows = model->rowCount(); - c = 0; selectedRow = 0; + while (true) { - QString name = DeviceConfig::DeviceName(midi_in_device_getdevice(c), midi_in_device_get_internal_name(c), 0); + const QString name = DeviceConfig::DeviceName(midi_in_device_getdevice(c), midi_in_device_get_internal_name(c), 0); if (name.isEmpty()) { break; } @@ -150,14 +163,19 @@ SettingsSound::onCurrentMachineChanged(const int machineId) c++; } + model->removeRows(0, removeRows); ui->comboBoxMidiIn->setEnabled(model->rowCount() > 0); ui->comboBoxMidiIn->setCurrentIndex(-1); ui->comboBoxMidiIn->setCurrentIndex(selectedRow); + // Standalone MPU401 ui->checkBoxMPU401->setChecked(mpu401_standalone_enable > 0); + + // Float32 Sound ui->checkBoxFloat32->setChecked(sound_is_float > 0); + // FM Driver switch (fm_driver) { case FM_DRV_YMFM: ui->radioButtonYMFM->setChecked(true); @@ -193,6 +211,7 @@ SettingsSound::on_comboBoxSoundCard1_currentIndexChanged(int index) return; } int sndCard = ui->comboBoxSoundCard1->currentData().toInt(); + if (sndCard == SOUND_INTERNAL) ui->pushButtonConfigureSoundCard1->setEnabled(machine_has_flags(machineId, MACHINE_SOUND) && device_has_config(machine_get_snd_device(machineId))); @@ -203,8 +222,9 @@ SettingsSound::on_comboBoxSoundCard1_currentIndexChanged(int index) void SettingsSound::on_pushButtonConfigureSoundCard1_clicked() { - int sndCard = ui->comboBoxSoundCard1->currentData().toInt(); - auto *device = sound_card_getdevice(sndCard); + int sndCard = ui->comboBoxSoundCard1->currentData().toInt(); + auto *device = sound_card_getdevice(sndCard); + if (sndCard == SOUND_INTERNAL) device = machine_get_snd_device(machineId); DeviceConfig::ConfigureDevice(device, 1, qobject_cast(Settings::settings)); @@ -216,15 +236,17 @@ SettingsSound::on_comboBoxSoundCard2_currentIndexChanged(int index) if (index < 0) { return; } + int sndCard = ui->comboBoxSoundCard2->currentData().toInt(); + ui->pushButtonConfigureSoundCard2->setEnabled(sound_card_has_config(sndCard)); } void SettingsSound::on_pushButtonConfigureSoundCard2_clicked() { - int sndCard = ui->comboBoxSoundCard2->currentData().toInt(); - auto *device = sound_card_getdevice(sndCard); + int sndCard = ui->comboBoxSoundCard2->currentData().toInt(); + const device_t *device = sound_card_getdevice(sndCard); DeviceConfig::ConfigureDevice(device, 2, qobject_cast(Settings::settings)); } @@ -234,15 +256,18 @@ SettingsSound::on_comboBoxSoundCard3_currentIndexChanged(int index) if (index < 0) { return; } + int sndCard = ui->comboBoxSoundCard3->currentData().toInt(); + ui->pushButtonConfigureSoundCard3->setEnabled(sound_card_has_config(sndCard)); } void SettingsSound::on_pushButtonConfigureSoundCard3_clicked() { - int sndCard = ui->comboBoxSoundCard3->currentData().toInt(); - auto *device = sound_card_getdevice(sndCard); + int sndCard = ui->comboBoxSoundCard3->currentData().toInt(); + const device_t *device = sound_card_getdevice(sndCard); + DeviceConfig::ConfigureDevice(device, 3, qobject_cast(Settings::settings)); } @@ -252,15 +277,18 @@ SettingsSound::on_comboBoxSoundCard4_currentIndexChanged(int index) if (index < 0) { return; } + int sndCard = ui->comboBoxSoundCard4->currentData().toInt(); + ui->pushButtonConfigureSoundCard4->setEnabled(sound_card_has_config(sndCard)); } void SettingsSound::on_pushButtonConfigureSoundCard4_clicked() { - int sndCard = ui->comboBoxSoundCard4->currentData().toInt(); - auto *device = sound_card_getdevice(sndCard); + int sndCard = ui->comboBoxSoundCard4->currentData().toInt(); + const device_t *device = sound_card_getdevice(sndCard); + DeviceConfig::ConfigureDevice(device, 4, qobject_cast(Settings::settings)); } @@ -270,6 +298,7 @@ SettingsSound::on_comboBoxMidiOut_currentIndexChanged(int index) if (index < 0) { return; } + ui->pushButtonConfigureMidiOut->setEnabled(midi_out_device_has_config(ui->comboBoxMidiOut->currentData().toInt())); ui->checkBoxMPU401->setEnabled(allowMpu401(ui) && (machine_has_bus(machineId, MACHINE_BUS_ISA) || machine_has_bus(machineId, MACHINE_BUS_MCA))); ui->pushButtonConfigureMPU401->setEnabled(allowMpu401(ui) && ui->checkBoxMPU401->isChecked()); @@ -288,6 +317,7 @@ SettingsSound::on_comboBoxMidiIn_currentIndexChanged(int index) if (index < 0) { return; } + ui->pushButtonConfigureMidiIn->setEnabled(midi_in_device_has_config(ui->comboBoxMidiIn->currentData().toInt())); ui->checkBoxMPU401->setEnabled(allowMpu401(ui) && (machine_has_bus(machineId, MACHINE_BUS_ISA) || machine_has_bus(machineId, MACHINE_BUS_MCA))); ui->pushButtonConfigureMPU401->setEnabled(allowMpu401(ui) && ui->checkBoxMPU401->isChecked());