home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cdtest.pas < prev    next >
Pascal/Delphi Source File  |  1996-11-24  |  5KB  |  139 lines

  1. (*--------------------------------------------------------------------*)
  2. (*                                                                    *)
  3. (* Program  . . . . . .  CDTEST                                       *)
  4. (* Source file  . . . .  CDTEST.PAS                                   *)
  5. (* Language . . . . . .  Object Pascal                                *)
  6. (* Compiler . . . . . .  Virtual Pascal/2 V1.10                       *)
  7. (* Operating system . .  OS/2 Warp V3                                 *)
  8. (* Author . . . . . . .  Th. Trepl, Munich Germany                    *)
  9. (*                       101353,671@CompuServ.com                     *)
  10. (* Reference  . . . . .  -                                            *)
  11. (*                                                                    *)
  12. (*--------------------------------------------------------------------*)
  13. (*                                                                    *)
  14. (* Description                                                        *)
  15. (* -----------                                                        *)
  16. (*                                                                    *)
  17. (* A very simple program to play audio tracks of a CD-ROM drive.      *)
  18. (* It build a random queue of all the titles and plays them.          *)
  19. (* Control is available using the keyboard.                           *)
  20. (*                                                                    *)
  21. (* The only sence of the program is to demonstrate the usage of the   *)
  22. (* modules CDAUDIO.PAS and CDBASE.PAS.                                *)
  23. (*                                                                    *)
  24. (* Key     Function                                                   *)
  25. (*  X      Exit the program                                           *)
  26. (*  +      Play next title of random queue                            *)
  27. (*  P      Set CD-Player in Pause Mode                                *)
  28. (*  R      Resume from Pause Mode                                     *)
  29. (*                                                                    *)
  30. (*--------------------------------------------------------------------*)
  31. Program CdTest;
  32. Uses Crt, CDAudio;
  33.  
  34. Var CD : TCDPlayer;
  35.     SelectedSongs : Array[1..255] Of Byte;
  36.     N, Cnt : Integer;
  37.     c : Char;
  38.     EndLoop : Boolean;
  39.  
  40. Procedure BuildRandom;
  41. Var i, t, Cnt : Integer;
  42.     TrackTbl : Array[1..255] Of Byte;
  43. Begin
  44.   WriteLn('Random sequence:');
  45.   i := 1;
  46.   For t:=CD.FirstTrack To CD.LastTrack Do
  47.     Begin
  48.       TrackTbl[i] := t;
  49.       Inc(i);
  50.     End;
  51.  
  52.   Randomize;
  53.   Cnt := CD.LastTrack - CD.FirstTrack + 1;
  54.   t := 1;
  55.   While Cnt > 1 Do
  56.     Begin
  57.       i := Random(Cnt) + 1;
  58.       SelectedSongs[t] := TrackTbl[i];
  59.       Write(' ',SelectedSongs[t]);
  60.       Move(TrackTbl[i+1], TrackTbl[i], 255-i);
  61.       Dec(Cnt);
  62.       Inc(t);
  63.     End;
  64.   SelectedSongs[t] := TrackTbl[1];
  65.   Write(' ',SelectedSongs[t]);
  66.   WriteLn;
  67.   WriteLn;
  68. End;
  69.  
  70. Procedure WriteStatus(Fnct : String);
  71. Var Track, Minute, Second : Byte;
  72. Begin
  73.   CD.CurrentPos(Track, Minute, Second);
  74.   Write('(',Fnct,') -',Track:3,': ');
  75.   If Minute < 10 Then Write('0');
  76.   Write(Minute, ':');
  77.   If Second < 10 Then Write('0');
  78.   Write(Second);
  79.   ClrEoL;
  80.   Write(^M);
  81. End;
  82.  
  83. Begin
  84.   WriteLn;
  85.   WriteLn('Simplest CD-Player');
  86.   WriteLn('------------------');
  87.   WriteLn;
  88.   WriteLn('X - Exit program');
  89.   Writeln('+ - Next title of queue');
  90.   Writeln('P - Pause');
  91.   Writeln('R - Resume from pause');
  92.   Writeln;
  93.   CD := TCDPlayer.Create(Nil);
  94.   CD.OpenPlayer(cDefaultDrive);
  95.  
  96.   BuildRandom;
  97.  
  98.   Cnt := CD.LastTrack - CD.FirstTrack + 1;
  99.   For N:=1 To Cnt Do
  100.     Begin
  101.       CD.Play(SelectedSongs[N]);
  102.       EndLoop := False;
  103.       Repeat
  104.         WriteStatus('Play ');
  105.         Delay(500);
  106.         C := #0;
  107.         If KeyPressed Then
  108.           Begin
  109.             c := UpCase(ReadKey);
  110.             Case c Of
  111.               '+' : Begin
  112.                       CD.Stop;
  113.                       EndLoop := True;
  114.                     End;
  115.               'P' : Begin { Pause }
  116.                       CD.Stop;
  117.                       WriteStatus('Pause');
  118.                       Repeat
  119.                         c := UpCase(ReadKey);
  120.                       Until c In ['X','R'];
  121.                       If c = 'R'
  122.                         Then CD.Resume
  123.                         Else EndLoop := True;
  124.                     End;
  125.               'X' : Begin { eXit }
  126.                       CD.Stop;
  127.                       EndLoop := True;
  128.                     End;
  129.             End;
  130.           End;
  131.         EndLoop := EndLoop Or Not CD.Playing;
  132.       Until EndLoop;
  133.       If C = 'X' Then Break;
  134.     End;
  135.  
  136.   CD.Destroy;
  137. End.
  138.  
  139.