Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/base/UPlaylist.pas
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ TPlaylistManager = class
procedure LoadPlayLists;
function LoadPlayList(Index: Cardinal; const Filename: IPath): Boolean;
function ReloadPlayList(Index: Cardinal): Boolean;
function ApplyPlayList(Index: Integer): Boolean;
procedure SavePlayList(Index: Cardinal);

procedure RestoreSongOrder;
Expand Down Expand Up @@ -211,7 +212,7 @@ function TPlayListManager.LoadPlayList(Index: Cardinal; const Filename: IPath):
Playlists[Index].Filename := Filename;
Playlists[Index].Name := '';
Playlists[Index].FixedOrder := False;
Playlists[Index].LastRead := FileAge(Filename.ToNative);
Playlists[Index].LastRead := FileAge(FilenameAbs.ToNative);

//Read Until End of File
while TextStream.ReadLine(Line) do
Expand Down Expand Up @@ -334,28 +335,31 @@ procedure TPlayListManager.SavePlayList(Index: Cardinal);
Log.LogError('Could not write Playlistfile "' + Playlists[Index].Name + '"');
end;
TextStream.Free;
Playlists[Index].LastRead := FileAge(PlaylistFile.ToNative);
end;

{**
* Display a Playlist in CatSongs
*}
procedure TPlayListManager.SetPlayList(Index: Integer; SongID: Integer = -1);
function TPlayListManager.ApplyPlayList(Index: Integer): Boolean;
var
I, SongIdx: Integer;
Found: Boolean;
begin
Result := False;

if (Index < 0) or (Index > High(PlayLists)) then
exit;
Exit;

RestoreSongOrder;

if Playlists[Index].FixedOrder then
ApplyPlaylistOrder(Index)
begin
ApplyPlaylistOrder(Index);
ScreenSong.SyncCoversToSongs;
end
else
SongOrderDirty := False;

ScreenSong.SyncCoversToSongs;

//Hide all Songs
for I := 0 to high(CatSongs.Song) do
CatSongs.Song[I].Visible := False;
Expand Down Expand Up @@ -398,6 +402,17 @@ procedure TPlayListManager.SetPlayList(Index: Integer; SongID: Integer = -1);
else
ScreenSong.ShowCatTLCustom(Format(Theme.Playlist.CatText,[Playlists[Index].Name + ' [Fixed Order: Off]']));

Result := True;
end;

procedure TPlayListManager.SetPlayList(Index: Integer; SongID: Integer = -1);
var
I: Integer;
Found: Boolean;
begin
if not ApplyPlayList(Index) then
Exit;

//Fix SongSelection
ScreenSong.Interaction := 0;
Found := False;
Expand Down
127 changes: 127 additions & 0 deletions src/screens/UScreenSong.pas
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ TScreenSong = class(TMenu)
LastPreviewStartTime: integer;
LastChangeSoundTime: integer;
LastScrollStopTime: integer;
LastPlaylistReloadTime: integer;
PreviewEndReloaded: boolean;

RandomSongOrder: CardinalArray;
NextRandomSongIdx: cardinal;
RandomSearchOrder: CardinalArray;

procedure StartMusicPreview();
procedure StartVideoPreview();
function ReloadCurrentPlaylist(ForceCheck: boolean): boolean;
public
TextArtist: integer;
TextTitle: integer;
Expand Down Expand Up @@ -348,6 +351,7 @@ implementation
MAX_TIME_MOUSE_SELECT = 800;
CHANGE_SOUND_THROTTLE_MS = 200;
PREVIEW_DEBOUNCE_MS = 150;
PLAYLIST_RELOAD_INTERVAL_MS = 10000;

// ***** Public methods ****** //
function TScreenSong.EnsureMedleyData(SongIndex: integer; MinSource: TMedleySource): boolean;
Expand Down Expand Up @@ -1952,6 +1956,8 @@ constructor TScreenSong.Create;
LastPreviewStartTime := 0;
LastChangeSoundTime := 0;
LastScrollStopTime := 0;
LastPlaylistReloadTime := 0;
PreviewEndReloaded := false;

NextRandomSongIdx := High(cardinal);
NextRandomSearchIdx := High(cardinal);
Expand Down Expand Up @@ -2133,6 +2139,7 @@ procedure TScreenSong.OnSongDeSelect;
StopMusicPreview();
StopVideoPreview();
PreviewOpened := -1;
PreviewEndReloaded := false;

//SetScrollRefresh;
end;
Expand Down Expand Up @@ -2940,6 +2947,8 @@ procedure TScreenSong.OnShow;

// reset video playback engine
fCurrentVideo := nil;
PreviewEndReloaded := false;
LastPlaylistReloadTime := SDL_GetTicks;

