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

  1. unit frmMain;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, ComCtrls, StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     GroupBox1: TGroupBox;
  12.     ListBox1: TListBox;
  13.     Button1: TButton;
  14.     Label1: TLabel;
  15.     TrackBar1: TTrackBar;
  16.     Timer1: TTimer;
  17.     OpenDialog1: TOpenDialog;
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure FormDestroy(Sender: TObject);
  20.     procedure Timer1Timer(Sender: TObject);
  21.     procedure TrackBar1Change(Sender: TObject);
  22.     procedure Button1Click(Sender: TObject);
  23.   private
  24.     { Private declarations }
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. uses Bass;
  35.  
  36. var
  37.   chan: HSTREAM;
  38.  
  39. {$R *.dfm}
  40.  
  41. // display error messages
  42. procedure Error(es: String);
  43. begin
  44.   MessageBox(Application.Handle, PChar(es + #13#10 + '(error code: ' + IntToStr(BASS_ErrorGetCode()) + ')'), PChar('Error'), MB_OK);
  45. end;
  46.  
  47. procedure TForm1.FormCreate(Sender: TObject);
  48. var
  49.   sRec: TSearchRec;
  50.   i: Integer;
  51. begin
  52.     // Check that BASS 2.2 was loaded
  53.     if (BASS_GetVersion <> DWORD(MAKELONG(2,2))) then
  54.   begin
  55.         MessageBox(0,'BASS version 2.2 was not loaded','Incorrect BASS.DLL',0);
  56.         Halt;
  57.     end;
  58.  
  59.   // initialize default output device
  60.   if (not BASS_Init(-1,44100,0,Handle,nil)) then
  61.   begin
  62.     Error('Can''t initialize device');
  63.     Halt;
  64.   end;
  65.   // look for plugins (in the current directory)
  66.   i := FindFirst('bass*.dll', faAnyFile, sRec);
  67.   while i = 0 do
  68.   begin
  69.     if (BASS_PluginLoad(pchar(sRec.Name)) <> 0) then // plugin loaded...
  70.       ListBox1.Items.Add(sRec.Name);
  71.     i := FindNext(sRec);
  72.   end;
  73.   FindClose(sRec);
  74.  
  75.   if (ListBox1.Items.Count = 0) then // no plugins...
  76.   begin
  77.     ListBox1.Items.Add('no plugins - ');
  78.     ListBox1.Items.Add('visit the BASS');
  79.     ListBox1.Items.Add('webpage to get some');
  80.   end;
  81. end;
  82.  
  83. procedure TForm1.FormDestroy(Sender: TObject);
  84. begin
  85.   BASS_Free();
  86.   BASS_PluginFree(0);
  87. end;
  88.  
  89. procedure TForm1.Timer1Timer(Sender: TObject);
  90. begin
  91.   TrackBar1.Position := Trunc(BASS_ChannelBytes2Seconds(chan,BASS_ChannelGetPosition(chan))); // update position
  92. end;
  93.  
  94. procedure TForm1.TrackBar1Change(Sender: TObject);
  95. begin
  96.   // set the position
  97.   BASS_ChannelSetPosition(chan,BASS_ChannelSeconds2Bytes(chan,TrackBar1.Position));
  98. end;
  99.  
  100. procedure TForm1.Button1Click(Sender: TObject);
  101. var
  102.   info: BASS_CHANNELINFO;
  103. begin
  104.   if (not OpenDialog1.Execute) then
  105.     Exit;
  106.  
  107.   BASS_StreamFree(chan);
  108.   chan := BASS_StreamCreateFile(False, pchar(OpenDialog1.FileName), 0, 0, BASS_SAMPLE_LOOP);
  109.   if (chan = 0) then
  110.   begin // it ain't playable
  111.     Button1.Caption := 'Click here to open a file...';
  112.     Label1.Caption := '';
  113.     Error('Can''t play the file');
  114.     Exit;
  115.   end;
  116.  
  117.   BASS_ChannelGetInfo(chan, info);
  118.   Button1.Caption := OpenDialog1.FileName;
  119.   Label1.Caption := 'channel type = ' + IntToHex(info.ctype, 5);
  120.   TrackBar1.Max := Trunc(BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan)));
  121.   BASS_ChannelPlay(chan, False);
  122. end;
  123.  
  124. end.
  125.