John Hall - Tue Jan 2 13:46:54 PST 2001
authorSam Lantinga <slouken@lokigames.com>
Tue, 02 Jan 2001 21:48:29 +0000
changeset 756024df94730b
parent 74 8bab4b6ed7e1
child 76 1d974913b859
John Hall - Tue Jan 2 13:46:54 PST 2001
* Added support to playmus for track switching with Ctrl-C
* Added support to playmus for multiple command line files
CHANGES
playmus.c
     1.1 --- a/CHANGES	Mon Dec 18 03:08:03 2000 +0000
     1.2 +++ b/CHANGES	Tue Jan 02 21:48:29 2001 +0000
     1.3 @@ -1,3 +1,8 @@
     1.4 +
     1.5 +1.1.1:
     1.6 +John Hall - Tue Jan  2 13:46:54 PST 2001
     1.7 + * Added support to playmus for track switching with Ctrl-C
     1.8 + * Added support to playmus for multiple command line files
     1.9  
    1.10  1.1.0:
    1.11  Sam Lantinga - Wed Nov 29 20:47:13 PST 2000
     2.1 --- a/playmus.c	Mon Dec 18 03:08:03 2000 +0000
     2.2 +++ b/playmus.c	Tue Jan 02 21:48:29 2001 +0000
     2.3 @@ -36,6 +36,7 @@
     2.4  
     2.5  static int audio_open = 0;
     2.6  static Mix_Music *music = NULL;
     2.7 +static int next_track = 0;
     2.8  
     2.9  void CleanUp(void)
    2.10  {
    2.11 @@ -81,6 +82,15 @@
    2.12  		   Mix_PausedMusic() ? "yes" : "no");
    2.13  }
    2.14  
    2.15 +void IntHandler(int sig)
    2.16 +{
    2.17 +	switch (sig) {
    2.18 +	        case SIGINT:
    2.19 +			next_track++;
    2.20 +			break;
    2.21 +	}
    2.22 +}
    2.23 +
    2.24  main(int argc, char *argv[])
    2.25  {
    2.26  	int audio_rate;
    2.27 @@ -134,7 +144,7 @@
    2.28  		exit(255);
    2.29  	}
    2.30  	atexit(CleanUp);
    2.31 -	signal(SIGINT, exit);
    2.32 +	signal(SIGINT, IntHandler);
    2.33  	signal(SIGTERM, exit);
    2.34  
    2.35  	/* Open the audio device */
    2.36 @@ -153,21 +163,33 @@
    2.37  	/* Set the external music player, if any */
    2.38  	Mix_SetMusicCMD(getenv("MUSIC_CMD"));
    2.39  
    2.40 -	/* Load the requested music file */
    2.41 -	music = Mix_LoadMUS(argv[i]);
    2.42 -	if ( music == NULL ) {
    2.43 -		fprintf(stderr, "Couldn't load %s: %s\n",
    2.44 -						argv[i], SDL_GetError());
    2.45 -		exit(2);
    2.46 -	}
    2.47 +	while (argv[i]) {
    2.48 +		next_track = 0;
    2.49 +		
    2.50 +		/* Load the requested music file */
    2.51 +		music = Mix_LoadMUS(argv[i]);
    2.52 +		if ( music == NULL ) {
    2.53 +			fprintf(stderr, "Couldn't load %s: %s\n",
    2.54 +				argv[i], SDL_GetError());
    2.55 +			exit(2);
    2.56 +		}
    2.57 +		
    2.58 +		/* Play and then exit */
    2.59 +		printf("Playing %s\n", argv[i]);
    2.60 +		Mix_FadeInMusic(music,looping,2000);
    2.61 +		while ( !next_track && Mix_PlayingMusic() || Mix_PausedMusic() ) {
    2.62 +			if(interactive)
    2.63 +				Menu();
    2.64 +			else
    2.65 +				SDL_Delay(100);
    2.66 +		}
    2.67 +		Mix_FreeMusic(music);
    2.68  
    2.69 -	/* Play and then exit */
    2.70 -	Mix_FadeInMusic(music,looping,2000);
    2.71 -	while ( Mix_PlayingMusic() || Mix_PausedMusic() ) {
    2.72 -		if(interactive)
    2.73 -			Menu();
    2.74 -		else
    2.75 -			SDL_Delay(100);
    2.76 +		/* If the user presses Ctrl-C more than once, exit. */
    2.77 +		SDL_Delay(500);
    2.78 +		if ( next_track > 1 ) break;
    2.79 +		
    2.80 +		i++;
    2.81  	}
    2.82  	exit(0);
    2.83  }