1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
| unit uSongList;
interface
uses
Windows, SysUtils, Classes, Contnrs;
type
TSongInfo = class
private
fFileName, fTitle, fArtist, fAlbum, fYear, fComment: string;
fGenre, fDuration : integer;
protected
function ID3V1Exists: boolean;
procedure readID3V1; // not defined
procedure writeID3V1; // not defined
public
property FileName : string read fFileName write fFileName;
property Title : string read fTitle write fTitle;
property Artist : string read fArtist write fArtist;
property Album : string read fAlbum write fAlbum;
property Year : string read fYear write fYear;
property Comment : string read fComment write fComment;
property Genre : integer read fGenre write fGenre;
property Duration : integer read fDuration write fDuration;
public
procedure ExplodeDuration(var vMin, vSec, vMSec: word);
constructor Create; overload;
constructor Create(aFileName: string); overload;
constructor Create(aFileName, aTitle, aArtist, aAlbum, aYear, aComment: string; aGenre, aDuration: integer); overload;
end;
TPlayList = class(Contnrs.TObjectList)
private
fLastPlayed: integer;
fItemIndex : integer;
protected
function GetItem(aIndex: Integer): TSongInfo;
procedure SetItem(aIndex: Integer; aSongInfo: TSongInfo);
public
property Items[Index: Integer]: TSongInfo read GetItem write SetItem; default;
// playlist specific functions
function GetShuffled: TSongInfo;
function Previous: TSongInfo;
function Next: TSongInfo;
property CurrentSongIndex: integer read fItemIndex;
// list functions
function Add(aSongInfo: TSongInfo): Integer;
function Extract(aSongInfo: TSongInfo): TSongInfo;
function Remove(aSongInfo: TSongInfo): Integer;
function IndexOf(aSongInfo: TSongInfo): Integer;
procedure Insert(aIndex: Integer; aSongInfo: TSongInfo);
function First: TSongInfo;
function Last: TSongInfo;
procedure LoadFromFile(aFileName: string); // not defined
procedure SaveToFile(aFileName: string); // not defined
constructor Create; reintroduce;
end;
implementation
{ TSongInfo }
constructor TSongInfo.Create;
begin
fFileName := '';
fTitle := '';
fArtist := '';
fAlbum := '';
fYear := '';
fComment := '';
fGenre := 0;
fDuration := 0;
end;
constructor TSongInfo.Create(aFileName, aTitle, aArtist, aAlbum, aYear, aComment: string; aGenre, aDuration: integer);
begin
fFileName := aFileName;
fTitle := aTitle;
fArtist := aArtist;
fAlbum := aAlbum;
fYear := aYear;
fComment := aComment;
fGenre := aGenre;
fDuration := aDuration;
end;
procedure TSongInfo.ExplodeDuration(var vMin, vSec, vMSec: word);
begin
vMSec := fDuration mod 1000;
vSec := (fDuration div 1000) mod 60;
vMin := (fDuration div 60000) mod 60;
end;
function TSongInfo.ID3V1Exists: boolean;
begin
result := false;
end;
procedure TSongInfo.readID3V1;
begin
//
end;
procedure TSongInfo.writeID3V1;
begin
//
end;
constructor TSongInfo.Create(aFileName: string);
begin
fFileName := aFileName;
fTitle := '';
fArtist := '';
fAlbum := '';
fYear := '';
fComment := '';
fGenre := 0;
fDuration := 0;
readID3V1;
end;
{ TSongInfoList }
function TPlayList.Add(aSongInfo: TSongInfo): Integer;
begin
result := inherited Add(aSongInfo);
end;
constructor TPlayList.Create;
begin
inherited Create(True);
fLastPlayed := -1;
end;
function TPlayList.Extract(aSongInfo: TSongInfo): TSongInfo;
begin
result := TSongInfo(inherited Extract(aSongInfo));
end;
function TPlayList.First: TSongInfo;
begin
result := TSongInfo(inherited First);
end;
function TPlayList.GetItem(aIndex: Integer): TSongInfo;
begin
result := TSongInfo(inherited GetItem(aIndex));
end;
function TPlayList.GetShuffled: TSongInfo;
var R, C: integer;
begin
C := Count;
R := random(C);
while (R = fLastPlayed) and (R <> fItemIndex) do
R := random(C);
fItemIndex := R;
result := Items[fItemIndex];
end;
function TPlayList.IndexOf(aSongInfo: TSongInfo): Integer;
begin
result := inherited indexOf(aSongInfo);
end;
procedure TPlayList.Insert(aIndex: Integer; aSongInfo: TSongInfo);
begin
inherited Insert(aIndex, aSongInfo);
end;
function TPlayList.Last: TSongInfo;
begin
result := TSongInfo(inherited Last);
end;
procedure TPlayList.LoadFromFile(aFileName: string);
begin
//
end;
function TPlayList.Next: TSongInfo;
begin
fItemIndex := (fItemIndex + 1) mod Count;
result := Items[fItemIndex];
end;
function TPlayList.Previous: TSongInfo;
begin
fItemIndex := fItemIndex -1;
if fItemIndex < 0 then
fItemIndex := Count-1;
result := Items[fItemIndex];
end;
function TPlayList.Remove(aSongInfo: TSongInfo): Integer;
begin
result := inherited Remove(aSongInfo);
end;
procedure TPlayList.SaveToFile(aFileName: string);
begin
//
end;
procedure TPlayList.SetItem(aIndex: Integer; aSongInfo: TSongInfo);
begin
inherited SetItem(aIndex, aSongInfo);
end;
initialization
Randomize;
end. |
Partager