+/** Return true iff the given buffer is a valid MIDI event.
+ * \a len must be exactly correct for the contents of \a buffer
+ */
+static inline bool
+midi_event_is_valid(const uint8_t* buffer, size_t len)
+{
+ uint8_t status = buffer[0];
+ if (status < 0x80) {
+ return false;
+ }
+ const int size = midi_event_size(buffer);
+ 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;
+}
+
+LIBEVORAL_API std::string midi_note_name (uint8_t noteval);
+