$NetBSD: patch-ah,v 1.5 2006/08/12 14:51:39 darcy Exp $ --- internals.c.orig Tue Jan 12 19:59:45 1993 +++ internals.c @@ -22,6 +22,9 @@ # include "debug.h" # include "cdrom_globs.h" +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) +# include "cdrom_freebsd.h" +#endif #ifdef sun # include "cdrom_sun.h" #endif @@ -29,13 +32,14 @@ # include "cdrom_sgi.h" #endif - +static void scan_update(); static XtIntervalId ivid = -1; static XtIntervalId scanivid = -1; static XtIntervalId stativid = -1; static unsigned int timer_mod = 1000 / TIMER_PERIOD; unsigned int timer_fsecs; +extern AppData app_data; int cdrom_get_curtime() { @@ -76,6 +80,170 @@ cdrom_get_curtime() { } } +/* + * called by update_track when the cd has hit + * the end of the track or the disc. + */ +static void +cdrom_atend() { + cdrom_timer_off(); + leds_stop(); + debug_printf(1, "cdrom_atend: at end\n"); + +#ifdef sgi + /* Force a stop to kill the child (if any). + * This is due to some sort of weirdness when the SGI runs off the + * disc during a CDreadda(). + */ + if (cdi.scsi_audio) { + cdrom_stop(); + } +#endif + if (cdi.state & CDROM_STATE_SHUFFLE) { + + if (cdi.currand == cdi.ntracks) { + if ((cdi.state & CDROM_STATE_CYCLE) == 0) { + debug_printf(1, "cdrom_atend: shuffle done\n"); + + cdrom_reset(); + return; + } + + debug_printf(1, "cdrom_atend: shuffle cycling\n"); + shuffle_setup(); + } + + cdi.curtrack = shuffle_next_track(); + } + else if (cdi.state & CDROM_STATE_PROGRAM) { + if ((cdi.curtrack = program_goto_next_track()) == 0) + { + if (cdi.state & CDROM_STATE_CYCLE) + { + debug_printf(1, "cdrom_atend: cycling program\n"); + cdi.curtrack = program_resume(); + timer_fsecs = 0; + cdi.duration = 0; + timer_button_update(); + + (void) cdrom_play(); + } + else + { + debug_printf(1, "cdrom_atend: all done\n"); + cdrom_reset(); + } + return; + } + } + + else if ((cdi.curtrack < cdi.maxtrack) && (cdi.curtrack != 0)) { + debug_printf(1, "cdrom_atend: continuing\n"); + cdi.curtrack++; + } + else if (cdi.state & CDROM_STATE_CYCLE) { + debug_printf(1, "cdrom_atend: cycling\n"); + cdi.curtrack = cdi.mintrack; + } + else { + debug_printf(1, "cdrom_atend: all done\n"); + buttons_reset(); + cdrom_reset(); + return; + } + + timer_fsecs = 0; + cdi.duration = 0; + timer_button_update(); + + (void) cdrom_play(); +} + +/* + * update_track is called when the timeout fires; it updates curtrack and + * calls the label update routine. + */ +/*ARGSUSED*/ +static void +update_track(data, id) + XtPointer *data; + XtIntervalId *id; +{ + unsigned int curtrack; + Arg args[1]; + Boolean state; + + extern Widget rew_button_widget; + extern Widget ff_button_widget; +#ifdef sgi + + int vol; +#endif + + if ((curtrack = cdrom_get_curtrack()) != cdi.curtrack) { + if (curtrack == 0) { + cdrom_atend(); + + return; + } + + timer_fsecs = 0; + cdi.duration = 0; + timer_button_update(); + + cdi.curtrack = curtrack; + track_button_update(); + } + +#ifdef sgi + /* Update the volume control */ + if ((vol = cdrom_get_volume()) != 0) { + set_volume(vol); + } +#endif + + XtSetArg(args[0], XtNstate, &state); + XtGetValues(rew_button_widget, args, 1); + if (state == True) + { + cdrom_rewind(); + leds_update(BACKWARDS); + if (cdi.state & CDROM_STATE_PAUSE) { + if (cdrom_pause() != -1) + cdi.state &= ~CDROM_STATE_STOP; + } + ivid = XtAppAddTimeOut(appc, + (int)(app_data.scanPauseInterval * 1000.0), + update_track, NULL); + } + else + { + leds_update(FORWARDS); + XtSetArg(args[0], XtNstate, &state); + XtGetValues(ff_button_widget, args, 1); + if (state == True) + { + cdrom_ff(); + if (cdi.state & CDROM_STATE_PAUSE) { + if (cdrom_pause() != -1) + cdi.state &= ~CDROM_STATE_STOP; + } + + ivid = XtAppAddTimeOut(appc, + (int)(app_data.scanPauseInterval * 1000.0), + update_track, NULL); + } + else + { + if ((timer_fsecs++ % timer_mod) == 0) { + timer_button_update(); + } + ivid = XtAppAddTimeOut(appc, TIMER_PERIOD, + update_track, NULL); + } + } +} + /* * we poll the cd-rom drive every TIMER_PERIOD milliseconds to see where @@ -83,8 +251,6 @@ cdrom_get_curtime() { */ void cdrom_timer_on() { - static void update_track(); - if (cdi.state & CDROM_STATE_PLAY) ivid = XtAppAddTimeOut(appc, TIMER_PERIOD, update_track, NULL); } @@ -170,7 +336,6 @@ cdrom_rewind () { struct msf track_start; struct msf start_addr, end_addr; int curtrack; - extern void scan_update(); if (cdrom_get_curmsf(&start_addr) == -1) { debug_printf(1, "rew: error reading location\n"); @@ -196,11 +361,11 @@ cdrom_rewind () { if (((cdi.state & CDROM_STATE_PLAY) && ((track_start.minute * 60) + track_start.second) >= ((start_addr.minute * 60) + start_addr.second - - scanSkipInterval)) || + app_data.scanSkipInterval)) || ((cdi.state & CDROM_STATE_PAUSE) && ((track_start.minute * 60) + track_start.second) >= ((start_addr.minute * 60) + start_addr.second - - pauseSkipInterval))) + app_data.pauseSkipInterval))) { start_addr = track_start; start_addr.second++; /* guarantee we never back up too far */ @@ -208,9 +373,9 @@ cdrom_rewind () { else { if (cdi.state & CDROM_STATE_PAUSE) { - start_addr.second -= pauseSkipInterval; + start_addr.second -= app_data.pauseSkipInterval; } else if (cdi.state & CDROM_STATE_PLAY) { - start_addr.second -= scanSkipInterval; + start_addr.second -= app_data.scanSkipInterval; } if ((char) start_addr.second < 0) { @@ -223,9 +388,9 @@ cdrom_rewind () { else /* normal case */ { if (cdi.state & CDROM_STATE_PAUSE) { - start_addr.second -= pauseSkipInterval; + start_addr.second -= app_data.pauseSkipInterval; } else if (cdi.state & CDROM_STATE_PLAY) { - start_addr.second -= scanSkipInterval; + start_addr.second -= app_data.scanSkipInterval; } if ((char) start_addr.second < 0) { @@ -274,7 +439,7 @@ cdrom_rewind () { { if (scanivid == -1) scanivid = XtAppAddTimeOut(appc, - (int)(pausePauseInterval * 1000.0), + (int)(app_data.pausePauseInterval * 1000.0), scan_update, NULL); cdi.state &= ~CDROM_STATE_PAUSE; /* allow timer to change */ @@ -304,7 +469,6 @@ cdrom_ff () { struct msf start_addr, end_addr, next_start; char t; int curtrack; - extern void scan_update(); if (cdrom_get_curmsf(&start_addr) == -1) { debug_printf(1, "ff: error reading location\n"); @@ -332,11 +496,11 @@ cdrom_ff () { if (((cdi.state & CDROM_STATE_PLAY) && ((next_start.minute * 60) + next_start.second) <= ((start_addr.minute * 60) + start_addr.second + - scanSkipInterval)) || + app_data.scanSkipInterval)) || ((cdi.state & CDROM_STATE_PAUSE) && ((next_start.minute * 60) + next_start.second) <= ((start_addr.minute * 60) + start_addr.second + - pauseSkipInterval))) + app_data.pauseSkipInterval))) { /* start at end of current track */ @@ -346,9 +510,9 @@ cdrom_ff () { else { if (cdi.state & CDROM_STATE_PAUSE) { - start_addr.second += pauseSkipInterval; + start_addr.second += app_data.pauseSkipInterval; } else if (cdi.state & CDROM_STATE_PLAY) { - start_addr.second += scanSkipInterval; + start_addr.second += app_data.scanSkipInterval; } if (start_addr.second >= 60) { @@ -360,9 +524,9 @@ cdrom_ff () { else { if (cdi.state & CDROM_STATE_PAUSE) { - start_addr.second += pauseSkipInterval; + start_addr.second += app_data.pauseSkipInterval; } else if (cdi.state & CDROM_STATE_PLAY) { - start_addr.second += scanSkipInterval; + start_addr.second += app_data.scanSkipInterval; } if (start_addr.second >= 60) { @@ -413,7 +577,7 @@ cdrom_ff () { { if (scanivid == -1) scanivid = XtAppAddTimeOut(appc, - (int)(pausePauseInterval * 1000.0), + (int)(app_data.pausePauseInterval * 1000.0), scan_update, NULL); cdi.state &= ~CDROM_STATE_PAUSE; /* allow timer to change */ @@ -435,85 +599,6 @@ cdrom_ff () { /* - * called by update_track when the cd has hit - * the end of the track or the disc. - */ -static void -cdrom_atend() { - cdrom_timer_off(); - leds_stop(); - debug_printf(1, "cdrom_atend: at end\n"); - -#ifdef sgi - /* Force a stop to kill the child (if any). - * This is due to some sort of weirdness when the SGI runs off the - * disc during a CDreadda(). - */ - if (cdi.scsi_audio) { - cdrom_stop(); - } -#endif - if (cdi.state & CDROM_STATE_SHUFFLE) { - - if (cdi.currand == cdi.ntracks) { - if ((cdi.state & CDROM_STATE_CYCLE) == 0) { - debug_printf(1, "cdrom_atend: shuffle done\n"); - - cdrom_reset(); - return; - } - - debug_printf(1, "cdrom_atend: shuffle cycling\n"); - shuffle_setup(); - } - - cdi.curtrack = shuffle_next_track(); - } - else if (cdi.state & CDROM_STATE_PROGRAM) { - if ((cdi.curtrack = program_goto_next_track()) == 0) - { - if (cdi.state & CDROM_STATE_CYCLE) - { - debug_printf(1, "cdrom_atend: cycling program\n"); - cdi.curtrack = program_resume(); - timer_fsecs = 0; - cdi.duration = 0; - timer_button_update(); - - (void) cdrom_play(); - } - else - { - debug_printf(1, "cdrom_atend: all done\n"); - cdrom_reset(); - } - return; - } - } - - else if ((cdi.curtrack < cdi.maxtrack) && (cdi.curtrack != 0)) { - debug_printf(1, "cdrom_atend: continuing\n"); - cdi.curtrack++; - } - else if (cdi.state & CDROM_STATE_CYCLE) { - debug_printf(1, "cdrom_atend: cycling\n"); - cdi.curtrack = cdi.mintrack; - } - else { - debug_printf(1, "cdrom_atend: all done\n"); - buttons_reset(); - cdrom_reset(); - return; - } - - timer_fsecs = 0; - cdi.duration = 0; - timer_button_update(); - - (void) cdrom_play(); -} - -/* * scan_update is called when the scan timeout fires; it updates the timer * and calls the label update routine. */ @@ -557,7 +642,7 @@ scan_update(data, id) cdi.state &= ~CDROM_STATE_STOP; } ivid = XtAppAddTimeOut(appc, - (int)(scanPauseInterval * 1000.0), + (int)(app_data.scanPauseInterval * 1000.0), scan_update, NULL); } else @@ -574,7 +659,7 @@ scan_update(data, id) } ivid = XtAppAddTimeOut(appc, - (int)(scanPauseInterval * 1000.0), + (int)(app_data.scanPauseInterval * 1000.0), scan_update, NULL); } else if (scanivid != -1) { @@ -607,89 +692,3 @@ update_status(data, id) /* Reset timer */ stativid = XtAppAddTimeOut(appc, 1000, update_status, NULL); } - -/* - * update_track is called when the timeout fires; it updates curtrack and - * calls the label update routine. - */ -/*ARGSUSED*/ -static void -update_track(data, id) - XtPointer *data; - XtIntervalId *id; -{ - unsigned int curtrack; - Arg args[1]; - Boolean state; - - extern Widget rew_button_widget; - extern Widget ff_button_widget; -#ifdef sgi - - int vol; -#endif - - if ((curtrack = cdrom_get_curtrack()) != cdi.curtrack) { - if (curtrack == 0) { - cdrom_atend(); - - return; - } - - timer_fsecs = 0; - cdi.duration = 0; - timer_button_update(); - - cdi.curtrack = curtrack; - track_button_update(); - } - -#ifdef sgi - /* Update the volume control */ - if ((vol = cdrom_get_volume()) != 0) { - set_volume(vol); - } -#endif - - XtSetArg(args[0], XtNstate, &state); - XtGetValues(rew_button_widget, args, 1); - if (state == True) - { - cdrom_rewind(); - leds_update(BACKWARDS); - if (cdi.state & CDROM_STATE_PAUSE) { - if (cdrom_pause() != -1) - cdi.state &= ~CDROM_STATE_STOP; - } - ivid = XtAppAddTimeOut(appc, - (int)(scanPauseInterval * 1000.0), - update_track, NULL); - } - else - { - leds_update(FORWARDS); - XtSetArg(args[0], XtNstate, &state); - XtGetValues(ff_button_widget, args, 1); - if (state == True) - { - cdrom_ff(); - if (cdi.state & CDROM_STATE_PAUSE) { - if (cdrom_pause() != -1) - cdi.state &= ~CDROM_STATE_STOP; - } - - ivid = XtAppAddTimeOut(appc, - (int)(scanPauseInterval * 1000.0), - update_track, NULL); - } - else - { - if ((timer_fsecs++ % timer_mod) == 0) { - timer_button_update(); - } - ivid = XtAppAddTimeOut(appc, TIMER_PERIOD, - update_track, NULL); - } - } -} -