All relevant SoundMacros implemented, voice and engine tweaks

This commit is contained in:
Jack Andersen
2016-05-06 11:22:39 -10:00
parent 9860e3859c
commit 708662c23e
10 changed files with 487 additions and 63 deletions

View File

@@ -15,12 +15,22 @@ Engine::Engine(IBackendVoiceAllocator& backend)
Voice* Engine::_allocateVoice(const AudioGroup& group, double sampleRate, bool dynamicPitch, bool emitter)
{
m_activeVoices.emplace_back(*this, group, m_nextVid++, emitter);
auto it = m_activeVoices.emplace(m_activeVoices.end(), *this, group, m_nextVid++, emitter);
m_activeVoices.back().m_backendVoice =
m_backend.allocateVoice(m_activeVoices.back(), sampleRate, dynamicPitch);
m_activeVoices.back().m_engineIt = it;
return &m_activeVoices.back();
}
std::list<Voice>::iterator Engine::_destroyVoice(Voice* voice)
{
#ifndef NDEBUG
assert(this == &voice->getEngine());
#endif
voice->_destroy();
return m_activeVoices.erase(voice->m_engineIt);
}
AudioGroup* Engine::_findGroupFromSfxId(int sfxId, const AudioGroupSampleDirectory::Entry*& entOut) const
{
for (const auto& grp : m_audioGroups)
@@ -147,4 +157,30 @@ Voice* Engine::findVoice(int vid)
return nullptr;
}
/** Stop all voices in `kg`, stops immediately (no KeyOff) when `flag` set */
void Engine::killKeygroup(uint8_t kg, uint8_t flag)
{
for (auto it = m_activeVoices.begin() ; it != m_activeVoices.end() ;)
{
if (it->m_keygroup == kg)
{
if (flag)
{
it = _destroyVoice(&*it);
continue;
}
it->keyOff();
}
++it;
}
}
/** Send all voices using `macroId` the message `val` */
void Engine::sendMacroMessage(ObjectId macroId, int32_t val)
{
for (auto it = m_activeVoices.begin() ; it != m_activeVoices.end() ; ++it)
if (it->getObjectId() == macroId)
it->message(val);
}
}