Browse Source

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.
master
cancel 5 years ago
parent
commit
1d43d3f5c9
  1. 12
      tui_main.c

12
tui_main.c

@ -865,6 +865,18 @@ void midi_mode_deinit(Midi_mode *mm) {
break; break;
#ifdef FEAT_PORTMIDI #ifdef FEAT_PORTMIDI
case Midi_mode_type_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); Pm_Close(mm->portmidi.stream);
break; break;
#endif #endif

Loading…
Cancel
Save