From 62b57c7fd44a475c8aba481f273b4125172902a2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 2 Jan 2001 21:48:29 +0000 Subject: [PATCH] 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 | 5 +++++ playmus.c | 52 +++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index 33f86c70..b99c751e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,9 @@ +1.1.1: +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 + 1.1.0: Sam Lantinga - Wed Nov 29 20:47:13 PST 2000 * Package specifically for SDL 1.1 (no real reason API-wise, but for clarity) diff --git a/playmus.c b/playmus.c index a4690f50..77d3b32d 100644 --- a/playmus.c +++ b/playmus.c @@ -36,6 +36,7 @@ static int audio_open = 0; static Mix_Music *music = NULL; +static int next_track = 0; void CleanUp(void) { @@ -81,6 +82,15 @@ void Menu(void) Mix_PausedMusic() ? "yes" : "no"); } +void IntHandler(int sig) +{ + switch (sig) { + case SIGINT: + next_track++; + break; + } +} + main(int argc, char *argv[]) { int audio_rate; @@ -134,7 +144,7 @@ main(int argc, char *argv[]) exit(255); } atexit(CleanUp); - signal(SIGINT, exit); + signal(SIGINT, IntHandler); signal(SIGTERM, exit); /* Open the audio device */ @@ -153,21 +163,33 @@ main(int argc, char *argv[]) /* Set the external music player, if any */ Mix_SetMusicCMD(getenv("MUSIC_CMD")); - /* Load the requested music file */ - music = Mix_LoadMUS(argv[i]); - if ( music == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", - argv[i], SDL_GetError()); - exit(2); - } + while (argv[i]) { + next_track = 0; + + /* Load the requested music file */ + music = Mix_LoadMUS(argv[i]); + if ( music == NULL ) { + fprintf(stderr, "Couldn't load %s: %s\n", + argv[i], SDL_GetError()); + exit(2); + } + + /* Play and then exit */ + printf("Playing %s\n", argv[i]); + Mix_FadeInMusic(music,looping,2000); + while ( !next_track && Mix_PlayingMusic() || Mix_PausedMusic() ) { + if(interactive) + Menu(); + else + SDL_Delay(100); + } + Mix_FreeMusic(music); - /* Play and then exit */ - Mix_FadeInMusic(music,looping,2000); - while ( Mix_PlayingMusic() || Mix_PausedMusic() ) { - if(interactive) - Menu(); - else - SDL_Delay(100); + /* If the user presses Ctrl-C more than once, exit. */ + SDL_Delay(500); + if ( next_track > 1 ) break; + + i++; } exit(0); }