mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 08:52:00 +00:00
sdlmusic: Implement graceful playback failure
git-svn-id: https://svn.eduke32.com/eduke32@6890 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
03f2cdd9b3
commit
b5caf1cd1e
1 changed files with 23 additions and 9 deletions
|
@ -359,13 +359,14 @@ int32_t MUSIC_StopSong(void)
|
||||||
} // MUSIC_StopSong
|
} // MUSIC_StopSong
|
||||||
|
|
||||||
#if defined FORK_EXEC_MIDI
|
#if defined FORK_EXEC_MIDI
|
||||||
static void playmusic()
|
static int32_t playmusic()
|
||||||
{
|
{
|
||||||
pid_t pid = vfork();
|
pid_t pid = vfork();
|
||||||
|
|
||||||
if (pid==-1) // error
|
if (pid==-1) // error
|
||||||
{
|
{
|
||||||
initprintf("%s: vfork: %s\n", __func__, strerror(errno));
|
initprintf("%s: vfork: %s\n", __func__, strerror(errno));
|
||||||
|
return MUSIC_Error;
|
||||||
}
|
}
|
||||||
else if (pid==0) // child
|
else if (pid==0) // child
|
||||||
{
|
{
|
||||||
|
@ -380,6 +381,8 @@ static void playmusic()
|
||||||
{
|
{
|
||||||
external_midi_pid = pid;
|
external_midi_pid = pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return MUSIC_Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sigchld_handler(int signo)
|
static void sigchld_handler(int signo)
|
||||||
|
@ -408,9 +411,6 @@ static void sigchld_handler(int signo)
|
||||||
int32_t MUSIC_PlaySong(char *song, int32_t songsize, int32_t loopflag)
|
int32_t MUSIC_PlaySong(char *song, int32_t songsize, int32_t loopflag)
|
||||||
{
|
{
|
||||||
// initprintf("MUSIC_PlaySong");
|
// initprintf("MUSIC_PlaySong");
|
||||||
// TODO: graceful failure
|
|
||||||
MUSIC_StopSong();
|
|
||||||
|
|
||||||
if (external_midi)
|
if (external_midi)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
@ -440,14 +440,23 @@ int32_t MUSIC_PlaySong(char *song, int32_t songsize, int32_t loopflag)
|
||||||
|
|
||||||
#if defined FORK_EXEC_MIDI
|
#if defined FORK_EXEC_MIDI
|
||||||
external_midi_restart = loopflag;
|
external_midi_restart = loopflag;
|
||||||
playmusic();
|
int32_t retval = playmusic();
|
||||||
|
if (retval != MUSIC_Ok)
|
||||||
|
return retval;
|
||||||
#else
|
#else
|
||||||
music_musicchunk = Mix_LoadMUS(external_midi_tempfn);
|
music_musicchunk = Mix_LoadMUS(external_midi_tempfn);
|
||||||
if (!music_musicchunk)
|
if (!music_musicchunk)
|
||||||
|
{
|
||||||
initprintf("Mix_LoadMUS: %s\n", Mix_GetError());
|
initprintf("Mix_LoadMUS: %s\n", Mix_GetError());
|
||||||
|
return MUSIC_Error;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else initprintf("%s: fopen: %s\n", __func__, strerror(errno));
|
else
|
||||||
|
{
|
||||||
|
initprintf("%s: fopen: %s\n", __func__, strerror(errno));
|
||||||
|
return MUSIC_Error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
music_musicchunk = Mix_LoadMUS_RW(SDL_RWFromMem(song, songsize)
|
music_musicchunk = Mix_LoadMUS_RW(SDL_RWFromMem(song, songsize)
|
||||||
|
@ -456,9 +465,14 @@ int32_t MUSIC_PlaySong(char *song, int32_t songsize, int32_t loopflag)
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
|
||||||
if (music_musicchunk != NULL)
|
if (music_musicchunk == NULL)
|
||||||
if (Mix_PlayMusic(music_musicchunk, (loopflag == MUSIC_LoopSong)?-1:0) == -1)
|
return MUSIC_Error;
|
||||||
initprintf("Mix_PlayMusic: %s\n", Mix_GetError());
|
|
||||||
|
if (Mix_PlayMusic(music_musicchunk, (loopflag == MUSIC_LoopSong)?-1:0) == -1)
|
||||||
|
{
|
||||||
|
initprintf("Mix_PlayMusic: %s\n", Mix_GetError());
|
||||||
|
return MUSIC_Error;
|
||||||
|
}
|
||||||
|
|
||||||
return MUSIC_Ok;
|
return MUSIC_Ok;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue