home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / mp3osr05.zip / src / mp3lb.pas < prev    next >
Pascal/Delphi Source File  |  2000-01-02  |  3KB  |  125 lines

  1. (*
  2.  * part of MPEG searcher project
  3.  *  (c) 1999 by Alexander Trunov, 2:5069/10, jnc@mail.ru
  4.  *)
  5.  
  6. unit mp3lb;
  7.  
  8. interface
  9.  
  10. uses
  11.   Objects, Views, Dialogs, ID3v1, DOS, Drivers
  12.   {$IFDEF virtualpascal}, Use32{$ENDIF}
  13.   ;
  14.  
  15. const
  16.   cmListItemFocused = 205;
  17.  
  18. type
  19.   Pmp3 = ^Tmp3;
  20.   Tmp3 = object(TObject)
  21.     tag: PjID3v1;
  22.     Filename: FNameStr;
  23.     constructor Init(const FN: FNameStr; ReadTag: Boolean);
  24.     destructor Done; virtual;
  25.     procedure ReadTagNow;
  26.   end;
  27.  
  28.   PMP3ListBox = ^TMP3ListBox;
  29.   TMP3ListBox = object(TListViewer)
  30.     List: PCollection;
  31.     constructor Init(var Bounds: TRect; AScrollBar: PScrollBar);
  32.     procedure NewList(AList: PCollection); virtual;
  33.     function GetText(Item: Integer; MaxLen: Integer): string; virtual;
  34.     procedure FocusItem(Item: Integer); virtual;
  35.   end;
  36.  
  37. implementation
  38.  
  39. uses
  40.   StdDlg, App, MsgBox, Codepage
  41. {$IFNDEF fpc}, EditChD{$ENDIF}
  42.   ;
  43.  
  44. {$I nonfpc.inc}
  45.  
  46. procedure TMP3ListBox.FocusItem(Item: Integer);
  47. begin
  48.   inherited FocusItem(Item);
  49.   Message(Owner, evBroadcast, cmListItemFocused, @Self);
  50. end;
  51.  
  52. function TMP3ListBox.GetText(Item: Integer; MaxLen: Integer): string;
  53. begin
  54.   if List <> nil then
  55.     Result := ShrinkPath(Pmp3(List^.Items^[Item])^.Filename, MaxLen - 3)
  56.   else
  57.     Result := '';
  58.   {$ifdef win32}
  59.   Result := Win2Alt(Result);
  60.   {$endif}
  61. end;
  62.  
  63. constructor TMP3ListBox.Init(var Bounds: TRect; AScrollBar: PScrollBar);
  64. begin
  65.   inherited Init(Bounds, 1, nil, AScrollBar);
  66.   List := nil;
  67.   SetRange(0);
  68. end;
  69.  
  70. procedure TMP3ListBox.NewList(AList: PCollection);
  71. begin
  72.   if List <> nil then
  73.     Dispose(List, Done);
  74.   List := AList;
  75.   if List <> nil then
  76.     SetRange(List^.Count)
  77.   else
  78.     SetRange(0);
  79.   if Range > 0 then
  80.     FocusItem(0);
  81.   DrawView;
  82. end;
  83.  
  84. procedure Tmp3.ReadTagNow;
  85. var
  86.   stream: PDosStream;
  87.   tagData: PTagData;
  88. begin
  89.   if tag <> nil then
  90.     FreeMem(tag);
  91.   stream := New(PDosStream, Init(Filename, stOpenRead));
  92.   tagData := New(PTagData, Init(stream));
  93.  
  94.   tagData^.ReadTag;
  95.   GetMem(tag, SizeOf(TjID3v1));
  96.   Move(tagData^.tag, tag^, SizeOf(TjID3v1));
  97.  
  98.   Dispose(tagData, Done);
  99.   Dispose(stream, Done);
  100. end;
  101.  
  102. constructor Tmp3.Init(const FN: FNameStr; ReadTag: Boolean);
  103. var
  104.   tagData: PTagData;
  105.   stream: PDosStream;
  106. begin
  107.   inherited Init;
  108.   tag := nil;
  109.   Filename := FN;
  110.   tag := nil;
  111.   if ReadTag then
  112.   begin
  113.     ReadTagNow;
  114.   end;
  115. end;
  116.  
  117. destructor Tmp3.Done;
  118. begin
  119.   if tag <> nil then
  120.     FreeMem(tag, SizeOf(TjID3v1));
  121.   inherited Done;
  122. end;
  123.  
  124. end.
  125.