commit 6f8fa21f092b51c76edabac7d21b9f80cea0ac23 parent fd6729e458dd1b141a874fc64a2aba3e5a1ca7d5 Author: dsp56300 <dsp56300@users.noreply.github.com> Date: Mon, 7 Oct 2024 23:19:35 +0200 allow to write individual bytes to midi buffer parser Diffstat:
M | source/synthLib/midiBufferParser.cpp | | | 70 | +++++++++++++++++++++++++++++++++++----------------------------------- |
M | source/synthLib/midiBufferParser.h | | | 1 | + |
2 files changed, 36 insertions(+), 35 deletions(-)
diff --git a/source/synthLib/midiBufferParser.cpp b/source/synthLib/midiBufferParser.cpp @@ -6,53 +6,53 @@ namespace synthLib { void MidiBufferParser::write(const std::vector<uint8_t>& _data) { - if(_data.empty()) + for (const auto d : _data) + write(d); + } + + void MidiBufferParser::write(uint8_t d) + { + if(d == synthLib::M_STARTOFSYSEX) + { + flushSysex(); + m_sysex = true; + m_sysexBuffer.push_back(d); return; + } - for (const auto d : _data) + if(m_sysex) { - if(d == synthLib::M_STARTOFSYSEX) + if(d == synthLib::M_ENDOFSYSEX) { flushSysex(); - m_sysex = true; + return; + } + if(d < 0x80) + { m_sysexBuffer.push_back(d); - continue; + return; } - - if(m_sysex) + if(d >= 0xf0) { - if(d == synthLib::M_ENDOFSYSEX) - { - flushSysex(); - continue; - } - if(d < 0x80) - { - m_sysexBuffer.push_back(d); - continue; - } - if(d >= 0xf0) - { - // system realtime intercepting sysex - m_midiEvents.emplace_back(MidiEventSource::Plugin, d); - continue; - } - - flushSysex(); // aborted sysex + // system realtime intercepting sysex + m_midiEvents.emplace_back(MidiEventSource::Plugin, d); + return; } - if(m_pendingEventLen == 0) - m_pendingEvent.a = d; - else if(m_pendingEventLen == 1) - m_pendingEvent.b = d; - else if(m_pendingEventLen == 2) - m_pendingEvent.c = d; + flushSysex(); // aborted sysex + } - ++m_pendingEventLen; + if(m_pendingEventLen == 0) + m_pendingEvent.a = d; + else if(m_pendingEventLen == 1) + m_pendingEvent.b = d; + else if(m_pendingEventLen == 2) + m_pendingEvent.c = d; - if(lengthFromStatusByte(m_pendingEvent.a) == m_pendingEventLen) - flushEvent(); - } + ++m_pendingEventLen; + + if(lengthFromStatusByte(m_pendingEvent.a) == m_pendingEventLen) + flushEvent(); } void MidiBufferParser::getEvents(std::vector<synthLib::SMidiEvent>& _events) diff --git a/source/synthLib/midiBufferParser.h b/source/synthLib/midiBufferParser.h @@ -11,6 +11,7 @@ namespace synthLib { public: void write(const std::vector<uint8_t>& _data); + void write(uint8_t _data); void getEvents(std::vector<synthLib::SMidiEvent>& _events); static constexpr uint32_t lengthFromStatusByte(const uint8_t _sb)