diff --git a/include/amuse/SongState.hpp b/include/amuse/SongState.hpp index f0c3294..57a1f45 100644 --- a/include/amuse/SongState.hpp +++ b/include/amuse/SongState.hpp @@ -109,6 +109,9 @@ public: * @return `true` if END reached */ bool advance(Sequencer& seq, double dt); + + /** Get current song tempo in BPM */ + uint32_t getTempo() const {return m_tempo;} }; } diff --git a/lib/Sequencer.cpp b/lib/Sequencer.cpp index b415d74..e39e327 100644 --- a/lib/Sequencer.cpp +++ b/lib/Sequencer.cpp @@ -169,7 +169,7 @@ std::shared_ptr Sequencer::ChannelState::keyOn(uint8_t note, uint8_t velo (*ret)->installCtrlValues(m_ctrlVals); ObjectId oid = (m_parent.m_audioGroup.getDataFormat() == DataFormat::PC) ? m_page->objId : SBig(m_page->objId); - if (!(*ret)->loadSoundObject(oid, 0, 1000.f, note, velocity, m_ctrlVals[1])) + if (!(*ret)->loadSoundObject(oid, 0, m_parent.m_ticksPerSec, note, velocity, m_ctrlVals[1])) { m_parent.m_engine._destroyVoice(ret); return {}; @@ -465,6 +465,7 @@ void Sequencer::playSong(const unsigned char* arrData, bool dieOnEnd) m_arrData = arrData; m_dieOnEnd = dieOnEnd; m_songState.initialize(arrData); + setTempo(m_songState.getTempo() * 384 / 60); m_state = SequencerState::Playing; } diff --git a/lib/SongState.cpp b/lib/SongState.cpp index 69dd309..614fbe9 100644 --- a/lib/SongState.cpp +++ b/lib/SongState.cpp @@ -326,6 +326,7 @@ bool SongState::advance(Sequencer& seq, double dt) { /* Turn over tempo */ m_tempo = change.m_tempo; + seq.setTempo(m_tempo * 384 / 60); ++m_tempoPtr; continue; } diff --git a/lib/SoundMacroState.cpp b/lib/SoundMacroState.cpp index fddd0ce..90d18ed 100644 --- a/lib/SoundMacroState.cpp +++ b/lib/SoundMacroState.cpp @@ -216,7 +216,7 @@ bool SoundMacroState::advance(Voice& vox, double dt) m_pc.back().second = macroStep; else vox.loadSoundObject(macroId, macroStep, m_ticksPerSec, - m_initKey, m_initVel, m_initMod); + m_initKey, m_initVel, m_initMod); } break; @@ -300,7 +300,7 @@ bool SoundMacroState::advance(Voice& vox, double dt) m_pc.back().second = macroStep; else vox.loadSoundObject(macroId, macroStep, m_ticksPerSec, - m_initKey, m_initVel, m_initMod); + m_initKey, m_initVel, m_initMod); break; } @@ -389,7 +389,7 @@ bool SoundMacroState::advance(Voice& vox, double dt) m_pc.back().second = macroStep; else vox.loadSoundObject(macroId, macroStep, m_ticksPerSec, - m_initKey, m_initVel, m_initMod); + m_initKey, m_initVel, m_initMod); } break; @@ -512,7 +512,7 @@ bool SoundMacroState::advance(Voice& vox, double dt) m_pc.back().second = macroStep; else vox.loadSoundObject(macroId, macroStep, m_ticksPerSec, - m_initKey, m_initVel, m_initMod); + m_initKey, m_initVel, m_initMod); } break; @@ -769,7 +769,7 @@ bool SoundMacroState::advance(Voice& vox, double dt) m_pc.push_back({m_pc.back().first, macroStep}); else vox.loadSoundObject(macroId, macroStep, m_ticksPerSec, - m_initKey, m_initVel, m_initMod, true); + m_initKey, m_initVel, m_initMod, true); m_header = *reinterpret_cast(m_pc.back().first); if (vox.getAudioGroup().getDataFormat() != DataFormat::PC)