home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / mp3osr05.zip / src / sortings.pas < prev    next >
Pascal/Delphi Source File  |  1999-12-12  |  2KB  |  84 lines

  1. (*
  2.  * part of MPEG searcher project
  3.  *  (c) 1999 by Alexander Trunov, 2:5069/10, jnc@mail.ru
  4.  *)
  5.  
  6. unit Sortings;
  7.  
  8. interface
  9.  
  10. uses
  11.   ID3v1, Objects, mp3lb;
  12.  
  13. type
  14.   TFNGetTag = function(FN: string): PjID3v1;
  15.   TSepFactor = (faAlbum, faArtist, faTitle, faComment, faYear);
  16.  
  17. function SeparateCollection(factor: TSepFactor;
  18.   coll: PCollection; GetTag: TFNGetTag): PCollection;
  19.  
  20. implementation
  21.  
  22. function SeparateCollection(factor: TSepFactor;
  23.   coll: PCollection; GetTag: TFNGetTag): PCollection;
  24. var
  25.   rColl: PCollection;
  26.   subColl: PStringCollection;
  27.   i: Integer;
  28.   firstItem, FN, Item: string;
  29.   tag: PjID3v1;
  30. begin
  31.   Result := nil;
  32.   rColl := New(PCollection, Init(10, 10));
  33.  
  34.   while coll^.Count > 0 do
  35.   begin
  36.  
  37.     subColl := New(PStringCollection, Init(10, 10));
  38.  
  39.     i := 0;
  40.     firstItem := '1234567890123456789012345678901234567890';
  41.     //  needed tag item will never equal that line
  42.     // since the length of it will be always not greater than 30 bytes
  43.     // o kak zagnul ;)
  44.     while i < coll^.Count do
  45.     begin
  46.       FN := Pmp3(coll^.Items^[i])^.Filename;
  47.       tag := GetTag(FN);
  48.       case factor of
  49.         faAlbum: Item := tag^.Album;
  50.         faArtist: Item := tag^.Artist;
  51.         faTitle: Item := tag^.Songname;
  52.         faComment: Item := tag^.Comment;
  53.         faYear: Item := tag^.Year;
  54.       end;
  55.       if firstItem = '1234567890123456789012345678901234567890' then
  56.       begin
  57.         firstItem := Item;
  58.         subColl^.Insert(coll^.Items^[i]);
  59.         coll^.AtDelete(i);
  60.         FreeMem(tag, SizeOf(tag^));
  61.         Continue;
  62.       end;
  63.       if Item = firstItem then
  64.       begin
  65.         subColl^.Insert(coll^.Items^[i]);
  66.         coll^.AtDelete(i);
  67.         FreeMem(tag, SizeOf(tag^));
  68.         Continue;
  69.       end;
  70.  
  71.       FreeMem(tag, SizeOf(tag^));
  72.       inc(i);
  73.     end;
  74.  
  75.     rColl^.Insert(subColl);
  76.  
  77.   end;
  78.  
  79.   Result := rColl;
  80.  
  81. end;
  82.  
  83. end.
  84.