Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFX: Support replaying the current BGM when changed #2150

Merged
merged 3 commits into from
Dec 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions soh/soh/Enhancements/sfx-editor/SfxEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,28 @@ std::map<u16, std::tuple<std::string, std::string, SeqType>> 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();
}
}
Comment on lines +195 to +204
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you really should only keep this one method and call Audio_QueueSeqCmd(0x00000000 | curSeqId); in here.. In the two places where you do call ReplayCurrentBGM you actually do the SEQ_BGM_WORLD anyway.

Copy link
Contributor Author

@Archez Archez Dec 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do the same BGM_WORLD check, but those two areas are the reset all/randomizer all, that first do a loop to update all the options, then sets the CVARs at the end. So ReplayCurrentBGM happens after the loop, and doesn't have the specific seqKey to pass in.

I could move the those BGM_WORLD checks to also be in ReplayCurrentBgm, or I could combine the two functions, but that would mean moving the function inside of that loop and having it check on each iteration, which is what I was trying to avoid. (it probably wouldn't have any performance impact, since it only happens on pressing a button)


void Draw_SfxTab(const std::string& tabId, const std::map<u16, std::tuple<std::string, std::string, SeqType>>& map, SeqType type) {
const std::string hiddenTabId = "##" + tabId;
const std::string resetAllButton = "Reset All" + hiddenTabId;
Expand All @@ -198,6 +220,9 @@ void Draw_SfxTab(const std::string& tabId, const std::map<u16, std::tuple<std::s
}
}
SohImGui::RequestCvarSaveOnNextTick();
if (type == SEQ_BGM_WORLD) {
ReplayCurrentBGM();
}
}
ImGui::SameLine();
if (ImGui::Button(randomizeAllButton.c_str())) {
Expand All @@ -222,6 +247,9 @@ void Draw_SfxTab(const std::string& tabId, const std::map<u16, std::tuple<std::s
}
}
SohImGui::RequestCvarSaveOnNextTick();
if (type == SEQ_BGM_WORLD) {
ReplayCurrentBGM();
}
}

ImGui::BeginTable(tabId.c_str(), 3, ImGuiTableFlags_SizingFixedFit);
Expand Down Expand Up @@ -263,6 +291,7 @@ void Draw_SfxTab(const std::string& tabId, const std::map<u16, std::tuple<std::s
if (ImGui::Selectable(std::get<0>(seqData).c_str())) {
CVar_SetS32(cvarKey.c_str(), value);
SohImGui::RequestCvarSaveOnNextTick();
UpdateCurrentBGM(defaultValue, type);
}
}

Expand Down Expand Up @@ -299,6 +328,7 @@ void Draw_SfxTab(const std::string& tabId, const std::map<u16, std::tuple<std::s
if (ImGui::Button(resetButton.c_str())) {
CVar_SetS32(cvarKey.c_str(), defaultValue);
SohImGui::RequestCvarSaveOnNextTick();
UpdateCurrentBGM(defaultValue, seqType);
}
ImGui::SameLine();
ImGui::PushItemWidth(-FLT_MIN);
Expand All @@ -310,6 +340,7 @@ void Draw_SfxTab(const std::string& tabId, const std::map<u16, std::tuple<std::s
if (seqType & type) {
CVar_SetS32(cvarKey.c_str(), value);
SohImGui::RequestCvarSaveOnNextTick();
UpdateCurrentBGM(defaultValue, type);
break;
}
}
Expand Down