isle-portable/LEGO1/mxmusicmanager.cpp

151 lines
2.8 KiB
C++
Raw Normal View History

#include "mxmusicmanager.h"
#include "mxticklemanager.h"
2023-10-06 09:00:00 -04:00
#include "mxomni.h"
2023-10-06 09:00:00 -04:00
#include <windows.h>
DECOMP_SIZE_ASSERT(MxMusicManager, 0x58);
2023-10-06 09:00:00 -04:00
// OFFSET: LEGO1 0x100c05a0
MxMusicManager::MxMusicManager()
2023-10-06 09:00:00 -04:00
{
Init();
}
// OFFSET: LEGO1 0x100c0630
MxMusicManager::~MxMusicManager()
2023-10-06 09:00:00 -04:00
{
Destroy(TRUE);
2023-10-06 09:00:00 -04:00
}
// OFFSET: LEGO1 0x100c0b20
void MxMusicManager::DeinitializeMIDI()
2023-10-06 09:00:00 -04:00
{
m_criticalSection.Enter();
if (m_MIDIInitialized)
2023-10-06 09:00:00 -04:00
{
m_MIDIInitialized = FALSE;
midiStreamStop(m_MIDIStreamH);
midiOutUnprepareHeader(m_MIDIStreamH, m_MIDIHdrP, sizeof(MIDIHDR));
midiOutSetVolume(m_MIDIStreamH, m_MIDIVolume);
midiStreamClose(m_MIDIStreamH);
delete m_MIDIHdrP;
InitData();
2023-10-06 09:00:00 -04:00
}
m_criticalSection.Leave();
2023-10-06 09:00:00 -04:00
}
// OFFSET: LEGO1 0x100c0690
void MxMusicManager::Init()
2023-10-06 09:00:00 -04:00
{
m_multiplier = 100;
2023-10-06 09:00:00 -04:00
InitData();
}
// OFFSET: LEGO1 0x100c06a0
void MxMusicManager::InitData()
2023-10-06 09:00:00 -04:00
{
m_MIDIStreamH = 0;
m_MIDIInitialized = FALSE;
m_unk38 = 0;
m_unk3c = 0;
m_unk40 = 0;
m_unk44 = 0;
m_unk48 = 0;
m_MIDIHdrP = NULL;
2023-10-06 09:00:00 -04:00
}
// OFFSET: LEGO1 0x100c06c0
void MxMusicManager::Destroy(MxBool p_fromDestructor)
2023-10-06 09:00:00 -04:00
{
if (m_thread)
2023-10-06 09:00:00 -04:00
{
m_thread->Terminate();
if (m_thread)
2023-10-06 09:00:00 -04:00
{
delete m_thread;
}
}
else
{
TickleManager()->UnregisterClient(this);
}
m_criticalSection.Enter();
2023-10-06 09:00:00 -04:00
DeinitializeMIDI();
Init();
m_criticalSection.Leave();
2023-10-06 09:00:00 -04:00
if (!p_fromDestructor)
2023-10-06 09:00:00 -04:00
{
MxAudioManager::Destroy();
}
}
// OFFSET: LEGO1 0x100c0930
void MxMusicManager::Destroy()
2023-10-06 09:00:00 -04:00
{
Destroy(FALSE);
2023-10-06 09:00:00 -04:00
}
// OFFSET: LEGO1 0x100c09a0
MxS32 MxMusicManager::CalculateVolume(MxS32 p_volume)
2023-10-06 09:00:00 -04:00
{
MxS32 result = (p_volume * 0xffff) / 100;
return (result << 0x10) | result;
}
// OFFSET: LEGO1 0x100c07f0
void MxMusicManager::SetMIDIVolume()
2023-10-06 09:00:00 -04:00
{
MxS32 result = (m_volume * m_multiplier) / 0x64;
HMIDISTRM streamHandle = m_MIDIStreamH;
2023-10-06 09:00:00 -04:00
if (streamHandle)
{
MxS32 volume = CalculateVolume(result);
midiOutSetVolume(streamHandle, volume);
}
}
// OFFSET: LEGO1 0x100c0940
void MxMusicManager::SetVolume(MxS32 p_volume)
2023-10-06 09:00:00 -04:00
{
MxAudioManager::SetVolume(p_volume);
m_criticalSection.Enter();
2023-10-06 09:00:00 -04:00
SetMIDIVolume();
m_criticalSection.Leave();
2023-10-06 09:00:00 -04:00
}
// OFFSET: LEGO1 0x100c0840
MxResult MxMusicManager::Create(MxU32 p_frequencyMS, MxBool p_createThread)
2023-10-06 09:00:00 -04:00
{
MxResult status = FAILURE;
MxBool locked = FALSE;
if (MxAudioManager::InitPresenters() == SUCCESS) {
if (p_createThread) {
m_criticalSection.Enter();
2023-10-06 09:00:00 -04:00
locked = TRUE;
m_thread = new MxTickleThread(this, p_frequencyMS);
2023-10-06 09:00:00 -04:00
if (!m_thread || m_thread->Start(0, 0) != SUCCESS)
goto done;
2023-10-06 09:00:00 -04:00
}
else
TickleManager()->RegisterClient(this, p_frequencyMS);
status = SUCCESS;
2023-10-06 09:00:00 -04:00
}
done:
2023-10-06 09:00:00 -04:00
if (status != SUCCESS)
Destroy();
if (locked)
m_criticalSection.Leave();
2023-10-06 09:00:00 -04:00
return status;
}