From 9529cc121786540ed4c45869624c587b49bdfc39 Mon Sep 17 00:00:00 2001 From: Adam Bird Date: Fri, 23 Dec 2022 23:50:39 -0500 Subject: [PATCH] SFX: Support replaying the current BGM when changed (#2150) * add support for reloading the current bgm when changing it in the sfx editor * clarify audio command with comment * fix wrong seq type after merge --- soh/soh/Enhancements/sfx-editor/SfxEditor.cpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/soh/soh/Enhancements/sfx-editor/SfxEditor.cpp b/soh/soh/Enhancements/sfx-editor/SfxEditor.cpp index 43367f749..9ac5a0cbe 100644 --- a/soh/soh/Enhancements/sfx-editor/SfxEditor.cpp +++ b/soh/soh/Enhancements/sfx-editor/SfxEditor.cpp @@ -181,6 +181,28 @@ std::map> sfxEditorSequenceMa {NA_SE_EV_CHICKEN_CRY_A, {"Chicken Cry", "NA_SE_EV_CHICKEN_CRY_A", SEQ_SFX}}, }; +// Grabs the current BGM sequence ID and replays it +// which will lookup the proper override, or reset back to vanilla +void ReplayCurrentBGM() { + u16 curSeqId = func_800FA0B4(SEQ_PLAYER_BGM_MAIN); + // TODO: replace with Audio_StartSeq when the macro is shared + // The fade time and audio player flags will always be 0 in the case of replaying the BGM, so they are not set here + Audio_QueueSeqCmd(0x00000000 | curSeqId); +} + +// Attempt to update the BGM if it matches the current sequence that is being played +// The seqKey that is passed in should be the vanilla ID, not the override ID +void UpdateCurrentBGM(u16 seqKey, SeqType seqType) { + if (seqType != SEQ_BGM_WORLD) { + return; + } + + u16 curSeqId = func_800FA0B4(SEQ_PLAYER_BGM_MAIN); + if (curSeqId == seqKey) { + ReplayCurrentBGM(); + } +} + void Draw_SfxTab(const std::string& tabId, const std::map>& map, SeqType type) { const std::string hiddenTabId = "##" + tabId; const std::string resetAllButton = "Reset All" + hiddenTabId; @@ -198,6 +220,9 @@ void Draw_SfxTab(const std::string& tabId, const std::map(seqData).c_str())) { CVar_SetS32(cvarKey.c_str(), value); SohImGui::RequestCvarSaveOnNextTick(); + UpdateCurrentBGM(defaultValue, type); } } @@ -299,6 +328,7 @@ void Draw_SfxTab(const std::string& tabId, const std::map