Example #1
0
File: songs.c Project: paud/d2x-xl
//returns 1 if track started sucessfully
//start at tracknum.  if keep_playing set, play to end of disc.  else
//play only specified track
int play_redbook_track(int tracknum,int keep_playing)
{
	gameStates.sound.bRedbookPlaying = 0;
#ifdef _DEBUG
	tracknum = 1;
#endif

	if (!RBAEnabled() && gameStates.sound.bRedbookEnabled && !gameOpts->sound.bUseRedbook)
		reinit_redbook();

	if (force_rb_register) {
		RBARegisterCD();			//get new track list for new CD
		force_rb_register = 0;
	}

	if (gameStates.sound.bRedbookEnabled && RBAEnabled()) {
		int num_tracks = RBAGetNumberOfTracks();
		if (tracknum <= num_tracks)
			if (RBAPlayTracks(tracknum,keep_playing?num_tracks:tracknum))  {
				gameStates.sound.bRedbookPlaying = tracknum;
			}
	}

	return (gameStates.sound.bRedbookPlaying != 0);
}
Example #2
0
File: songs.c Project: paud/d2x-xl
void PlayLevelSong( int levelnum )
{
	int songnum;
	int n_tracks;
	int bD1Song = (gameData.missions.list[gameData.missions.nCurrentMission].descent_version == 1);

	Assert( levelnum != 0 );

	if ( !gameData.songs.bInitialized )
		songs_init();
	SongsStopAll();
	nCurrentLevelSong = levelnum;
	songnum = (levelnum > 0) ? levelnum - 1 : -levelnum;
	gameStates.sound.nCurrentSong = songnum;
	if (!RBAEnabled() && gameStates.sound.bRedbookEnabled && gameOpts->sound.bUseRedbook)
		reinit_redbook();
	if (force_rb_register) {
		RBARegisterCD();			//get new track list for new CD
		force_rb_register = 0;
	}
	if (gameStates.sound.bRedbookEnabled && RBAEnabled() && (n_tracks = RBAGetNumberOfTracks()) > 1) {
		//try to play redbook
		play_redbook_track(REDBOOK_FIRST_LEVEL_TRACK + (songnum % (n_tracks-REDBOOK_FIRST_LEVEL_TRACK+1)),1);
	}
	if (! gameStates.sound.bRedbookPlaying) {			//not playing redbook, so play midi
		songnum = gameData.songs.nLevelSongs [bD1Song] ? gameData.songs.nFirstLevelSong [bD1Song] + (songnum % gameData.songs.nLevelSongs [bD1Song]) : 0;
		gameStates.sound.nCurrentSong = songnum;
			DigiPlayMidiSong( 
				gameData.songs.info [songnum].filename, 
				gameData.songs.info [songnum].melodic_bank_file, 
				gameData.songs.info [songnum].drum_bank_file, 
				1, 
				bD1Song);
	}
}
Example #3
0
void PlayLevelSong (int nLevel, int bFromHog)
{
	int	nSong;
	int	nTracks;
	int	bD1Song = (gameData.missions.list [gameData.missions.nCurrentMission].nDescentVersion == 1);
	char	szFilename [FILENAME_LEN];

if (!nLevel)
	return;
if (!gameData.songs.bInitialized)
	SongsInit ();
SongsStopAll ();
nCurrentLevelSong = nLevel;
nSong = (nLevel > 0) ? nLevel - 1 : -nLevel;
gameStates.sound.nCurrentSong = nSong;
if (!RBAEnabled () && gameStates.sound.bRedbookEnabled && gameOpts->sound.bUseRedbook)
	ReInitRedbook ();
if (bForceRBRegister) {
	RBARegisterCD ();			//get new track list for new CD
	bForceRBRegister = 0;
	}
if (bFromHog) {
	strcpy (szFilename, LevelSongName (nLevel));
	if (*szFilename && CFExtract (szFilename, gameFolders.szDataDir, 0, szFilename)) {
		char	szSong [FILENAME_LEN];

		sprintf (szSong, "%s%s%s", gameFolders.szCacheDir, *gameFolders.szCacheDir ? "/" : "", szFilename);
		if (DigiPlayMidiSong (szSong, NULL, NULL, 1, 0))
			return;
		}
	}
if ((nLevel > 0) && gameData.songs.user.nLevelSongs) {
	if (DigiPlayMidiSong (gameData.songs.user.pszLevelSongs [(nLevel - 1) % gameData.songs.user.nLevelSongs], NULL, NULL, 1, 0))
		return;
	}
if (gameStates.sound.bRedbookEnabled && RBAEnabled () && (nTracks = RBAGetNumberOfTracks ()) > 1)	//try to play redbook
	PlayRedbookTrack (REDBOOK_FIRST_LEVEL_TRACK + (nSong % (nTracks-REDBOOK_FIRST_LEVEL_TRACK+1)),1);
if (!gameStates.sound.bRedbookPlaying) {			//not playing redbook, so play midi
	nSong = gameData.songs.nLevelSongs [bD1Song] ? gameData.songs.nFirstLevelSong [bD1Song] + (nSong % gameData.songs.nLevelSongs [bD1Song]) : 0;
	gameStates.sound.nCurrentSong = nSong;
		DigiPlayMidiSong (
			gameData.songs.info [nSong].filename,
			gameData.songs.info [nSong].melodicBankFile,
			gameData.songs.info [nSong].drumBankFile,
			1,
			bD1Song);
	}
}
Example #4
0
void SongsInit ()
{
	int	i, bD1Songs;
	char	*p, inputline [81];
	CFILE	cf;

if (gameData.songs.bInitialized)
	return;
CFUseD1HogFile ("descent.hog");
for (i = 0, bD1Songs = 0; bD1Songs < 2; bD1Songs++) {
		if (!FindArg ("-nomixer"))
			CD_blast_mixer ();   // Crank it!
	if (CFExist ("descent.sng", gameFolders.szDataDir, bD1Songs)) {   // mac (demo?) datafiles don't have the .sng file
		if (!CFOpen (&cf, "descent.sng", gameFolders.szDataDir, "rb", bD1Songs)) {
			if (bD1Songs)
				break;
			else
				Error ("Couldn't open descent.sng");
			}
		while (CFGetS (inputline, 80, &cf)) {
			if ((p = strchr (inputline,'\n')))
				*p = '\0';
			if (*inputline) {
				Assert(i < MAX_NUM_SONGS);
				if (3 == sscanf (inputline, "%s %s %s",
									  gameData.songs.info [i].filename,
									  gameData.songs.info [i].melodicBankFile,
									  gameData.songs.info [i].drumBankFile)) {
					if (!gameData.songs.nFirstLevelSong [bD1Songs] && strstr (gameData.songs.info [i].filename, "game01.hmp"))
						 gameData.songs.nFirstLevelSong [bD1Songs] = i;
					if (bD1Songs && strstr (gameData.songs.info [i].filename, "endlevel.hmp"))
						gameData.songs.nD1EndLevelSong = i;
					i++;
					}
				}
			}
		gameData.songs.nSongs [bD1Songs] = i;
		gameData.songs.nLevelSongs [bD1Songs] = gameData.songs.nSongs [bD1Songs] - gameData.songs.nFirstLevelSong [bD1Songs];
		if (!gameData.songs.nFirstLevelSong [bD1Songs])
			Error ("Descent 1 songs are missing.");
		CFClose(&cf);
		}
	gameData.songs.nTotalSongs = i;
	gameData.songs.bInitialized = 1;
	//	RBA Hook
	if (!gameOpts->sound.bUseRedbook)
		gameStates.sound.bRedbookEnabled = 0;
	else {	// use redbook
			RBAInit ();
		if (RBAEnabled ()) {
			SetRedbookVolume(gameConfig.nRedbookVolume);
			RBARegisterCD ();
			}
		}
	atexit(RBAStop);    // stop song on exit
	}
}
Example #5
0
void ReInitRedbook ()
{
RBAInit ();
if (RBAEnabled ()) {
	SetRedbookVolume (gameConfig.nRedbookVolume);
	RBARegisterCD ();
	bForceRBRegister = 0;
	}
}
Example #6
0
void songs_play_level_song( int levelnum )
{
	int songnum;
	int n_tracks;

	Assert( levelnum != 0 );

	songs_init();

	songs_stop_all();
	
	if (cGameSongsAvailable < 1)
		return;

	current_song_level = levelnum;

	if (levelnum < 0)
		songnum = (-levelnum) % cGameSongsAvailable;
	else
		songnum = (levelnum-1) % cGameSongsAvailable;

	if (!RBAEnabled() && GameCfg.SndEnableRedbook)	// need this to determine if we currently have the official CD
		reinit_redbook();

	n_tracks = RBAGetNumberOfTracks();
	
	if (RBAEnabled() && GameCfg.SndEnableRedbook) {
		
		//try to play redbook
		
		play_redbook_track(REDBOOK_FIRST_LEVEL_TRACK + (songnum % (n_tracks-REDBOOK_FIRST_LEVEL_TRACK+1)),!songs_haved1_cd());
	}
	
	if (! Redbook_playing) {			//not playing redbook, so play midi
		songnum += SONG_LEVEL_MUSIC;
		digi_play_midi_song( Songs[songnum].filename, Songs[songnum].melodic_bank_file, Songs[songnum].drum_bank_file, 1 );
	}
}
Example #7
0
//------------------------------------------------------------------------------
//returns 1 if track started sucessfully
//start at nTrack.  if bKeepPlaying set, play to end of disc.  else
//play only specified track
int PlayRedbookTrack (int nTrack, int bKeepPlaying)
{
gameStates.sound.bRedbookPlaying = 0;
#if DBG
nTrack = 1;
#endif

if (!RBAEnabled () && gameStates.sound.bRedbookEnabled && !gameOpts->sound.bUseRedbook)
	ReInitRedbook ();

if (bForceRBRegister) {
	RBARegisterCD ();			//get new track list for new CD
	bForceRBRegister = 0;
	}
if (gameStates.sound.bRedbookEnabled && RBAEnabled ()) {
	int nTracks = RBAGetNumberOfTracks ();
	if (nTrack <= nTracks)
		if (RBAPlayTracks(nTrack, bKeepPlaying ? nTracks : nTrack))  {
			gameStates.sound.bRedbookPlaying = nTrack;
			}
	}
return (gameStates.sound.bRedbookPlaying != 0);
}
Example #8
0
File: songs.c Project: paud/d2x-xl
void reinit_redbook()
{
	#ifndef __MSDOS__
		RBAInit();
	#else
		RBAInit(toupper(CDROM_dir[0]) - 'A');
	#endif

	if (RBAEnabled())
	{
		set_redbook_volume(gameConfig.nRedbookVolume);
		RBARegisterCD();
		force_rb_register=0;
	}
}
Example #9
0
//returns 1 if track started sucessfully
//start at tracknum.  if keep_playing set, play to end of disc.  else
//play only specified track
int play_redbook_track(int tracknum,int keep_playing)
{
	Redbook_playing = 0;
	
	if (!RBAEnabled() && GameCfg.SndEnableRedbook)
		reinit_redbook();
	
	if (GameCfg.SndEnableRedbook) {
		int num_tracks = RBAGetNumberOfTracks();
		if (tracknum <= num_tracks)
			if (RBAPlayTracks(tracknum,keep_playing?num_tracks:tracknum))  {
				Redbook_playing = tracknum;
			}
	}
		
		return (Redbook_playing != 0);
}
Example #10
0
// play track given by levelnum (depending on the music type and it's playing behaviour) or increment/decrement current track number via offset value
int songs_play_level_song( int levelnum, int offset )
{
    int songnum;

    Assert( levelnum != 0 );

    songs_init();
    if (!Songs_initialized)
        return 0;

    songnum = (levelnum>0)?(levelnum-1):(-levelnum);

    switch (GameCfg.MusicType)
    {
    case MUSIC_TYPE_BUILTIN:
    {
        if (offset)
            return Song_playing;

        Song_playing = -1;
        if ((Num_bim_songs - SONG_FIRST_LEVEL_SONG) > 0)
        {
            songnum = SONG_FIRST_LEVEL_SONG + (songnum % (Num_bim_songs - SONG_FIRST_LEVEL_SONG));
#ifdef _WIN32
            if (GameArg.SndDisableSdlMixer)
            {
                if (digi_win32_play_midi_song( BIMSongs[songnum].filename, 1 )) // NOTE: If SDL_mixer active, this will still be called in mix_play_file in case file is hmp
                {
                    Song_playing = songnum;
                }
            }
#ifdef USE_SDLMIXER
            else
#endif
#endif
#ifdef USE_SDLMIXER
            {
                if (mix_play_file(BIMSongs[songnum].filename, 1, NULL))
                {
                    Song_playing = songnum;
                }
            }
#endif
        }
        break;
    }
    case MUSIC_TYPE_REDBOOK:
    {
        int n_tracks = RBAGetNumberOfTracks();
        int tracknum;

        if (!offset)
        {
            // we have just been told to play the same as we do already -> ignore
            if (Song_playing >= SONG_FIRST_LEVEL_SONG && songnum + SONG_FIRST_LEVEL_SONG == Song_playing)
                return Song_playing;

            tracknum = REDBOOK_FIRST_LEVEL_TRACK + ((n_tracks<=REDBOOK_FIRST_LEVEL_TRACK) ? 0 : (songnum % (n_tracks-REDBOOK_FIRST_LEVEL_TRACK)));
        }
        else
        {
            tracknum = Redbook_playing+offset;
            if (tracknum < REDBOOK_FIRST_LEVEL_TRACK)
                tracknum = n_tracks - (REDBOOK_FIRST_LEVEL_TRACK - tracknum) + 1;
            else if (tracknum > n_tracks)
                tracknum = REDBOOK_FIRST_LEVEL_TRACK + (tracknum - n_tracks) - 1;
        }

        Song_playing = -1;
        if (RBAEnabled() && (tracknum <= n_tracks))
        {
            if (RBAPlayTracks(tracknum, !songs_haved1_cd()?n_tracks:tracknum, songs_haved1_cd() ? redbook_repeat_func : redbook_first_song_func))
            {
                Song_playing = songnum + SONG_FIRST_LEVEL_SONG;
                Redbook_playing = tracknum;
            }
        }
        break;
    }
#ifdef USE_SDLMIXER
    case MUSIC_TYPE_CUSTOM:
    {
        if (GameCfg.CMLevelMusicPlayOrder == MUSIC_CM_PLAYORDER_RAND)
            GameCfg.CMLevelMusicTrack[0] = d_rand() % GameCfg.CMLevelMusicTrack[1]; // simply a random selection - no check if this song has already been played. But that's how I roll!
        else if (!offset)
        {
            if (GameCfg.CMLevelMusicPlayOrder == MUSIC_CM_PLAYORDER_CONT)
            {
                static int last_songnum = -1;

                if (Song_playing >= SONG_FIRST_LEVEL_SONG)
                    return Song_playing;

                // As soon as we start a new level, go to next track
                if (last_songnum != -1 && songnum != last_songnum)
                    ((GameCfg.CMLevelMusicTrack[0]+1>=GameCfg.CMLevelMusicTrack[1])?GameCfg.CMLevelMusicTrack[0]=0:GameCfg.CMLevelMusicTrack[0]++);
                last_songnum = songnum;
            }
            else if (GameCfg.CMLevelMusicPlayOrder == MUSIC_CM_PLAYORDER_LEVEL)
                GameCfg.CMLevelMusicTrack[0] = (songnum % GameCfg.CMLevelMusicTrack[1]);
        }
        else
        {
            GameCfg.CMLevelMusicTrack[0] += offset;
            if (GameCfg.CMLevelMusicTrack[0] < 0)
                GameCfg.CMLevelMusicTrack[0] = GameCfg.CMLevelMusicTrack[1] + GameCfg.CMLevelMusicTrack[0];
            if (GameCfg.CMLevelMusicTrack[0] + 1 > GameCfg.CMLevelMusicTrack[1])
                GameCfg.CMLevelMusicTrack[0] = GameCfg.CMLevelMusicTrack[0] - GameCfg.CMLevelMusicTrack[1];
        }

        Song_playing = -1;
        if (jukebox_play())
            Song_playing = songnum + SONG_FIRST_LEVEL_SONG;

        break;
    }
#endif
    default:
        Song_playing = -1;
        break;
    }

    // If we couldn't play the song, most likely because it wasn't specified, play no music.
    if (Song_playing == -1)
        songs_stop_all();

    return Song_playing;
}
Example #11
0
File: songs.c Project: paud/d2x-xl
void songs_init()
{
	int i, bD1Songs;
	char inputline[80+1];
	CFILE * fp;

if ( gameData.songs.bInitialized ) 
	return;
CFUseD1HogFile("descent.hog");
for (bD1Songs = 0; bD1Songs < 2; bD1Songs++) {
	#if !defined(WINDOWS)
		if (!FindArg("-nomixer"))
			CD_blast_mixer();   // Crank it!
	#endif
	if (CFExist("descent.sng", gameFolders.szDataDir, bD1Songs)) {   // mac (demo?) datafiles don't have the .sng file
		fp = CFOpen( "descent.sng", gameFolders.szDataDir, "rb", bD1Songs );
		if ( fp == NULL ) {
			if (bD1Songs)
				break;
			else
				Error( "Couldn't open descent.sng" );
			}
		i = gameData.songs.nSongs;
		while (CFGetS(inputline, 80, fp ))
		{
			char *p = strchr(inputline,'\n');
			if (p) *p = '\0';
			if ( strlen( inputline ) )
			{
				Assert( i < MAX_NUM_SONGS );
				sscanf( inputline, "%s %s %s",
						gameData.songs.info[i].filename,
						gameData.songs.info[i].melodic_bank_file,
						gameData.songs.info[i].drum_bank_file );
				if (!gameData.songs.nFirstLevelSong [bD1Songs] && strstr (gameData.songs.info [i].filename, "game01.hmp"))
					 gameData.songs.nFirstLevelSong [bD1Songs] = i;
				if (bD1Songs && strstr (gameData.songs.info [i].filename, "endlevel.hmp"))
					gameData.songs.nD1EndLevelSong = i;

				////printf( "%d. '%s' '%s' '%s'\n",i,gameData.songs.info[i].filename,gameData.songs.info[i].melodic_bank_file,gameData.songs.info[i].drum_bank_file );
				i++;
			}
		}
		if (bD1Songs) 
			gameData.songs.nD1Songs = i - gameData.songs.nSongs;
		else
			gameData.songs.nD2Songs = i - gameData.songs.nSongs;
		gameData.songs.nSongs = i;
		gameData.songs.nLevelSongs [bD1Songs] = gameData.songs.nSongs - gameData.songs.nFirstLevelSong [bD1Songs];
		if (!gameData.songs.nFirstLevelSong [bD1Songs])
			Error("gameData.songs.info are missing.");
		CFClose(fp);
	}
	gameData.songs.bInitialized = 1;
	//	RBA Hook
	#if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
		if (!gameOpts->sound.bUseRedbook)
			gameStates.sound.bRedbookEnabled = 0;
		else	// use redbook
		{
			#ifndef __MSDOS__
				RBAInit();
			#else
				RBAInit(toupper(CDROM_dir[0]) - 'A');
			#endif

				if (RBAEnabled())
			{
				set_redbook_volume(gameConfig.nRedbookVolume);
				RBARegisterCD();
			}
		}
		atexit(RBAStop);    // stop song on exit
	#endif	// endof ifndef SHAREWARE, ie ifdef SHAREWARE
	}
}