Convert audio sliders from float to int (#4709)

* Audio sliders float -> int

* Implement migrator

* Must construct additional if statements
This commit is contained in:
aMannus 2024-12-23 20:35:56 +01:00 committed by GitHub
parent e8cf9a61cc
commit 1c2fbba709
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 38 additions and 24 deletions

View File

@ -233,18 +233,18 @@ void DrawSettingsMenu() {
if (ImGui::BeginMenu("Settings"))
{
if (ImGui::BeginMenu("Audio")) {
UIWidgets::PaddedEnhancementSliderFloat("Master Volume: %.1f %%", "##Master_Vol", CVAR_SETTING("Volume.Master"), 0.0f, 1.0f, "", 1.0f, true, true, false, true);
if (UIWidgets::PaddedEnhancementSliderFloat("Main Music Volume: %.1f %%", "##Main_Music_Vol", CVAR_SETTING("Volume.MainMusic"), 0.0f, 1.0f, "", 1.0f, true, true, false, true)) {
Audio_SetGameVolume(SEQ_PLAYER_BGM_MAIN, CVarGetFloat(CVAR_SETTING("Volume.MainMusic"), 1.0f));
UIWidgets::PaddedEnhancementSliderInt("Master Volume: %d %%", "##Master_Vol", CVAR_SETTING("Volume.Master"), 0, 100, "", 100, true, false, true);
if (UIWidgets::PaddedEnhancementSliderInt("Main Music Volume: %d %%", "##Main_Music_Vol", CVAR_SETTING("Volume.MainMusic"), 0, 100, "", 100, true, false, true)) {
Audio_SetGameVolume(SEQ_PLAYER_BGM_MAIN, ((float)CVarGetInteger(CVAR_SETTING("Volume.MainMusic"), 100) / 100.0f));
}
if (UIWidgets::PaddedEnhancementSliderFloat("Sub Music Volume: %.1f %%", "##Sub_Music_Vol", CVAR_SETTING("Volume.SubMusic"), 0.0f, 1.0f, "", 1.0f, true, true, false, true)) {
Audio_SetGameVolume(SEQ_PLAYER_BGM_SUB, CVarGetFloat(CVAR_SETTING("Volume.SubMusic"), 1.0f));
if (UIWidgets::PaddedEnhancementSliderInt("Sub Music Volume: %d %%", "##Sub_Music_Vol", CVAR_SETTING("Volume.SubMusic"), 0, 100, "", 100, true, false, true)) {
Audio_SetGameVolume(SEQ_PLAYER_BGM_SUB, ((float)CVarGetInteger(CVAR_SETTING("Volume.SubMusic"), 100) / 100.0f));
}
if (UIWidgets::PaddedEnhancementSliderFloat("Sound Effects Volume: %.1f %%", "##Sound_Effect_Vol", CVAR_SETTING("Volume.SFX"), 0.0f, 1.0f, "", 1.0f, true, true, false, true)) {
Audio_SetGameVolume(SEQ_PLAYER_SFX, CVarGetFloat(CVAR_SETTING("Volume.SFX"), 1.0f));
if (UIWidgets::PaddedEnhancementSliderInt("Fanfare Volume: %d %%", "##Fanfare_Vol", CVAR_SETTING("Volume.Fanfare"), 0, 100, "", 100, true, false, true)) {
Audio_SetGameVolume(SEQ_PLAYER_FANFARE, ((float)CVarGetInteger(CVAR_SETTING("Volume.Fanfare"), 100) / 100.0f));
}
if (UIWidgets::PaddedEnhancementSliderFloat("Fanfare Volume: %.1f %%", "##Fanfare_Vol", CVAR_SETTING("Volume.Fanfare"), 0.0f, 1.0f, "", 1.0f, true, true, false, true)) {
Audio_SetGameVolume(SEQ_PLAYER_FANFARE, CVarGetFloat(CVAR_SETTING("Volume.Fanfare"), 1.0f));
if (UIWidgets::PaddedEnhancementSliderInt("Sound Effects Volume: %d %%", "##Sound_Effect_Vol", CVAR_SETTING("Volume.SFX"), 0, 100, "", 100, true, false, true)) {
Audio_SetGameVolume(SEQ_PLAYER_SFX, ((float)CVarGetInteger(CVAR_SETTING("Volume.SFX"), 100) / 100.0f));
}
static std::unordered_map<Ship::AudioBackend, const char*> audioBackendNames = {

View File

@ -61,11 +61,6 @@ namespace SOH {
{ MigrationAction::Rename, "gGfxDebuggerEnabled", "gOpenWindows.GfxDebugger" },
{ MigrationAction::Rename, "gStatsEnabled", "gOpenWindows.Stats" },
{ MigrationAction::Rename, "gDisableChangingSettings", "gSettings.DisableChanges" },
{ MigrationAction::Rename, "gGameMasterVolume", "gSettings.Volume.Master" },
{ MigrationAction::Rename, "gMainMusicVolume", "gSettings.Volume.MainMusic" },
{ MigrationAction::Rename, "gSubMusicVolume", "gSettings.Volume.SubMusic" },
{ MigrationAction::Rename, "gSFXMusicVolume", "gSettings.Volume.SFX" },
{ MigrationAction::Rename, "gFanfareVolume", "gSettings.Volume.Fanfare" },
{ MigrationAction::Rename, "gExtraLatencyThreshold", "gSettings.ExtraLatencyThreshold" },
{ MigrationAction::Rename, "gImGuiScale", "gSettings.ImGuiScale" },
{ MigrationAction::Rename, "gTitleScreenTranslation", "gSettings.TitleScreenTranslation" },
@ -77,11 +72,6 @@ namespace SOH {
{ MigrationAction::Rename, "gLowResMode", "gSettings.LowResMode" },
{ MigrationAction::Rename, "gZFightingMode", "gSettings.ZFightingMode" },
{ MigrationAction::Rename, "gDisableChangingSettings", "gSettings.DisableChanges" },
{ MigrationAction::Rename, "gGameMasterVolume", "gSettings.Volume.Master" },
{ MigrationAction::Rename, "gMainMusicVolume", "gSettings.Volume.MainMusic" },
{ MigrationAction::Rename, "gSubMusicVolume", "gSettings.Volume.SubMusic" },
{ MigrationAction::Rename, "gSFXMusicVolume", "gSettings.Volume.SFX" },
{ MigrationAction::Rename, "gFanfareVolume", "gSettings.Volume.Fanfare" },
{ MigrationAction::Rename, "gExtraLatencyThreshold", "gSettings.ExtraLatencyThreshold" },
{ MigrationAction::Rename, "gImGuiScale", "gSettings.ImGuiScale" },
{ MigrationAction::Rename, "gTitleScreenTranslation", "gSettings.TitleScreenTranslation" },

View File

@ -71,12 +71,36 @@ namespace SOH {
void ConfigVersion3Updater::Update(Ship::Config* conf) {
conf->EraseBlock("Controllers");
if (conf->GetNestedJson().contains("CVars") && conf->GetNestedJson()["CVars"].contains("gInjectItemCounts")) {
CVarClear("gInjectItemCounts");
CVarSetInteger("gEnhancements.InjectItemCounts.GoldSkulltula", 1);
CVarSetInteger("gEnhancements.InjectItemCounts.HeartContainer", 1);
CVarSetInteger("gEnhancements.InjectItemCounts.HeartPiece", 1);
}
// Migrate all audio settings to ints
if (conf->GetNestedJson().contains("CVars") && conf->GetNestedJson()["CVars"].contains("gGameMasterVolume")) {
CVarSetInteger("gSettings.Volume.Master", (int32_t)(CVarGetFloat("gGameMasterVolume", 1.0f) * 100));
CVarClear("gGameMasterVolume");
}
if (conf->GetNestedJson().contains("CVars") && conf->GetNestedJson()["CVars"].contains("gMainMusicVolume")) {
CVarSetInteger("gSettings.Volume.MainMusic", (int32_t)(CVarGetFloat("gMainMusicVolume", 1.0f) * 100));
CVarClear("gMainMusicVolume");
}
if (conf->GetNestedJson().contains("CVars") && conf->GetNestedJson()["CVars"].contains("gSubMusicVolume")) {
CVarSetInteger("gSettings.Volume.SubMusic", (int32_t)(CVarGetFloat("gSubMusicVolume", 1.0f) * 100));
CVarClear("gSubMusicVolume");
}
if (conf->GetNestedJson().contains("CVars") && conf->GetNestedJson()["CVars"].contains("gSFXMusicVolume")) {
CVarSetInteger("gSettings.Volume.SFX", (int32_t)(CVarGetFloat("gSFXMusicVolume", 1.0f) * 100));
CVarClear("gSFXMusicVolume");
}
if (conf->GetNestedJson().contains("CVars") && conf->GetNestedJson()["CVars"].contains("gFanfareVolume")) {
CVarSetInteger("gSettings.Volume.Fanfare", (int32_t)(CVarGetFloat("gFanfareVolume", 1.0f) * 100));
CVarClear("gFanfareVolume");
}
for (Migration migration : version3Migrations) {
if (migration.action == MigrationAction::Rename) {
CVarCopy(migration.from.c_str(), migration.to.value().c_str());

View File

@ -109,10 +109,10 @@ void AudioMgr_Init(AudioMgr* audioMgr, void* stack, OSPri pri, OSId id, SchedCon
Audio_InitSound();
osSendMesgPtr(&audioMgr->unk_C8, NULL, OS_MESG_BLOCK);
Audio_SetGameVolume(SEQ_PLAYER_BGM_MAIN, CVarGetFloat(CVAR_SETTING("Volume.MainMusic"), 1.0f));
Audio_SetGameVolume(SEQ_PLAYER_BGM_SUB, CVarGetFloat(CVAR_SETTING("Volume.SubMusic"), 1.0f));
Audio_SetGameVolume(SEQ_PLAYER_FANFARE, CVarGetFloat(CVAR_SETTING("Volume.Fanfare"), 1.0f));
Audio_SetGameVolume(SEQ_PLAYER_SFX, CVarGetFloat(CVAR_SETTING("Volume.SFX"), 1.0f));
Audio_SetGameVolume(SEQ_PLAYER_BGM_MAIN, ((float)CVarGetInteger(CVAR_SETTING("Volume.MainMusic"), 100) / 100.0f));
Audio_SetGameVolume(SEQ_PLAYER_BGM_SUB, ((float)CVarGetInteger(CVAR_SETTING("Volume.SubMusic"), 100) / 100.0f));
Audio_SetGameVolume(SEQ_PLAYER_FANFARE, ((float)CVarGetInteger(CVAR_SETTING("Volume.Fanfare"), 100) / 100.0f));
Audio_SetGameVolume(SEQ_PLAYER_SFX, ((float)CVarGetInteger(CVAR_SETTING("Volume.SFX"), 100) / 100.0f));
// Removed due to crash
//IrqMgr_AddClient(audioMgr->irqMgr, &irqClient, &audioMgr->unk_74);

View File

@ -95,7 +95,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
vel = 0.0f > vel ? 0.0f : vel;
vel = 1.0f < vel ? 1.0f : vel;
float master_vol = CVarGetFloat(CVAR_SETTING("Volume.Master"), 1.0f);
float master_vol = (float)CVarGetInteger(CVAR_SETTING("Volume.Master"), 100) / 100.0f;
sub->targetVolLeft = (s32)((vel * volLeft) * (0x1000 - 0.001f)) * master_vol;
sub->targetVolRight = (s32)((vel * volRight) * (0x1000 - 0.001f)) * master_vol;