Partial fix for bug 934 - Native MIDI on OS X does not loop
authorSam Lantinga <slouken@libsdl.org>
Sat, 31 Dec 2011 23:00:03 -0500
changeset 5271eddea51f162
parent 526 7a8f0018e23d
child 528 bc0dfe8ae026
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
music.c
     1.1 --- a/CHANGES	Sat Dec 31 21:26:46 2011 -0500
     1.2 +++ b/CHANGES	Sat Dec 31 23:00:03 2011 -0500
     1.3 @@ -1,4 +1,6 @@
     1.4  1.2.12:
     1.5 +Sam Lantinga - Sat Dec 31 22:56:34 EST 2011
     1.6 + * Fixed looping MIDI music
     1.7  Sam Lantinga - Sat Dec 31 19:11:59 EST 2011
     1.8   * Fixed dropping audio in the FLAC audio decoding
     1.9  Sam Lantinga - Sat Dec 31 18:32:05 EST 2011
     2.1 --- a/music.c	Sat Dec 31 21:26:46 2011 -0500
     2.2 +++ b/music.c	Sat Dec 31 23:00:03 2011 -0500
     2.3 @@ -196,7 +196,6 @@
     2.4  static int music_halt_or_loop (void)
     2.5  {
     2.6  	/* Restart music if it has to loop */
     2.7 -	
     2.8  	if (!music_internal_playing()) 
     2.9  	{
    2.10  		/* Restart music if it has to loop at a high level */
    2.11 @@ -252,10 +251,6 @@
    2.12  			}
    2.13  		}
    2.14  		
    2.15 -		music_halt_or_loop();
    2.16 -		if (!music_internal_playing())
    2.17 -			return;
    2.18 -
    2.19  		switch (music_playing->type) {
    2.20  #ifdef CMD_MUSIC
    2.21  			case MUS_CMD:
    2.22 @@ -282,14 +277,14 @@
    2.23  #ifdef USE_FLUIDSYNTH_MIDI
    2.24  				if ( fluidsynth_ok ) {
    2.25  					fluidsynth_playsome(music_playing->data.fluidsynthmidi, stream, len);
    2.26 -					goto skip;
    2.27 +					break;
    2.28  				}
    2.29  #endif
    2.30  #ifdef USE_TIMIDITY_MIDI
    2.31  				if ( timidity_ok ) {
    2.32  					int samples = len / samplesize;
    2.33    					Timidity_PlaySome(stream, samples);
    2.34 -					goto skip;
    2.35 +					break;
    2.36  				}
    2.37  #endif
    2.38  				break;
    2.39 @@ -319,14 +314,12 @@
    2.40  				/* Unknown music type?? */
    2.41  				break;
    2.42  		}
    2.43 -	}
    2.44  
    2.45 -skip:
    2.46 -	/* Handle seamless music looping */
    2.47 -	if (left > 0 && left < len) {
    2.48 +		/* Handle seamless music looping */
    2.49  		music_halt_or_loop();
    2.50 -		if (music_internal_playing())
    2.51 +		if (left > 0 && left < len && music_internal_playing()) {
    2.52  			music_mixer(udata, stream+(len-left), left);
    2.53 +		}
    2.54  	}
    2.55  }
    2.56