Skip to content

Commit

Permalink
John Hall - Tue Jan 2 13:46:54 PST 2001
Browse files Browse the repository at this point in the history
 * Added support to playmus for track switching with Ctrl-C
 * Added support to playmus for multiple command line files
  • Loading branch information
Sam Lantinga committed Jan 2, 2001
1 parent 4e2baf2 commit 62b57c7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
5 changes: 5 additions & 0 deletions 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)
Expand Down
52 changes: 37 additions & 15 deletions playmus.c
Expand Up @@ -36,6 +36,7 @@

static int audio_open = 0;
static Mix_Music *music = NULL;
static int next_track = 0;

void CleanUp(void)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand All @@ -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);
}

0 comments on commit 62b57c7

Please sign in to comment.