Cover loading refactored

Fixed song loading check
Correct use of CoverTextureBig
This commit is contained in:
Flamefire committed 2013-02-23 14:04:38 +01:00
1 parent 9761c115b2
commit 5ff1677563
7 files changed
+114 -184

No files matched your search

+1 -1
View File
@@ -324,7 +324,7 @@ namespace Vocaluxe.Base
CInput.Update(); CInput.Update();
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && _CurrentScreen != EScreens.ScreenSing) if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && _CurrentScreen != EScreens.ScreenSing)
CSongs.LoadCover(30L, 1); CSongs.LoadCover();
if (CSettings.GameState != EGameState.EditTheme) if (CSettings.GameState != EGameState.EditTheme)
{ {
+9 -4
View File
@@ -607,15 +607,20 @@ namespace Vocaluxe.Base
return null; return null;
CSong song = CSongs.VisibleSongs[VisibleIndex]; CSong song = CSongs.VisibleSongs[VisibleIndex];
if (song == null) //Flamefire: Why copy the song-instance??? Cover and stuff will be loaded twice!
return null; //And for unknown reason causes no-big-cover bug if covers are not loaded on startup
return song;
//if (song == null)
// return null;
return new CSong(song); //return new CSong(song);
} }
public CSong GetSongByID(int SongID) public CSong GetSongByID(int SongID)
{ {
return new CSong(CSongs.GetSong(SongID)); //Flamefire: Why copy?
//return new CSong(CSongs.GetSong(SongID));
return CSongs.GetSong(SongID);
} }
public CSong[] GetSongs() public CSong[] GetSongs()
+19 -76
View File
@@ -55,7 +55,7 @@ namespace Vocaluxe.Base
private static ESongSorting _SongSorting = CConfig.SongSorting; private static ESongSorting _SongSorting = CConfig.SongSorting;
private static bool _ShowDuetSongs = true; private static bool _ShowDuetSongs = true;
private static Thread _CoverLoaderThread = new Thread(new ThreadStart(_LoadCover)); private static Thread _CoverLoaderThread = null;
public static string SearchFilter public static string SearchFilter
{ {
@@ -197,28 +197,26 @@ namespace Vocaluxe.Base
if (!_SongsLoaded) if (!_SongsLoaded)
return; return;
if (SongIndex <= _Songs.Count) if (SongIndex < _Songs.Count)
{ {
_Songs[SongIndex].CoverTextureSmall = Texture; _Songs[SongIndex].CoverTextureSmall = Texture;
//_Songs[SongIndex].CoverSmallLoaded = true; if (SongIndex == _Songs.Count - 1)
_CoverLoaded = true;
} }
if (SongIndex == _Songs.Count - 1)
_CoverLoaded = true;
} }
public static void SetCoverBig(int SongIndex, STexture Texture) public static void SetCoverBig(int SongIndex, STexture Texture)
{ {
if (!_SongsLoaded) if (!_SongsLoaded)
return; return;
if (SongIndex <= _Songs.Count) if (SongIndex < _Songs.Count)
{ {
_Songs[SongIndex].CoverTextureBig = Texture; _Songs[SongIndex].CoverTextureBig = Texture;
_Songs[SongIndex].CoverBigLoaded = true; if (SongIndex == _Songs.Count - 1)
_CoverLoaded = true;
} }
if (SongIndex == _Songs.Count - 1)
_CoverLoaded = true;
} }
public static string GetCurrentCategoryName() public static string GetCurrentCategoryName()
@@ -1027,6 +1025,9 @@ namespace Vocaluxe.Base
{ {
Song.ID = _Songs.Count; Song.ID = _Songs.Count;
_Songs.Add(Song); _Songs.Add(Song);
//Workaround to load notes if they are not loaded with the covers as there is no seperate progress indicator
if (CConfig.CoverLoading != ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART)
Song.ReadNotes();
} }
} }
CLog.StopBenchmark(2, "Read TXTs"); CLog.StopBenchmark(2, "Read TXTs");
@@ -1037,100 +1038,42 @@ namespace Vocaluxe.Base
Category = -1; Category = -1;
_SongsLoaded = true; _SongsLoaded = true;
if (CConfig.Renderer != ERenderer.TR_CONFIG_SOFTWARE && CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART) if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART)
{ {
CLog.StartBenchmark(2, "Load Covers/Notes"); CLog.StartBenchmark(2, "Load Covers/Notes");
for (int i = 0; i < _Songs.Count; i++) _LoadCover();
{
CSong song = _Songs[i];
song.ReadNotes();
STexture texture = song.CoverTextureSmall;
song.CoverTextureBig = texture;
_CoverLoadIndex++;
if (i % 100 == 0)
{
CDataBase.CommitCovers();
GC.Collect();
}
}
_CoverLoaded = true;
CDataBase.CommitCovers();
CLog.StopBenchmark(2, "Load Covers/Notes"); CLog.StopBenchmark(2, "Load Covers/Notes");
} }
CLog.StopBenchmark(1, "Load Songs "); CLog.StopBenchmark(1, "Load Songs ");
GC.Collect(); GC.Collect();
} }
public static void LoadCover(long WaitTime, int NumLoads) public static void LoadCover()
{ {
if (CConfig.Renderer == ERenderer.TR_CONFIG_SOFTWARE) if (CConfig.Renderer == ERenderer.TR_CONFIG_SOFTWARE)
return; //should be removed as soon as the other renderer are ready for queque
if (!SongsLoaded)
return; return;
if (CoverLoaded) if (!SongsLoaded || CoverLoaded)
return; return;
if (_CoverLoaderThread.ThreadState == System.Threading.ThreadState.Unstarted) if (_CoverLoaderThread == null)
{ {
_CoverLoaderThread = new Thread(new ThreadStart(_LoadCover));
_CoverLoaderThread.Name = "CoverLoader"; _CoverLoaderThread.Name = "CoverLoader";
_CoverLoaderThread.Priority = ThreadPriority.BelowNormal; _CoverLoaderThread.Priority = ThreadPriority.BelowNormal;
_CoverLoaderThread.IsBackground = true; _CoverLoaderThread.IsBackground = true;
_CoverLoaderThread.Start(); _CoverLoaderThread.Start();
} }
/*
if (!_CoverLoadTimer.IsRunning)
{
_CoverLoadTimer.Reset();
_CoverLoadTimer.Start();
}
STexture texture = new STexture(-1);
if (_CoverLoadTimer.ElapsedMilliseconds >= WaitTime)
{
for (int i = 0; i < NumLoads; i++)
{
CSong song = new CSong();
int n = GetNextSongWithoutCover(ref song);
if (n < 0)
return;
song.ReadNotes();
texture = song.CoverTextureSmall;
SetCoverSmall(n, texture);
SetCoverBig(n, texture);
if (CoverLoaded)
CDataBase.CommitCovers();
_CoverLoadTimer.Reset();
_CoverLoadTimer.Start();
}
}
* */
} }
private static void _LoadCover() private static void _LoadCover()
{ {
for (int i = 0; i < _Songs.Count; i++) foreach(CSong song in _Songs)
{ {
CSong song = _Songs[i];
song.ReadNotes(); song.ReadNotes();
STexture texture = song.CoverTextureSmall; song.LoadSmallCover();
song.CoverTextureBig = texture;
_CoverLoadIndex++;
} }
GC.Collect();
_CoverLoaded = true; _CoverLoaded = true;
CDataBase.CommitCovers(); CDataBase.CommitCovers();
} }
+5 -12
View File
@@ -165,8 +165,7 @@ namespace Vocaluxe.Screens
else else
_timer.Start(); _timer.Start();
bool next = ((CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART && CSongs.CoverLoaded) || bool next = (CConfig.CoverLoading != ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART || CSongs.CoverLoaded);
CConfig.CoverLoading != ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART);
if ((_IntroOutPlayed || _SkipIntro) && next && CSettings.GameState != EGameState.EditTheme && CSongs.SongsLoaded) if ((_IntroOutPlayed || _SkipIntro) && next && CSettings.GameState != EGameState.EditTheme && CSongs.SongsLoaded)
{ {
@@ -244,23 +243,17 @@ namespace Vocaluxe.Screens
{ {
_CurrentIntroVideoNr = 0; _CurrentIntroVideoNr = 0;
_Intros[0].Start(); _Intros[0].Start();
} }else if (_CurrentIntroVideoNr == 0 && _Intros[0].IsFinished && CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART)
if (_CurrentIntroVideoNr == 0 && _Intros[0].IsFinished && CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART)
{ {
_CurrentIntroVideoNr = 1; _CurrentIntroVideoNr = 1;
_Intros[1].Loop = true; _Intros[1].Loop = true;
_Intros[1].Start(); _Intros[1].Start();
} }else if ((_CurrentIntroVideoNr == 1 && CSongs.CoverLoaded) ||
(_CurrentIntroVideoNr == 0 && _Intros[0].IsFinished))
if ((_CurrentIntroVideoNr == 1 && CSongs.CoverLoaded) ||
(_CurrentIntroVideoNr == 0 && _Intros[0].IsFinished && CConfig.CoverLoading != ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART))
{ {
_CurrentIntroVideoNr = 2; _CurrentIntroVideoNr = 2;
_Intros[2].Start(); _Intros[2].Start();
} }else if (_CurrentIntroVideoNr == 2 && _Intros[2].IsFinished)
if (_CurrentIntroVideoNr == 2 && _Intros[2].IsFinished)
_IntroOutPlayed = true; _IntroOutPlayed = true;
} }
} }
+4 -4
View File
@@ -209,7 +209,7 @@ namespace Vocaluxe.Screens
} }
CConfig.PlayerInfo = (EPlayerInfo)mode; CConfig.PlayerInfo = (EPlayerInfo)mode;
CConfig.SaveConfig(); CConfig.SaveConfig();
SetVisuability(); SetVisibility();
break; break;
case Keys.S: case Keys.S:
@@ -432,7 +432,7 @@ namespace Vocaluxe.Screens
{ {
Statics[htStatics(StaticAvatars[p, CGame.NumPlayer - 1])].Aspect = EAspect.Crop; Statics[htStatics(StaticAvatars[p, CGame.NumPlayer - 1])].Aspect = EAspect.Crop;
} }
SetVisuability(); SetVisibility();
UpdateAvatars(); UpdateAvatars();
UpdateNames(); UpdateNames();
@@ -592,7 +592,7 @@ namespace Vocaluxe.Screens
return; return;
} }
if (!song.CoverSmallLoaded) if (!song.NotesLoaded)
song.ReadNotes(); song.ReadNotes();
string songname = song.Artist + " - " + song.Title; string songname = song.Artist + " - " + song.Title;
@@ -911,7 +911,7 @@ namespace Vocaluxe.Screens
} }
} }
private void SetVisuability() private void SetVisibility()
{ {
Statics[htStatics(StaticLyricsDuet)].Visible = false; Statics[htStatics(StaticLyricsDuet)].Visible = false;
Statics[htStatics(StaticLyricHelper)].Visible = false; Statics[htStatics(StaticLyricHelper)].Visible = false;
+70 -82
View File
@@ -69,7 +69,8 @@ namespace Vocaluxe.Menu.SongMenu
public class CSong public class CSong
{ {
private bool _CoverLoaded = false; private bool _CoverSmallLoaded = false;
private bool _CoverBigLoaded = false;
private bool _NotesLoaded = false; private bool _NotesLoaded = false;
private STexture _CoverTextureSmall = new STexture(-1); private STexture _CoverTextureSmall = new STexture(-1);
private STexture _CoverTextureBig = new STexture(-1); private STexture _CoverTextureBig = new STexture(-1);
@@ -96,34 +97,24 @@ namespace Vocaluxe.Menu.SongMenu
public bool CoverSmallLoaded public bool CoverSmallLoaded
{ {
get { return _CoverLoaded; } get { return _CoverSmallLoaded; }
}
public bool CoverBigLoaded
{
get { return _CoverBigLoaded; }
} }
public bool NotesLoaded public bool NotesLoaded
{ {
get { return _NotesLoaded; } get { return _NotesLoaded; }
} }
public bool CoverBigLoaded = false;
public STexture CoverTextureSmall public STexture CoverTextureSmall
{ {
get get
{ {
if (!_CoverLoaded) if (!_CoverSmallLoaded)
{ {
//Why in hell would you load the notes to get the cover??? LoadSmallCover();
//if (!_NotesLoaded)
// this.ReadNotes();
if (this.CoverFileName != String.Empty)
{
if (!CBase.Base.DataBase.GetCover(Path.Combine(this.Folder, this.CoverFileName), ref _CoverTextureSmall, CBase.Base.Config.GetCoverSize()))
_CoverTextureSmall = CBase.Base.Cover.GetNoCover();
}
else
_CoverTextureSmall = CBase.Base.Cover.GetNoCover();
_CoverLoaded = true;
} }
return _CoverTextureSmall; return _CoverTextureSmall;
} }
@@ -131,14 +122,23 @@ namespace Vocaluxe.Menu.SongMenu
set set
{ {
_CoverTextureSmall = value; _CoverTextureSmall = value;
_CoverLoaded = true; _CoverSmallLoaded = true;
} }
} }
public STexture CoverTextureBig public STexture CoverTextureBig
{ {
get { return _CoverTextureBig; } get
set { _CoverTextureBig = value; } {
if (_CoverBigLoaded)
return _CoverTextureBig;
else
return _CoverTextureSmall;
}
set {
_CoverTextureBig = value;
_CoverBigLoaded = true;
}
} }
public string Title = String.Empty; public string Title = String.Empty;
@@ -238,8 +238,8 @@ namespace Vocaluxe.Menu.SongMenu
this.VideoFileName = song.VideoFileName; this.VideoFileName = song.VideoFileName;
this.VideoAspect = song.VideoAspect; this.VideoAspect = song.VideoAspect;
this._CoverLoaded = song._CoverLoaded; this._CoverSmallLoaded = song._CoverSmallLoaded;
this.CoverBigLoaded = song.CoverBigLoaded; this._CoverBigLoaded = song._CoverBigLoaded;
this._NotesLoaded = song._NotesLoaded; this._NotesLoaded = song._NotesLoaded;
this.Artist = song.Artist; this.Artist = song.Artist;
@@ -604,8 +604,12 @@ namespace Vocaluxe.Menu.SongMenu
{ {
return ReadNotes(Path.Combine(this.Folder, this.FileName)); return ReadNotes(Path.Combine(this.Folder, this.FileName));
} }
public bool ReadNotes(string FilePath) public bool ReadNotes(string FilePath, bool forceReload=false)
{ {
//Skip loading if already done and no reload is forced
if (_NotesLoaded && !forceReload)
return true;
if (!File.Exists(FilePath)) if (!File.Exists(FilePath))
{ {
CBase.Base.Log.LogError("Error loading song. The file does not exist: " + FilePath); CBase.Base.Log.LogError("Error loading song. The file does not exist: " + FilePath);
@@ -809,6 +813,21 @@ namespace Vocaluxe.Menu.SongMenu
} }
} }
public void LoadSmallCover()
{
if (_CoverSmallLoaded)
return;
if (this.CoverFileName != String.Empty)
{
if (!CBase.Base.DataBase.GetCover(Path.Combine(this.Folder, this.CoverFileName), ref _CoverTextureSmall, CBase.Base.Config.GetCoverSize()))
_CoverTextureSmall = CBase.Base.Cover.GetNoCover();
}
else
_CoverTextureSmall = CBase.Base.Cover.GetNoCover();
_CoverSmallLoaded = true;
}
private void CheckFiles() private void CheckFiles()
{ {
CHelper Helper = new CHelper(); CHelper Helper = new CHelper();
@@ -861,24 +880,12 @@ namespace Vocaluxe.Menu.SongMenu
public int length; public int length;
} }
private void FindRefrain() private List<Series> GetSeries()
{ {
if (this.IsDuet)
{
this.Medley.Source = EMedleySource.None;
return;
}
if (this.Medley.Source == EMedleySource.Tag)
return;
if (!this.CalculateMedley)
return;
CLines lines = this.Notes.GetLines(0); CLines lines = this.Notes.GetLines(0);
if (lines.LineCount == 0) if (lines.LineCount == 0)
return; return null;
// build sentences list // build sentences list
List<string> sentences = new List<string>(); List<string> sentences = new List<string>();
@@ -921,6 +928,26 @@ namespace Vocaluxe.Menu.SongMenu
} }
} }
} }
return series;
}
private void FindRefrain()
{
if (this.IsDuet)
{
this.Medley.Source = EMedleySource.None;
return;
}
if (this.Medley.Source == EMedleySource.Tag)
return;
if (!this.CalculateMedley)
return;
List<Series> series = GetSeries();
if (series == null)
return;
// search for longest series // search for longest series
int longest = 0; int longest = 0;
@@ -930,6 +957,8 @@ namespace Vocaluxe.Menu.SongMenu
longest = i; longest = i;
} }
CLines lines = this.Notes.GetLines(0);
// set medley vars // set medley vars
if (series.Count > 0 && series[longest].length > CBase.Base.Settings.GetMedleyMinSeriesLength()) if (series.Count > 0 && series[longest].length > CBase.Base.Settings.GetMedleyMinSeriesLength())
{ {
@@ -972,52 +1001,11 @@ namespace Vocaluxe.Menu.SongMenu
} }
private void FindShortEnd(){ private void FindShortEnd(){
CLines lines = this.Notes.GetLines(0); List<Series> series = GetSeries();
if (series == null)
if (lines.LineCount == 0)
return; return;
// build sentences list CLines lines = this.Notes.GetLines(0);
List<string> sentences = new List<string>();
foreach (CLine line in lines.Line)
{
if (line.Points != 0)
sentences.Add(line.Lyrics);
else
sentences.Add(String.Empty);
}
// find equal sentences series
List<Series> series = new List<Series>();
for (int i = 0; i < lines.LineCount - 1; i++)
{
for (int j = i + 1; j < lines.LineCount; j++)
{
if (sentences[i] == sentences[j] && sentences[i] != String.Empty)
{
Series tempSeries = new Series();
tempSeries.start = i;
tempSeries.end = i;
int max = 0;
if (j + j - i - 1 > lines.LineCount - 1)
max = lines.LineCount - 1 - j;
else
max = j - i - 1;
for (int k = 1; k <= max; k++)
{
if (sentences[i + k] == sentences[j + k] && sentences[i + k] != String.Empty)
tempSeries.end = i + k;
else
break;
}
tempSeries.length = tempSeries.end - tempSeries.start + 1;
series.Add(tempSeries);
}
}
}
//Calculate length of singing //Calculate length of singing
int stop = (lines.Line[lines.Line.Length - 1].LastNoteBeat - lines.Line[0].FirstNoteBeat) / 2 + lines.Line[0].StartBeat; int stop = (lines.Line[lines.Line.Length - 1].LastNoteBeat - lines.Line[0].FirstNoteBeat) / 2 + lines.Line[0].StartBeat;
@@ -132,7 +132,7 @@ namespace Vocaluxe.Menu.SongMenu
int actcat = _PreviewSelected; int actcat = _PreviewSelected;
if ((CBase.Base.Songs.GetNumCategories() > 0) && (actcat < 0)) if ((CBase.Base.Songs.GetNumCategories() > 0) && (actcat < 0))
{ {
_CoverBig.Texture = CBase.Base.Songs.GetCategory(0).CoverTextureSmall; _CoverBig.Texture = CBase.Base.Songs.GetCategory(0).CoverTextureBig;
_Artist.Text = CBase.Base.Songs.GetCategory(0).Name; _Artist.Text = CBase.Base.Songs.GetCategory(0).Name;
_Title.Text = String.Empty; _Title.Text = String.Empty;
_SongLength.Text = String.Empty; _SongLength.Text = String.Empty;
@@ -456,7 +456,7 @@ namespace Vocaluxe.Menu.SongMenu
{ {
CSong song = CBase.Base.Songs.GetVisibleSong(actsong); CSong song = CBase.Base.Songs.GetVisibleSong(actsong);
_CoverBig.Texture = song.CoverTextureSmall; _CoverBig.Texture = song.CoverTextureBig;
_Artist.Text = song.Artist; _Artist.Text = song.Artist;
_Title.Text = song.Title; _Title.Text = song.Title;
_DuetIcon.Visible = song.IsDuet; _DuetIcon.Visible = song.IsDuet;
@@ -479,7 +479,7 @@ namespace Vocaluxe.Menu.SongMenu
int actcat = _PreviewSelected; int actcat = _PreviewSelected;
if ((CBase.Base.Songs.GetNumCategories() > actcat) && (actcat >= 0)) if ((CBase.Base.Songs.GetNumCategories() > actcat) && (actcat >= 0))
{ {
_CoverBig.Texture = CBase.Base.Songs.GetCategory(actcat).CoverTextureSmall; _CoverBig.Texture = CBase.Base.Songs.GetCategory(actcat).CoverTextureBig;
_Artist.Text = CBase.Base.Songs.GetCategory(actcat).Name; _Artist.Text = CBase.Base.Songs.GetCategory(actcat).Name;
int num = CBase.Base.Songs.NumSongsInCategory(actcat); int num = CBase.Base.Songs.NumSongsInCategory(actcat);
@@ -499,8 +499,9 @@ namespace Vocaluxe.Menu.SongMenu
_TextBG.Draw(); _TextBG.Draw();
_CoverBig.Draw(1f, EAspect.Crop); _CoverBig.Draw(1f, EAspect.Crop);
if (_vidtex.color.A < 1) //Flamefire: Why draw twice?
_CoverBig.Draw(1f, EAspect.Crop); //if (_vidtex.color.A < 1)
// _CoverBig.Draw(1f, EAspect.Crop);
if (_vidtex.index != -1 && _Video != -1) if (_vidtex.index != -1 && _Video != -1)
{ {