commit fd805aaa5c9e558c2dad643d5890784d9677a483 parent 19cc3311a81687d829a1ddb37f9e6519c43db801 Author: dsp56300 <lyve2909+githubdsp56300@gmail.com> Date: Wed, 14 Jul 2021 16:10:41 +0200 reduce MIDI clock generator CPU usage Diffstat:
M | source/synthLib/plugin.cpp | | | 21 | +++++++++++++-------- |
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/source/synthLib/plugin.cpp b/source/synthLib/plugin.cpp @@ -146,25 +146,30 @@ namespace synthLib SMidiEvent evClock; + const auto midiEventsEmpty = m_midiIn.empty(); + for(float pos = std::floor(firstSamplePos); pos < max; pos += samplesPerClock) { const int insertPos = dsp56k::floor_int(pos); bool found = false; - for(auto it = m_midiIn.begin(); it != m_midiIn.end(); ++it) + if(!midiEventsEmpty) { - if(it->offset > insertPos) + for(auto it = m_midiIn.begin(); it != m_midiIn.end(); ++it) { - evClock.a = needsStart ? M_START : M_TIMINGCLOCK; - evClock.offset = insertPos; - m_midiIn.insert(it, evClock); - found = true; - break; + if(it->offset > insertPos) + { + evClock.a = needsStart ? M_START : M_TIMINGCLOCK; + evClock.offset = insertPos; + m_midiIn.insert(it, evClock); + found = true; + break; + } } } - if(!found) + if(midiEventsEmpty || !found) { evClock.a = needsStart ? M_START : M_TIMINGCLOCK; evClock.offset = insertPos;