From 206919735bafe22bc41619879a6a1f6332b40d15 Mon Sep 17 00:00:00 2001 From: roblabla Date: Sun, 24 Nov 2024 23:22:49 +0100 Subject: [PATCH] Implement MidiOutput::FadeOutSetVolume --- config/implemented.csv | 1 + config/stubbed.csv | 1 - src/MidiOutput.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/config/implemented.csv b/config/implemented.csv index bd69bf6f..93ea3057 100644 --- a/config/implemented.csv +++ b/config/implemented.csv @@ -258,6 +258,7 @@ th06::MidiOutput::ReleaseFileData th06::MidiOutput::StopPlayback th06::MidiOutput::SetFadeOut th06::MidiOutput::ProcessMsg +th06::MidiOutput::FadeOutSetVolume th06::MidiOutput::Ntohs th06::MidiOutput::SkipVariableLength th06::MidiOutput::~MidiOutput diff --git a/config/stubbed.csv b/config/stubbed.csv index f554223e..13fc2e64 100644 --- a/config/stubbed.csv +++ b/config/stubbed.csv @@ -1,3 +1,2 @@ th06::AnmManager::DrawEndingRect th06::MainMenu::SelectRelated -th06::MidiOutput::FadeOutSetVolume diff --git a/src/MidiOutput.cpp b/src/MidiOutput.cpp index f5236a83..6f0ef057 100644 --- a/src/MidiOutput.cpp +++ b/src/MidiOutput.cpp @@ -716,4 +716,36 @@ void MidiOutput::ProcessMsg(MidiTrack *track) return; } +#pragma var_order(arg1, idx, volumeByte, midiStatus, volumeClamped) +void MidiOutput::FadeOutSetVolume(i32 volume) +{ + i32 volumeClamped; + u32 volumeByte; + i32 idx; + i32 arg1; + u32 midiStatus; + + if (this->unk2d4 != 0) + { + return; + } + arg1 = 7; + for (idx = 0; idx < ARRAY_SIZE_SIGNED(this->channels); idx += 1) + { + midiStatus = (idx + 0xb0) & 0xff; + volumeClamped = (i32)(this->channels[idx].channelVolume * this->fadeOutVolumeMultiplier) + volume; + if (volumeClamped < 0) + { + volumeClamped = 0; + } + else if (volumeClamped > 127) + { + volumeClamped = 127; + } + volumeByte = volumeClamped & 0xff; + this->midiOutDev.SendShortMsg(midiStatus, arg1, volumeByte); + } + return; +} + }; // namespace th06