From fe07a2f926ac379657a08a916405818b1687f181 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Thu, 23 Oct 2014 17:05:57 +0200 Subject: [PATCH] Generate Covers for songs --- Output/Cover/Blue.xml | 2 +- Vocaluxe/Base/CMain.cs | 5 +++++ Vocaluxe/Lib/Draw/CTextureProvider.cs | 29 +++++++++++++++------------ VocaluxeLib/IBasic.cs | 1 + VocaluxeLib/Songs/CSong.cs | 7 +++---- VocaluxeLib/Structs.cs | 1 + 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Output/Cover/Blue.xml b/Output/Cover/Blue.xml index 8afbbb3b..833e2465 100644 --- a/Output/Cover/Blue.xml +++ b/Output/Cover/Blue.xml @@ -7,7 +7,7 @@ - + Default diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index ffbabbc9..2437fc6b 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -871,6 +871,11 @@ namespace Vocaluxe.Base { return CCover.NoCover; } + + public CTextureRef GenerateCover(string text, ECoverGeneratorType type, CSong firstSong) + { + return CCover.GenerateCover(text, type, firstSong); + } } class CBdataBase : IDataBase diff --git a/Vocaluxe/Lib/Draw/CTextureProvider.cs b/Vocaluxe/Lib/Draw/CTextureProvider.cs index 0782f73b..12ab6c75 100644 --- a/Vocaluxe/Lib/Draw/CTextureProvider.cs +++ b/Vocaluxe/Lib/Draw/CTextureProvider.cs @@ -833,23 +833,26 @@ namespace Vocaluxe.Lib.Draw public CTextureRef CopyTexture(CTextureRef textureRef) { - _EnsureMainThread(); - TTextureType texture; - if (!_GetTexture(textureRef, out texture, false)) - return null; - // If bitmap is not yet loaded, wait for it - if (!String.IsNullOrEmpty(texture.TexturePath)) + // Lock to make sure the texture is not disposed while we are in this method + lock (_Textures) { - Task loader; - lock (_BitmapsLoading) + TTextureType texture; + if (!_GetTexture(textureRef, out texture, false)) + return null; + // If bitmap is not yet loaded, wait for it + if (!String.IsNullOrEmpty(texture.TexturePath)) { - _BitmapsLoading.TryGetValue(texture.TexturePath, out loader); + Task loader; + lock (_BitmapsLoading) + { + _BitmapsLoading.TryGetValue(texture.TexturePath, out loader); + } + if (loader != null) + textureRef.OrigSize = loader.Result; } - if (loader != null) - textureRef.OrigSize = loader.Result; + Debug.Assert(textureRef.OrigSize.Width > 0); + return _GetTextureReference(textureRef.OrigSize, texture); } - Debug.Assert(textureRef.OrigSize.Width > 0); - return _GetTextureReference(textureRef.OrigSize, texture); } /// diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index 42bd1948..0b858def 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -283,6 +283,7 @@ namespace VocaluxeLib public interface ICover { CTextureRef GetNoCover(); + CTextureRef GenerateCover(string text, ECoverGeneratorType type, CSong firstSong); } public interface IDataBase diff --git a/VocaluxeLib/Songs/CSong.cs b/VocaluxeLib/Songs/CSong.cs index a5baf8e5..3a5cb2d0 100644 --- a/VocaluxeLib/Songs/CSong.cs +++ b/VocaluxeLib/Songs/CSong.cs @@ -314,11 +314,10 @@ namespace VocaluxeLib.Songs return; if (CoverFileName != "") { - if (!CBase.DataBase.GetCover(Path.Combine(Folder, CoverFileName), ref _CoverTextureSmall, CBase.Config.GetCoverSize())) - _CoverTextureSmall = CBase.Cover.GetNoCover(); + if (CBase.DataBase.GetCover(Path.Combine(Folder, CoverFileName), ref _CoverTextureSmall, CBase.Config.GetCoverSize())) + return; } - else - _CoverTextureSmall = CBase.Cover.GetNoCover(); + _CoverTextureSmall = CBase.Cover.GenerateCover(Title, ECoverGeneratorType.Song, null); } private void _CheckFiles() diff --git a/VocaluxeLib/Structs.cs b/VocaluxeLib/Structs.cs index 85650c1a..13c9bcd8 100644 --- a/VocaluxeLib/Structs.cs +++ b/VocaluxeLib/Structs.cs @@ -29,6 +29,7 @@ namespace VocaluxeLib public enum ECoverGeneratorType { Default, + Song, Folder, Artist, Letter,