diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index ea7e9364..65165cf4 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Threading.Tasks; using VocaluxeLib; using VocaluxeLib.Songs; using VocaluxeLib.Draw; @@ -47,6 +48,10 @@ namespace Vocaluxe.Base private static bool _BackgroundMusicAdded; private static bool _Disabled; + private static Task _PreviewStartHelperTask; + private static int _PreviewStartWaitCounter; + private const int _PreviewStartWaitMaxTries = 10; + public static bool VideoEnabled { get { return _CurPlayer.VideoEnabled; } @@ -249,6 +254,14 @@ namespace Vocaluxe.Base public static void Update() { + if (_PreviewStartHelperTask != null && ( _PreviewPlayer.Length > 0 || _PreviewStartWaitCounter++ >= _PreviewStartWaitMaxTries)) + { + _PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext()); + _PreviewStartHelperTask.Dispose(); + _PreviewStartHelperTask = null; + _PreviewStartWaitCounter = 0; + } + if (!IsPlaying) return; @@ -299,31 +312,41 @@ namespace Vocaluxe.Base bool songChanged = _CurPlayer.SongID != song.ID; _PreviewPlayer.Load(song); + //Change song position only if song is changed or near to end if (songChanged || _CurPlayer.Position + 30 < _CurPlayer.Length) { - float length = _PreviewPlayer.Length; - if (length < 1) - length = 30; // If length is unknow or invalid assume a length of 30s + _PreviewStartHelperTask = new Task(() => + { + float length = _PreviewPlayer.Length; + if (length < 1) + length = 30; // If length is unknow or invalid assume a length of 30s - if (start < 0) - start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime; - if (start > length - 5f) - start = Math.Max(0f, Math.Min(length / 4f, length - 5f)); - if (start >= 0.5f) - start -= 0.5f; + if (start < 0) + start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime; + if (start > length - 5f) + start = Math.Max(0f, Math.Min(length / 4f, length - 5f)); + if (start >= 0.5f) + start -= 0.5f; - _PreviewPlayer.Position = start; + _PreviewPlayer.Position = start; + Play(); + }); + _CurPlayer = _PreviewPlayer; } else { + _PreviewStartHelperTask.Dispose(); + _PreviewStartHelperTask = null; _PreviewPlayer.Position = _CurPlayer.Position; + _CurPlayer = _PreviewPlayer; + Play(); } - _CurPlayer = _PreviewPlayer; + - Play(); + } public static void StopPreview() diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 6409815a..ea133582 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -163,6 +163,7 @@ namespace Vocaluxe.Base [DefaultValue(EOffOn.TR_CONFIG_OFF)] public EOffOn ServerActive; [DefaultValue(EOffOn.TR_CONFIG_OFF)] public EOffOn ServerEncryption; [DefaultValue(3000)] public int ServerPort; + [DefaultValue(70)] public int SongCountCoverThreshold; } #pragma warning restore 649 // ReSharper restore UnassignedField.Global @@ -495,6 +496,8 @@ namespace Vocaluxe.Base return "Server Encryption On/Off: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn))); case "ServerPort": return "Server Port (default: 3000) [1..65535]"; + case "SongCountCoverThreshold": + return "Threshold of songs for that covers will not longer be included in get-all-songs-requests (e.g. song list) (default: 70) [-1..65535] -1 => always deliver covers"; case "Stretch": return "Stretch view to full window size: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn))); default: diff --git a/Vocaluxe/Base/Server/CVocaluxeServer.cs b/Vocaluxe/Base/Server/CVocaluxeServer.cs index 138df11f..477713b6 100644 --- a/Vocaluxe/Base/Server/CVocaluxeServer.cs +++ b/Vocaluxe/Base/Server/CVocaluxeServer.cs @@ -624,11 +624,20 @@ namespace Vocaluxe.Base.Server return _GetSongInfo(song, true); } + + private static SSongInfo[] _SongInfoCache = null; public static SSongInfo[] GetAllSongs() { - List songs = CSongs.Songs; - return (from s in songs - select _GetSongInfo(s, false)).ToArray(); + bool sendCovers = CConfig.Config.Server.SongCountCoverThreshold == -1 || CConfig.Config.Server.SongCountCoverThreshold > CSongs.Songs.Count; + + if (_SongInfoCache == null) + { + List songs = CSongs.Songs; + _SongInfoCache = (from s in songs + select _GetSongInfo(s, sendCovers)).AsParallel().ToArray(); + } + + return _SongInfoCache; } public static string GetMp3Path(int songId) @@ -658,7 +667,17 @@ namespace Vocaluxe.Base.Server result.IsDuet = song.IsDuet; result.SongId = song.ID; if (includeCover) - result.Cover = new CBase64Image(_CreateDelayedImage(song.Folder + "\\" + song.CoverFileName)); + { + if (song.CoverFileName == "") + { + result.Cover = new CBase64Image(_CreateDelayedImage("Website\\img\\noCover.png")); + } + else + { + result.Cover = new CBase64Image(_CreateDelayedImage(song.Folder + "\\" + song.CoverFileName)); + } + } + } return result; } diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 51aca1ce..5d49a606 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -684,7 +684,7 @@ namespace Vocaluxe.Screens { int song = _SongMenu.GetSelectedSongNr(); if (song >= 0 && song < CSongs.VisibleSongs.Count) - selectionText = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title + " ( "+(song+1)+" / "+CSongs.NumAllSongs+" )"; + selectionText = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title + " ( "+(song+1)+" / "+CSongs.NumSongsVisible+" )"; } else { diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 6c0011d3..00fca9f4 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -540,26 +540,26 @@ powershell -command "(Get-Content -Encoding UTF8 '$(ProjectDir)Properties\Assemb - + - + - + - + \ No newline at end of file diff --git a/Vocaluxe/Website/js/main.js b/Vocaluxe/Website/js/main.js index 94df59ad..3b9f96da 100644 --- a/Vocaluxe/Website/js/main.js +++ b/Vocaluxe/Website/js/main.js @@ -897,9 +897,26 @@ } for (var id in allSongsCache) { - $('
  • '/*+' '*/ + '

    ' + allSongsCache[id].Artist + '

    ' + allSongsCache[id].Title + '

  • ') + var coverString = ""; + var currentCoverId = ""; + + if (allSongsCache[id].Cover !== null) { + if (allSongsCache[id].Cover.base64Data !== "") { + coverString = ''; + } + else if (allSongsCache[id].Cover.imageId !== "") { + currentCoverId = "songListCoverId_" + id; + coverString = ''; + } + } + + $('
  • ' + coverString + '

    ' + allSongsCache[id].Artist + '

    ' + allSongsCache[id].Title + '

  • ') .appendTo('#selectSongList') .click(handleSelectSongLineClick); + + if (currentCoverId !== "") { + imageLoader.delayedImageLoad($("#" + currentCoverId)[0], allSongsCache[id].Cover.imageId, "img/noCover.png"); + } } $('#selectSongList').listview('refresh'); diff --git a/Vocaluxe/packages.config b/Vocaluxe/packages.config index fe9f7814..491119d1 100644 --- a/Vocaluxe/packages.config +++ b/Vocaluxe/packages.config @@ -1,13 +1,13 @@  - + - + diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index ca1f9323..21e66baf 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -415,7 +415,7 @@ namespace VocaluxeLib.Menu.SongMenu if (song == null) return; - CBase.BackgroundMusic.LoadPreview(song); + CBase.BackgroundMusic.LoadPreview(song, song.Preview.StartTime); } protected void _ResetPreview(bool playBGagain = true)