From 3a8a9f0ef27cd2c396e10b7a41196e6e864f30b0 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 19 May 2016 01:03:38 -1000 Subject: [PATCH] Various engine bug fixes --- driver/main.cpp | 2 +- include/amuse/Sequencer.hpp | 2 +- include/amuse/Voice.hpp | 2 +- lib/Sequencer.cpp | 9 ++++++++- lib/Voice.cpp | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/driver/main.cpp b/driver/main.cpp index 888b2e9..0a2b230 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -205,7 +205,7 @@ struct AppCallback : boo::IApplicationCallback m_setupId = setupId; if (m_seq) { - m_seq->stopSong(); + m_seq->stopSong(true); m_seq->kill(); } m_seq = m_engine->seqPlay(m_groupId, setupId, nullptr); diff --git a/include/amuse/Sequencer.hpp b/include/amuse/Sequencer.hpp index 90ad721..c067a8e 100644 --- a/include/amuse/Sequencer.hpp +++ b/include/amuse/Sequencer.hpp @@ -54,7 +54,7 @@ class Sequencer : public Entity /** Voices corresponding to currently-pressed keys in channel */ std::unordered_map> m_chanVoxs; std::unordered_set> m_keyoffVoxs; - int8_t m_ctrlVals[128]; /**< MIDI controller values */ + int8_t m_ctrlVals[128] = {}; /**< MIDI controller values */ float m_curPitchWheel = 0.f; /**< MIDI pitch-wheel */ int8_t m_curProgram = 0; /**< MIDI program number */ float m_curVol = 1.f; /**< Current volume of channel */ diff --git a/include/amuse/Voice.hpp b/include/amuse/Voice.hpp index 17510b1..400b00e 100644 --- a/include/amuse/Voice.hpp +++ b/include/amuse/Voice.hpp @@ -60,7 +60,7 @@ class Voice : public Entity int16_t m_prev1 = 0; /**< DSPADPCM prev sample */ int16_t m_prev2 = 0; /**< DSPADPCM prev-prev sample */ double m_sampleRate = 32000.0; /**< Current sample rate computed from relative sample key or SETPITCH */ - double m_voiceTime; /**< Current seconds of voice playback (per-sample resolution) */ + double m_voiceTime = 0.0; /**< Current seconds of voice playback (per-sample resolution) */ VoiceState m_voxState = VoiceState::Dead; /**< Current high-level state of voice */ bool m_sustained = false; /**< Sustain pedal pressed for this voice */ diff --git a/lib/Sequencer.cpp b/lib/Sequencer.cpp index dc3c013..c21c3e1 100644 --- a/lib/Sequencer.cpp +++ b/lib/Sequencer.cpp @@ -144,7 +144,14 @@ std::shared_ptr Sequencer::ChannelState::keyOn(uint8_t note, uint8_t velo return {}; /* Ensure keyoff sent first */ - keyOff(note, 0); + auto keySearch = m_chanVoxs.find(note); + if (keySearch != m_chanVoxs.cend()) + { + keySearch->second->keyOff(); + keySearch->second->setPedal(false); + m_keyoffVoxs.emplace(std::move(keySearch->second)); + m_chanVoxs.erase(keySearch); + } std::shared_ptr ret = m_parent.m_engine._allocateVoice(m_parent.m_audioGroup, m_parent.m_groupId, 32000.0, diff --git a/lib/Voice.cpp b/lib/Voice.cpp index dc54120..873558d 100644 --- a/lib/Voice.cpp +++ b/lib/Voice.cpp @@ -445,7 +445,7 @@ size_t Voice::supplyAudio(size_t samples, int16_t* data) if (dead && m_voxState == VoiceState::KeyOff && m_sampleEndTrap.macroId == 0xffff && m_messageTrap.macroId == 0xffff && - m_volAdsr.isComplete()) + (!m_curSample || (m_curSample && m_volAdsr.isComplete()))) { m_voxState = VoiceState::Dead; }