ref: 1d43d3f5c9e7efc40873f5b6dffe2dd5bf7fb07b
parent: 99681ce7bc1589d63cd80eb11e1c9beff52e78b9
author: cancel <cancel@cancel.fm>
date: Wed Jan 22 12:58:34 EST 2020
Fix potential MIDI notes stuck on due to PortMidi latency Since we changed to use PortMidi's timestamping and buffering stuff, (because otherwise MIDI timing gets messed up for some people for some unknown reason), there's now a chance that MIDI notes can get stuck on when quitting orca, because PortMidi seems to be dumb and won't immediately send the pending events. So we have to manually spin and wait for them to be sent. There doesn't appear to be a way to forcefully flush them, so we're stuck adding an delay.
--- a/tui_main.c
+++ b/tui_main.c
@@ -865,6 +865,18 @@
break;
#ifdef FEAT_PORTMIDI
case Midi_mode_type_portmidi:
+ // Because PortMidi seems to work correctly ony more platforms when using
+ // its timing stuff, we are using it. And because we are using it, and
+ // because it may be buffering events for sending 'later', we might have
+ // pending outgoing MIDI events. We'll need to wait until they finish being
+ // before calling Pm_Close, otherwise users could have problems like MIDI
+ // notes being stuck on. This is slow and blocking, but not much we can do
+ // about it right now.
+ //
+ // TODO use nansleep on platforms that support it.
+ for (U64 start = stm_now();
+ stm_ms(stm_since(start)) <= (double)Portmidi_artificial_latency;)
+ sleep(0);
Pm_Close(mm->portmidi.stream);
break;
#endif