mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-08 15:44:56 +00:00
CScriptMidi and work on CGameArea loading
This commit is contained in:
@@ -3,9 +3,58 @@
|
||||
namespace urde
|
||||
{
|
||||
|
||||
std::unordered_set<CMidiHandle> CMidiManager::m_MidiWrappers = {};
|
||||
|
||||
void CMidiManager::StopAll()
|
||||
{
|
||||
for (auto it = m_MidiWrappers.begin() ; it != m_MidiWrappers.end() ;)
|
||||
it = Stop(it, 0);
|
||||
}
|
||||
|
||||
void CMidiManager::Stop(const CMidiHandle& handle, float fadeTime)
|
||||
{
|
||||
handle->GetAudioSysHandle()->stopSong(fadeTime);
|
||||
m_MidiWrappers.erase(handle);
|
||||
}
|
||||
|
||||
std::unordered_set<CMidiHandle>::iterator
|
||||
CMidiManager::Stop(std::unordered_set<CMidiHandle>::iterator handle, float fadeTime)
|
||||
{
|
||||
const CMidiHandle& h = *handle;
|
||||
h->GetAudioSysHandle()->stopSong(fadeTime);
|
||||
return m_MidiWrappers.erase(handle);
|
||||
}
|
||||
|
||||
CMidiHandle CMidiManager::Play(const CMidiData& data, float fadeTime, bool stopExisting, float volume)
|
||||
{
|
||||
if (stopExisting)
|
||||
for (auto it = m_MidiWrappers.begin() ; it != m_MidiWrappers.end() ;)
|
||||
it = Stop(it, fadeTime);
|
||||
|
||||
CMidiHandle handle = *m_MidiWrappers.insert(std::make_shared<CMidiWrapper>()).first;
|
||||
handle->SetAudioSysHandle(CAudioSys::GetAmuseEngine().seqPlay(
|
||||
data.GetGroupId(), data.GetSetupId(), data.GetArrData()));
|
||||
handle->GetAudioSysHandle()->setVolume(volume, fadeTime);
|
||||
handle->SetSongId(data.GetSetupId());
|
||||
return handle;
|
||||
}
|
||||
|
||||
CMidiManager::CMidiData::CMidiData(CInputStream& in)
|
||||
{
|
||||
in.readUint32Big();
|
||||
x0_setupId = in.readUint32Big();
|
||||
x2_groupId = in.readUint32Big();
|
||||
x4_agscId = in.readUint32Big();
|
||||
u32 length = in.readUint32Big();
|
||||
x8_arrData.reset(new u8[length]);
|
||||
in.readUBytesToBuf(x8_arrData.get(), length);
|
||||
}
|
||||
|
||||
CFactoryFnReturn FMidiDataFactory(const SObjectTag& tag, CInputStream& in,
|
||||
const CVParamTransfer& parms,
|
||||
CObjectReference* selfRef)
|
||||
{
|
||||
return TToken<CMidiManager::CMidiData>::GetIObjObjectFor(std::make_unique<CMidiManager::CMidiData>(in));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,62 @@
|
||||
#ifndef __URDE_CMIDIMANAGER_HPP__
|
||||
#define __URDE_CMIDIMANAGER_HPP__
|
||||
|
||||
#include "CSfxManager.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
class CMidiManager
|
||||
{
|
||||
public:
|
||||
class CMidiData
|
||||
{
|
||||
u16 x0_setupId;
|
||||
u16 x2_groupId;
|
||||
ResId x4_agscId;
|
||||
std::unique_ptr<u8[]> x8_arrData;
|
||||
public:
|
||||
u16 GetSetupId() const { return x0_setupId; }
|
||||
u16 GetGroupId() const { return x2_groupId; }
|
||||
ResId GetAGSCAssetId() const { return x4_agscId; }
|
||||
const u8* GetArrData() const { return x8_arrData.get(); }
|
||||
CMidiData(CInputStream& in);
|
||||
};
|
||||
|
||||
class CMidiWrapper
|
||||
{
|
||||
std::shared_ptr<amuse::Sequencer> x0_sequencer;
|
||||
//CSfxHandle x4_handle;
|
||||
u16 x8_songId;
|
||||
bool xa_available = true;
|
||||
public:
|
||||
const std::shared_ptr<amuse::Sequencer>& GetAudioSysHandle() const { return x0_sequencer; }
|
||||
void SetAudioSysHandle(const std::shared_ptr<amuse::Sequencer>& sequencer) { x0_sequencer = sequencer; }
|
||||
//const CSfxHandle& GetManagerHandle() const { return x4_handle; }
|
||||
//void SetMidiHandle(const CSfxHandle& handle) { x4_handle = handle; }
|
||||
bool IsAvailable() const { return xa_available; }
|
||||
void SetAvailable(bool available) { xa_available = available; }
|
||||
u16 GetSongId() const { return x8_songId; }
|
||||
void SetSongId(u16 songId) { x8_songId = songId; }
|
||||
};
|
||||
using CMidiHandle = std::shared_ptr<CMidiWrapper>;
|
||||
|
||||
static void StopAll();
|
||||
static void Stop(const CMidiHandle& handle, float fadeTime);
|
||||
static std::unordered_set<CMidiHandle>::iterator
|
||||
Stop(std::unordered_set<CMidiHandle>::iterator handle, float fadeTime);
|
||||
static CMidiHandle Play(const CMidiData& data, float fadeTime, bool stopExisting, float volume);
|
||||
|
||||
private:
|
||||
static std::unordered_set<CMidiHandle> m_MidiWrappers;
|
||||
};
|
||||
|
||||
CFactoryFnReturn FMidiDataFactory(const SObjectTag& tag, CInputStream& in,
|
||||
const CVParamTransfer& parms,
|
||||
CObjectReference* selfRef);
|
||||
|
||||
using CMidiHandle = CMidiManager::CMidiHandle;
|
||||
|
||||
}
|
||||
|
||||
#endif // __URDE_CMIDIMANAGER_HPP__
|
||||
|
||||
Reference in New Issue
Block a user