music.c
changeset 11 3939a99bf422
parent 10 2fbd0414a1fc
child 12 f38e14b566c8
equal deleted inserted replaced
10:2fbd0414a1fc 11:3939a99bf422
   114 			/* To avoid concurrency problems and the use of mutexes,
   114 			/* To avoid concurrency problems and the use of mutexes,
   115 			   the music is always stopped from the sound thread */
   115 			   the music is always stopped from the sound thread */
   116 			lowlevel_halt(); /* This function sets music_playing to NULL */
   116 			lowlevel_halt(); /* This function sets music_playing to NULL */
   117 			return;
   117 			return;
   118 		}	
   118 		}	
   119 		if ( music_playing && music_loops && !lowlevel_playing() ) {
       
   120 			if ( -- music_loops ) {
       
   121 				Mix_RewindMusic();
       
   122 				if ( lowlevel_play(music_playing) < 0 )
       
   123 					music_stopped = 1; /* Something went wrong */
       
   124 			}
       
   125 		}
       
   126 		if ( !music_stopped && music_playing->fading != MIX_NO_FADING ) {
   119 		if ( !music_stopped && music_playing->fading != MIX_NO_FADING ) {
   127 			Uint32 ticks = SDL_GetTicks() - music_playing->ticks_fade;
   120 			Uint32 ticks = SDL_GetTicks() - music_playing->ticks_fade;
   128 			if( ticks > music_playing->fade_length ) {
   121 			if( ticks > music_playing->fade_length ) {
   129 				if ( music_playing->fading == MIX_FADING_OUT ) {
   122 				if ( music_playing->fading == MIX_FADING_OUT ) {
   130 					music_volume = music_playing->fade_volume;
   123 					music_volume = music_playing->fade_volume;
   147 					Mix_VolumeMusic((music_playing->fade_volume * ticks) 
   140 					Mix_VolumeMusic((music_playing->fade_volume * ticks) 
   148 									/ music_playing->fade_length);
   141 									/ music_playing->fade_length);
   149 				}
   142 				}
   150 			}
   143 			}
   151 		}
   144 		}
       
   145 		if ( music_loops && !lowlevel_playing() ) {
       
   146 			if ( -- music_loops ) {
       
   147 				Mix_RewindMusic();
       
   148 				if ( lowlevel_play(music_playing) < 0 ) {
       
   149 					fprintf(stderr,"Warning: Music restart failed.\n");
       
   150 					music_stopped = 1; /* Something went wrong */
       
   151 					music_playing->fading = MIX_NO_FADING;
       
   152 				}
       
   153 			}
       
   154 		}
   152 		switch (music_playing->type) {
   155 		switch (music_playing->type) {
   153 #ifdef CMD_MUSIC
   156 #ifdef CMD_MUSIC
   154 			case MUS_CMD:
   157 			case MUS_CMD:
   155 				/* The playing is done externally */
   158 				/* The playing is done externally */
   156 				break;
   159 				break;
   623 	if(music_playing->fading != MIX_NO_FADING) /* Restore volume */
   626 	if(music_playing->fading != MIX_NO_FADING) /* Restore volume */
   624 		music_volume = music_playing->fade_volume;
   627 		music_volume = music_playing->fade_volume;
   625 	music_playing->fading = MIX_NO_FADING;
   628 	music_playing->fading = MIX_NO_FADING;
   626 	music_playing = 0;
   629 	music_playing = 0;
   627 	music_active = 0;
   630 	music_active = 0;
       
   631 	music_loops = 0;
   628 	music_stopped = 0;
   632 	music_stopped = 0;
   629 }
   633 }
   630 
   634 
   631 /* Halt playing of music */
   635 /* Halt playing of music */
   632 int Mix_HaltMusic(void)
   636 int Mix_HaltMusic(void)