From 22d7fbd5211d79493da755e23604089b14c9b418 Mon Sep 17 00:00:00 2001 From: negativeExponent <54053706+negativeExponent@users.noreply.github.com> Date: Fri, 26 Jul 2024 02:38:09 +0800 Subject: [PATCH] alsa_midi: Prevent some notes to linger when application is closed (#16815) Appears to be enough to silence any lingering notes when midi is playing and core is suddenly closed. Tried adding this on the core side but midi_free comes first before retro_deinit/retro_unload_game so the driver was already closed. Another way to fix this in the core's side is to call 'flush' immediately after any midi writes, but that doesn't appear to be the api's design, flush is supposed to get called at the end of the retro_run. Im open for any better methods. but this should work for the issue without causing other problems. Co-authored-by: negativeExponent --- midi/drivers/alsa_midi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/midi/drivers/alsa_midi.c b/midi/drivers/alsa_midi.c index c4a6813a06..14ede84c40 100644 --- a/midi/drivers/alsa_midi.c +++ b/midi/drivers/alsa_midi.c @@ -157,7 +157,11 @@ static void alsa_midi_free(void *p) if (d) { if (d->seq) + { + snd_seq_drain_output(d->seq); snd_seq_close(d->seq); + } + free(d); } }