2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/Audio/CMidiManager.hpp"
|
2017-02-18 02:19:50 +00:00
|
|
|
|
2022-02-19 13:04:45 +00:00
|
|
|
#include "Runtime/Streams/CInputStream.hpp"
|
2022-02-18 07:37:54 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2017-02-18 02:19:50 +00:00
|
|
|
|
2017-02-27 05:25:14 +00:00
|
|
|
std::unordered_set<CMidiHandle> CMidiManager::m_MidiWrappers = {};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMidiManager::StopAll() {
|
|
|
|
for (auto it = m_MidiWrappers.begin(); it != m_MidiWrappers.end();)
|
|
|
|
it = Stop(it, 0.f);
|
2017-02-27 05:25:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMidiManager::Stop(const CMidiHandle& handle, float fadeTime) {
|
|
|
|
handle->GetAudioSysHandle()->stopSong(fadeTime);
|
|
|
|
m_MidiWrappers.erase(handle);
|
2017-02-27 05:25:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
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);
|
2017-02-27 05:25:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
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;
|
2017-02-27 05:25:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CMidiManager::CMidiData::CMidiData(CInputStream& in) {
|
2022-02-18 07:37:54 +00:00
|
|
|
in.ReadLong();
|
|
|
|
x0_setupId = in.ReadLong();
|
|
|
|
x2_groupId = in.ReadLong();
|
2022-02-19 13:04:45 +00:00
|
|
|
x4_agscId = in.Get<CAssetId>();
|
2022-02-18 07:37:54 +00:00
|
|
|
u32 length = in.ReadLong();
|
2018-12-08 05:30:43 +00:00
|
|
|
x8_arrData.reset(new u8[length]);
|
2022-02-18 07:37:54 +00:00
|
|
|
in.ReadBytes(reinterpret_cast<char*>(x8_arrData.get()), length);
|
2017-02-27 05:25:14 +00:00
|
|
|
}
|
2017-02-18 02:19:50 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CFactoryFnReturn FMidiDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& parms,
|
|
|
|
CObjectReference* selfRef) {
|
|
|
|
return TToken<CMidiManager::CMidiData>::GetIObjObjectFor(std::make_unique<CMidiManager::CMidiData>(in));
|
2017-02-18 02:19:50 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|