From ec617e7489c7141cec9649a036cc6beabd70c994 Mon Sep 17 00:00:00 2001 From: Stephane Peter Date: Mon, 1 Nov 1999 00:40:43 +0000 Subject: [PATCH] - Massive bugfixes for pausing/resuming music (handled in a generic way) - New functions to query the paused state of either music or channels - Added interactive mode (-i) to playmus, to aid debugging --- mixer.c | 8 ++++++++ mixer.h | 2 ++ music.c | 61 ++++++++++++++++++------------------------------------- playmus.c | 37 +++++++++++++++++++++++++++++---- 4 files changed, 63 insertions(+), 45 deletions(-) diff --git a/mixer.c b/mixer.c index 6ba60dde..b5bd082a 100644 --- a/mixer.c +++ b/mixer.c @@ -731,6 +731,14 @@ void Mix_Resume(int which) } } +int Mix_Paused(int which) +{ + if ( which < 0 || which > num_channels ) + return(0); + + return channel[which].paused != 0; +} + /* Change the group of a channel */ int Mix_GroupChannel(int which, int tag) { diff --git a/mixer.h b/mixer.h index ef0eb702..cfa3e1c9 100644 --- a/mixer.h +++ b/mixer.h @@ -186,11 +186,13 @@ extern Mix_Fading Mix_FadingChannel(int which); /* Pause/Resume a particular channel */ extern void Mix_Pause(int channel); extern void Mix_Resume(int channel); +extern int Mix_Paused(int channel); /* Pause/Resume the music stream */ extern void Mix_PauseMusic(void); extern void Mix_ResumeMusic(void); extern void Mix_RewindMusic(void); +extern int Mix_PausedMusic(void); /* Check the status of a specific channel. If the specified channel is -1, check all channels. diff --git a/music.c b/music.c index b1068b25..d0f2d546 100644 --- a/music.c +++ b/music.c @@ -54,6 +54,7 @@ static SDL_AudioSpec used_mixer; int music_active = 1; static int music_stopped = 0; +static int music_paused = 0; static int music_loops = 0; static char *music_cmd = NULL; static int samplesize; @@ -102,7 +103,6 @@ static int timidity_ok; /* Local low-level functions prototypes */ static void lowlevel_halt(void); static int lowlevel_play(Mix_Music *music); -static int lowlevel_playing(void); /* Mixing function */ void music_mixer(void *udata, Uint8 *stream, int len) @@ -116,6 +116,10 @@ void music_mixer(void *udata, Uint8 *stream, int len) lowlevel_halt(); /* This function sets music_playing to NULL */ return; } + if ( music_paused ) { + return; + } + /* Handle fading */ if ( !music_stopped && music_playing->fading != MIX_NO_FADING ) { Uint32 ticks = SDL_GetTicks() - music_playing->ticks_fade; if( ticks > music_playing->fade_length ) { @@ -142,7 +146,8 @@ void music_mixer(void *udata, Uint8 *stream, int len) } } } - if ( music_loops && !lowlevel_playing() ) { + /* Restart music if it has to loop */ + if ( music_loops && !Mix_PlayingMusic() ) { if ( -- music_loops ) { Mix_RewindMusic(); if ( lowlevel_play(music_playing) < 0 ) { @@ -629,6 +634,7 @@ static void lowlevel_halt(void) music_playing = 0; music_active = 0; music_loops = 0; + music_paused = 0; music_stopped = 0; } @@ -671,39 +677,17 @@ Mix_Fading Mix_FadingMusic(void) void Mix_PauseMusic(void) { if ( music_playing && music_active && !music_stopped ) { - switch ( music_playing->type ) { -#ifdef CMD_MUSIC - case MUS_CMD: - MusicCMD_Pause(music_playing->data.cmd); - break; -#endif -#ifdef MP3_MUSIC - case MUS_MP3: - SMPEG_pause(music_playing->data.mp3); - break; -#endif - } + music_active = 0; + music_paused = 1; } - music_active = 0; } void Mix_ResumeMusic(void) { if ( music_playing && !music_active && !music_stopped ) { - switch ( music_playing->type ) { -#ifdef CMD_MUSIC - case MUS_CMD: - MusicCMD_Resume(music_playing->data.cmd); - break; -#endif -#ifdef MP3_MUSIC - case MUS_MP3: - SMPEG_pause(music_playing->data.mp3); - break; -#endif - } + music_active = 1; + music_paused = 0; } - music_active = 1; } void Mix_RewindMusic(void) @@ -720,10 +704,15 @@ void Mix_RewindMusic(void) } } +int Mix_PausedMusic(void) +{ + return music_paused; +} + /* Check the status of the music */ -static int lowlevel_playing(void) +int Mix_PlayingMusic(void) { - if ( music_playing && !music_stopped ) { + if ( music_playing && ! music_stopped ) { switch (music_playing->type) { #ifdef CMD_MUSIC case MUS_CMD: @@ -760,19 +749,9 @@ static int lowlevel_playing(void) break; #endif } - } - return(1); -} - -int Mix_PlayingMusic(void) -{ - int active; - active = lowlevel_playing(); - if ( !active && music_loops ) { return(1); - } else { - return(active); } + return(0); } /* Set the external music playback command */ diff --git a/playmus.c b/playmus.c index 874c7daa..6dadd327 100644 --- a/playmus.c +++ b/playmus.c @@ -56,15 +56,38 @@ void CleanUp(void) void Usage(char *argv0) { - fprintf(stderr, "Usage: %s |-l] [-8] [-r rate] [-s] \n", argv0); + fprintf(stderr, "Usage: %s [-i] |-l] [-8] [-r rate] [-s] \n", argv0); } - + +void Menu(void) +{ + char buf[10]; + + printf("Available commands: (p)ause (r)esume (h)alt > "); + fflush(stdin); + scanf("%s",buf); + switch(buf[0]){ + case 'p': case 'P': + Mix_PauseMusic(); + break; + case 'r': case 'R': + Mix_ResumeMusic(); + break; + case 'h': case 'H': + Mix_HaltMusic(); + break; + } + printf("Music playing: %s Paused: %s\n", Mix_PlayingMusic() ? "yes" : "no", + Mix_PausedMusic() ? "yes" : "no"); +} + main(int argc, char *argv[]) { Uint32 audio_rate; Uint16 audio_format; int audio_channels; int looping = 0; + int interactive = 0; int i; /* Initialize variables */ @@ -84,6 +107,9 @@ main(int argc, char *argv[]) if ( strcmp(argv[i], "-l") == 0 ) { looping = -1; } else + if ( strcmp(argv[i], "-i") == 0 ) { + interactive = 1; + } else if ( strcmp(argv[i], "-8") == 0 ) { audio_format = AUDIO_U8; } else { @@ -130,8 +156,11 @@ main(int argc, char *argv[]) /* Play and then exit */ Mix_FadeInMusic(music,looping,2000); - while ( Mix_PlayingMusic() ) { - SDL_Delay(100); + while ( Mix_PlayingMusic() || Mix_PausedMusic() ) { + if(interactive) + Menu(); + else + SDL_Delay(100); } exit(0); }