From 0a48c6b74b59906de3cac17d0af239fbf9e8e229 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Thu, 23 Oct 2014 16:16:24 +0200 Subject: [PATCH] Rename CoverGenerator --- Vocaluxe/Base/CCover.cs | 34 +++++++++---------- ...NoCoverGenerator.cs => CCoverGenerator.cs} | 4 +-- Vocaluxe/Base/CSongCategorizer.cs | 2 +- Vocaluxe/Vocaluxe.csproj | 2 +- 4 files changed, 20 insertions(+), 22 deletions(-) rename Vocaluxe/Base/{CNoCoverGenerator.cs => CCoverGenerator.cs} (99%) diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index a871355b..3c96da1a 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -39,7 +39,7 @@ namespace Vocaluxe.Base private const string _NoCoverName = "No Cover"; private const string _NoCoverNameAlt = "NoCover"; private static readonly Dictionary _Covers = new Dictionary(); - private static readonly Dictionary _NoCoverGenerators = new Dictionary(); + private static readonly Dictionary _CoverGenerators = new Dictionary(); private static readonly List _CoverThemes = new List(); private static readonly CancellationTokenSource _CancelToken = new CancellationTokenSource(); @@ -88,7 +88,7 @@ namespace Vocaluxe.Base } /// - /// Returns a STexture for a given cover name. Returns "NoCover" if the cover does not exist. + /// Returns a Texture reference for a given cover name. Returns "NoCover" if the cover does not exist. /// public static CTextureRef Cover(string name) { @@ -101,19 +101,17 @@ namespace Vocaluxe.Base } } - public static CTextureRef GenerateCover(string text, ESongSorting sorting, CCategory category) + public static CTextureRef GenerateCover(string text, ECoverGeneratorType type, CSong firstSong) { - CSong firstSong = category.GetSong(0); CTextureRef texture = CDraw.CopyTexture(NoCover); Task.Factory.StartNew(() => { _CancelToken.Token.ThrowIfCancellationRequested(); - ECoverGeneratorType type = _SongSortingToType(sorting); - Bitmap coverBmp = !_NoCoverGenerators.ContainsKey(type) - ? null : _NoCoverGenerators[type].GetCover(text, firstSong != null ? Path.Combine(firstSong.Folder, firstSong.CoverFileName) : null); + Bitmap coverBmp = !_CoverGenerators.ContainsKey(type) + ? null : _CoverGenerators[type].GetCover(text, firstSong != null ? Path.Combine(firstSong.Folder, firstSong.CoverFileName) : null); _CancelToken.Token.ThrowIfCancellationRequested(); - if (coverBmp == null && _NoCoverGenerators.ContainsKey(ECoverGeneratorType.Default)) - coverBmp = _NoCoverGenerators[ECoverGeneratorType.Default].GetCover(text, firstSong != null ? Path.Combine(firstSong.Folder, firstSong.CoverFileName) : null); + if (coverBmp == null && _CoverGenerators.ContainsKey(ECoverGeneratorType.Default)) + coverBmp = _CoverGenerators[ECoverGeneratorType.Default].GetCover(text, firstSong != null ? Path.Combine(firstSong.Folder, firstSong.CoverFileName) : null); _CancelToken.Token.ThrowIfCancellationRequested(); if (coverBmp != null) CDraw.EnqueueTextureUpdate(texture, coverBmp); @@ -155,9 +153,9 @@ namespace Vocaluxe.Base } _Covers.Clear(); } - lock (_NoCoverGenerators) + lock (_CoverGenerators) { - _NoCoverGenerators.Clear(); + _CoverGenerators.Clear(); } } @@ -229,10 +227,10 @@ namespace Vocaluxe.Base else CBase.Log.LogError("Covertheme \"" + coverThemeName + "\" does not include a cover file named \"" + _NoCoverName + "\" and cannot be used!", true, true); } - _LoadNoCoverThemes(coverTheme); + _LoadCoverGenerators(coverTheme); } - private static ECoverGeneratorType _SongSortingToType(ESongSorting sorting) + public static ECoverGeneratorType _SongSortingToType(ESongSorting sorting) { switch (sorting) { @@ -262,11 +260,11 @@ namespace Vocaluxe.Base } } - private static void _LoadNoCoverThemes(SThemeCover coverTheme) + private static void _LoadCoverGenerators(SThemeCover coverTheme) { CXMLReader xmlReader = CXMLReader.OpenFile(coverTheme.FilePath); string coverPath = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover, coverTheme.Folder); - lock (_NoCoverGenerators) + lock (_CoverGenerators) { int i = 1; while (xmlReader.ItemExists("//root/CoverGenerator" + i)) @@ -274,10 +272,10 @@ namespace Vocaluxe.Base SThemeCoverGenerator theme; if (xmlReader.Read("//root/CoverGenerator" + i, out theme)) { - if (_NoCoverGenerators.ContainsKey(theme.Type)) + if (_CoverGenerators.ContainsKey(theme.Type)) continue; - CNoCoverGenerator el = new CNoCoverGenerator(theme, coverPath); - _NoCoverGenerators.Add(theme.Type, el); + CCoverGenerator el = new CCoverGenerator(theme, coverPath); + _CoverGenerators.Add(theme.Type, el); } i++; } diff --git a/Vocaluxe/Base/CNoCoverGenerator.cs b/Vocaluxe/Base/CCoverGenerator.cs similarity index 99% rename from Vocaluxe/Base/CNoCoverGenerator.cs rename to Vocaluxe/Base/CCoverGenerator.cs index d92177e0..a1de5791 100644 --- a/Vocaluxe/Base/CNoCoverGenerator.cs +++ b/Vocaluxe/Base/CCoverGenerator.cs @@ -33,7 +33,7 @@ namespace Vocaluxe.Base /// Class that generates Covers if the right Cover is missing /// Themeable via the xml of the Cover theme /// - class CNoCoverGenerator + class CCoverGenerator { private readonly bool _Valid; private readonly SThemeCoverGenerator _Theme; @@ -49,7 +49,7 @@ namespace Vocaluxe.Base private static readonly char[] _SplitCharAfter = {':', '/', '-', ' ', ')', '.', '*', ','}; private static readonly char[] _SplitCharBefore = {'('}; - public CNoCoverGenerator(SThemeCoverGenerator theme, string basePath) + public CCoverGenerator(SThemeCoverGenerator theme, string basePath) { _Theme = theme; _Valid = true; diff --git a/Vocaluxe/Base/CSongCategorizer.cs b/Vocaluxe/Base/CSongCategorizer.cs index 7104c795..8f0491d5 100644 --- a/Vocaluxe/Base/CSongCategorizer.cs +++ b/Vocaluxe/Base/CSongCategorizer.cs @@ -181,7 +181,7 @@ namespace Vocaluxe.Base { cat.CoverTextureSmall = CCover.Cover(cat.Name); if (cat.CoverTextureSmall == CCover.NoCover) - cat.CoverTextureSmall = CCover.GenerateCover(cat.Name, CSongs.Sorter.SongSorting, cat); + cat.CoverTextureSmall = CCover.GenerateCover(cat.Name, CCover._SongSortingToType(CSongs.Sorter.SongSorting), cat.GetSong(0)); } _Changed = false; } diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 3bb3e2f5..c746bcc1 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -216,7 +216,7 @@ - +