music.c
changeset 529 9ca74f21d466
parent 528 bc0dfe8ae026
child 531 f9c790738ec3
     1.1 --- a/music.c	Sat Dec 31 23:28:23 2011 -0500
     1.2 +++ b/music.c	Sun Jan 01 00:47:32 2012 -0500
     1.3 @@ -279,6 +279,12 @@
     1.4  #endif
     1.5  #ifdef MID_MUSIC
     1.6  			case MUS_MID:
     1.7 +#ifdef USE_NATIVE_MIDI
     1.8 +  				if ( native_midi_ok ) {
     1.9 +					/* Native midi is handled asynchronously */
    1.10 +					goto skip;
    1.11 +	  			}
    1.12 +#endif
    1.13  #ifdef USE_FLUIDSYNTH_MIDI
    1.14  				if ( fluidsynth_ok ) {
    1.15  					fluidsynth_playsome(music_playing->data.fluidsynthmidi, stream, len);
    1.16 @@ -494,6 +500,7 @@
    1.17  		music->type = MUS_MID;
    1.18  #ifdef USE_NATIVE_MIDI
    1.19    		if ( native_midi_ok ) {
    1.20 +/*printf("Native MIDI\n");*/
    1.21    			music->data.nativemidi = native_midi_loadsong(file);
    1.22  	  		if ( music->data.nativemidi == NULL ) {
    1.23  		  		Mix_SetError("%s", native_midi_error());
    1.24 @@ -504,6 +511,7 @@
    1.25  #endif
    1.26  #ifdef USE_FLUIDSYNTH_MIDI
    1.27  		if ( fluidsynth_ok ) {
    1.28 +/*printf("FluidSynth MIDI\n");*/
    1.29  			music->data.fluidsynthmidi = fluidsynth_loadsong(file);
    1.30  			if ( music->data.fluidsynthmidi == NULL ) {
    1.31  				music->error = 1;
    1.32 @@ -513,6 +521,7 @@
    1.33  #endif
    1.34  #ifdef USE_TIMIDITY_MIDI
    1.35  		if ( timidity_ok ) {
    1.36 +/*printf("Timidity MIDI\n");*/
    1.37  			music->data.midi = Timidity_LoadSong(file);
    1.38  			if ( music->data.midi == NULL ) {
    1.39  				Mix_SetError("%s", Timidity_Error());
    1.40 @@ -730,6 +739,18 @@
    1.41  {
    1.42  	int retval = 0;
    1.43  
    1.44 +	/* Try to seek instead of do a full halt and restart.
    1.45 +	   This fixes a bug with native MIDI on Mac OS X, where you
    1.46 +	   can't really stop and restart from the audio callback.
    1.47 +	*/
    1.48 +	if ( music == music_playing
    1.49 +	  /* MUS_MOD position isn't time, it's pattern order number (??) */
    1.50 +	     && music->type != MUS_MOD ) {
    1.51 +		if ( music_internal_position(position) == 0 ) {
    1.52 +			return 0;
    1.53 +		}
    1.54 +	}
    1.55 +
    1.56  	/* Note the music we're playing */
    1.57  	if ( music_playing ) {
    1.58  		music_internal_halt();
    1.59 @@ -900,6 +921,18 @@
    1.60  		MOD_jump_to_time(music_playing->data.module, position);
    1.61  		break;
    1.62  #endif
    1.63 +#ifdef MID_MUSIC
    1.64 +	    case MUS_MID:
    1.65 +#ifdef USE_NATIVE_MIDI
    1.66 +		if ( native_midi_ok ) {
    1.67 +			retval = native_midi_jump_to_time(music_playing->data.nativemidi, position);
    1.68 +			break;
    1.69 +		}
    1.70 +#endif
    1.71 +		/* TODO: Implement this for other music backends */
    1.72 +		retval = -1;
    1.73 +		break;
    1.74 +#endif
    1.75  #ifdef OGG_MUSIC
    1.76  	    case MUS_OGG:
    1.77  		OGG_jump_to_time(music_playing->data.ogg, position);
    1.78 @@ -1317,7 +1350,7 @@
    1.79  
    1.80  	SDL_LockAudio();
    1.81  	if ( music_playing ) {
    1.82 -		playing = music_internal_playing();
    1.83 +		playing = music_loops || music_internal_playing();
    1.84  	}
    1.85  	SDL_UnlockAudio();
    1.86