// reset Medley-Playlist
SetLength(PlaylistMedley.Song, 0);
Expand Down Expand Up @@ -3028,6 +3037,7 @@ procedure TScreenSong.OnShowFinish;
if PlaylistMan.ReloadPlayList(PlaylistMan.CurPlayList) then
PlaylistMan.SetPlayList(PlaylistMan.CurPlayList, SongIndex);
end;
LastPlaylistReloadTime := SDL_GetTicks;

FilterDuetsInPartyMode; // in party mode

Expand Down Expand Up @@ -3065,6 +3075,113 @@ procedure TScreenSong.DrawExtensions;
end;
end;

function TScreenSong.ReloadCurrentPlaylist(ForceCheck: boolean): boolean;
var
CurrentSongRef: TSong;
PreviewSongRef: TSong;
NewInteraction: integer;
NewPreviewOpened: integer;
NowTicks: integer;

function FindSongRefIndex(SongRef: TSong): integer;
var
I: integer;
begin
Result := -1;
if not Assigned(SongRef) or (Length(CatSongs.Song) = 0) then
Exit;

for I := Low(CatSongs.Song) to High(CatSongs.Song) do
begin
if CatSongs.Song[I] = SongRef then
begin
Result := I;
Exit;
end;
end;
end;

begin
Result := false;

if not Assigned(PlayListMan) then
Exit;

if (PlayListMan.CurPlayList < 0) or
(PlayListMan.CurPlayList > High(PlayListMan.Playlists)) or
(CatSongs.CatNumShow <> -3) then
Exit;

NowTicks := SDL_GetTicks;
if not ForceCheck then
begin
if isScrolling or
((LastPlaylistReloadTime <> 0) and
(NowTicks - LastPlaylistReloadTime < PLAYLIST_RELOAD_INTERVAL_MS)) then
Exit;
end;
LastPlaylistReloadTime := NowTicks;

CurrentSongRef := nil;
PreviewSongRef := nil;
if (Length(CatSongs.Song) > 0) then
begin
if (Interaction >= Low(CatSongs.Song)) and (Interaction <= High(CatSongs.Song)) then
CurrentSongRef := CatSongs.Song[Interaction];

if (PreviewOpened >= Low(CatSongs.Song)) and (PreviewOpened <= High(CatSongs.Song)) then
PreviewSongRef := CatSongs.Song[PreviewOpened];
end;

if not PlayListMan.ReloadPlayList(Cardinal(PlayListMan.CurPlayList)) then
Exit;

if not PlayListMan.ApplyPlayList(PlayListMan.CurPlayList) then
Exit;

NewPreviewOpened := FindSongRefIndex(PreviewSongRef);
if (NewPreviewOpened >= 0) and CatSongs.Song[NewPreviewOpened].Visible then
PreviewOpened := NewPreviewOpened
else if (PreviewOpened <> -1) then
begin
StopMusicPreview();
StopVideoPreview();
PreviewOpened := -1;
PreviewEndReloaded := false;
end;

NewInteraction := FindSongRefIndex(CurrentSongRef);
if (NewInteraction >= 0) and CatSongs.Song[NewInteraction].Visible then
begin
Interaction := NewInteraction;
FixSelected;
SetScrollRefresh;
Result := true;
Exit;
end;

StopMusicPreview();
StopVideoPreview();
PreviewOpened := -1;
PreviewEndReloaded := false;

if CatSongs.VisibleSongs > 0 then
begin
NewInteraction := CatSongs.FindNextVisible(Interaction);
if NewInteraction = -1 then
NewInteraction := CatSongs.FindPreviousVisible(Interaction);

if NewInteraction <> -1 then
Interaction := NewInteraction;

FixSelected;
SetScrollRefresh;
LastScrollStopTime := SDL_GetTicks;
end;

Result := true;
end;

function TScreenSong.FinishedMusic: boolean;
begin

Expand All @@ -3082,6 +3199,7 @@ function TScreenSong.Draw: boolean;
begin

FadeMessage();
ReloadCurrentPlaylist(false);

if isScrolling then
begin
Expand Down Expand Up @@ -3129,7 +3247,14 @@ function TScreenSong.Draw: boolean;
//Log.LogBenchmark('SetScroll4', 5);

if (AudioPlayback.Finished) then
begin
if (PreviewOpened <> -1) and not PreviewEndReloaded then
begin
PreviewEndReloaded := true;
ReloadCurrentPlaylist(true);
end;
CoverTime := 0;
end;

//Fading Functions, Only if Covertime is under 5 Seconds
if (TSongMenuMode(Ini.SongMenu) in [smChessboard, smList]) then
Expand Down Expand Up @@ -3590,6 +3715,8 @@ procedure TScreenSong.StartMusicPreview();
PreviewPos: real;
PreviewVolume: single;
begin
PreviewEndReloaded := false;

if SongIndex <> -1 then
begin
PreviewOpened := SongIndex;
Expand Down