13
0

ALSA backend: tweak midi parser (fix start mid sequence)

This commit is contained in:
Robin Gareus 2014-06-03 01:00:58 +02:00
parent b050f91323
commit 01cedf0e05
2 changed files with 9 additions and 0 deletions

View File

@ -337,6 +337,7 @@ retry:
AlsaRawMidiIn::AlsaRawMidiIn (const char *device) AlsaRawMidiIn::AlsaRawMidiIn (const char *device)
: AlsaRawMidiIO (device, true) : AlsaRawMidiIO (device, true)
, _event(0,0) , _event(0,0)
, _first_time(true)
, _unbuffered_bytes(0) , _unbuffered_bytes(0)
, _total_bytes(0) , _total_bytes(0)
, _expected_bytes(0) , _expected_bytes(0)
@ -471,6 +472,9 @@ int
AlsaRawMidiIn::queue_event (const uint64_t time, const uint8_t *data, const size_t size) { AlsaRawMidiIn::queue_event (const uint64_t time, const uint8_t *data, const size_t size) {
const uint32_t buf_size = sizeof(MidiEventHeader) + size; const uint32_t buf_size = sizeof(MidiEventHeader) + size;
_event._pending = false; _event._pending = false;
if (size == 0) {
return -1;
}
if (_rb->write_space() < buf_size) { if (_rb->write_space() < buf_size) {
_DEBUGPRINT("AlsaRawMidiIn: ring buffer overflow\n"); _DEBUGPRINT("AlsaRawMidiIn: ring buffer overflow\n");
return -1; return -1;
@ -489,6 +493,10 @@ AlsaRawMidiIn::parse_events (const uint64_t time, const uint8_t *data, const siz
} }
} }
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
if (_first_time && !(data[i] & 0x80)) {
continue;
}
_first_time = false; /// TODO optimize e.g. use fn pointer to different parse_events()
if (process_byte(time, data[i])) { if (process_byte(time, data[i])) {
if (queue_event (_event._time, _parser_buffer, _event._size)) { if (queue_event (_event._time, _parser_buffer, _event._size)) {
return; return;

View File

@ -143,6 +143,7 @@ private:
} }
} _event; } _event;
bool _first_time;
size_t _unbuffered_bytes; size_t _unbuffered_bytes;
size_t _total_bytes; size_t _total_bytes;
size_t _expected_bytes; size_t _expected_bytes;