2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
35 song_info Songs[MAX_NUM_SONGS];
36 int Songs_initialized = 0;
42 extern void digi_stop_current_song();
44 int Redbook_enabled = 1;
46 //0 if redbook is no playing, else the track number
47 int Redbook_playing = 0;
49 #define NumLevelSongs (Num_songs - SONG_FIRST_LEVEL_SONG)
51 extern int CD_blast_mixer();
54 #define REDBOOK_VOLUME_SCALE (255/3) //255 is MAX
56 #define REDBOOK_VOLUME_SCALE (255)
59 //takes volume in range 0..8
60 void set_redbook_volume(int volume)
63 RBASetVolume(0); // makes the macs sound really funny
65 RBASetVolume(volume*REDBOOK_VOLUME_SCALE/8);
68 extern char CDROM_dir[];
76 if ( Songs_initialized ) return;
79 #if !defined(MACINTOSH) && !defined(WINDOWS) // don't crank it if on a macintosh!!!!!
80 if (!FindArg("-nomixer"))
81 CD_blast_mixer(); // Crank it!
85 #ifndef MACINTOSH // macs don't use the .sng file
86 fp = cfopen( "descent.sng", "rb" );
89 Error( "Couldn't open descent.sng" );
92 while (cfgets(inputline, 80, fp ))
94 char *p = strchr(inputline,'\n');
96 if ( strlen( inputline ) )
98 Assert( i < MAX_NUM_SONGS );
99 sscanf( inputline, "%s %s %s",
101 Songs[i].melodic_bank_file,
102 Songs[i].drum_bank_file );
103 //printf( "%d. '%s' '%s' '%s'\n",i,Songs[i].filename,Songs[i].melodic_bank_file,Songs[i].drum_bank_file );
108 if (Num_songs <= SONG_FIRST_LEVEL_SONG)
109 Error("Must have at least %d songs",SONG_FIRST_LEVEL_SONG+1);
111 #endif // endof ifdef macintosh for dealing with the .sng file
113 Songs_initialized = 1;
116 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
117 if (FindArg("-noredbook"))
123 #if defined(WINDOWS) || defined(MACINTOSH)
126 RBAInit(toupper(CDROM_dir[0]) - 'A');
131 set_redbook_volume(Config_redbook_volume);
135 //atexit(RBAStop); // stop song on exit
136 #endif // endof ifndef SHAREWARE, ie ifdef SHAREWARE
139 #define FADE_TIME (f1_0/2)
141 //stop the redbook, so we can read off the CD
142 void songs_stop_redbook(void)
144 int old_volume = Config_redbook_volume*REDBOOK_VOLUME_SCALE/8;
145 fix old_time = timer_get_fixed_seconds();
147 if (Redbook_playing) { //fade out volume
150 fix t = timer_get_fixed_seconds();
152 new_volume = fixmuldiv(old_volume,(FADE_TIME - (t-old_time)),FADE_TIME);
157 RBASetVolume(new_volume);
159 } while (new_volume > 0);
162 //RBAStop(); // Stop CD, if playing
164 RBASetVolume(old_volume); //restore volume
170 //stop any songs - midi or redbook - that are currently playing
171 void songs_stop_all(void)
173 digi_stop_current_song(); // Stop midi song, if playing
175 songs_stop_redbook(); // Stop CD, if playing
178 int force_rb_register=0;
180 void reinit_redbook()
182 #if defined(WINDOWS) || defined(MACINTOSH)
185 RBAInit(toupper(CDROM_dir[0]) - 'A');
190 set_redbook_volume(Config_redbook_volume);
197 //returns 1 if track started sucessfully
198 //start at tracknum. if keep_playing set, play to end of disc. else
199 //play only specified track
200 int play_redbook_track(int tracknum,int keep_playing)
204 if (!RBAEnabled() && Redbook_enabled && !FindArg("-noredbook"))
207 if (force_rb_register) {
208 RBARegisterCD(); //get new track list for new CD
209 force_rb_register = 0;
212 if (Redbook_enabled && RBAEnabled()) {
213 int num_tracks = RBAGetNumberOfTracks();
214 if (tracknum <= num_tracks)
215 if (RBAPlayTracks(tracknum,keep_playing?num_tracks:tracknum)) {
216 Redbook_playing = tracknum;
220 return (Redbook_playing != 0);
223 #define REDBOOK_TITLE_TRACK 2
224 #define REDBOOK_CREDITS_TRACK 3
225 #define REDBOOK_FIRST_LEVEL_TRACK (songs_haved2_cd()?4:1)
227 // songs_haved2_cd returns 1 if the descent 2 CD is in the drive and
230 int songs_haved2_cd()
232 char temp[128],cwd[128];
236 strcpy(temp,CDROM_dir);
238 #ifndef MACINTOSH //for PC, strip of trailing slash
239 if (temp[strlen(temp)-1] == '\\')
240 temp[strlen(temp)-1] = 0;
243 if ( !chdir(temp) ) {
252 void songs_play_song( int songnum, int repeat )
255 Assert(songnum != SONG_ENDLEVEL && songnum != SONG_ENDGAME); //not in full version
258 if ( !Songs_initialized )
261 //stop any music already playing
265 //do we want any of these to be redbook songs?
267 if (force_rb_register) {
268 RBARegisterCD(); //get new track list for new CD
269 force_rb_register = 0;
272 if (songnum == SONG_TITLE)
273 play_redbook_track(REDBOOK_TITLE_TRACK,0);
274 else if (songnum == SONG_CREDITS)
275 play_redbook_track(REDBOOK_CREDITS_TRACK,0);
277 if (!Redbook_playing) { //not playing redbook, so play midi
280 digi_play_midi_song( Songs[songnum].filename, Songs[songnum].melodic_bank_file, Songs[songnum].drum_bank_file, repeat );
282 digi_play_midi_song(songnum, repeat);
287 int current_song_level;
289 void songs_play_level_song( int levelnum )
294 Assert( levelnum != 0 );
296 if ( !Songs_initialized )
301 current_song_level = levelnum;
303 songnum = (levelnum>0)?(levelnum-1):(-levelnum);
305 if (!RBAEnabled() && Redbook_enabled && !FindArg("-noredbook"))
308 if (force_rb_register) {
309 RBARegisterCD(); //get new track list for new CD
310 force_rb_register = 0;
313 if (Redbook_enabled && RBAEnabled() && (n_tracks = RBAGetNumberOfTracks()) > 1) {
315 //try to play redbook
317 mprintf((0,"n_tracks = %d\n",n_tracks));
319 play_redbook_track(REDBOOK_FIRST_LEVEL_TRACK + (songnum % (n_tracks-REDBOOK_FIRST_LEVEL_TRACK+1)),1);
322 if (! Redbook_playing) { //not playing redbook, so play midi
324 songnum = SONG_FIRST_LEVEL_SONG + (songnum % NumLevelSongs);
327 digi_play_midi_song( Songs[songnum].filename, Songs[songnum].melodic_bank_file, Songs[songnum].drum_bank_file, 1 );
329 digi_play_midi_song( songnum, 1 );
335 //this should be called regularly to check for redbook restart
336 void songs_check_redbook_repeat()
338 static fix last_check_time;
341 if (!Redbook_playing || Config_redbook_volume==0) return;
343 current_time = timer_get_fixed_seconds();
344 if (current_time < last_check_time || (current_time - last_check_time) >= F2_0) {
345 if (!RBAPeekPlayStatus()) {
347 // if title ends, start credit music
348 // if credits music ends, restart it
349 if (Redbook_playing == REDBOOK_TITLE_TRACK || Redbook_playing == REDBOOK_CREDITS_TRACK)
350 play_redbook_track(REDBOOK_CREDITS_TRACK,0);
352 //songs_goto_next_song();
354 //new code plays all tracks to end of disk, so if disk has
355 //stopped we must be at end. So start again with level 1 song.
357 songs_play_level_song(1);
361 last_check_time = current_time;
365 //goto the next level song
366 void songs_goto_next_song()
368 if (Redbook_playing) //get correct track
369 current_song_level = RBAGetTrackNum() - REDBOOK_FIRST_LEVEL_TRACK + 1;
371 songs_play_level_song(current_song_level+1);
375 //goto the previous level song
376 void songs_goto_prev_song()
378 if (Redbook_playing) //get correct track
379 current_song_level = RBAGetTrackNum() - REDBOOK_FIRST_LEVEL_TRACK + 1;
381 if (current_song_level > 1)
382 songs_play_level_song(current_song_level-1);