From d2188c271cf59d4806b0fbd772c91e5e8e890333 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 31 Dec 2011 23:00:03 -0500 Subject: [PATCH] Partial fix for bug 934 - Native MIDI on OS X does not loop This fixes short midi files with large sound buffers when the application stops the music if it ever stops playing for a period of time. --- CHANGES | 2 ++ music.c | 17 +++++------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 71ff2686..31e372f9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,6 @@ 1.2.12: +Sam Lantinga - Sat Dec 31 22:56:34 EST 2011 + * Fixed looping MIDI music Sam Lantinga - Sat Dec 31 19:11:59 EST 2011 * Fixed dropping audio in the FLAC audio decoding Sam Lantinga - Sat Dec 31 18:32:05 EST 2011 diff --git a/music.c b/music.c index 452aacf7..50c43d39 100644 --- a/music.c +++ b/music.c @@ -196,7 +196,6 @@ void Mix_HookMusicFinished(void (*music_finished)(void)) static int music_halt_or_loop (void) { /* Restart music if it has to loop */ - if (!music_internal_playing()) { /* Restart music if it has to loop at a high level */ @@ -252,10 +251,6 @@ void music_mixer(void *udata, Uint8 *stream, int len) } } - music_halt_or_loop(); - if (!music_internal_playing()) - return; - switch (music_playing->type) { #ifdef CMD_MUSIC case MUS_CMD: @@ -282,14 +277,14 @@ void music_mixer(void *udata, Uint8 *stream, int len) #ifdef USE_FLUIDSYNTH_MIDI if ( fluidsynth_ok ) { fluidsynth_playsome(music_playing->data.fluidsynthmidi, stream, len); - goto skip; + break; } #endif #ifdef USE_TIMIDITY_MIDI if ( timidity_ok ) { int samples = len / samplesize; Timidity_PlaySome(stream, samples); - goto skip; + break; } #endif break; @@ -319,14 +314,12 @@ void music_mixer(void *udata, Uint8 *stream, int len) /* Unknown music type?? */ break; } - } -skip: - /* Handle seamless music looping */ - if (left > 0 && left < len) { + /* Handle seamless music looping */ music_halt_or_loop(); - if (music_internal_playing()) + if (left > 0 && left < len && music_internal_playing()) { music_mixer(udata, stream+(len-left), left); + } } }