aboutsummaryrefslogtreecommitdiffstats
path: root/Lua/src/base/USongs.pas
diff options
context:
space:
mode:
Diffstat (limited to 'Lua/src/base/USongs.pas')
-rw-r--r--Lua/src/base/USongs.pas576
1 files changed, 291 insertions, 285 deletions
diff --git a/Lua/src/base/USongs.pas b/Lua/src/base/USongs.pas
index 7f5125a9..baeec13a 100644
--- a/Lua/src/base/USongs.pas
+++ b/Lua/src/base/USongs.pas
@@ -40,74 +40,79 @@ interface
{$ENDIF}
uses
+ SysUtils,
+ Classes,
{$IFDEF MSWINDOWS}
Windows,
DirWatch,
{$ELSE}
{$IFNDEF DARWIN}
- syscall,
+ syscall,
{$ENDIF}
baseunix,
UnixType,
{$ENDIF}
- SysUtils,
- Classes,
UPlatform,
ULog,
UTexture,
UCommon,
- {$IFDEF DARWIN}
- cthreads,
- {$ENDIF}
{$IFDEF USE_PSEUDO_THREAD}
- PseudoThread,
+ PseudoThread,
{$ENDIF}
+ UPath,
USong,
UCatCovers;
type
+ TSongFilter = (
+ fltAll,
+ fltTitle,
+ fltArtist
+ );
TBPM = record
- BPM: real;
- StartBeat: real;
+ BPM: real;
+ StartBeat: real;
end;
TScore = record
- Name: widestring;
- Score: integer;
- Length: string;
+ Name: UTF8String;
+ Score: integer;
+ Length: string;
end;
+ TPathDynArray = array of IPath;
+
{$IFDEF USE_PSEUDO_THREAD}
- TSongs = class( TPseudoThread )
+ TSongs = class(TPseudoThread)
{$ELSE}
- TSongs = class( TThread )
+ TSongs = class(TThread)
{$ENDIF}
private
- fNotify, fWatch : longint;
- fParseSongDirectory : boolean;
- fProcessing : boolean;
+ fNotify, fWatch: longint;
+ fParseSongDirectory: boolean;
+ fProcessing: boolean;
{$ifdef MSWINDOWS}
- fDirWatch : TDirectoryWatch;
+ fDirWatch: TDirectoryWatch;
{$endif}
procedure int_LoadSongList;
procedure DoDirChanged(Sender: TObject);
protected
procedure Execute; override;
public
- SongList : TList; // array of songs
- Selected : integer; // selected song index
+ SongList: TList; // array of songs
+ Selected: integer; // selected song index
constructor Create();
destructor Destroy(); override;
procedure LoadSongList; // load all songs
- procedure BrowseDir(Dir: widestring); // should return number of songs in the future
- procedure BrowseTXTFiles(Dir: widestring);
- procedure BrowseXMLFiles(Dir: widestring);
+ procedure FindFilesByExtension(const Dir: IPath; const Ext: IPath; Recursive: Boolean; var Files: TPathDynArray);
+ procedure BrowseDir(Dir: IPath); // should return number of songs in the future
+ procedure BrowseTXTFiles(Dir: IPath);
+ procedure BrowseXMLFiles(Dir: IPath);
procedure Sort(Order: integer);
- function FindSongFile(Dir, Mask: widestring): widestring;
- property Processing : boolean read fProcessing;
+ property Processing: boolean read fProcessing;
end;
@@ -116,24 +121,24 @@ type
Selected: integer; // selected song index
Order: integer; // order type (0=title)
CatNumShow: integer; // Category Number being seen
- CatCount: integer; //Number of Categorys
+ CatCount: integer; // Number of Categorys
procedure SortSongs();
- procedure Refresh; // refreshes arrays by recreating them from Songs array
- procedure ShowCategory(Index: integer); // expands all songs in category
- procedure HideCategory(Index: integer); // hides all songs in category
- procedure ClickCategoryButton(Index: integer); // uses ShowCategory and HideCategory when needed
- procedure ShowCategoryList; //Hides all Songs And Show the List of all Categorys
- function FindNextVisible(SearchFrom:integer): integer; //Find Next visible Song
- function VisibleSongs: integer; // returns number of visible songs (for tabs)
- function VisibleIndex(Index: integer): integer; // returns visible song index (skips invisible)
-
- function SetFilter(FilterStr: string; const fType: Byte): Cardinal;
+ procedure Refresh; // refreshes arrays by recreating them from Songs array
+ procedure ShowCategory(Index: integer); // expands all songs in category
+ procedure HideCategory(Index: integer); // hides all songs in category
+ procedure ClickCategoryButton(Index: integer); // uses ShowCategory and HideCategory when needed
+ procedure ShowCategoryList; // Hides all Songs And Show the List of all Categorys
+ function FindNextVisible(SearchFrom: integer): integer; // Find Next visible Song
+ function VisibleSongs: integer; // returns number of visible songs (for tabs)
+ function VisibleIndex(Index: integer): integer; // returns visible song index (skips invisible)
+
+ function SetFilter(FilterStr: UTF8String; Filter: TSongFilter): cardinal;
end;
var
- Songs: TSongs; // all songs
- CatSongs: TCatSongs; // categorized songs
+ Songs: TSongs; // all songs
+ CatSongs: TCatSongs; // categorized songs
const
IN_ACCESS = $00000001; //* File was accessed */
@@ -151,12 +156,17 @@ const
implementation
-uses StrUtils,
- UGraphic,
- UCovers,
- UFiles,
- UMain,
- UIni;
+uses
+ StrUtils,
+ UCovers,
+ UFiles,
+ UGraphic,
+ UMain,
+ UIni,
+ UPathUtils,
+ UNote,
+ UFilesystem,
+ UUnicodeUtils;
constructor TSongs.Create();
begin
@@ -168,7 +178,7 @@ begin
// FIXME: threaded loading does not work this way.
// It will just cause crashes but nothing else at the moment.
- (*
+(*
{$ifdef MSWINDOWS}
fDirWatch := TDirectoryWatch.create(nil);
fDirWatch.OnChange := DoDirChanged;
@@ -179,7 +189,7 @@ begin
// now we can start the thread
Resume();
- *)
+*)
// until it is fixed, simply load the song-list
int_LoadSongList();
@@ -187,7 +197,7 @@ end;
destructor TSongs.Destroy();
begin
- FreeAndNil( SongList );
+ FreeAndNil(SongList);
inherited;
end;
@@ -198,7 +208,7 @@ end;
procedure TSongs.Execute();
var
- fChangeNotify : THandle;
+ fChangeNotify: THandle;
begin
{$IFDEF USE_PSEUDO_THREAD}
int_LoadSongList();
@@ -230,15 +240,15 @@ begin
// browse directories
for I := 0 to SongPaths.Count-1 do
- BrowseDir(SongPaths[I]);
+ BrowseDir(SongPaths[I] as IPath);
- if assigned( CatSongs ) then
+ if assigned(CatSongs) then
CatSongs.Refresh;
- if assigned( CatCovers ) then
+ if assigned(CatCovers) then
CatCovers.Load;
- //if assigned( Covers ) then
+ //if assigned(Covers) then
// Covers.Load;
if assigned(ScreenSong) then
@@ -262,84 +272,92 @@ begin
Resume();
end;
-procedure TSongs.BrowseDir(Dir: widestring);
+procedure TSongs.BrowseDir(Dir: IPath);
begin
- BrowseTXTFiles(Dir);
- BrowseXMLFiles(Dir);
+ BrowseTXTFiles(Dir);
+ BrowseXMLFiles(Dir);
end;
-procedure TSongs.BrowseTXTFiles(Dir: widestring);
+procedure TSongs.FindFilesByExtension(const Dir: IPath; const Ext: IPath; Recursive: Boolean; var Files: TPathDynArray);
var
- i : integer;
- Files : TDirectoryEntryArray;
- lSong : TSong;
+ Iter: IFileIterator;
+ FileInfo: TFileInfo;
+ FileName: IPath;
begin
-
- try
- Files := Platform.DirectoryFindFiles( Dir, '.txt', true)
- except
- Log.LogError('Couldn''t deal with directory/file: ' + Dir + ' in TSongs.BrowseTXTFiles')
- end;
-
- for i := 0 to Length(Files)-1 do
+ // search for all files and directories
+ Iter := FileSystem.FileFind(Dir.Append('*'), faAnyFile);
+ while (Iter.HasNext) do
begin
- if Files[i].IsDirectory then
+ FileInfo := Iter.Next;
+ FileName := FileInfo.Name;
+ if ((FileInfo.Attr and faDirectory) <> 0) then
begin
- BrowseTXTFiles( Dir + Files[i].Name + PathDelim ); //Recursive Call
+ if Recursive and (not FileName.Equals('.')) and (not FileName.Equals('..')) then
+ FindFilesByExtension(Dir.Append(FileName), Ext, true, Files);
end
else
begin
- lSong := TSong.create( Dir + Files[i].Name );
-
- if lSong.Analyse then
- SongList.add( lSong )
- else
+ if (Ext.Equals(FileName.GetExtension(), true)) then
begin
- Log.LogError('AnalyseFile failed for "' + Files[i].Name + '".');
- freeandnil( lSong );
+ SetLength(Files, Length(Files)+1);
+ Files[High(Files)] := Dir.Append(FileName);
end;
-
end;
end;
- SetLength( Files, 0);
-
end;
-procedure TSongs.BrowseXMLFiles(Dir: widestring);
+procedure TSongs.BrowseTXTFiles(Dir: IPath);
var
- i : integer;
- Files : TDirectoryEntryArray;
- lSong : TSong;
+ I: integer;
+ Files: TPathDynArray;
+ Song: TSong;
+ Extension: IPath;
begin
+ SetLength(Files, 0);
+ Extension := Path('.txt');
+ FindFilesByExtension(Dir, Extension, true, Files);
- try
- Files := Platform.DirectoryFindFiles( Dir, '.xml', true)
- except
- Log.LogError('Couldn''t deal with directory/file: ' + Dir + ' in TSongs.BrowseXMLFiles')
- end;
-
- for i := 0 to Length(Files)-1 do
+ for I := 0 to High(Files) do
begin
- if Files[i].IsDirectory then
- begin
- BrowseXMLFiles( Dir + Files[i].Name + PathDelim ); //Recursive Call
- end
+ Song := TSong.Create(Files[I]);
+
+ if Song.Analyse then
+ SongList.Add(Song)
else
begin
- lSong := TSong.create( Dir + Files[i].Name );
+ Log.LogError('AnalyseFile failed for "' + Files[I].ToNative + '".');
+ FreeAndNil(Song);
+ end;
+ end;
- if lSong.AnalyseXML then
- SongList.add( lSong )
- else
- begin
- Log.LogError('AnalyseFile failed for "' + Files[i].Name + '".');
- freeandnil( lSong );
- end;
+ SetLength(Files, 0);
+end;
+procedure TSongs.BrowseXMLFiles(Dir: IPath);
+var
+ I: integer;
+ Files: TPathDynArray;
+ Song: TSong;
+ Extension: IPath;
+begin
+ SetLength(Files, 0);
+ Extension := Path('.xml');
+ FindFilesByExtension(Dir, Extension, true, Files);
+
+ for I := 0 to High(Files) do
+ begin
+ Song := TSong.Create(Files[I]);
+
+ if Song.AnalyseXML then
+ SongList.Add(Song)
+ else
+ begin
+ Log.LogError('AnalyseFile failed for "' + Files[I].ToNative + '".');
+ FreeAndNil(Song);
end;
end;
- SetLength( Files, 0);
+ SetLength(Files, 0);
end;
(*
@@ -348,32 +366,32 @@ end;
function CompareByEdition(Song1, Song2: Pointer): integer;
begin
- Result := CompareText(TSong(Song1).Edition, TSong(Song2).Edition);
+ Result := UTF8CompareText(TSong(Song1).Edition, TSong(Song2).Edition);
end;
function CompareByGenre(Song1, Song2: Pointer): integer;
begin
- Result := CompareText(TSong(Song1).Genre, TSong(Song2).Genre);
+ Result := UTF8CompareText(TSong(Song1).Genre, TSong(Song2).Genre);
end;
function CompareByTitle(Song1, Song2: Pointer): integer;
begin
- Result := CompareText(TSong(Song1).Title, TSong(Song2).Title);
+ Result := UTF8CompareText(TSong(Song1).Title, TSong(Song2).Title);
end;
function CompareByArtist(Song1, Song2: Pointer): integer;
begin
- Result := CompareText(TSong(Song1).Artist, TSong(Song2).Artist);
+ Result := UTF8CompareText(TSong(Song1).Artist, TSong(Song2).Artist);
end;
function CompareByFolder(Song1, Song2: Pointer): integer;
begin
- Result := CompareText(TSong(Song1).Folder, TSong(Song2).Folder);
+ Result := UTF8CompareText(TSong(Song1).Folder, TSong(Song2).Folder);
end;
function CompareByLanguage(Song1, Song2: Pointer): integer;
begin
- Result := CompareText(TSong(Song1).Language, TSong(Song2).Language);
+ Result := UTF8CompareText(TSong(Song1).Language, TSong(Song2).Language);
end;
procedure TSongs.Sort(Order: integer);
@@ -392,8 +410,6 @@ begin
CompareFunc := CompareByArtist;
sFolder: // by folder
CompareFunc := CompareByFolder;
- sTitle2: // by title2
- CompareFunc := CompareByTitle;
sArtist2: // by artist2
CompareFunc := CompareByArtist;
sLanguage: // by Language
@@ -410,18 +426,6 @@ begin
MergeSort(SongList, CompareFunc);
end;
-function TSongs.FindSongFile(Dir, Mask: widestring): widestring;
-var
- SR: TSearchRec; // for parsing song directory
-begin
- Result := '';
- if FindFirst(Dir + Mask, faDirectory, SR) = 0 then
- begin
- Result := SR.Name;
- end; // if
- FindClose(SR);
-end;
-
procedure TCatSongs.SortSongs();
begin
case Ini.Sorting of
@@ -452,12 +456,8 @@ begin
Songs.Sort(sTitle);
Songs.Sort(sArtist);
end;
- sTitle2: begin
- Songs.Sort(sArtist2);
- Songs.Sort(sTitle2);
- end;
sArtist2: begin
- Songs.Sort(sTitle2);
+ Songs.Sort(sTitle);
Songs.Sort(sArtist2);
end;
end; // case
@@ -467,27 +467,27 @@ procedure TCatSongs.Refresh;
var
SongIndex: integer;
CurSong: TSong;
- CatIndex: integer; // index of current song in Song
- Letter: char; // current letter for sorting using letter
- CurCategory: string; // current edition for sorting using edition, genre etc.
- Order: integer; // number used for ordernum
- LetterTmp: char;
- CatNumber: integer; // Number of Song in Category
-
- procedure AddCategoryButton(const CategoryName: string);
+ CatIndex: integer; // index of current song in Song
+ Letter: UCS4Char; // current letter for sorting using letter
+ CurCategory: UTF8String; // current edition for sorting using edition, genre etc.
+ Order: integer; // number used for ordernum
+ LetterTmp: UCS4Char;
+ CatNumber: integer; // Number of Song in Category
+
+ procedure AddCategoryButton(const CategoryName: UTF8String);
var
PrevCatBtnIndex: integer;
begin
Inc(Order);
CatIndex := Length(Song);
SetLength(Song, CatIndex+1);
- Song[CatIndex] := TSong.Create();
- Song[CatIndex].Artist := '[' + CategoryName + ']';
- Song[CatIndex].Main := true;
+ Song[CatIndex] := TSong.Create();
+ Song[CatIndex].Artist := '[' + CategoryName + ']';
+ Song[CatIndex].Main := true;
Song[CatIndex].OrderTyp := 0;
Song[CatIndex].OrderNum := Order;
- Song[CatIndex].Cover := CatCovers.GetCover(Ini.Sorting, CategoryName);
- Song[CatIndex].Visible := true;
+ Song[CatIndex].Cover := CatCovers.GetCover(Ini.Sorting, CategoryName);
+ Song[CatIndex].Visible := true;
// set number of songs in previous category
PrevCatBtnIndex := CatIndex - CatNumber - 1;
@@ -498,21 +498,21 @@ var
end;
begin
- CatNumShow := -1;
+ CatNumShow := -1;
SortSongs();
CurCategory := '';
- Order := 0;
- CatNumber := 0;
+ Order := 0;
+ CatNumber := 0;
// Note: do NOT set Letter to ' ', otherwise no category-button will be
// created for songs beginning with ' ' if songs of this category exist.
// TODO: trim song-properties so ' ' will not occur as first chararcter.
- Letter := #0;
+ Letter := 0;
// clear song-list
- for SongIndex := 0 to Songs.SongList.Count-1 do
+ for SongIndex := 0 to Songs.SongList.Count - 1 do
begin
// free category buttons
// Note: do NOT delete songs, they are just references to Songs.SongList entries
@@ -522,107 +522,108 @@ begin
end;
SetLength(Song, 0);
- for SongIndex := 0 to Songs.SongList.Count-1 do
+ for SongIndex := 0 to Songs.SongList.Count - 1 do
begin
CurSong := TSong(Songs.SongList[SongIndex]);
// if tabs are on, add section buttons for each new section
if (Ini.Tabs = 1) then
begin
- if (Ini.Sorting = sEdition) and
- (CompareText(CurCategory, CurSong.Edition) <> 0) then
- begin
- CurCategory := CurSong.Edition;
-
- // TODO: remove this block if it is not needed anymore
- {
- if CurSection = 'Singstar Part 2' then CoverName := 'Singstar';
- if CurSection = 'Singstar German' then CoverName := 'Singstar';
- if CurSection = 'Singstar Spanish' then CoverName := 'Singstar';
- if CurSection = 'Singstar Italian' then CoverName := 'Singstar';
- if CurSection = 'Singstar French' then CoverName := 'Singstar';
- if CurSection = 'Singstar 80s Polish' then CoverName := 'Singstar 80s';
- }
-
- // add Category Button
- AddCategoryButton(CurCategory);
- end
-
- else if (Ini.Sorting = sGenre) and
- (CompareText(CurCategory, CurSong.Genre) <> 0) then
- begin
- CurCategory := CurSong.Genre;
- // add Genre Button
- AddCategoryButton(CurCategory);
- end
-
- else if (Ini.Sorting = sLanguage) and
- (CompareText(CurCategory, CurSong.Language) <> 0) then
- begin
- CurCategory := CurSong.Language;
- // add Language Button
- AddCategoryButton(CurCategory);
- end
-
- else if (Ini.Sorting = sTitle) and
- (Length(CurSong.Title) >= 1) and
- (Letter <> UpperCase(CurSong.Title)[1]) then
- begin
- Letter := Uppercase(CurSong.Title)[1];
- // add a letter Category Button
- AddCategoryButton(Letter);
- end
+ case (Ini.Sorting) of
+ sEdition: begin
+ if (CompareText(CurCategory, CurSong.Edition) <> 0) then
+ begin
+ CurCategory := CurSong.Edition;
+
+ // add Category Button
+ AddCategoryButton(CurCategory);
+ end;
+ end;
- else if (Ini.Sorting = sArtist) and
- (Length(CurSong.Artist) >= 1) and
- (Letter <> UpperCase(CurSong.Artist)[1]) then
- begin
- Letter := UpperCase(CurSong.Artist)[1];
- // add a letter Category Button
- AddCategoryButton(Letter);
- end
+ sGenre: begin
+ if (CompareText(CurCategory, CurSong.Genre) <> 0) then
+ begin
+ CurCategory := CurSong.Genre;
+ // add Genre Button
+ AddCategoryButton(CurCategory);
+ end;
+ end;
- else if (Ini.Sorting = sFolder) and
- (CompareText(CurCategory, CurSong.Folder) <> 0) then
- begin
- CurCategory := CurSong.Folder;
- // add folder tab
- AddCategoryButton(CurCategory);
- end
+ sLanguage: begin
+ if (CompareText(CurCategory, CurSong.Language) <> 0) then
+ begin
+ CurCategory := CurSong.Language;
+ // add Language Button
+ AddCategoryButton(CurCategory);
+ end
+ end;
- else if (Ini.Sorting = sTitle2) and
- (Length(CurSong.Title) >= 1) then
- begin
- // pack all numbers into a category named '#'
- if (CurSong.Title[1] >= '0') and (CurSong.Title[1] <= '9') then
- LetterTmp := '#'
- else
- LetterTmp := UpperCase(CurSong.Title)[1];
+ sTitle: begin
+ if (Length(CurSong.Title) >= 1) then
+ begin
+ LetterTmp := UCS4UpperCase(UTF8ToUCS4String(CurSong.Title)[0]);
+ { all numbers and some punctuation chars are put into a
+ category named '#'
+ we can't put the other punctuation chars into this category
+ because they are not in order, so there will be two different
+ categories named '#' }
+ if (LetterTmp in [Ord('!') .. Ord('?')]) then
+ LetterTmp := Ord('#')
+ else
+ LetterTmp := UCS4UpperCase(LetterTmp);
+ if (Letter <> LetterTmp) then
+ begin
+ Letter := LetterTmp;
+ // add a letter Category Button
+ AddCategoryButton(UCS4ToUTF8String(Letter));
+ end;
+ end;
+ end;
- if (Letter <> LetterTmp) then
- begin
- Letter := LetterTmp;
- // add a letter Category Button
- AddCategoryButton(Letter);
+ sArtist: begin
+ if (Length(CurSong.Artist) >= 1) then
+ begin
+ LetterTmp := UCS4UpperCase(UTF8ToUCS4String(CurSong.Artist)[0]);
+ { all numbers and some punctuation chars are put into a
+ category named '#'
+ we can't put the other punctuation chars into this category
+ because they are not in order, so there will be two different
+ categories named '#' }
+ if (LetterTmp in [Ord('!') .. Ord('?')]) then
+ LetterTmp := Ord('#')
+ else
+ LetterTmp := UCS4UpperCase(LetterTmp);
+
+ if (Letter <> LetterTmp) then
+ begin
+ Letter := LetterTmp;
+ // add a letter Category Button
+ AddCategoryButton(UCS4ToUTF8String(Letter));
+ end;
+ end;
end;
- end
- else if (Ini.Sorting = sArtist2) and
- (Length(CurSong.Artist)>=1) then
- begin
- // pack all numbers into a category named '#'
- if (CurSong.Artist[1] >= '0') and (CurSong.Artist[1] <= '9') then
- LetterTmp := '#'
- else
- LetterTmp := UpperCase(CurSong.Artist)[1];
+ sFolder: begin
+ if (UTF8CompareText(CurCategory, CurSong.Folder) <> 0) then
+ begin
+ CurCategory := CurSong.Folder;
+ // add folder tab
+ AddCategoryButton(CurCategory);
+ end;
+ end;
- if (Letter <> LetterTmp) then
- begin
- Letter := LetterTmp;
- // add a letter Category Button
- AddCategoryButton(Letter);
+ sArtist2: begin
+ { this new sorting puts all songs by the same artist into
+ a single category }
+ if (UTF8CompareText(CurCategory, CurSong.Artist) <> 0) then
+ begin
+ CurCategory := CurSong.Artist;
+ // add folder tab
+ AddCategoryButton(CurCategory);
+ end;
end;
- end;
- end;
+
+ end; // case (Ini.Sorting)
+ end; // if (Ini.Tabs = 1)
CatIndex := Length(Song);
SetLength(Song, CatIndex+1);
@@ -640,19 +641,18 @@ begin
CurSong.Visible := true
else if (Ini.Tabs = 1) then
CurSong.Visible := false;
-
- {
+{
if (Ini.Tabs = 1) and (Order = 1) then
begin
//open first tab
CurSong.Visible := true;
end;
CurSong.Visible := true;
- }
+}
end;
// set CatNumber of last category
- if (Ini.Tabs_at_startup = 1) and (High(Song) >= 1) then
+ if (Ini.TabsAtStartup = 1) and (High(Song) >= 1) then
begin
// set number of songs in previous category
SongIndex := CatIndex - CatNumber;
@@ -666,7 +666,7 @@ end;
procedure TCatSongs.ShowCategory(Index: integer);
var
- S: integer; // song
+ S: integer; // song
begin
CatNumShow := Index;
for S := 0 to high(CatSongs.Song) do
@@ -678,13 +678,13 @@ begin
CatSongs.Song[S].Visible := false;
}
// KMS: This should be the same, but who knows :-)
- CatSongs.Song[S].Visible := ( (CatSongs.Song[S].OrderNum = Index) and (not CatSongs.Song[S].Main) );
+ CatSongs.Song[S].Visible := ((CatSongs.Song[S].OrderNum = Index) and (not CatSongs.Song[S].Main));
end;
end;
procedure TCatSongs.HideCategory(Index: integer); // hides all songs in category
var
- S: integer; // song
+ S: integer; // song
begin
for S := 0 to high(CatSongs.Song) do
begin
@@ -695,7 +695,7 @@ end;
procedure TCatSongs.ClickCategoryButton(Index: integer);
var
- Num: integer;
+ Num: integer;
begin
Num := CatSongs.Song[Index].OrderNum;
if Num <> CatNumShow then
@@ -711,7 +711,7 @@ end;
//Hide Categorys when in Category Hack
procedure TCatSongs.ShowCategoryList;
var
- S: integer;
+ S: integer;
begin
// Hide All Songs Show All Cats
for S := 0 to high(CatSongs.Song) do
@@ -721,23 +721,27 @@ begin
end;
//Hide Categorys when in Category Hack End
-//Wrong song selected when tabs on bug
-function TCatSongs.FindNextVisible(SearchFrom:integer): integer;//Find next Visible Song
+// Wrong song selected when tabs on bug
+function TCatSongs.FindNextVisible(SearchFrom:integer): integer;// Find next Visible Song
var
I: integer;
begin
Result := -1;
- I := SearchFrom + 1;
- while not CatSongs.Song[I].Visible do
+ I := SearchFrom;
+ while (Result = -1) do
begin
Inc (I);
- if (I>high(CatSongs.Song)) then
- I := low(CatSongs.Song);
- if (I = SearchFrom) then //Make One Round and no song found->quit
- break;
+
+ if (I > High(CatSongs.Song)) then
+ I := Low(CatSongs.Song);
+ if (I = SearchFrom) then // Make One Round and no song found->quit
+ Break;
+
+ if (CatSongs.Song[I].Visible) then
+ Result := I;
end;
end;
-//Wrong song selected when tabs on bug End
+// Wrong song selected when tabs on bug End
(**
* Returns the number of visible songs.
@@ -763,71 +767,73 @@ var
SongIndex: integer;
begin
Result := 0;
- for SongIndex := 0 to Index-1 do
+ for SongIndex := 0 to Index - 1 do
begin
if (CatSongs.Song[SongIndex].Visible) then
Inc(Result);
end;
end;
-function TCatSongs.SetFilter(FilterStr: string; const fType: Byte): Cardinal;
+function TCatSongs.SetFilter(FilterStr: UTF8String; Filter: TSongFilter): cardinal;
var
- I, J: integer;
- cString: string;
- SearchStr: array of string;
+ I, J: integer;
+ TmpString: UTF8String;
+ WordArray: array of UTF8String;
begin
- {fType: 0: All
- 1: Title
- 2: Artist}
FilterStr := Trim(FilterStr);
- if FilterStr<>'' then
+ if (FilterStr <> '') then
begin
Result := 0;
- //Create Search Array
- SetLength(SearchStr, 1);
- I := Pos (' ', FilterStr);
+
+ // initialize word array
+ SetLength(WordArray, 1);
+
+ // Copy words to SearchStr
+ I := Pos(' ', FilterStr);
while (I <> 0) do
begin
- SetLength (SearchStr, Length(SearchStr) + 1);
- cString := Copy(FilterStr, 1, I-1);
- if (cString <> ' ') and (cString <> '') then
- SearchStr[High(SearchStr)-1] := cString;
- Delete (FilterStr, 1, I);
+ WordArray[High(WordArray)] := Copy(FilterStr, 1, I-1);
+ SetLength(WordArray, Length(WordArray) + 1);
- I := Pos (' ', FilterStr);
+ FilterStr := TrimLeft(Copy(FilterStr, I+1, Length(FilterStr)-I));
+ I := Pos(' ', FilterStr);
end;
- //Copy last Word
- if (FilterStr <> ' ') and (FilterStr <> '') then
- SearchStr[High(SearchStr)] := FilterStr;
- for I:=0 to High(Song) do
+ // Copy last word
+ WordArray[High(WordArray)] := FilterStr;
+
+ for I := 0 to High(Song) do
begin
if not Song[i].Main then
begin
- case fType of
- 0: cString := Song[I].Artist + ' ' + Song[i].Title + ' ' + Song[i].Folder;
- 1: cString := Song[I].Title;
- 2: cString := Song[I].Artist;
+ case Filter of
+ fltAll:
+ TmpString := Song[I].Artist + ' ' + Song[i].Title + ' ' + Song[i].Folder;
+ fltTitle:
+ TmpString := Song[I].Title;
+ fltArtist:
+ TmpString := Song[I].Artist;
end;
- Song[i].Visible:=True;
- //Look for every Searched Word
- for J := 0 to High(SearchStr) do
+ Song[i].Visible := true;
+ // Look for every searched word
+ for J := 0 to High(WordArray) do
begin
- Song[i].Visible := Song[i].Visible and AnsiContainsText(cString, SearchStr[J])
+ Song[i].Visible := Song[i].Visible and
+ UTF8ContainsText(TmpString, WordArray[J])
end;
if Song[i].Visible then
Inc(Result);
end
else
- Song[i].Visible:=False;
+ Song[i].Visible := false;
end;
CatNumShow := -2;
end
else
begin
- for i:=0 to High(Song) do
+ for i := 0 to High(Song) do
begin
- Song[i].Visible := (Ini.Tabs=1) = Song[i].Main;
+ Song[i].Visible := (Ini.Tabs = 1) = Song[i].Main;
CatNumShow := -1;
end;
Result := 0;