From b4a5c76847f86507fa03e0ce4b31dc8647ada1fd Mon Sep 17 00:00:00 2001 From: Domppari Date: Sun, 4 Jan 2026 09:32:25 +0200 Subject: [PATCH] HDD audio setting now populates audio profiles for selected HDD rpm --- src/disk/hdd.c | 8 +++++++ src/disk/hdd_audio.c | 10 ++++++++ src/include/86box/hdd.h | 1 + src/include/86box/hdd_audio.h | 2 ++ src/qt/qt_settingsharddisks.cpp | 41 +++++++++++++++++++++++++-------- src/qt/qt_settingsharddisks.hpp | 1 + 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/disk/hdd.c b/src/disk/hdd.c index cd34b66fa..bbbec0865 100644 --- a/src/disk/hdd.c +++ b/src/disk/hdd.c @@ -589,6 +589,14 @@ hdd_preset_get_internal_name(int preset) return hdd_speed_presets[preset].internal_name; } +uint32_t +hdd_preset_get_rpm(int preset) +{ + if (preset < 0 || preset >= hdd_preset_get_num()) + return 0; + return hdd_speed_presets[preset].rpm; +} + int hdd_preset_get_from_internal_name(char *s) { diff --git a/src/disk/hdd_audio.c b/src/disk/hdd_audio.c index bc3f9ed95..464f3e224 100644 --- a/src/disk/hdd_audio.c +++ b/src/disk/hdd_audio.c @@ -107,6 +107,8 @@ hdd_audio_load_profiles(void) const char *internal_name = ini_section_get_string(cat, "internal_name", "unknown"); strncpy(config->internal_name, internal_name, sizeof(config->internal_name) - 1); + config->rpm = ini_section_get_int(cat, "rpm", 0); + /* Load spindle motor sample files */ const char *file = ini_section_get_string(cat, "spindlemotor_start_file", ""); strncpy(config->spindlemotor_start.filename, file, sizeof(config->spindlemotor_start.filename) - 1); @@ -167,6 +169,14 @@ hdd_audio_get_profile_internal_name(int id) return audio_profiles[id].internal_name; } +uint32_t +hdd_audio_get_profile_rpm(int id) +{ + if (id < 0 || id >= audio_profile_count) + return 0; + return audio_profiles[id].rpm; +} + int hdd_audio_get_profile_by_internal_name(const char *internal_name) { diff --git a/src/include/86box/hdd.h b/src/include/86box/hdd.h index ddf8fdbe6..d8f275de3 100644 --- a/src/include/86box/hdd.h +++ b/src/include/86box/hdd.h @@ -234,6 +234,7 @@ extern double hdd_seek_get_time(hard_disk_t *hdd, uint32_t dst_addr, uint8_ int hdd_preset_get_num(void); const char *hdd_preset_getname(int preset); extern const char *hdd_preset_get_internal_name(int preset); +extern uint32_t hdd_preset_get_rpm(int preset); extern int hdd_preset_get_from_internal_name(char *s); extern void hdd_preset_apply(int hdd_id); diff --git a/src/include/86box/hdd_audio.h b/src/include/86box/hdd_audio.h index 050bff0a0..8dfac0c00 100644 --- a/src/include/86box/hdd_audio.h +++ b/src/include/86box/hdd_audio.h @@ -35,6 +35,7 @@ typedef struct { int id; char name[128]; char internal_name[64]; + uint32_t rpm; hdd_audio_sample_config_t spindlemotor_start; hdd_audio_sample_config_t spindlemotor_loop; hdd_audio_sample_config_t spindlemotor_stop; @@ -47,6 +48,7 @@ extern int hdd_audio_get_profile_count(void); extern const hdd_audio_profile_config_t *hdd_audio_get_profile(int id); extern const char *hdd_audio_get_profile_name(int id); extern const char *hdd_audio_get_profile_internal_name(int id); +extern uint32_t hdd_audio_get_profile_rpm(int id); extern int hdd_audio_get_profile_by_internal_name(const char *internal_name); /* HDD audio initialization and cleanup */ diff --git a/src/qt/qt_settingsharddisks.cpp b/src/qt/qt_settingsharddisks.cpp index 7939cb989..849c34305 100644 --- a/src/qt/qt_settingsharddisks.cpp +++ b/src/qt/qt_settingsharddisks.cpp @@ -148,15 +148,6 @@ SettingsHarddisks::SettingsHarddisks(QWidget *parent) Harddrives::populateBuses(ui->comboBoxBus->model()); - /* Populate audio profile combobox */ - int profile_count = hdd_audio_get_profile_count(); - for (int i = 0; i < profile_count; i++) { - const char *name = hdd_audio_get_profile_name(i); - if (name) { - ui->comboBoxAudio->addItem(name, i); - } - } - on_comboBoxBus_currentIndexChanged(0); } @@ -288,6 +279,35 @@ SettingsHarddisks::on_comboBoxSpeed_currentIndexChanged(int index) auto col = idx.siblingAtColumn(ColumnSpeed); model->setData(col, ui->comboBoxSpeed->currentData(Qt::UserRole), Qt::UserRole); model->setData(col, QObject::tr(hdd_preset_getname(ui->comboBoxSpeed->currentData(Qt::UserRole).toUInt()))); + + /* Reset audio profile to None when speed/model changes */ + auto audioCol = idx.siblingAtColumn(ColumnAudio); + model->setData(audioCol, 0, Qt::UserRole); + model->setData(audioCol, QObject::tr("None")); + } + + /* Repopulate audio profiles based on the selected speed preset's RPM */ + populateAudioProfiles(); +} + +void +SettingsHarddisks::populateAudioProfiles() +{ + ui->comboBoxAudio->clear(); + + /* Get RPM from currently selected speed preset */ + uint32_t target_rpm = hdd_preset_get_rpm(ui->comboBoxSpeed->currentData(Qt::UserRole).toUInt()); + + /* Populate audio profile combobox with matching RPM profiles */ + int profile_count = hdd_audio_get_profile_count(); + for (int i = 0; i < profile_count; i++) { + const char *name = hdd_audio_get_profile_name(i); + uint32_t profile_rpm = hdd_audio_get_profile_rpm(i); + + /* Include profile if it has no RPM set (0) or matches target RPM */ + if (name && (profile_rpm == 0 || profile_rpm == target_rpm)) { + ui->comboBoxAudio->addItem(name, i); + } } } @@ -342,6 +362,9 @@ SettingsHarddisks::onTableRowChanged(const QModelIndex ¤t) if (!match.isEmpty()) ui->comboBoxSpeed->setCurrentIndex(match.first().row()); + /* Populate audio profiles based on selected speed preset's RPM */ + populateAudioProfiles(); + model = ui->comboBoxAudio->model(); match = model->match(model->index(0, 0), Qt::UserRole, audio); if (!match.isEmpty()) diff --git a/src/qt/qt_settingsharddisks.hpp b/src/qt/qt_settingsharddisks.hpp index b8d298bb4..f082c7de6 100644 --- a/src/qt/qt_settingsharddisks.hpp +++ b/src/qt/qt_settingsharddisks.hpp @@ -35,6 +35,7 @@ private slots: private: Ui::SettingsHarddisks *ui; void enableCurrentlySelectedChannel(); + void populateAudioProfiles(); bool buschangeinprogress = false; };