home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 November / CDVD1105.ISO / Software / Freeware / programare / bass / Delphi / multi / Unit1.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2005-09-14  |  2.4 KB  |  100 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, Bass;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     GroupBox1: TGroupBox;
  12.     GroupBox2: TGroupBox;
  13.     Button1: TButton;
  14.     Button2: TButton;
  15.     OpenDialog1: TOpenDialog;
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  18.     procedure Button1Click(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.     outdev: array[0..1] of DWORD;
  24.     chan: array[0..1] of HSTREAM;
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. uses Unit2;
  33.  
  34. {$R *.dfm}
  35.  
  36. procedure TForm1.FormCreate(Sender: TObject);
  37. begin
  38.   if (BASS_GetVersion <> DWORD(MAKELONG(2,2))) then
  39.   begin
  40.         MessageBox(0, 'BASS version 2.2 was not loaded', 'Incorrect BASS.DLL', 0);
  41.     Halt;
  42.   end;
  43.  
  44.   Application.CreateForm(TForm2, Form2);
  45.   Form2.Caption := 'select output device #1';
  46.   outdev[0] := Form2.ShowModal;
  47.   Form2.Free;
  48.   Application.CreateForm(TForm2, Form2);
  49.   Form2.Caption := 'select output device #2';
  50.   outdev[1] := Form2.ShowModal;
  51.   Form2.Free;
  52.  
  53.   if (not BASS_Init(outdev[0], 44100, 0, Handle, nil)) then
  54.   begin
  55.     MessageBox(0, PChar('Cant''t initialize device 1' + #13#10 + 'Error #' + IntToStr(BASS_ErrorGetCode)), 'Error', MB_ICONERROR);
  56.     Halt;
  57.   end;
  58.   if (not BASS_Init(outdev[1], 44100, 0, Handle, nil)) then
  59.   begin
  60.     MessageBox(0, PChar('Cant''t initialize device 2' + #13#10 + 'Error #' + IntToStr(BASS_ErrorGetCode)), 'Error', MB_ICONERROR);
  61.     Halt;
  62.   end;
  63. end;
  64.  
  65. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  66. begin
  67.   BASS_SetDevice(outdev[0]);
  68.   BASS_Free;
  69.   BASS_SetDevice(outdev[1]);
  70.   BASS_Free;
  71.  
  72.   Action := caFree;
  73. end;
  74.  
  75. procedure TForm1.Button1Click(Sender: TObject);
  76. var
  77.   curdev: Integer;
  78. begin
  79.   if (not OpenDialog1.Execute) then
  80.     Exit;
  81.  
  82.   curdev := TButton(Sender).Tag;
  83.  
  84.   BASS_StreamFree(chan[curdev]);
  85.   BASS_SetDevice(outdev[curdev]);
  86.  
  87.   chan[curdev] := BASS_StreamCreateFile(False, PChar(OpenDialog1.FileName), 0, 0, BASS_SAMPLE_LOOP);
  88.   if (chan[curdev] = 0) then
  89.   begin
  90.     TButton(Sender).Caption := 'click here to open a file...';
  91.     MessageBox(0, 'Can''t play the file', 'Error', MB_ICONERROR);
  92.     Exit;
  93.   end;
  94.  
  95.   TButton(Sender).Caption := OpenDialog1.FileName;
  96.   BASS_ChannelPlay(chan[curdev], False);
  97. end;
  98.  
  99. end.
  100.