commit 1efb35470df9161ba52605eef6ef8c46a7651336
parent 0b35709b4e4e96cba7f2dc1553a02b3e1cd7449d
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Tue, 18 Jan 2022 21:30:30 +0100
if the ring buffer is full, only process one midi message, not all midi messages in the buffer
Diffstat:
2 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/source/synthLib/plugin.cpp b/source/synthLib/plugin.cpp
@@ -23,7 +23,7 @@ namespace synthLib
if(m_midiInRingBuffer.full())
{
std::lock_guard lock(m_lock);
- processMidiInEvents();
+ processMidiInEvent(m_midiInRingBuffer.pop_front());
}
m_midiInRingBuffer.push_back(_ev);
}
@@ -221,40 +221,45 @@ namespace synthLib
{
const auto ev = m_midiInRingBuffer.pop_front();
- // sysex might be send in multiple chunks. Happens if coming from hardware
- if (!ev.sysex.empty())
+ processMidiInEvent(ev);
+ }
+ }
+
+ void Plugin::processMidiInEvent(const SMidiEvent& _ev)
+ {
+ // sysex might be send in multiple chunks. Happens if coming from hardware
+ if (!_ev.sysex.empty())
+ {
+ const bool isComplete = _ev.sysex.front() == M_STARTOFSYSEX && _ev.sysex.back() == M_ENDOFSYSEX;
+
+ if (isComplete)
{
- const bool isComplete = ev.sysex.front() == M_STARTOFSYSEX && ev.sysex.back() == M_ENDOFSYSEX;
+ m_midiIn.push_back(_ev);
+ return;
+ }
- if (isComplete)
- {
- m_midiIn.push_back(ev);
- continue;
- }
+ const bool isStart = _ev.sysex.front() == M_STARTOFSYSEX && _ev.sysex.back() != M_ENDOFSYSEX;
+ const bool isEnd = _ev.sysex.front() != M_STARTOFSYSEX && _ev.sysex.back() == M_ENDOFSYSEX;
- const bool isStart = ev.sysex.front() == M_STARTOFSYSEX && ev.sysex.back() != M_ENDOFSYSEX;
- const bool isEnd = ev.sysex.front() != M_STARTOFSYSEX && ev.sysex.back() == M_ENDOFSYSEX;
+ if (isStart)
+ {
+ m_pendingSysexInput = _ev;
+ return;
+ }
- if (isStart)
- {
- m_pendingSysexInput = ev;
- continue;
- }
+ if (!m_pendingSysexInput.sysex.empty())
+ {
+ m_pendingSysexInput.sysex.insert(m_pendingSysexInput.sysex.end(), _ev.sysex.begin(), _ev.sysex.end());
- if (!m_pendingSysexInput.sysex.empty())
+ if (isEnd)
{
- m_pendingSysexInput.sysex.insert(m_pendingSysexInput.sysex.end(), ev.sysex.begin(), ev.sysex.end());
-
- if (isEnd)
- {
- m_midiIn.push_back(m_pendingSysexInput);
- m_pendingSysexInput.sysex.clear();
- }
+ m_midiIn.push_back(m_pendingSysexInput);
+ m_pendingSysexInput.sysex.clear();
}
}
-
- m_midiIn.push_back(ev);
}
+
+ m_midiIn.push_back(_ev);
}
void Plugin::setBlockSize(const uint32_t _blockSize)
diff --git a/source/synthLib/plugin.h b/source/synthLib/plugin.h
@@ -38,6 +38,7 @@ namespace synthLib
float* getDummyBuffer(size_t _minimumSize);
void updateDeviceLatency();
void processMidiInEvents();
+ void processMidiInEvent(const SMidiEvent& _ev);
dsp56k::RingBuffer<SMidiEvent, 1024, false> m_midiInRingBuffer;
std::vector<SMidiEvent> m_midiIn;