Increase speed of cover loading
This commit is contained in:
1 parent
3bce89eecf
commit
f0b227798e
2 files changed
+30
-51
No files matched your search
@@ -187,9 +187,6 @@ namespace Vocaluxe.Base
|
|||||||
CController.Update();
|
CController.Update();
|
||||||
CProfiles.Update();
|
CProfiles.Update();
|
||||||
|
|
||||||
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && _CurrentScreen != EScreens.ScreenSing)
|
|
||||||
CSongs.LoadCover();
|
|
||||||
|
|
||||||
if (CSettings.ProgramState != EProgramState.EditTheme)
|
if (CSettings.ProgramState != EProgramState.EditTheme)
|
||||||
{
|
{
|
||||||
run &= _HandleInputs(keys, mouse);
|
run &= _HandleInputs(keys, mouse);
|
||||||
|
|||||||
+30
-48
@@ -21,6 +21,7 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using VocaluxeLib;
|
using VocaluxeLib;
|
||||||
using VocaluxeLib.Songs;
|
using VocaluxeLib.Songs;
|
||||||
|
|
||||||
@@ -134,23 +135,13 @@ namespace Vocaluxe.Base
|
|||||||
Category--;
|
Category--;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetNextSongWithoutCover(ref CSong song)
|
private static int _NumSongsWithCoverLoaded;
|
||||||
|
public static int NumSongsWithCoverLoaded
|
||||||
{
|
{
|
||||||
if (!SongsLoaded)
|
get { return _NumSongsWithCoverLoaded; }
|
||||||
return -1;
|
private set { _NumSongsWithCoverLoaded = value; }
|
||||||
|
|
||||||
if (NumSongsWithCoverLoaded < _Songs.Count)
|
|
||||||
{
|
|
||||||
song = _Songs[NumSongsWithCoverLoaded];
|
|
||||||
NumSongsWithCoverLoaded++;
|
|
||||||
return NumSongsWithCoverLoaded;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int NumSongsWithCoverLoaded { get; private set; }
|
|
||||||
|
|
||||||
public static string GetCurrentCategoryName()
|
public static string GetCurrentCategoryName()
|
||||||
{
|
{
|
||||||
return _IsCatIndexValid(_CatIndex) ? Categories[_CatIndex].Name : "";
|
return _IsCatIndexValid(_CatIndex) ? Categories[_CatIndex].Name : "";
|
||||||
@@ -371,59 +362,50 @@ namespace Vocaluxe.Base
|
|||||||
Category = -1;
|
Category = -1;
|
||||||
SongsLoaded = true;
|
SongsLoaded = true;
|
||||||
|
|
||||||
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART)
|
switch (CConfig.CoverLoading)
|
||||||
{
|
{
|
||||||
CLog.StartBenchmark("Load Covers");
|
case ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART:
|
||||||
_LoadCover();
|
_LoadCovers();
|
||||||
CLog.StopBenchmark("Load Covers");
|
break;
|
||||||
|
case ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC:
|
||||||
|
_LoadCoversAsync();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
CLog.StopBenchmark("Load Songs ");
|
CLog.StopBenchmark("Load Songs");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadCover()
|
private static void _LoadCoversAsync()
|
||||||
{
|
{
|
||||||
if (CConfig.Renderer == ERenderer.TR_CONFIG_SOFTWARE)
|
|
||||||
return; //should be removed as soon as the other renderer are ready for queue
|
|
||||||
|
|
||||||
if (!SongsLoaded || CoverLoaded)
|
if (!SongsLoaded || CoverLoaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_CoverLoaderThread != null)
|
if (_CoverLoaderThread != null)
|
||||||
return;
|
return;
|
||||||
_CoverLoaderThread = new Thread(_LoadCover) {Name = "CoverLoader", Priority = ThreadPriority.BelowNormal, IsBackground = true};
|
_CoverLoaderThread = new Thread(_LoadCovers) {Name = "CoverLoader", Priority = ThreadPriority.BelowNormal, IsBackground = true};
|
||||||
_CoverLoaderThread.Start();
|
_CoverLoaderThread.Start();
|
||||||
|
|
||||||
/*
|
|
||||||
if (_CoverLoadTimer.ElapsedMilliseconds >= WaitTime)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < NumLoads; i++)
|
|
||||||
{
|
|
||||||
CSong song = null;
|
|
||||||
int n = GetNextSongWithoutCover(ref song);
|
|
||||||
|
|
||||||
if (n < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
song.LoadSmallCover();
|
|
||||||
|
|
||||||
if (n == NumAllSongs)
|
|
||||||
CDataBase.CommitCovers();
|
|
||||||
}
|
|
||||||
_CoverLoadTimer.Reset();
|
|
||||||
_CoverLoadTimer.Start();
|
|
||||||
}
|
|
||||||
* */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void _LoadCover()
|
private static void _LoadCovers()
|
||||||
{
|
{
|
||||||
|
CLog.StartBenchmark("Load Covers");
|
||||||
|
int songCount = _Songs.Count;
|
||||||
|
AutoResetEvent ev = new AutoResetEvent(songCount == 0);
|
||||||
|
|
||||||
|
NumSongsWithCoverLoaded = 0;
|
||||||
foreach (CSong song in _Songs)
|
foreach (CSong song in _Songs)
|
||||||
{
|
{
|
||||||
song.LoadSmallCover();
|
CSong tmp = song;
|
||||||
NumSongsWithCoverLoaded++;
|
Task.Factory.StartNew(() =>
|
||||||
|
{
|
||||||
|
tmp.LoadSmallCover();
|
||||||
|
if (Interlocked.Increment(ref _NumSongsWithCoverLoaded) >= songCount)
|
||||||
|
ev.Set();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
ev.WaitOne();
|
||||||
_CoverLoaded = true;
|
_CoverLoaded = true;
|
||||||
CDataBase.CommitCovers();
|
CDataBase.CommitCovers();
|
||||||
|
CLog.StopBenchmark("Load Covers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user