00001 #include "common.h"
00002 #include <signal.h>
00003
00004 int repeat= 1;
00005
00006 void stopplay (int signo);
00007 void hhmmss (u_int16_t seconds, u_int16_t *hh, u_int16_t *mm, u_int16_t *ss);
00008 void usage (void);
00009
00010 int main (int argc, char **argv)
00011 {
00012 njb_t njbs[NJB_MAX_DEVICES], *njb;
00013 int i, n, status, change, opt, debug;
00014 u_int16_t sec, hh, mm, ss;
00015 u_int32_t trackid;
00016 extern char *optarg;
00017 extern int optind;
00018
00019 debug= 0;
00020
00021 while ( (opt= getopt(argc, argv, "D:")) != -1 ) {
00022 switch (opt) {
00023 case 'D':
00024 debug= atoi(optarg);
00025 break;
00026 default:
00027 break;
00028 }
00029 }
00030 argc-= optind;
00031 argv+= optind;
00032
00033 if ( ! argc ) usage();
00034
00035 if ( debug ) NJB_Set_Debug(debug);
00036
00037 signal(SIGINT, stopplay);
00038
00039 if (NJB_Discover(njbs, 0, &n) == -1) {
00040 fprintf(stderr, "could not locate any jukeboxes\n");
00041 return 1;
00042 }
00043
00044 if ( n == 0 ) {
00045 fprintf(stderr, "no NJB devices found\n");
00046 return 0;
00047 }
00048
00049 njb= njbs;
00050
00051 if ( NJB_Open(njb) == -1 ) {
00052 NJB_Error_Dump(njb,stderr);
00053 return 1;
00054 }
00055
00056 if ( NJB_Capture(njb) == -1 ) {
00057 NJB_Error_Dump(njb,stderr);
00058 return 1;
00059 }
00060
00061 for (i= 0; i< argc; i++) {
00062 trackid= strtoul(argv[i], NULL, 10);
00063
00064 if ( i == 0 ) {
00065 status= NJB_Play_Track(njb, trackid);
00066 } else {
00067 status= NJB_Queue_Track(njb, trackid);
00068 }
00069
00070 if ( status == -1 ) NJB_Error_Dump(njb,stderr);
00071 }
00072
00073 printf("---> Hit ^C to exit <---\n");
00074
00075 change= 0;
00076 i= 0;
00077 printf("Track ID %10.10s: 00:00:00\b\b\b\b\b\b\b", argv[i]);
00078 fflush(stdout);
00079 while ( repeat ) {
00080 if ( change ) {
00081 i++;
00082 if ( i == argc ) {
00083 repeat= 0;
00084 } else {
00085 printf("\rTrack ID %10.10s: 00:00:00\b\b\b\b\b\b\b",
00086 argv[i]);
00087 fflush(stdout);
00088 }
00089 change= 0;
00090 } else
00091 NJB_Elapsed_Time(njb, &sec, &change);
00092 hhmmss(sec, &hh, &mm, &ss);
00093 printf("%02u:%02u:%02u\b\b\b\b\b\b\b\b", hh, mm, ss);
00094 fflush(stdout);
00095
00096 sleep(1);
00097 }
00098 printf("\n");
00099
00100 NJB_Stop_Play(njb);
00101
00102 NJB_Release(njb);
00103
00104 NJB_Close(njb);
00105 return 0;
00106 }
00107
00108 void stopplay (int signo)
00109 {
00110 repeat= 0;
00111 }
00112
00113 void hhmmss (u_int16_t seconds, u_int16_t *hh, u_int16_t *mm, u_int16_t *ss)
00114 {
00115 if ( seconds >= 3600 ) *hh= seconds/3600;
00116 seconds-= 3600*(*hh);
00117 if ( seconds >= 60 ) *mm= seconds/60;
00118 *ss= seconds-(60*(*mm));
00119 }
00120
00121 void usage (void) {
00122 fprintf(stderr, "usage: play [ -D debuglvl ] <trackid> ...\n");
00123 exit(1);
00124 }