From fb0d1ccb6289823a68a1ad05b588224fea9a3c0a Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Sat, 25 Nov 2023 13:26:44 -0500 Subject: [PATCH] Implement/match MxLoopingMIDIPresenter (#302) * Implement/match MxLoopingMIDIPresenter * Move declarations --- LEGO1/mxloopingmidipresenter.cpp | 54 ++++++++++++++++++++++++++++++++ LEGO1/mxloopingmidipresenter.h | 6 ++-- LEGO1/mxmidipresenter.h | 1 + LEGO1/mxmusicmanager.cpp | 2 +- LEGO1/mxmusicmanager.h | 2 +- 5 files changed, 61 insertions(+), 4 deletions(-) diff --git a/LEGO1/mxloopingmidipresenter.cpp b/LEGO1/mxloopingmidipresenter.cpp index ebeed4b4..d1b670ac 100644 --- a/LEGO1/mxloopingmidipresenter.cpp +++ b/LEGO1/mxloopingmidipresenter.cpp @@ -1,5 +1,59 @@ #include "mxloopingmidipresenter.h" #include "decomp.h" +#include "mxdssound.h" +#include "mxmusicmanager.h" +#include "mxomni.h" DECOMP_SIZE_ASSERT(MxLoopingMIDIPresenter, 0x58); + +// OFFSET: LEGO1 0x100b1830 TEMPLATE +// MxLoopingMIDIPresenter::ClassName + +// OFFSET: LEGO1 0x100b1840 TEMPLATE +// MxLoopingMIDIPresenter::IsA + +// OFFSET: LEGO1 0x100b19c0 TEMPLATE +// MxLoopingMIDIPresenter::`scalar deleting destructor' + +// OFFSET: LEGO1 0x100c2a80 +void MxLoopingMIDIPresenter::StreamingTickle() +{ + if (m_action->GetLoopCount()) { + MxMIDIPresenter::StreamingTickle(); + return; + } + + if (!m_chunk) { + m_chunk = NextChunk(); + return; + } + + if (m_chunk->GetTime() + m_action->GetDuration() <= m_action->GetElapsedTime()) { + m_previousTickleStates |= 1 << (unsigned char) m_currentTickleState; + m_currentTickleState = TickleState_Done; + } +} + +// OFFSET: LEGO1 0x100c2ae0 +void MxLoopingMIDIPresenter::DoneTickle() +{ + if (m_action->GetLoopCount()) + MxMIDIPresenter::DoneTickle(); + else + EndAction(); +} + +// OFFSET: LEGO1 0x100c2b00 +undefined4 MxLoopingMIDIPresenter::PutData() +{ + m_criticalSection.Enter(); + + if (m_currentTickleState == TickleState_Streaming && m_chunk && !MusicManager()->GetMIDIInitialized()) { + SetVolume(((MxDSSound*) m_action)->GetVolume()); + MusicManager()->FUN_100c09c0(m_chunk->GetData(), !m_action->GetLoopCount() ? -1 : m_action->GetLoopCount()); + } + + m_criticalSection.Leave(); + return 0; +} diff --git a/LEGO1/mxloopingmidipresenter.h b/LEGO1/mxloopingmidipresenter.h index 45f03875..142b2b7f 100644 --- a/LEGO1/mxloopingmidipresenter.h +++ b/LEGO1/mxloopingmidipresenter.h @@ -7,18 +7,20 @@ // SIZE 0x58 class MxLoopingMIDIPresenter : public MxMIDIPresenter { public: - // OFFSET: LEGO1 0x100b1830 inline virtual const char* ClassName() const override // vtable+0xc { // 0x10101de0 return "MxLoopingMIDIPresenter"; } - // OFFSET: LEGO1 0x100b1840 inline virtual MxBool IsA(const char* name) const override // vtable+0x10 { return !strcmp(name, MxLoopingMIDIPresenter::ClassName()) || MxMIDIPresenter::IsA(name); } + + virtual void StreamingTickle() override; // vtable+0x20 + virtual void DoneTickle() override; // vtable+0x2c + virtual undefined4 PutData() override; // vtable+0x4c }; #endif // MXLOOPINGMIDIPRESENTER_H diff --git a/LEGO1/mxmidipresenter.h b/LEGO1/mxmidipresenter.h index 0d2afc2d..6bc7d8e6 100644 --- a/LEGO1/mxmidipresenter.h +++ b/LEGO1/mxmidipresenter.h @@ -37,6 +37,7 @@ class MxMIDIPresenter : public MxMusicPresenter { void Init(); void Destroy(MxBool p_fromDestructor); +protected: MxStreamChunk* m_chunk; }; diff --git a/LEGO1/mxmusicmanager.cpp b/LEGO1/mxmusicmanager.cpp index 1e971f4d..90af1789 100644 --- a/LEGO1/mxmusicmanager.cpp +++ b/LEGO1/mxmusicmanager.cpp @@ -137,7 +137,7 @@ MxS32 MxMusicManager::CalculateVolume(MxS32 p_volume) } // OFFSET: LEGO1 0x100c09c0 STUB -undefined4 MxMusicManager::FUN_100c09c0(MxU8* p_data, undefined4) +undefined4 MxMusicManager::FUN_100c09c0(MxU8* p_data, MxS32 p_loopCount) { // TODO return 0; diff --git a/LEGO1/mxmusicmanager.h b/LEGO1/mxmusicmanager.h index b4a3a1c4..36c9ddf3 100644 --- a/LEGO1/mxmusicmanager.h +++ b/LEGO1/mxmusicmanager.h @@ -18,7 +18,7 @@ class MxMusicManager : public MxAudioManager { inline MxBool GetMIDIInitialized() { return m_MIDIInitialized; } void DeinitializeMIDI(); - undefined4 FUN_100c09c0(MxU8* p_data, undefined4); + undefined4 FUN_100c09c0(MxU8* p_data, MxS32 p_loopCount); void SetMultiplier(MxS32 p_multiplier); private: