HDD audio setting now populates audio profiles for selected HDD rpm

This commit is contained in:
Domppari
2026-01-04 09:32:25 +02:00
parent b13e4c44b4
commit b4a5c76847
6 changed files with 54 additions and 9 deletions

View File

@@ -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)
{

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -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 */

View File

@@ -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 &current)
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())

View File

@@ -35,6 +35,7 @@ private slots:
private:
Ui::SettingsHarddisks *ui;
void enableCurrentlySelectedChannel();
void populateAudioProfiles();
bool buschangeinprogress = false;
};