mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
Advance to the next track when the current one
finishes
This commit is contained in:
parent
990f42683f
commit
e10670b8bc
3 changed files with 65 additions and 26 deletions
|
@ -33,6 +33,8 @@ static byte remap[100];
|
|||
static char playTrackName[MAX_QPATH];
|
||||
static double old_cdvolume;
|
||||
|
||||
static void CDAudio_Next(void);
|
||||
|
||||
static void CDAudio_Eject(void)
|
||||
{
|
||||
// FIXME: call backend
|
||||
|
@ -41,9 +43,23 @@ static void CDAudio_Eject(void)
|
|||
|
||||
static qboolean CDAudio_IsNumberedTrack(const char *trackName)
|
||||
{
|
||||
char numberAsString[10];
|
||||
sprintf(numberAsString, "%d", (int)atoi(trackName));
|
||||
return 0 == strcmp(trackName, numberAsString);
|
||||
int len = strlen(trackName);
|
||||
int i;
|
||||
for ( i = 0; i < len; i++ )
|
||||
{
|
||||
if (!isdigit(trackName[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void CDAudio_FinishedCallback(void *userdata)
|
||||
{
|
||||
// Hack to go to next track
|
||||
Con_Printf("Advancing because we hit the end of a track...\n");
|
||||
CDAudio_Next();
|
||||
}
|
||||
|
||||
void CDAudio_PlayNamed(const char *name, qboolean looping)
|
||||
|
@ -65,7 +81,7 @@ void CDAudio_PlayNamed(const char *name, qboolean looping)
|
|||
{
|
||||
track = remap[track];
|
||||
}
|
||||
sprintf(playTrackName, "%d", track);
|
||||
sprintf(playTrackName, "%02d", track);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -87,7 +103,11 @@ void CDAudio_PlayNamed(const char *name, qboolean looping)
|
|||
playing = true;
|
||||
|
||||
// FIXME: make backend play
|
||||
S_Base_StartBackgroundTrack(playTrackName, NULL);
|
||||
qboolean success = S_Base_StartBackgroundTrack(playTrackName, playLooping, CDAudio_FinishedCallback, NULL);
|
||||
if (!success)
|
||||
{
|
||||
Con_Printf("WARNING: Couldn't open music file %s\n", playTrackName);
|
||||
}
|
||||
}
|
||||
|
||||
void CDAudio_Play(byte track, qboolean looping)
|
||||
|
@ -123,7 +143,10 @@ static void CDAudio_Next(void)
|
|||
return;
|
||||
|
||||
if (!CDAudio_IsNumberedTrack(playTrackName))
|
||||
{
|
||||
playing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
track = atoi(playTrackName) + 1;
|
||||
|
||||
|
@ -355,6 +378,7 @@ void CDAudio_Update(void)
|
|||
CDAudio_SetVolume (&bgmvolume);
|
||||
|
||||
// FIXME: update backend
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,7 +34,8 @@ void S_StopAllSoundsC(void);
|
|||
snd_stream_t *s_backgroundStream = NULL;
|
||||
static qboolean s_backgroundPaused = false;
|
||||
static char s_backgroundLoop[MAX_QPATH];
|
||||
|
||||
static S_BackgroundTrackFinishedCallback s_backgroundFinishedCallback;
|
||||
static void *s_backgroundFinishedCallbackUserData;
|
||||
|
||||
// =======================================================================
|
||||
// Internal sound data & structures
|
||||
|
@ -995,25 +996,19 @@ void S_Base_StopBackgroundTrack( void ) {
|
|||
S_StartBackgroundTrack
|
||||
======================
|
||||
*/
|
||||
void S_Base_StartBackgroundTrack( const char *intro, const char *loop ){
|
||||
if ( !intro ) {
|
||||
intro = "";
|
||||
}
|
||||
if ( !loop || !loop[0] ) {
|
||||
loop = intro;
|
||||
}
|
||||
Con_DPrintf( "S_StartBackgroundTrack( %s, %s )\n", intro, loop );
|
||||
qboolean S_Base_StartBackgroundTrack( const char *trackname, qboolean loop, S_BackgroundTrackFinishedCallback callback, void *userdata ) {
|
||||
Con_DPrintf( "S_StartBackgroundTrack( %s, %s )\n", trackname, (loop ? "looped" : "not looped") );
|
||||
|
||||
if(!*intro)
|
||||
if(!*trackname)
|
||||
{
|
||||
S_Base_StopBackgroundTrack();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !loop ) {
|
||||
s_backgroundLoop[0] = 0;
|
||||
} else {
|
||||
strncpy( s_backgroundLoop, loop, sizeof( s_backgroundLoop ) );
|
||||
strncpy( s_backgroundLoop, trackname, MAX_QPATH );
|
||||
s_backgroundLoop[MAX_QPATH-1] = '\0';
|
||||
}
|
||||
|
||||
|
@ -1028,15 +1023,17 @@ void S_Base_StartBackgroundTrack( const char *intro, const char *loop ){
|
|||
}
|
||||
|
||||
// Open stream
|
||||
s_backgroundStream = S_CodecOpenStream(intro);
|
||||
s_backgroundStream = S_CodecOpenStream(trackname);
|
||||
if(!s_backgroundStream) {
|
||||
Con_Printf( "WARNING: couldn't open music file %s\n", intro );
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
//if(s_backgroundStream->info.channels != 2 || s_backgroundStream->info.rate != 22050) {
|
||||
// Con_Printf( "WARNING: music file %s is %d channels and %d Hz\n", intro, s_backgroundStream->info.channels, s_backgroundStream->info.rate );
|
||||
//}
|
||||
|
||||
if (!loop) {
|
||||
s_backgroundFinishedCallback = callback;
|
||||
s_backgroundFinishedCallbackUserData = userdata;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1107,13 +1104,18 @@ void S_UpdateBackgroundTrack( void ) {
|
|||
{
|
||||
S_CodecCloseStream(s_backgroundStream);
|
||||
s_backgroundStream = NULL;
|
||||
S_Base_StartBackgroundTrack( s_backgroundLoop, s_backgroundLoop );
|
||||
S_Base_StartBackgroundTrack( s_backgroundLoop, true, NULL, NULL );
|
||||
if(!s_backgroundStream)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
S_Base_StopBackgroundTrack();
|
||||
|
||||
if (s_backgroundFinishedCallback)
|
||||
{
|
||||
(*s_backgroundFinishedCallback)(s_backgroundFinishedCallbackUserData);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1121,6 +1123,16 @@ void S_UpdateBackgroundTrack( void ) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
==========================
|
||||
S_BackgroundTrackIsPlaying
|
||||
==========================
|
||||
*/
|
||||
qboolean S_BackgroundTrackIsPlaying( void )
|
||||
{
|
||||
return (NULL != s_backgroundStream) && (!s_backgroundPaused);
|
||||
}
|
||||
|
||||
void S_BlockSound (void)
|
||||
{
|
||||
/* FIXME: do we really need the blocking at the
|
||||
|
|
|
@ -140,11 +140,14 @@ void SNDDMA_BlockSound(void);
|
|||
/* unblocks the output upon window focus gain */
|
||||
void SNDDMA_UnblockSound(void);
|
||||
|
||||
typedef void (*S_BackgroundTrackFinishedCallback)(void *userdata);
|
||||
|
||||
void S_PauseBackgroundTrack( void );
|
||||
void S_ResumeBackgroundTrack( void );
|
||||
void S_Base_StopBackgroundTrack( void );
|
||||
void S_Base_StartBackgroundTrack( const char *intro, const char *loop );
|
||||
qboolean S_Base_StartBackgroundTrack( const char *intro, qboolean loop, S_BackgroundTrackFinishedCallback callback, void *userdata );
|
||||
void S_UpdateBackgroundTrack( void );
|
||||
qboolean S_BackgroundTrackIsPlaying( void );
|
||||
|
||||
// ====================================================================
|
||||
// User-setable variables
|
||||
|
|
Loading…
Reference in a new issue