ALSA backend: tweak midi parser (fix start mid sequence)
authorRobin Gareus <robin@gareus.org>
Mon, 2 Jun 2014 23:00:58 +0000 (01:00 +0200)
committerRobin Gareus <robin@gareus.org>
Mon, 2 Jun 2014 23:00:58 +0000 (01:00 +0200)
libs/backends/alsa/alsa_rawmidi.cc
libs/backends/alsa/alsa_rawmidi.h

index 377cff4f47cca44929f8dc4b05c036986499be4f..035860c259540ea19de243a0ced765663f7523a6 100644 (file)
@@ -337,6 +337,7 @@ retry:
 AlsaRawMidiIn::AlsaRawMidiIn (const char *device)
                : AlsaRawMidiIO (device, true)
                , _event(0,0)
+               , _first_time(true)
                , _unbuffered_bytes(0)
                , _total_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) {
        const uint32_t  buf_size = sizeof(MidiEventHeader) + size;
        _event._pending = false;
+       if (size == 0) {
+               return -1;
+       }
        if (_rb->write_space() < buf_size) {
                _DEBUGPRINT("AlsaRawMidiIn: ring buffer overflow\n");
                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) {
+               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 (queue_event (_event._time, _parser_buffer, _event._size)) {
                                return;
index 9353b92a2fc0c8134ac20e31c6aa359614b25b8d..eafdf0756103b2b57b2ea67ee0fef1b115224e55 100644 (file)
@@ -143,6 +143,7 @@ private:
                }
        } _event;
 
+       bool    _first_time;
        size_t  _unbuffered_bytes;
        size_t  _total_bytes;
        size_t  _expected_bytes;