/* A "poor-man's" CD player for OS/2 using REXX */
/* Xavier Caballe - December 1993               */

/* Initialize MCIAPI */
call RxFuncAdd 'mciRxInit', 'MCIAPI', 'mciRxInit';
call mciRxInit;

/* Initialize variables */
A = 0;
P = 0;

/* Open a CD for subsequent manipulation */
Ordre = 'open cdaudio01 alias cederom wait';
call Executa;
say '';

/* Get the number of tracks on the disk */
Ordre = 'status cederom number of tracks wait';
call Executa;
say 'Songs on the CD disk:' RetStr;
Cancons = RetStr;

/* Get the beginning of each track */
do until A = Cancons
   A = A + 1;
   Ordre = 'status cederom position track 'A' wait';
   call Executa;
   say 'The track number 'A' begins at:' RetStr;
   P.A = RetStr;
end;

/* Get the last track */
Ordre = 'status cederom length wait';
call Executa;
say 'Last track on the CD disk:' RetStr;
UltimaPista = RetStr;

/* Data input */
Repetir:
say '';
say 'Which song will you listen? ';
pull Numero;
NumeroPlus1 = Numero + 1;
CanconsPlus1 = Cancons + 1;
P.CanconsPlus1 = UltimaPista;
if Numero < 1 | Numero > Cancons then do;
   say 'Wrong answer.';
   Signal Repetir;
end;

/* Play the selected song */
Ordre = 'play cederom from 'P.Numero' to 'P.NumeroPlus1' wait';
call Executa;

/* That's all, folks! */
Ordre = 'close cederom';
call Executa;
call mciRxExit;
exit;

/* Send a MCI command string to MMPM/2 */
Executa:

rc = mciRxSendString(Ordre, 'RetStr', '0', '0');
if (rc <> 0) then do
   say "Error No = " Ordre;
   say 'Code No. = ' rc;
   GetErr = mciRxGetErrorString(rc, 'ErrStVar');
   say 'Message  =' ErrStVar;
end;
return