Midi CC events have no event-ID
[ardour.git] / libs / evoral / evoral / midi_util.h
index 6c394b14b82942bcb2ab57d3ce33dbca572c5c63..9341e1afb28db89a4ac5a5c57d68b4de6c76819c 100644 (file)
@@ -22,7 +22,6 @@
 #include <iostream>
 
 #include <stdint.h>
-#include <stdbool.h>
 #include <string>
 #include <sys/types.h>
 #include <assert.h>
@@ -96,7 +95,9 @@ midi_event_size(const uint8_t* buffer)
                int end;
                
                for (end = 1; buffer[end] != MIDI_CMD_COMMON_SYSEX_END; end++) {
-                       assert((buffer[end] & 0x80) == 0);
+                       if ((buffer[end] & 0x80) != 0) {
+                               return -1;
+                       }
                }
                assert(buffer[end] == MIDI_CMD_COMMON_SYSEX_END);
                return end + 1;
@@ -119,6 +120,16 @@ midi_event_is_valid(const uint8_t* buffer, size_t len)
        if (size < 0 || (size_t)size != len) {
                return false;
        }
+       if (status < 0xf0) {
+               /* Channel messages: all start with status byte followed by
+                * non status bytes.
+                */
+               for (size_t i = 1; i < len; ++i) {
+                       if ((buffer[i] & 0x80) != 0) {
+                               return false;  // Non-status byte has MSb set
+                       }
+               }
+       }
        return true;
 }