Fix record/import of note ons with velocity 0.
authorDavid Robillard <d@drobilla.net>
Thu, 19 Feb 2015 21:54:21 +0000 (16:54 -0500)
committerDavid Robillard <d@drobilla.net>
Thu, 19 Feb 2015 23:38:30 +0000 (18:38 -0500)
Best to just do this as early as possible to avoid having to deal with this
situation all over the code.

Also fixes violation of LV2 MIDI specification, which requires no such events
are delivered to plugins.

libs/ardour/midi_port.cc
libs/evoral/src/SMF.cpp

index b12999cc9f090305811e4655170b98c192c9ef4d..ccd6e9848b6b7edb88e9f3d4b64d84acff6d8cc2 100644 (file)
@@ -117,6 +117,10 @@ MidiPort::get_midi_buffer (pframes_t nframes)
                                if (buf[0] == 0xfe) {
                                        /* throw away active sensing */
                                        continue;
+                               } if (buf[0] == 0x90 && buf[2] == 0) {
+                                       /* normalize note on with velocity 0 to proper note off */
+                                       buf[0] = 0x80;  /* note off */
+                                       buf[2] = 0x40;  /* default velocity */
                                }
                                
                                /* check that the event is in the acceptable time range */
index 42c5369b7662fdb2001bbf27f8136ae08599b76e..edf33c23f20bce3a598fd63b31ec602a34065417 100644 (file)
@@ -287,6 +287,11 @@ SMF::read_event(uint32_t* delta_t, uint32_t* size, uint8_t** buf, event_id_t* no
                }
                memcpy(*buf, event->midi_buffer, size_t(event_size));
                *size = event_size;
+               if ((*buf)[0] == 0x90 && (*buf)[2] == 0) {
+                       /* normalize note on with velocity 0 to proper note off */
+                       (*buf)[0] = 0x80;  /* note off */
+                       (*buf)[2] = 0x40;  /* default velocity */
+               }
 
                if (!midi_event_is_valid(*buf, *size)) {
                        cerr << "WARNING: SMF ignoring illegal MIDI event" << endl;