From c2462d723ac81e2002017546de36b5126f73c08d Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 18 Oct 2013 21:18:45 +0200 Subject: [PATCH 01/18] Fix weird formatting in CScreenSong.cs (no code changes) --- Vocaluxe.sln | 5 +-- Vocaluxe/Screens/CScreenSong.cs | 65 ++++++++++++++++----------------- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/Vocaluxe.sln b/Vocaluxe.sln index d894246e..0896a6f6 100644 --- a/Vocaluxe.sln +++ b/Vocaluxe.sln @@ -1,6 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Express 2012 for Windows Desktop +# Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vocaluxe", "Vocaluxe\Vocaluxe.csproj", "{2A1E0F2D-5392-4BB7-B0A1-A9DFA13E79FF}" ProjectSection(ProjectDependencies) = postProject {6F3E1874-F28A-40E9-AFBD-31934D593678} = {6F3E1874-F28A-40E9-AFBD-31934D593678} @@ -154,7 +154,4 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(Performance) = preSolution - HasPerformanceSessions = true - EndGlobalSection EndGlobal diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 0fbe7096..0f410bc1 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -105,7 +105,7 @@ namespace Vocaluxe.Screens _ButtonsJoker.Clear(); for (int i = 0; i < CSettings.MaxNumPlayer; i++) _ButtonsJoker.Add("ButtonJoker" + (i + 1)); - List blist = new List(); + var blist = new List(); blist.AddRange(_ButtonsJoker); blist.Add(_ButtonOptionsClose); blist.Add(_ButtonOptionsPlaylist); @@ -123,7 +123,7 @@ namespace Vocaluxe.Screens _TextsPlayer.Clear(); for (int i = 0; i < CSettings.MaxNumPlayer; i++) _TextsPlayer.Add("TextPlayer" + (i + 1)); - List tlist = new List(); + var tlist = new List(); tlist.AddRange(_TextsPlayer); tlist.Add(_TextCategory); tlist.Add(_TextSelection); @@ -172,7 +172,7 @@ namespace Vocaluxe.Screens { if (_SearchActive) _ApplyNewSearchFilter(_SearchText + keyEvent.Unicode); - else if(!_Sso.Selection.PartyMode) + else if (!_Sso.Selection.PartyMode) { _JumpTo(keyEvent.Unicode); return true; @@ -862,7 +862,7 @@ namespace Vocaluxe.Screens CGame.Reset(); CGame.ClearSongs(); - List ids = new List(); + var ids = new List(); for (int i = 0; i < CSongs.AllSongs.Count; i++) ids.Add(i); @@ -870,7 +870,7 @@ namespace Vocaluxe.Screens { int songNr = ids[CGame.Rand.Next(ids.Count)]; - EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; + var gm = EGameMode.TR_GAMEMODE_NORMAL; if (CSongs.AllSongs[songNr].IsDuet) gm = EGameMode.TR_GAMEMODE_DUET; @@ -894,7 +894,7 @@ namespace Vocaluxe.Screens { int songNr = ids[CGame.Rand.Next(ids.Count)]; - EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; + var gm = EGameMode.TR_GAMEMODE_NORMAL; if (CSongs.AllSongs[songNr].IsDuet) gm = EGameMode.TR_GAMEMODE_DUET; @@ -1009,10 +1009,10 @@ namespace Vocaluxe.Screens int curSelected = _SongMenus[_SongMenu].GetActualSelection(); bool firstLevel = CConfig.Tabs == EOffOn.TR_CONFIG_OFF && CSongs.IsInCategory; bool secondSort = CConfig.Tabs == EOffOn.TR_CONFIG_ON && - (CConfig.SongSorting == ESongSorting.TR_CONFIG_ARTIST || - CConfig.SongSorting == ESongSorting.TR_CONFIG_ARTIST_LETTER || - CConfig.SongSorting == ESongSorting.TR_CONFIG_FOLDER || - CConfig.SongSorting == ESongSorting.TR_CONFIG_TITLE_LETTER); + (CConfig.SongSorting == ESongSorting.TR_CONFIG_ARTIST || + CConfig.SongSorting == ESongSorting.TR_CONFIG_ARTIST_LETTER || + CConfig.SongSorting == ESongSorting.TR_CONFIG_FOLDER || + CConfig.SongSorting == ESongSorting.TR_CONFIG_TITLE_LETTER); if (firstLevel && !secondSort) { //TODO: What's to do with multiple tags? @@ -1029,7 +1029,7 @@ namespace Vocaluxe.Screens visibleID = _FindIndex(songs, start, element => element.Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)); break; - //TODO: Does this make sense? Maybe we should deactivate this for years? You could only jump between 1 and 2 + //TODO: Does this make sense? Maybe we should deactivate this for years? You could only jump between 1 and 2 case ESongSorting.TR_CONFIG_YEAR: case ESongSorting.TR_CONFIG_DECADE: if (curSelected >= 0 && curSelected < ct - 1 && songs[curSelected].Year.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)) @@ -1076,7 +1076,7 @@ namespace Vocaluxe.Screens if (visibleID > -1) _SongMenus[_SongMenu].SetSelectedSong(visibleID); } - else if(!CSongs.IsInCategory) + else if (!CSongs.IsInCategory) { ReadOnlyCollection categories = CSongs.Categories; int ct = categories.Count; @@ -1126,27 +1126,26 @@ namespace Vocaluxe.Screens private void _ToggleSongOptions(ESongOptionsView view) { - - _SelectSlides[_SelectSlideOptionsMode].Visible = false; - _SelectSlides[_SelectSlideOptionsPlaylistAdd].Visible = false; - _SelectSlides[_SelectSlideOptionsPlaylistOpen].Visible = false; - _SelectSlides[_SelectSlideOptionsNumMedleySongs].Visible = false; - _Buttons[_ButtonOptionsClose].Visible = false; - _Buttons[_ButtonOptionsSing].Visible = false; - _Buttons[_ButtonOptionsPlaylist].Visible = false; - _Buttons[_ButtonOptionsRandom].Visible = false; - _Buttons[_ButtonOptionsRandomCategory].Visible = false; - _Buttons[_ButtonOptionsSingAll].Visible = false; - _Buttons[_ButtonOptionsSingAllVisible].Visible = false; - _Buttons[_ButtonOptionsOpenSelectedItem].Visible = false; - _Buttons[_ButtonOptionsRandomMedley].Visible = false; - _Buttons[_ButtonOptionsStartMedley].Visible = false; - _Texts[_TextOptionsTitle].Visible = false; - _Statics[_StaticOptionsBG].Visible = false; - _Buttons[_ButtonOpenOptions].Visible = true; + _SelectSlides[_SelectSlideOptionsMode].Visible = false; + _SelectSlides[_SelectSlideOptionsPlaylistAdd].Visible = false; + _SelectSlides[_SelectSlideOptionsPlaylistOpen].Visible = false; + _SelectSlides[_SelectSlideOptionsNumMedleySongs].Visible = false; + _Buttons[_ButtonOptionsClose].Visible = false; + _Buttons[_ButtonOptionsSing].Visible = false; + _Buttons[_ButtonOptionsPlaylist].Visible = false; + _Buttons[_ButtonOptionsRandom].Visible = false; + _Buttons[_ButtonOptionsRandomCategory].Visible = false; + _Buttons[_ButtonOptionsSingAll].Visible = false; + _Buttons[_ButtonOptionsSingAllVisible].Visible = false; + _Buttons[_ButtonOptionsOpenSelectedItem].Visible = false; + _Buttons[_ButtonOptionsRandomMedley].Visible = false; + _Buttons[_ButtonOptionsStartMedley].Visible = false; + _Texts[_TextOptionsTitle].Visible = false; + _Statics[_StaticOptionsBG].Visible = false; + _Buttons[_ButtonOpenOptions].Visible = true; - if (CSongs.VisibleSongs.Count > 0) - { + if (CSongs.VisibleSongs.Count > 0) + { _SongOptionsActive = view != ESongOptionsView.None; if (_SongOptionsActive) @@ -1170,7 +1169,7 @@ namespace Vocaluxe.Screens private void _ShowSongOptionsSong() { - EGameMode lastMode = EGameMode.TR_GAMEMODE_NORMAL; + var lastMode = EGameMode.TR_GAMEMODE_NORMAL; if (_AvailableGameModes.Count > 0) lastMode = _AvailableGameModes[_SelectSlides[_SelectSlideOptionsMode].Selection]; _AvailableGameModes.Clear(); From 4dd9f44f3d5bb3c32b4a543ab4b97f5fbd3c924b Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 18 Oct 2013 21:29:06 +0200 Subject: [PATCH 02/18] Fix showing of song menu if not in category --- Vocaluxe/Screens/CScreenSong.cs | 44 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 0f410bc1..7ea0ee2e 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -1016,7 +1016,10 @@ namespace Vocaluxe.Screens if (firstLevel && !secondSort) { //TODO: What's to do with multiple tags? + //Flamefire: What? We only sorted by one tag, sorting by multiple tags (e.g. Album) will be by e.g. the first entry. That can be used here too as otherwhise it will confuse users because it jumps randomly + //How can we get current letter? I think we have to save it - Or is there a better method? + //"Current letter"? The letter that was typed last? Doesn't matter as we are starting the search on current selected song ReadOnlyCollection songs = CSongs.VisibleSongs; int ct = songs.Count; int visibleID = -1; @@ -1030,6 +1033,7 @@ namespace Vocaluxe.Screens break; //TODO: Does this make sense? Maybe we should deactivate this for years? You could only jump between 1 and 2 + //Keep it for consistency. Decades are reasonable though. case ESongSorting.TR_CONFIG_YEAR: case ESongSorting.TR_CONFIG_DECADE: if (curSelected >= 0 && curSelected < ct - 1 && songs[curSelected].Year.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)) @@ -1144,27 +1148,29 @@ namespace Vocaluxe.Screens _Statics[_StaticOptionsBG].Visible = false; _Buttons[_ButtonOpenOptions].Visible = true; - if (CSongs.VisibleSongs.Count > 0) - { - _SongOptionsActive = view != ESongOptionsView.None; + if (view == ESongOptionsView.None) + _SongOptionsActive = false; + else if (CSongs.IsInCategory) + _SongOptionsActive = CSongs.VisibleSongs.Count > 0; + else + _SongOptionsActive = CSongs.Categories.Count > 0; - if (_SongOptionsActive) - { - //Has to be done here otherwhise changed playlist names will not appear until OnShow is called! - _UpdatePlaylistNames(); + if (!_SongOptionsActive) + return; - _Texts[_TextOptionsTitle].Visible = true; - _Buttons[_ButtonOptionsClose].Visible = true; - _Statics[_StaticOptionsBG].Visible = true; - _Buttons[_ButtonOpenOptions].Visible = false; - if (view == ESongOptionsView.Song) - _ShowSongOptionsSong(); - else if (view == ESongOptionsView.General) - _ShowSongOptionsGeneral(); - else if (view == ESongOptionsView.Medley) - _ShowSongOptionsMedley(); - } - } + //Has to be done here otherwhise changed playlist names will not appear until OnShow is called! + _UpdatePlaylistNames(); + + _Texts[_TextOptionsTitle].Visible = true; + _Buttons[_ButtonOptionsClose].Visible = true; + _Statics[_StaticOptionsBG].Visible = true; + _Buttons[_ButtonOpenOptions].Visible = false; + if (view == ESongOptionsView.Song) + _ShowSongOptionsSong(); + else if (view == ESongOptionsView.General) + _ShowSongOptionsGeneral(); + else if (view == ESongOptionsView.Medley) + _ShowSongOptionsMedley(); } private void _ShowSongOptionsSong() From 155718456cec7d9f1513090f6c1b039b8f9233c4 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 18 Oct 2013 21:29:43 +0200 Subject: [PATCH 03/18] Fix file-not-found exception --- VocaluxeLib/CHelper.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/VocaluxeLib/CHelper.cs b/VocaluxeLib/CHelper.cs index af49179f..24e8a0bd 100644 --- a/VocaluxeLib/CHelper.cs +++ b/VocaluxeLib/CHelper.cs @@ -69,7 +69,7 @@ namespace VocaluxeLib public static int TryReadInt(StreamReader sr) { string value = String.Empty; - + try { int tmp = sr.Peek(); @@ -79,7 +79,7 @@ namespace VocaluxeLib if (sr.EndOfStream) break; - char chr = (char)sr.Read(); + var chr = (char)sr.Read(); value += chr.ToString(); tmp = sr.Peek(); } @@ -141,8 +141,10 @@ namespace VocaluxeLib public static List ListFiles(string path, string cast, bool recursive = false, bool fullpath = false) { - List files = new List(); - DirectoryInfo dir = new DirectoryInfo(path); + var files = new List(); + var dir = new DirectoryInfo(path); + if (!dir.Exists) + return files; try { From 3b82d5c13c6ba3fc6d4fd3b9a009052048a3943d Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 18 Oct 2013 23:25:42 +0200 Subject: [PATCH 04/18] Fix for inconsistent song Menu Multiple refactoring due to ambiguous meanings --- .../PartyModeTicTacToe/CPartyModeTicTacToe.cs | 22 +-- .../CPartyScreenTicTacToeConfig.cs | 44 +++-- Vocaluxe/Base/CMain.cs | 14 +- Vocaluxe/Base/CSongs.cs | 43 ++++- VocaluxeLib/IBasic.cs | 3 +- .../Menu/SongMenu/CSongMenuFramework.cs | 31 ++-- .../Menu/SongMenu/CSongMenuTileBoard.cs | 161 +++++++++--------- VocaluxeLib/Songs/CCategory.cs | 6 + 8 files changed, 180 insertions(+), 144 deletions(-) diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index d7730f65..b2633588 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -248,7 +248,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe public override void DataFromScreen(string screenName, Object data) { - SDataFromScreen dataFrom = new SDataFromScreen(); + var dataFrom = new SDataFromScreen(); switch (screenName) { case "PartyScreenTicTacToeConfig": @@ -492,7 +492,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe public override void SongSelected(int songID) { - EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; + var gm = EGameMode.TR_GAMEMODE_NORMAL; switch (_GameData.GameMode) { @@ -525,7 +525,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _GameData.Rounds = new List(); for (int i = 0; i < _GameData.NumFields; i++) { - CRound r = new CRound(); + var r = new CRound(); _GameData.Rounds.Add(r); } } @@ -540,11 +540,11 @@ namespace VocaluxeLib.PartyModes.TicTacToe _GameData.PlayerTeam2 = new List(); //Prepare Player-IDs - List ids1 = new List(); - List ids2 = new List(); + var ids1 = new List(); + var ids2 = new List(); //Add IDs to team-list while (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0] && - _GameData.PlayerTeam2.Count < _GameData.NumFields + _GameData.NumJokerRetry[1] ) + _GameData.PlayerTeam2.Count < _GameData.NumFields + _GameData.NumJokerRetry[1]) { if (ids1.Count == 0) { @@ -579,7 +579,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe case 1: { //Prepare Player-IDs - List ids = new List(); + var ids = new List(); //Add IDs to team-list while (_GameData.PlayerTeam1.Count < _GameData.NumFields + _GameData.NumJokerRetry[0] && ids.Count == 0) { @@ -602,7 +602,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe case 2: { //Prepare Player-IDs - List ids = new List(); + var ids = new List(); //Add IDs to team-list while (_GameData.PlayerTeam2.Count < _GameData.NumFields + _GameData.NumJokerRetry[1] && ids.Count == 0) { @@ -627,7 +627,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _PrepareSongList() { - EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; + var gm = EGameMode.TR_GAMEMODE_NORMAL; switch (_GameData.GameMode) { @@ -646,7 +646,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe while (_GameData.Songs.Count < (_GameData.NumFields + _GameData.NumJokerRandom[0] + _GameData.NumJokerRandom[1])) { - List songs = new List(); + var songs = new List(); switch (_GameData.SongSource) { case ESongSource.TR_PLAYLIST: @@ -678,7 +678,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe case ESongSource.TR_CATEGORY: CBase.Songs.SetCategory(_GameData.CategoryID); - for (int i = 0; i < CBase.Songs.NumSongsInCategory(_GameData.CategoryID); i++) + for (int i = 0; i < CBase.Songs.GetNumSongsVisible(); i++) { // ReSharper disable LoopCanBeConvertedToQuery foreach (EGameMode mode in CBase.Songs.GetVisibleSong(i).AvailableGameModes) diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs index a03c839d..b967c56e 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using VocaluxeLib.Menu; +using VocaluxeLib.Songs; namespace VocaluxeLib.PartyModes.TicTacToe { @@ -61,7 +62,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _ThemeButtons = new string[] {_ButtonNext, _ButtonBack}; _Data = new SDataFromScreen(); - SFromScreenConfig config = new SFromScreenConfig + var config = new SFromScreenConfig { PlaylistID = 0, NumFields = 9, @@ -78,7 +79,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe { try { - SDataToScreenConfig config = (SDataToScreenConfig)receivedData; + var config = (SDataToScreenConfig)receivedData; _Data.ScreenConfig.NumFields = config.NumFields; _Data.ScreenConfig.NumPlayerTeam1 = config.NumPlayerTeam1; _Data.ScreenConfig.NumPlayerTeam2 = config.NumPlayerTeam2; @@ -209,13 +210,13 @@ namespace VocaluxeLib.PartyModes.TicTacToe _SelectSlides[_SelectSlidePlaylist].Selection = _Data.ScreenConfig.PlaylistID; _SelectSlides[_SelectSlidePlaylist].Visible = _Data.ScreenConfig.SongSource == ESongSource.TR_PLAYLIST; - string[] categories = new string[CBase.Songs.GetNumCategories()]; + var categories = new string[CBase.Songs.GetNumCategories()]; for (int i = 0; i < CBase.Songs.GetNumCategories(); i++) categories[i] = CBase.Songs.GetCategory(i).Name; _SelectSlides[_SelectSlideCategory].Clear(); for (int i = 0; i < categories.Length; i++) { - string value = categories[i] + " (" + CBase.Songs.NumSongsInCategory(i) + " " + CBase.Language.Translate("TR_SONGS", _PartyModeID) + ")"; + string value = categories[i] + " (" + CBase.Songs.GetNumSongsNotSungInCategory(i) + " " + CBase.Language.Translate("TR_SONGS", _PartyModeID) + ")"; _SelectSlides[_SelectSlideCategory].AddValue(value); } _SelectSlides[_SelectSlideCategory].Selection = _Data.ScreenConfig.CategoryID; @@ -242,7 +243,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _Data.ScreenConfig.CategoryID = _SelectSlides[_SelectSlideCategory].Selection; _Data.ScreenConfig.GameMode = (EPartyGameMode)_SelectSlides[_SelectSlideGameMode].Selection; - EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; + var gm = EGameMode.TR_GAMEMODE_NORMAL; switch (_Data.ScreenConfig.GameMode) { @@ -282,25 +283,22 @@ namespace VocaluxeLib.PartyModes.TicTacToe } if (_Data.ScreenConfig.SongSource == ESongSource.TR_CATEGORY) { - if (CBase.Songs.GetNumCategories() > 0) - { - if (CBase.Songs.NumSongsInCategory(_Data.ScreenConfig.CategoryID) > 0) - { - CBase.Songs.SetCategory(_Data.ScreenConfig.CategoryID); - _ConfigOk = false; - for (int i = 0; i < CBase.Songs.NumSongsInCategory(_Data.ScreenConfig.CategoryID); i++) - { - _ConfigOk = CBase.Songs.GetVisibleSong(i).AvailableGameModes.Any(mode => mode == gm); - if (_ConfigOk) - break; - } - CBase.Songs.SetCategory(-1); - } - else - _ConfigOk = false; - } - else + if (CBase.Songs.GetNumCategories() == 0) _ConfigOk = false; + else if (CBase.Songs.GetNumSongsNotSungInCategory(_Data.ScreenConfig.CategoryID) <= 0) + _ConfigOk = false; + else + { + CBase.Songs.SetCategory(_Data.ScreenConfig.CategoryID); + _ConfigOk = false; + foreach (CSong song in CBase.Songs.GetVisibleSongs()) + { + _ConfigOk = song.AvailableGameModes.Any(mode => mode == gm); + if (_ConfigOk) + break; + } + CBase.Songs.SetCategory(-1); + } } if (_Data.ScreenConfig.SongSource == ESongSource.TR_ALLSONGS) { diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 18867da3..7dd65963 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -598,9 +598,14 @@ namespace Vocaluxe.Base return CSongs.NumCategories; } - public int NumSongsInCategory(int categoryIndex) + public int GetNumSongsInCategory(int categoryIndex) { - return CSongs.NumSongsInCategory(categoryIndex); + return CSongs.GetNumSongsInCategory(categoryIndex); + } + + public int GetNumSongsNotSungInCategory(int categoryIndex) + { + return CSongs.GetNumSongsNotSungInCategory(categoryIndex); } public bool IsInCategory() @@ -655,10 +660,7 @@ namespace Vocaluxe.Base public CCategory GetCategory(int index) { - if (index >= CSongs.NumCategories) - return null; - - return new CCategory(CSongs.Categories[index]); + return CSongs.GetCategoryByIndex(index); } public void AddPartySongSung(int songID) diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index 05f7ac31..c2188a3b 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -66,7 +66,7 @@ namespace Vocaluxe.Base public static int NumSongsVisible { - get { return _CatIndex < 0 ? 0 : Categories[_CatIndex].Songs.Count(sp => !sp.IsSung); } + get { return VisibleSongs.Count; } } public static int NumCategories @@ -104,9 +104,19 @@ namespace Vocaluxe.Base /// /// Category index /// - public static int NumSongsInCategory(int catIndex) + public static int GetNumSongsInCategory(int catIndex) { - return _IsCatIndexValid(catIndex) ? Categories[catIndex].Songs.Count(sp => !sp.IsSung) : 0; + return _IsCatIndexValid(catIndex) ? Categories[catIndex].Songs.Count : 0; + } + + /// + /// Returns the number of song that are not sung in the category specified with CatIndex + /// + /// Category index + /// Number of visible songs in that category + public static int GetNumSongsNotSungInCategory(int catIndex) + { + return _IsCatIndexValid(catIndex) ? Categories[catIndex].GetNumSongsNotSung() : 0; } public static void NextCategory() @@ -159,9 +169,8 @@ namespace Vocaluxe.Base foreach (CSongPointer song in category.Songs.Where(song => song.SongID == songID)) { song.IsSung = true; - int catIndex = _GetCategoryNumber(category); - if (NumSongsInCategory(catIndex) == 0) - ResetPartySongSung(catIndex); + if (category.GetNumSongsNotSung() == 0) + ResetPartySongSung(_GetCategoryNumber(category)); return; } } @@ -251,7 +260,7 @@ namespace Vocaluxe.Base { get { - List songs = new List(); + var songs = new List(); if (_IsCatIndexValid(_CatIndex)) { // ReSharper disable LoopCanBeConvertedToQuery @@ -271,6 +280,24 @@ namespace Vocaluxe.Base get { return Categorizer.Categories.AsReadOnly(); } } + /// + /// Gets category with given index or null for invalid index + /// + /// + /// category with given index or null for invalid index + public static CCategory GetCategoryByIndex(int index) + { + if (!_IsCatIndexValid(index)) + return null; + + return Categorizer.Categories[index]; + } + + /// + /// Gets visible song with given index or null for invalid index or song not visible + /// + /// + /// visible song with given index or null for invalid index or song not visible public static CSong GetVisibleSongByIndex(int index) { if (index < 0) @@ -298,7 +325,7 @@ namespace Vocaluxe.Base _Songs.Clear(); CLog.StartBenchmark(2, "List Songs"); - List files = new List(); + var files = new List(); foreach (string p in CConfig.SongFolder) { string path = p; diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index 648224d7..fc9871a8 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -206,7 +206,8 @@ namespace VocaluxeLib int GetNumSongs(); int GetNumSongsVisible(); int GetNumCategories(); - int NumSongsInCategory(int categoryIndex); + int GetNumSongsInCategory(int categoryIndex); + int GetNumSongsNotSungInCategory(int categoryIndex); bool IsInCategory(); int GetCurrentCategoryIndex(); diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index be9dd224..916ab688 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -130,7 +130,6 @@ namespace VocaluxeLib.Menu.SongMenu { if ((_SelectedInternal != _SelectedPending) && (_Timer.ElapsedMilliseconds >= _PendingTime)) { - _Timer.Stop(); _Timer.Reset(); _SelectedInternal = _SelectedPending; } @@ -140,7 +139,6 @@ namespace VocaluxeLib.Menu.SongMenu { if (value == -1) { - _Timer.Stop(); _Timer.Reset(); _SelectedInternal = -1; @@ -148,26 +146,28 @@ namespace VocaluxeLib.Menu.SongMenu return; } - if ((value != _SelectedInternal) && (value != _SelectedPending)) + if (value == _SelectedPending) { - _Timer.Reset(); - _Timer.Start(); - - _SelectedPending = value; + if (_Timer.ElapsedMilliseconds >= _PendingTime || _SelectedInternal == -1) + { + _Timer.Reset(); + _SelectedInternal = _SelectedPending; + } } - - if ((value == _SelectedPending) && ((_Timer.ElapsedMilliseconds >= _PendingTime) || (_SelectedInternal == -1))) + else { - _Timer.Stop(); - _Timer.Reset(); - _SelectedInternal = _SelectedPending; + if (value != _SelectedInternal) + { + _Timer.Reset(); + _Timer.Start(); + } + _SelectedPending = value; } } } protected void _SetSelectedNow() { - _Timer.Stop(); _Timer.Reset(); _SelectedInternal = _SelectedPending; } @@ -518,7 +518,10 @@ namespace VocaluxeLib.Menu.SongMenu _Active = active; } - public virtual bool IsMouseOverActualSelection(SMouseEvent mEvent) { return false; } + public virtual bool IsMouseOverActualSelection(SMouseEvent mEvent) + { + return false; + } public virtual int GetSelectedSong() { diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index d263fe92..8cf5a77d 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -92,9 +92,9 @@ namespace VocaluxeLib.Menu.SongMenu { for (int j = 0; j < _NumW; j++) { - SRectF rect = new SRectF(_Theme.SongMenuTileBoard.TileRect.X + j * (_TileW + _SpaceW), - _Theme.SongMenuTileBoard.TileRect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, _Rect.Z); - CStatic tile = new CStatic(_PartyModeID, _CoverTexture, Color, rect); + var rect = new SRectF(_Theme.SongMenuTileBoard.TileRect.X + j * (_TileW + _SpaceW), + _Theme.SongMenuTileBoard.TileRect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, _Rect.Z); + var tile = new CStatic(_PartyModeID, _CoverTexture, Color, rect); _Tiles.Add(tile); } } @@ -129,6 +129,73 @@ namespace VocaluxeLib.Menu.SongMenu } } + private void _UpdatePreview() + { + //First hide everything so we just have to set what we actually want + _CoverBig.Texture = _CoverBigTexture; + _Artist.Text = String.Empty; + _Title.Text = String.Empty; + _SongLength.Text = String.Empty; + _DuetIcon.Visible = false; + _VideoIcon.Visible = false; + _MedleyCalcIcon.Visible = false; + _MedleyTagIcon.Visible = false; + + //Check if nothing is selected (for preview) + if (_PreviewSelected < 0) + return; + + if (CBase.Songs.IsInCategory()) + { + CSong song = CBase.Songs.GetVisibleSong(_PreviewSelected); + //Check if we have a valid song (song still visible, index >=0 etc is checked by framework) + if (song == null) + { + //Display at least the category + CCategory category = CBase.Songs.GetCategory(CBase.Songs.GetCurrentCategoryIndex()); + //Check if we have a valid category + if (category == null) + return; + _CoverBig.Texture = category.CoverTextureBig; + _Artist.Text = category.Name; + return; + } + _CoverBig.Texture = song.CoverTextureBig; + _Artist.Text = song.Artist; + _Title.Text = song.Title; + _DuetIcon.Visible = song.IsDuet; + _VideoIcon.Visible = song.VideoFileName != ""; + _MedleyCalcIcon.Visible = song.Medley.Source == EMedleySource.Calculated; + _MedleyTagIcon.Visible = song.Medley.Source == EMedleySource.Tag; + + float time = CBase.Sound.GetLength(_SongStream); + if (Math.Abs(song.Finish) > 0.001) + time = song.Finish; + + time -= song.Start; + var min = (int)Math.Floor(time / 60f); + var sec = (int)(time - min * 60f); + _SongLength.Text = min.ToString("00") + ":" + sec.ToString("00"); + } + else + { + CCategory category = CBase.Songs.GetCategory(_PreviewSelected); + //Check if we have a valid category + if (category == null) + return; + _CoverBig.Texture = category.CoverTextureBig; + _Artist.Text = category.Name; + + int num = category.GetNumSongsNotSung(); + // ReSharper disable ConvertIfStatementToConditionalTernaryExpression + if (num != 1) + // ReSharper restore ConvertIfStatementToConditionalTernaryExpression + _Title.Text = CBase.Language.Translate("TR_SCREENSONG_NUMSONGS").Replace("%v", num.ToString()); + else + _Title.Text = CBase.Language.Translate("TR_SCREENSONG_NUMSONG").Replace("%v", num.ToString()); + } + } + public override void OnShow() { if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0 && !CBase.Songs.IsInCategory()) @@ -141,33 +208,16 @@ namespace VocaluxeLib.Menu.SongMenu SetSelectedSong(_ActSong); _AfterCategoryChange(); - int actcat = _PreviewSelected; - if ((CBase.Songs.GetNumCategories() > 0) && (actcat < 0)) + if (_PreviewSelected < 0) { - _CoverBig.Texture = CBase.Songs.GetCategory(0).CoverTextureBig; - _Artist.Text = CBase.Songs.GetCategory(0).Name; - _Title.Text = String.Empty; - _SongLength.Text = String.Empty; _PreviewSelected = 0; _Locked = 0; - _DuetIcon.Visible = false; - _VideoIcon.Visible = false; - _MedleyCalcIcon.Visible = false; - _MedleyTagIcon.Visible = false; } if (CBase.Songs.GetNumSongsVisible() == 0 && CBase.Songs.GetSearchFilter() != "") { - _CoverBig.Texture = _CoverBigTexture; - _Artist.Text = String.Empty; - _Title.Text = String.Empty; - _SongLength.Text = String.Empty; _PreviewSelected = -1; _Locked = -1; - _DuetIcon.Visible = false; - _VideoIcon.Visible = false; - _MedleyCalcIcon.Visible = false; - _MedleyTagIcon.Visible = false; } } @@ -394,63 +444,12 @@ namespace VocaluxeLib.Menu.SongMenu tile.Draw(1.2f, tile.Rect.Z - 0.1f, EAspect.Crop); else { - // ReSharper disable ConvertIfStatementToConditionalTernaryExpression - if (tile.Texture != _CoverTexture) - // ReSharper restore ConvertIfStatementToConditionalTernaryExpression - tile.Draw(1f, tile.Rect.Z, EAspect.Crop); - else - tile.Draw(1f, tile.Rect.Z, EAspect.Stretch); + EAspect aspect = (tile.Texture != _CoverTexture) ? EAspect.Crop : EAspect.Stretch; + tile.Draw(1f, tile.Rect.Z, aspect); } } - if (CBase.Songs.IsInCategory()) - { - int actsong = _PreviewSelected; - if ((CBase.Songs.GetNumSongsVisible() > actsong) && (actsong >= 0)) - { - CSong song = CBase.Songs.GetVisibleSong(actsong); - - _CoverBig.Texture = song.CoverTextureBig; - _Artist.Text = song.Artist; - _Title.Text = song.Title; - _DuetIcon.Visible = song.IsDuet; - _VideoIcon.Visible = song.VideoFileName != ""; - _MedleyCalcIcon.Visible = song.Medley.Source == EMedleySource.Calculated; - _MedleyTagIcon.Visible = song.Medley.Source == EMedleySource.Tag; - - float time = CBase.Sound.GetLength(_SongStream); - if (Math.Abs(song.Finish) > 0.001) - time = song.Finish; - - time -= song.Start; - int min = (int)Math.Floor(time / 60f); - int sec = (int)(time - min * 60f); - _SongLength.Text = min.ToString("00") + ":" + sec.ToString("00"); - } - } - else - { - int actcat = _PreviewSelected; - if ((CBase.Songs.GetNumCategories() > actcat) && (actcat >= 0)) - { - _CoverBig.Texture = CBase.Songs.GetCategory(actcat).CoverTextureBig; - _Artist.Text = CBase.Songs.GetCategory(actcat).Name; - - int num = CBase.Songs.NumSongsInCategory(actcat); - // ReSharper disable ConvertIfStatementToConditionalTernaryExpression - if (num != 1) - // ReSharper restore ConvertIfStatementToConditionalTernaryExpression - _Title.Text = CBase.Language.Translate("TR_SCREENSONG_NUMSONGS").Replace("%v", num.ToString()); - else - _Title.Text = CBase.Language.Translate("TR_SCREENSONG_NUMSONG").Replace("%v", num.ToString()); - - _SongLength.Text = String.Empty; - _DuetIcon.Visible = false; - _VideoIcon.Visible = false; - _MedleyCalcIcon.Visible = false; - _MedleyTagIcon.Visible = false; - } - } + _UpdatePreview(); _TextBG.Draw(); @@ -458,11 +457,11 @@ namespace VocaluxeLib.Menu.SongMenu { if (_Vidtex.Color.A < 1) _CoverBig.Draw(1f, EAspect.Crop); - RectangleF bounds = new RectangleF(_CoverBig.Rect.X, _CoverBig.Rect.Y, _CoverBig.Rect.W, _CoverBig.Rect.H); + var bounds = new RectangleF(_CoverBig.Rect.X, _CoverBig.Rect.Y, _CoverBig.Rect.W, _CoverBig.Rect.H); RectangleF rect; CHelper.SetRect(bounds, out rect, _Vidtex.OrigAspect, EAspect.Crop); - SRectF vidRect = new SRectF(rect.X, rect.Y, rect.Width, rect.Height, _CoverBig.Rect.Z); - SRectF vidRectBounds = new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f); + var vidRect = new SRectF(rect.X, rect.Y, rect.Width, rect.Height, _CoverBig.Rect.Z); + var vidRectBounds = new SRectF(bounds.X, bounds.Y, bounds.Width, bounds.Height, 0f); CBase.Drawing.DrawTexture(_Vidtex, vidRect, _Vidtex.Color, vidRectBounds); CBase.Drawing.DrawTextureReflection(_Vidtex, vidRect, _Vidtex.Color, vidRectBounds, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight); @@ -490,7 +489,7 @@ namespace VocaluxeLib.Menu.SongMenu CStatic selCov = GetSelectedSongCover(); if (selCov.Texture == null) return false; - SRectF rect = new SRectF(selCov.Rect.X - selCov.Rect.W*0.2f, selCov.Rect.Y - selCov.Rect.H*0.2f, selCov.Rect.W*1.2f, selCov.Rect.H*1.2f, selCov.Rect.Z); + var rect = new SRectF(selCov.Rect.X - selCov.Rect.W * 0.2f, selCov.Rect.Y - selCov.Rect.H * 0.2f, selCov.Rect.W * 1.2f, selCov.Rect.H * 1.2f, selCov.Rect.Z); return CHelper.IsInBounds(rect, mEvent); } @@ -679,8 +678,8 @@ namespace VocaluxeLib.Menu.SongMenu { for (int j = 0; j < _NumW; j++) { - SRectF rect = new SRectF(_Rect.X + j * (_TileW + _SpaceW), _Rect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, _Rect.Z); - CStatic tile = new CStatic(_PartyModeID, _CoverTexture, Color, rect); + var rect = new SRectF(_Rect.X + j * (_TileW + _SpaceW), _Rect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, _Rect.Z); + var tile = new CStatic(_PartyModeID, _CoverTexture, Color, rect); _Tiles.Add(tile); } } diff --git a/VocaluxeLib/Songs/CCategory.cs b/VocaluxeLib/Songs/CCategory.cs index 4101d746..f8c203e3 100644 --- a/VocaluxeLib/Songs/CCategory.cs +++ b/VocaluxeLib/Songs/CCategory.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using VocaluxeLib.Draw; +using System.Linq; namespace VocaluxeLib.Songs { @@ -52,6 +53,11 @@ namespace VocaluxeLib.Songs } } + public int GetNumSongsNotSung() + { + return Songs.Count(sp => !sp.IsSung); + } + public CCategory(string name, CTexture coverSmall, CTexture coverBig) { Name = name; From 3a8acecd5cb5ad06c223473efcd3afdf13eb9a4a Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 18 Oct 2013 23:40:23 +0200 Subject: [PATCH 05/18] Use always the same xml writer settings --- Vocaluxe/Base/CConfig.cs | 16 ++++++---- Vocaluxe/Base/CMain.cs | 6 ++++ Vocaluxe/Base/CTheme.cs | 9 ++---- Vocaluxe/Lib/Playlist/CPlaylistFile.cs | 25 ++++----------- VocaluxeLib/IBasic.cs | 6 ++++ VocaluxeLib/Menu/CMenu.cs | 44 ++++++++++++-------------- VocaluxeLib/Profile/CProfile.cs | 11 ++----- 7 files changed, 54 insertions(+), 63 deletions(-) diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 7a68bc66..532a4ed6 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -35,7 +35,15 @@ namespace Vocaluxe.Base { static class CConfig { - private static readonly XmlWriterSettings _Settings = new XmlWriterSettings(); + /// + /// Uniform settings for writing XML files. ALWAYS use this! + /// + public static readonly XmlWriterSettings XMLSettings = new XmlWriterSettings + { + Indent = true, + Encoding = Encoding.UTF8, + ConformanceLevel = ConformanceLevel.Document + }; // Debug public static EDebugLevel DebugLevel = EDebugLevel.TR_CONFIG_OFF; @@ -142,10 +150,6 @@ namespace Vocaluxe.Base public static void Init() { - _Settings.Indent = true; - _Settings.Encoding = Encoding.UTF8; - _Settings.ConformanceLevel = ConformanceLevel.Document; - SongFolder.Add(Path.Combine(Directory.GetCurrentDirectory(), CSettings.FolderSongs)); #if INSTALLER @@ -304,7 +308,7 @@ namespace Vocaluxe.Base XmlWriter writer = null; try { - writer = XmlWriter.Create(Path.Combine(CSettings.DataPath, CSettings.FileConfig)); + writer = XmlWriter.Create(Path.Combine(CSettings.DataPath, CSettings.FileConfig), XMLSettings); writer.WriteStartDocument(); writer.WriteStartElement("root"); diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 7dd65963..ebadc6fd 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; +using System.Xml; using Vocaluxe.Base.Fonts; using VocaluxeLib; using VocaluxeLib.Game; @@ -141,6 +142,11 @@ namespace Vocaluxe.Base { return CConfig.GetMaxNumMics(); } + + public XmlWriterSettings GetXMLSettings() + { + return CConfig.XMLSettings; + } } class CBsettings : ISettings diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index 7f08c8e9..2133e6c6 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -107,7 +107,6 @@ namespace Vocaluxe.Base private const int _SkinSystemVersion = 3; #region Vars - private static readonly XmlWriterSettings _Settings = new XmlWriterSettings(); private static readonly List _Themes = new List(); public static string[] ThemeNames { @@ -148,10 +147,6 @@ namespace Vocaluxe.Base #region Theme and Skin loading and writing public static void InitTheme() { - _Settings.Indent = true; - _Settings.Encoding = Encoding.UTF8; - _Settings.ConformanceLevel = ConformanceLevel.Document; - _ListThemes(); ListSkins(); @@ -291,7 +286,7 @@ namespace Vocaluxe.Base private static void _SaveTheme(int themeIndex) { #region ThemeMainFile - using (XmlWriter writer = XmlWriter.Create(Path.Combine(_Themes[themeIndex].Path, _Themes[themeIndex].FileName), _Settings)) + using (XmlWriter writer = XmlWriter.Create(Path.Combine(_Themes[themeIndex].Path, _Themes[themeIndex].FileName), CConfig.XMLSettings)) { writer.WriteStartDocument(); writer.WriteStartElement("root"); @@ -333,7 +328,7 @@ namespace Vocaluxe.Base { for (int skinIndex = 0; skinIndex < _Skins.Count; skinIndex++) { - using (XmlWriter writer = XmlWriter.Create(Path.Combine(_Skins[skinIndex].Path, _Skins[skinIndex].FileName), _Settings)) + using (XmlWriter writer = XmlWriter.Create(Path.Combine(_Skins[skinIndex].Path, _Skins[skinIndex].FileName), CConfig.XMLSettings)) { writer.WriteStartDocument(); writer.WriteStartElement("root"); diff --git a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs index 1ea3e611..13c154e4 100644 --- a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs +++ b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs @@ -31,33 +31,22 @@ namespace Vocaluxe.Lib.Playlist { public class CPlaylistFile { - private static readonly XmlWriterSettings _Settings = new XmlWriterSettings(); - public string PlaylistName; public string PlaylistFile; public List Songs = new List(); public CPlaylistFile() { - _Init(); PlaylistName = string.Empty; PlaylistFile = string.Empty; } public CPlaylistFile(string file) { - _Init(); PlaylistFile = file; _LoadPlaylist(); } - private void _Init() - { - _Settings.Indent = true; - _Settings.Encoding = Encoding.UTF8; - _Settings.ConformanceLevel = ConformanceLevel.Document; - } - public void SavePlaylist() { if (PlaylistFile == "") @@ -88,7 +77,7 @@ namespace Vocaluxe.Lib.Playlist XmlWriter writer; try { - writer = XmlWriter.Create(PlaylistFile, _Settings); + writer = XmlWriter.Create(PlaylistFile, CConfig.XMLSettings); } catch (Exception e) { @@ -147,7 +136,7 @@ namespace Vocaluxe.Lib.Playlist Songs = new List(); List songs = xmlReader.GetValues("Songs"); - EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; + var gm = EGameMode.TR_GAMEMODE_NORMAL; foreach (string song in songs) { @@ -157,7 +146,7 @@ namespace Vocaluxe.Lib.Playlist xmlReader.GetValue("//root/Songs/" + song + "/Title", out title, String.Empty); xmlReader.TryGetEnumValue("//root/Songs/" + song + "/GameMode", ref gm); - CPlaylistSong playlistSong = new CPlaylistSong {SongID = -1}; + var playlistSong = new CPlaylistSong {SongID = -1}; foreach (CSong curSong in CSongs.AllSongs) { @@ -182,14 +171,14 @@ namespace Vocaluxe.Lib.Playlist public void AddSong(int songID) { - CPlaylistSong song = new CPlaylistSong {SongID = songID, GameMode = CSongs.GetSong(songID).IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL}; + var song = new CPlaylistSong {SongID = songID, GameMode = CSongs.GetSong(songID).IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL}; Songs.Add(song); } public void AddSong(int songID, EGameMode gm) { - CPlaylistSong song = new CPlaylistSong {SongID = songID, GameMode = gm}; + var song = new CPlaylistSong {SongID = songID, GameMode = gm}; Songs.Add(song); } @@ -216,7 +205,7 @@ namespace Vocaluxe.Lib.Playlist if (sourceNr < 0 || destNr < 0 || sourceNr == destNr || sourceNr > Songs.Count - 1 || destNr > Songs.Count - 1) return; - CPlaylistSong ps = new CPlaylistSong(Songs[sourceNr]); + var ps = new CPlaylistSong(Songs[sourceNr]); Songs.RemoveAt(sourceNr); Songs.Insert(destNr, ps); } @@ -226,7 +215,7 @@ namespace Vocaluxe.Lib.Playlist if (destNr < 0 || destNr > Songs.Count - 1) return; - CPlaylistSong ps = new CPlaylistSong(songID, gm); + var ps = new CPlaylistSong(songID, gm); Songs.Insert(destNr, ps); } } diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index fc9871a8..b8389d92 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; +using System.Xml; using VocaluxeLib.Draw; using VocaluxeLib.Game; using VocaluxeLib.Menu; @@ -54,6 +55,11 @@ namespace VocaluxeLib bool IsMicConfigured(int playerNr); int GetMaxNumMics(); + + /// + /// Get the uniform settings for writing XML files. ALWAYS use this! + /// + XmlWriterSettings GetXMLSettings(); } public interface ISettings diff --git a/VocaluxeLib/Menu/CMenu.cs b/VocaluxeLib/Menu/CMenu.cs index 4a3021b9..4c42bf0a 100644 --- a/VocaluxeLib/Menu/CMenu.cs +++ b/VocaluxeLib/Menu/CMenu.cs @@ -151,7 +151,7 @@ namespace VocaluxeLib.Menu { foreach (string elName in elements) { - T element = (T)Activator.CreateInstance(typeof(T), _PartyModeID); + var element = (T)Activator.CreateInstance(typeof(T), _PartyModeID); if (element.LoadTheme("//root/" + ThemeName, elName, xmlReader, skinIndex)) addElementHandler(element, elName); else @@ -198,10 +198,8 @@ namespace VocaluxeLib.Menu if (_ThemePath == "") return; - XmlWriterSettings settings = new XmlWriterSettings {Indent = true, Encoding = Encoding.UTF8, ConformanceLevel = ConformanceLevel.Document}; - string file = Path.Combine(_ThemePath, ThemeName + ".xml"); - using (XmlWriter writer = XmlWriter.Create(file, settings)) + using (XmlWriter writer = XmlWriter.Create(file, CBase.Config.GetXMLSettings())) { writer.WriteStartDocument(); writer.WriteStartElement("root"); @@ -770,7 +768,7 @@ namespace VocaluxeLib.Menu if (_Interactions.Count <= 0) return; - List items = new List(); + var items = new List(); for (int i = 0; i < _Interactions.Count; i++) { @@ -779,7 +777,7 @@ namespace VocaluxeLib.Menu _Interactions[i].Type != EType.NameSelection && _Interactions[i].Type != EType.Text && _Interactions[i].Type != EType.SongMenu && _Interactions[i].Type != EType.Equalizer && _Interactions[i].Type != EType.Playlist && _Interactions[i].Type != EType.ParticleEffect)) continue; - SZSort zs = new SZSort {ID = i, Z = _GetZValue(i)}; + var zs = new SZSort {ID = i, Z = _GetZValue(i)}; items.Add(zs); } @@ -1105,10 +1103,10 @@ namespace VocaluxeLib.Menu /// private bool _NextInteraction(SKeyEvent key) { - SKeyEvent[] directions = new SKeyEvent[4]; - float[] distances = new float[4]; - int[] stages = new int[4]; - int[] elements = new int[4]; + var directions = new SKeyEvent[4]; + var distances = new float[4]; + var stages = new int[4]; + var elements = new int[4]; for (int i = 0; i < 4; i++) directions[i] = new SKeyEvent(); @@ -1248,11 +1246,11 @@ namespace VocaluxeLib.Menu private float _GetDistanceDirect(SKeyEvent key, SRectF actualRect, SRectF targetRect) { - PointF source = new PointF(actualRect.X + actualRect.W / 2f, actualRect.Y + actualRect.H / 2f); - PointF dest = new PointF(targetRect.X + targetRect.W / 2f, targetRect.Y + targetRect.H / 2f); + var source = new PointF(actualRect.X + actualRect.W / 2f, actualRect.Y + actualRect.H / 2f); + var dest = new PointF(targetRect.X + targetRect.W / 2f, targetRect.Y + targetRect.H / 2f); - PointF vector = new PointF(dest.X - source.X, dest.Y - source.Y); - float distance = (float)Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y); + var vector = new PointF(dest.X - source.X, dest.Y - source.Y); + var distance = (float)Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y); bool inDirection = false; switch (key.Key) { @@ -1281,11 +1279,11 @@ namespace VocaluxeLib.Menu private float _GetDistance180(SKeyEvent key, SRectF actualRect, SRectF targetRect) { - PointF source = new PointF(actualRect.X + actualRect.W / 2f, actualRect.Y + actualRect.H / 2f); - PointF dest = new PointF(targetRect.X + targetRect.W / 2f, targetRect.Y + targetRect.H / 2f); + var source = new PointF(actualRect.X + actualRect.W / 2f, actualRect.Y + actualRect.H / 2f); + var dest = new PointF(targetRect.X + targetRect.W / 2f, targetRect.Y + targetRect.H / 2f); - PointF vector = new PointF(dest.X - source.X, dest.Y - source.Y); - float distance = (float)Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y); + var vector = new PointF(dest.X - source.X, dest.Y - source.Y); + var distance = (float)Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y); bool inDirection = false; switch (key.Key) { @@ -1584,7 +1582,7 @@ namespace VocaluxeLib.Menu private SRectF _GetRect(CInteraction interaction) { - SRectF result = new SRectF(); + var result = new SRectF(); switch (interaction.Type) { case EType.Button: @@ -1808,7 +1806,7 @@ namespace VocaluxeLib.Menu private void _LoadThemeBasics(CXMLReader xmlReader, int skinIndex) { // Backgrounds - CBackground background = new CBackground(_PartyModeID); + var background = new CBackground(_PartyModeID); int i = 1; while (background.LoadTheme("//root/" + ThemeName, "Background" + i, xmlReader, skinIndex)) { @@ -1818,7 +1816,7 @@ namespace VocaluxeLib.Menu } // Statics - CStatic stat = new CStatic(_PartyModeID); + var stat = new CStatic(_PartyModeID); i = 1; while (stat.LoadTheme("//root/" + ThemeName, "Static" + i, xmlReader, skinIndex)) { @@ -1828,7 +1826,7 @@ namespace VocaluxeLib.Menu } // Texts - CText text = new CText(_PartyModeID); + var text = new CText(_PartyModeID); i = 1; while (text.LoadTheme("//root/" + ThemeName, "Text" + i, xmlReader, skinIndex)) { @@ -1838,7 +1836,7 @@ namespace VocaluxeLib.Menu } // ParticleEffects - CParticleEffect partef = new CParticleEffect(_PartyModeID); + var partef = new CParticleEffect(_PartyModeID); i = 1; while (partef.LoadTheme("//root/" + ThemeName, "ParticleEffect" + i, xmlReader, skinIndex)) { diff --git a/VocaluxeLib/Profile/CProfile.cs b/VocaluxeLib/Profile/CProfile.cs index 11c9b840..e823b323 100644 --- a/VocaluxeLib/Profile/CProfile.cs +++ b/VocaluxeLib/Profile/CProfile.cs @@ -26,13 +26,6 @@ namespace VocaluxeLib.Profile { public class CProfile { - private static readonly XmlWriterSettings _Settings = new XmlWriterSettings - { - Indent = true, - Encoding = Encoding.UTF8, - ConformanceLevel = ConformanceLevel.Document - }; - public int ID; public string PlayerName; @@ -107,7 +100,7 @@ namespace VocaluxeLib.Profile public void SaveProfile() { if (String.IsNullOrEmpty(FilePath)) - FilePath = Path.Combine(CBase.Settings.GetDataPath(),CBase.Settings.GetFolderProfiles()); + FilePath = Path.Combine(CBase.Settings.GetDataPath(), CBase.Settings.GetFolderProfiles()); if (FileName == String.Empty) { string filename = string.Empty; @@ -139,7 +132,7 @@ namespace VocaluxeLib.Profile XmlWriter writer; try { - writer = XmlWriter.Create(Path.Combine(FilePath, FileName), _Settings); + writer = XmlWriter.Create(Path.Combine(FilePath, FileName), CBase.Config.GetXMLSettings()); } catch (Exception e) { From 60bd2c4da42008883b35faa0c2d55b076506104b Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 18 Oct 2013 23:50:47 +0200 Subject: [PATCH 06/18] Rename PreviewSelected to more meaningful PreviewId --- .../Menu/SongMenu/CSongMenuFramework.cs | 42 ++++++------- .../Menu/SongMenu/CSongMenuTileBoard.cs | 60 +++++++++---------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 916ab688..0c6a1269 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -114,26 +114,25 @@ namespace VocaluxeLib.Menu.SongMenu protected SRectF _Rect; protected SColorF _Color; - private int _SelectedInternal = -1; - private int _SelectedPending = -1; + private int _PreviewIdInternal = -1; + private int _PreviewIdPending = -1; protected long _PendingTime = 500L; - private int _LockedInternal = -1; protected bool _Active; protected float _MaxVolume = 100f; - protected int _PreviewSelected + protected int _PreviewId { //for preview only get { - if ((_SelectedInternal != _SelectedPending) && (_Timer.ElapsedMilliseconds >= _PendingTime)) + if ((_PreviewIdInternal != _PreviewIdPending) && (_Timer.ElapsedMilliseconds >= _PendingTime)) { _Timer.Reset(); - _SelectedInternal = _SelectedPending; + _PreviewIdInternal = _PreviewIdPending; } - return _SelectedInternal; + return _PreviewIdInternal; } set { @@ -141,27 +140,27 @@ namespace VocaluxeLib.Menu.SongMenu { _Timer.Reset(); - _SelectedInternal = -1; - _SelectedPending = -1; + _PreviewIdInternal = -1; + _PreviewIdPending = -1; return; } - if (value == _SelectedPending) + if (value == _PreviewIdPending) { - if (_Timer.ElapsedMilliseconds >= _PendingTime || _SelectedInternal == -1) + if (_Timer.ElapsedMilliseconds >= _PendingTime || _PreviewIdInternal == -1) { _Timer.Reset(); - _SelectedInternal = _SelectedPending; + _PreviewIdInternal = _PreviewIdPending; } } else { - if (value != _SelectedInternal) + if (value != _PreviewIdInternal) { _Timer.Reset(); _Timer.Start(); } - _SelectedPending = value; + _PreviewIdPending = value; } } } @@ -169,9 +168,10 @@ namespace VocaluxeLib.Menu.SongMenu protected void _SetSelectedNow() { _Timer.Reset(); - _SelectedInternal = _SelectedPending; + _PreviewIdInternal = _PreviewIdPending; } + private int _LockedInternal = -1; protected int _Locked { //the real selected song for singing @@ -436,8 +436,8 @@ namespace VocaluxeLib.Menu.SongMenu if (!_Initialized) return; - if (_Actsong != _PreviewSelected) - _SelectSong(_PreviewSelected); + if (_Actsong != _PreviewId) + _SelectSong(_PreviewId); if (_Streams.Count <= 0 || _Video == -1) return; @@ -484,7 +484,7 @@ namespace VocaluxeLib.Menu.SongMenu _Timer.Stop(); _Timer.Reset(); - _SelectedInternal = _SelectedPending; + _PreviewIdInternal = _PreviewIdPending; } public virtual void HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions songOptions) {} @@ -569,9 +569,9 @@ namespace VocaluxeLib.Menu.SongMenu { if (!_Initialized) return false; - if (CBase.Songs.IsInCategory() || _PreviewSelected < 0 || _PreviewSelected >= CBase.Songs.GetNumCategories()) + if (CBase.Songs.IsInCategory() || _PreviewId < 0 || _PreviewId >= CBase.Songs.GetNumCategories()) return false; - _EnterCategory(_PreviewSelected); + _EnterCategory(_PreviewId); return true; } @@ -665,7 +665,7 @@ namespace VocaluxeLib.Menu.SongMenu _Timer.Stop(); _Timer.Reset(); - _SelectedInternal = _SelectedPending; + _PreviewIdInternal = _PreviewIdPending; } #region ThemeEdit diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 8cf5a77d..faec64be 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -101,7 +101,7 @@ namespace VocaluxeLib.Menu.SongMenu _ScrollRect = new SRectF(0, 0, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), _Theme.SongMenuTileBoard.TileRect.Z); - _PreviewSelected = -1; + _PreviewId = -1; _Offset = 0; _CoverBig = _Theme.SongMenuTileBoard.StaticCoverBig; @@ -122,8 +122,8 @@ namespace VocaluxeLib.Menu.SongMenu if (songOptions.Selection.RandomOnly) { - _Locked = _PreviewSelected; - _ActualSelection = _PreviewSelected; + _Locked = _PreviewId; + _ActualSelection = _PreviewId; for (int i = 0; i < _Tiles.Count; i++) _Tiles[i].Selected = _Locked == i + _Offset; } @@ -142,12 +142,12 @@ namespace VocaluxeLib.Menu.SongMenu _MedleyTagIcon.Visible = false; //Check if nothing is selected (for preview) - if (_PreviewSelected < 0) + if (_PreviewId < 0) return; if (CBase.Songs.IsInCategory()) { - CSong song = CBase.Songs.GetVisibleSong(_PreviewSelected); + CSong song = CBase.Songs.GetVisibleSong(_PreviewId); //Check if we have a valid song (song still visible, index >=0 etc is checked by framework) if (song == null) { @@ -179,7 +179,7 @@ namespace VocaluxeLib.Menu.SongMenu } else { - CCategory category = CBase.Songs.GetCategory(_PreviewSelected); + CCategory category = CBase.Songs.GetCategory(_PreviewId); //Check if we have a valid category if (category == null) return; @@ -202,21 +202,21 @@ namespace VocaluxeLib.Menu.SongMenu _EnterCategory(0); _ActualSelection = -1; _Locked = -1; - _PreviewSelected = -1; + _PreviewId = -1; _UpdateList(0, true); //AfterCategoryChange(); SetSelectedSong(_ActSong); _AfterCategoryChange(); - if (_PreviewSelected < 0) + if (_PreviewId < 0) { - _PreviewSelected = 0; + _PreviewId = 0; _Locked = 0; } if (CBase.Songs.GetNumSongsVisible() == 0 && CBase.Songs.GetSearchFilter() != "") { - _PreviewSelected = -1; + _PreviewId = -1; _Locked = -1; } } @@ -237,13 +237,13 @@ namespace VocaluxeLib.Menu.SongMenu if ((_Locked == -1 || !sel) && (keyEvent.Key != Keys.Escape && keyEvent.Key != Keys.Back && keyEvent.Key != Keys.PageUp && keyEvent.Key != Keys.PageDown)) { - if (_PreviewSelected > -1) - _Locked = _PreviewSelected; + if (_PreviewId > -1) + _Locked = _PreviewId; else { _Locked = 0; _ActualSelection = 0; - _PreviewSelected = 0; + _PreviewId = 0; _SetSelectedNow(); _UpdateList(0, true); } @@ -255,10 +255,10 @@ namespace VocaluxeLib.Menu.SongMenu case Keys.Enter: if (!CBase.Songs.IsInCategory()) { - _EnterCategory(_PreviewSelected); + _EnterCategory(_PreviewId); keyEvent.Handled = true; } - else if (_ActualSelection > -1 && _PreviewSelected >= 0) + else if (_ActualSelection > -1 && _PreviewId >= 0) _Locked = _ActualSelection; break; @@ -353,7 +353,7 @@ namespace VocaluxeLib.Menu.SongMenu if (!keyEvent.Handled) { - _PreviewSelected = _Locked; + _PreviewId = _Locked; _ActualSelection = _Locked; for (int i = 0; i < _Tiles.Count; i++) @@ -378,11 +378,11 @@ namespace VocaluxeLib.Menu.SongMenu { if (mouseEvent.LB || !CBase.Songs.IsInCategory()) { - if (_PreviewSelected == i + _Offset) - _Locked = _PreviewSelected; + if (_PreviewId == i + _Offset) + _Locked = _PreviewId; else { - _PreviewSelected = i + _Offset; + _PreviewId = i + _Offset; _Locked = -1; } } @@ -413,10 +413,10 @@ namespace VocaluxeLib.Menu.SongMenu } if (mouseEvent.RB && CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && !songOptions.Selection.PartyMode) CBase.Graphics.FadeTo(EScreens.ScreenMain); - else if (_PreviewSelected != -1 && mouseEvent.LB && CBase.Songs.GetCurrentCategoryIndex() != -1 && !songOptions.Selection.PartyMode) + else if (_PreviewId != -1 && mouseEvent.LB && CBase.Songs.GetCurrentCategoryIndex() != -1 && !songOptions.Selection.PartyMode) { if (CHelper.IsInBounds(_CoverBig.Rect, mouseEvent) || CHelper.IsInBounds(_TextBG.Rect, mouseEvent)) - _Locked = _PreviewSelected; + _Locked = _PreviewId; } else if (mouseEvent.LB && (!CBase.Songs.IsInCategory())) { @@ -424,7 +424,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (tile.Texture != _CoverTexture && CHelper.IsInBounds(tile.Rect, mouseEvent)) { - _EnterCategory(_PreviewSelected); + _EnterCategory(_PreviewId); mouseEvent.Handled = true; return; } @@ -509,13 +509,13 @@ namespace VocaluxeLib.Menu.SongMenu if (_Locked == -1 || !sel) { - if (_PreviewSelected > -1) - _Locked = _PreviewSelected; + if (_PreviewId > -1) + _Locked = _PreviewId; else { _Locked = 0; _ActualSelection = 0; - _PreviewSelected = 0; + _PreviewId = 0; _SetSelectedNow(); _UpdateList(0, true); } @@ -524,13 +524,13 @@ namespace VocaluxeLib.Menu.SongMenu foreach (CStatic tile in _Tiles) tile.Selected = false; - _PreviewSelected = itemNr; + _PreviewId = itemNr; _SetSelectedNow(); _Locked = itemNr; _UpdateList(true); - _PreviewSelected = _Locked; + _PreviewId = _Locked; _ActualSelection = _Locked; if (_Locked - _Offset >= 0) @@ -557,7 +557,7 @@ namespace VocaluxeLib.Menu.SongMenu { base._EnterCategory(cat); - _PreviewSelected = 0; + _PreviewId = 0; _Locked = -1; _ActualSelection = 0; _AfterCategoryChange(); @@ -568,7 +568,7 @@ namespace VocaluxeLib.Menu.SongMenu { base._ShowCategories(); - _PreviewSelected = 0; + _PreviewId = 0; _Locked = -1; _ActualSelection = 0; _AfterCategoryChange(); @@ -596,7 +596,7 @@ namespace VocaluxeLib.Menu.SongMenu private void _AfterCategoryChange() { _SetSelectedNow(); - _SelectSong(_PreviewSelected); + _SelectSong(_PreviewId); foreach (CStatic tile in _Tiles) tile.Selected = false; From 03d92a474cdc5fc997393daf7f8db94edb0d45c1 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 18 Oct 2013 23:55:58 +0200 Subject: [PATCH 07/18] Remove PreviewId pending stuff (don't need that. If you need a fade or something implement it properly with timer, event... But PreviewId should really be the current preview element) --- .../Menu/SongMenu/CSongMenuFramework.cs | 62 +------------------ .../Menu/SongMenu/CSongMenuTileBoard.cs | 6 -- 2 files changed, 1 insertion(+), 67 deletions(-) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 0c6a1269..3807a7f2 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -100,7 +100,6 @@ namespace VocaluxeLib.Menu.SongMenu protected SThemeSongMenu _Theme; private bool _ThemeLoaded; - private readonly Stopwatch _Timer = new Stopwatch(); private readonly Stopwatch _VideoFadeTimer = new Stopwatch(); private readonly List _Streams = new List(); private int _Actsong = -1; @@ -114,62 +113,11 @@ namespace VocaluxeLib.Menu.SongMenu protected SRectF _Rect; protected SColorF _Color; - private int _PreviewIdInternal = -1; - private int _PreviewIdPending = -1; - protected long _PendingTime = 500L; - protected bool _Active; protected float _MaxVolume = 100f; - protected int _PreviewId - { - //for preview only - get - { - if ((_PreviewIdInternal != _PreviewIdPending) && (_Timer.ElapsedMilliseconds >= _PendingTime)) - { - _Timer.Reset(); - _PreviewIdInternal = _PreviewIdPending; - } - return _PreviewIdInternal; - } - set - { - if (value == -1) - { - _Timer.Reset(); - - _PreviewIdInternal = -1; - _PreviewIdPending = -1; - return; - } - - if (value == _PreviewIdPending) - { - if (_Timer.ElapsedMilliseconds >= _PendingTime || _PreviewIdInternal == -1) - { - _Timer.Reset(); - _PreviewIdInternal = _PreviewIdPending; - } - } - else - { - if (value != _PreviewIdInternal) - { - _Timer.Reset(); - _Timer.Start(); - } - _PreviewIdPending = value; - } - } - } - - protected void _SetSelectedNow() - { - _Timer.Reset(); - _PreviewIdInternal = _PreviewIdPending; - } + protected int _PreviewId { get; set; } private int _LockedInternal = -1; protected int _Locked @@ -481,10 +429,6 @@ namespace VocaluxeLib.Menu.SongMenu _Video = -1; CBase.Drawing.RemoveTexture(ref _Vidtex); - - _Timer.Stop(); - _Timer.Reset(); - _PreviewIdInternal = _PreviewIdPending; } public virtual void HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions songOptions) {} @@ -662,10 +606,6 @@ namespace VocaluxeLib.Menu.SongMenu _Video = -1; CBase.Drawing.RemoveTexture(ref _Vidtex); - - _Timer.Stop(); - _Timer.Reset(); - _PreviewIdInternal = _PreviewIdPending; } #region ThemeEdit diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index faec64be..7c923398 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -79,8 +79,6 @@ namespace VocaluxeLib.Menu.SongMenu _SpaceW = _Theme.SongMenuTileBoard.SpaceW; _SpaceH = _Theme.SongMenuTileBoard.SpaceH; - _PendingTime = 100L; - _TileW = (int)((_Theme.SongMenuTileBoard.TileRect.W - _SpaceW * (_NumW - 1)) / _NumW); _TileH = (int)((_Theme.SongMenuTileBoard.TileRect.H - _SpaceH * (_NumH - 1)) / _NumH); @@ -244,7 +242,6 @@ namespace VocaluxeLib.Menu.SongMenu _Locked = 0; _ActualSelection = 0; _PreviewId = 0; - _SetSelectedNow(); _UpdateList(0, true); } } @@ -516,7 +513,6 @@ namespace VocaluxeLib.Menu.SongMenu _Locked = 0; _ActualSelection = 0; _PreviewId = 0; - _SetSelectedNow(); _UpdateList(0, true); } } @@ -525,7 +521,6 @@ namespace VocaluxeLib.Menu.SongMenu tile.Selected = false; _PreviewId = itemNr; - _SetSelectedNow(); _Locked = itemNr; _UpdateList(true); @@ -595,7 +590,6 @@ namespace VocaluxeLib.Menu.SongMenu private void _AfterCategoryChange() { - _SetSelectedNow(); _SelectSong(_PreviewId); foreach (CStatic tile in _Tiles) From 3466c09851a05d643296743d1cde512d1331b47c Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 18 Oct 2013 23:59:37 +0200 Subject: [PATCH 08/18] Remove redundant code --- VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 3807a7f2..36642cc0 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -421,14 +421,7 @@ namespace VocaluxeLib.Menu.SongMenu public virtual void OnHide() { - foreach (int stream in _Streams) - CBase.Sound.FadeAndStop(stream, 0f, 0.75f); - _Streams.Clear(); - - CBase.Video.Close(_Video); - _Video = -1; - - CBase.Drawing.RemoveTexture(ref _Vidtex); + _Reset(); } public virtual void HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions songOptions) {} From 02825cf46a5b2f360e32026f9b6ae266fdf6684b Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sat, 19 Oct 2013 00:06:52 +0200 Subject: [PATCH 09/18] Update preview only when necessary --- VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs | 2 +- VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 36642cc0..0a6b74c6 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -117,7 +117,7 @@ namespace VocaluxeLib.Menu.SongMenu protected float _MaxVolume = 100f; - protected int _PreviewId { get; set; } + protected virtual int _PreviewId { get; set; } private int _LockedInternal = -1; protected int _Locked diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 7c923398..eed48eff 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -63,6 +63,15 @@ namespace VocaluxeLib.Menu.SongMenu public CSongMenuTileBoard(int partyModeID) : base(partyModeID) {} + protected override int _PreviewId + { + set + { + base._PreviewId = value; + _UpdatePreview(); + } + } + public override int GetActualSelection() { return _ActualSelection; @@ -446,8 +455,6 @@ namespace VocaluxeLib.Menu.SongMenu } } - _UpdatePreview(); - _TextBG.Draw(); if (_Vidtex != null && _Video != -1) @@ -591,6 +598,7 @@ namespace VocaluxeLib.Menu.SongMenu private void _AfterCategoryChange() { _SelectSong(_PreviewId); + _UpdatePreview(); foreach (CStatic tile in _Tiles) tile.Selected = false; From 4c8244601972fd0aaf6433b4dcac2aa3191bae55 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sat, 19 Oct 2013 01:49:34 +0200 Subject: [PATCH 10/18] Bugfix on Init() function of song Menu Refactoring w/o functional changes --- Vocaluxe/Screens/CScreenSong.cs | 2 +- VocaluxeLib/Menu/SongMenu/CSongMenu.cs | 7 +- .../Menu/SongMenu/CSongMenuFramework.cs | 107 ++++++++---------- .../Menu/SongMenu/CSongMenuTileBoard.cs | 41 +++---- VocaluxeLib/Menu/SongMenu/ISongMenu.cs | 2 +- 5 files changed, 69 insertions(+), 90 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 7ea0ee2e..b8da8624 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -660,7 +660,7 @@ namespace Vocaluxe.Screens CBackgroundMusic.Disabled = false; int song = _SongMenus[_SongMenu].GetActualSelection(); - if ((CSongs.Category >= 0 || CConfig.Tabs == EOffOn.TR_CONFIG_OFF) && song >= 0 && song < CSongs.VisibleSongs.Count) + if ((CSongs.IsInCategory || CConfig.Tabs == EOffOn.TR_CONFIG_OFF) && song >= 0 && song < CSongs.VisibleSongs.Count) _Texts[_TextSelection].Text = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title; else if (!CSongs.IsInCategory && song >= 0 && song < CSongs.Categories.Count) _Texts[_TextSelection].Text = CSongs.Categories[song].Name; diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenu.cs b/VocaluxeLib/Menu/SongMenu/CSongMenu.cs index b66013b4..5996bb0e 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenu.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenu.cs @@ -49,7 +49,7 @@ namespace VocaluxeLib.Menu.SongMenu public SRectF Rect { - get { return _SongMenu.GetRect(); } + get { return _SongMenu.Rect; } } #region ISongMenu @@ -158,11 +158,6 @@ namespace VocaluxeLib.Menu.SongMenu _SongMenu.SetVisible(visible); } - public SRectF GetRect() - { - return _SongMenu.GetRect(); - } - public bool IsSmallView() { return _SongMenu.IsSmallView(); diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 0a6b74c6..2b1971db 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -24,6 +24,7 @@ using System.IO; using System.Xml; using VocaluxeLib.Draw; using VocaluxeLib.PartyModes; +using VocaluxeLib.Songs; namespace VocaluxeLib.Menu.SongMenu { @@ -102,52 +103,35 @@ namespace VocaluxeLib.Menu.SongMenu private readonly Stopwatch _VideoFadeTimer = new Stopwatch(); private readonly List _Streams = new List(); - private int _Actsong = -1; - private int _Actsongstream = -1; protected CTexture _Vidtex; protected bool _Initialized; protected int _LastKnownNumSongs; protected int _LastKnownCategory = -1; - protected SRectF _Rect; protected SColorF _Color; protected bool _Active; protected float _MaxVolume = 100f; - protected virtual int _PreviewId { get; set; } + //the real selected song for singing + protected int _Locked { get; set; } - private int _LockedInternal = -1; - protected int _Locked + private int _PreviewIdInternal = -1; + protected virtual int _PreviewId { - //the real selected song for singing - get { return _LockedInternal; } - set { _LockedInternal = value; } + get { return _PreviewIdInternal; } + set { _PreviewIdInternal = value; } } - protected int _SongStream - { - get { return _Actsongstream; } - } + protected int _PreviewSongStream { get; private set; } - protected int _Video { get; private set; } + protected int _PreviewVideoStream { get; private set; } - protected int _ActSong - { - get { return _Actsong; } - } + protected int _ActPlayingSongId { get; private set; } - public SRectF Rect - { - get { return _Rect; } - } - - public SRectF GetRect() - { - return _Rect; - } + public SRectF Rect { get; protected set; } public SColorF Color { @@ -156,7 +140,7 @@ namespace VocaluxeLib.Menu.SongMenu public virtual int GetActualSelection() { - return _Actsong; + return -1; } private bool _Selected; @@ -186,7 +170,10 @@ namespace VocaluxeLib.Menu.SongMenu protected CSongMenuFramework(int partyModeID) { _PartyModeID = partyModeID; - _Video = -1; + _PreviewVideoStream = -1; + _PreviewSongStream = -1; + _ActPlayingSongId = -1; + _Locked = -1; _Theme = new SThemeSongMenu { SongMenuTileBoard = @@ -375,7 +362,7 @@ namespace VocaluxeLib.Menu.SongMenu public void UpdateRect(SRectF rect) { - _Rect = rect; + Rect = rect; Init(); } @@ -384,23 +371,23 @@ namespace VocaluxeLib.Menu.SongMenu if (!_Initialized) return; - if (_Actsong != _PreviewId) - _SelectSong(_PreviewId); + if (_ActPlayingSongId != _PreviewId) + _PlaySong(_PreviewId); - if (_Streams.Count <= 0 || _Video == -1) + if (_Streams.Count <= 0 || _PreviewVideoStream == -1) return; - if (CBase.Video.IsFinished(_Video) || CBase.Sound.IsFinished(_Actsongstream)) + if (CBase.Video.IsFinished(_PreviewVideoStream) || CBase.Sound.IsFinished(_PreviewSongStream)) { - CBase.Video.Close(_Video); - _Video = -1; + CBase.Video.Close(_PreviewVideoStream); + _PreviewVideoStream = -1; return; } - float time = CBase.Sound.GetPosition(_Actsongstream); + float time = CBase.Sound.GetPosition(_PreviewSongStream); float vtime; - if (CBase.Video.GetFrame(_Video, ref _Vidtex, time, out vtime)) + if (CBase.Video.GetFrame(_PreviewVideoStream, ref _Vidtex, time, out vtime)) { if (_VideoFadeTimer.ElapsedMilliseconds <= 3000L) _Vidtex.Color.A = _VideoFadeTimer.ElapsedMilliseconds / 3000f; @@ -414,7 +401,7 @@ namespace VocaluxeLib.Menu.SongMenu public virtual void OnShow() { - _Actsongstream = -1; + _PreviewSongStream = -1; _Vidtex = null; ApplyVolume(CBase.Config.GetPreviewMusicVolume()); } @@ -433,7 +420,7 @@ namespace VocaluxeLib.Menu.SongMenu if (!_Initialized || !_Visible) return; - if (_Video != -1) + if (_PreviewVideoStream != -1) CBase.Drawing.DrawTexture(_Vidtex, new SRectF(0, 0, 1280, 720, 0)); } @@ -538,33 +525,37 @@ namespace VocaluxeLib.Menu.SongMenu public void ApplyVolume() { - CBase.Sound.SetStreamVolume(_Actsongstream, CBase.Config.GetPreviewMusicVolume()); + CBase.Sound.SetStreamVolume(_PreviewSongStream, CBase.Config.GetPreviewMusicVolume()); } - protected void _SelectSong(int nr) + private void _PlaySong(int nr) { - if (CBase.Songs.IsInCategory() && (CBase.Songs.GetNumSongsVisible() > 0) && (nr >= 0) && ((_Actsong != nr) || (_Streams.Count == 0))) + if (CBase.Songs.IsInCategory() && (CBase.Songs.GetNumSongsVisible() > 0) && (nr >= 0) && ((_ActPlayingSongId != nr) || (_Streams.Count == 0))) { _Streams.ForEach(soundStream => CBase.Sound.FadeAndStop(soundStream, 0f, 1f)); _Streams.Clear(); - CBase.Video.Close(_Video); - _Video = -1; + CBase.Video.Close(_PreviewVideoStream); + _PreviewVideoStream = -1; CBase.Drawing.RemoveTexture(ref _Vidtex); - _Actsong = nr; - if (_Actsong >= CBase.Songs.GetNumSongsVisible()) - _Actsong = 0; + CSong song = CBase.Songs.GetVisibleSong(nr); + if (song == null) + { + _ActPlayingSongId = -1; + return; + } + _ActPlayingSongId = nr; - int stream = CBase.Sound.Load(Path.Combine(CBase.Songs.GetVisibleSong(_Actsong).Folder, CBase.Songs.GetVisibleSong(_Actsong).MP3FileName), true); + int stream = CBase.Sound.Load(Path.Combine(song.Folder, song.MP3FileName), true); CBase.Sound.SetStreamVolumeMax(stream, _MaxVolume); CBase.Sound.SetStreamVolume(stream, 0f); - float startposition = CBase.Songs.GetVisibleSong(_Actsong).PreviewStart; + float startposition = song.PreviewStart; - if (Math.Abs(startposition) < 0.001) + if (startposition < 0.001) startposition = CBase.Sound.GetLength(stream) / 4f; if (startposition >= 0.5f) @@ -574,14 +565,14 @@ namespace VocaluxeLib.Menu.SongMenu CBase.Sound.Play(stream); CBase.Sound.Fade(stream, 100f, 3f); _Streams.Add(stream); - _Actsongstream = stream; + _PreviewSongStream = stream; - if (CBase.Songs.GetVisibleSong(_Actsong).VideoFileName != "" && CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON) + if (song.VideoFileName != "" && CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON) { - _Video = CBase.Video.Load(Path.Combine(CBase.Songs.GetVisibleSong(_Actsong).Folder, CBase.Songs.GetVisibleSong(_Actsong).VideoFileName)); - if (_Video == -1) + _PreviewVideoStream = CBase.Video.Load(Path.Combine(song.Folder, song.VideoFileName)); + if (_PreviewVideoStream == -1) return; - CBase.Video.Skip(_Video, startposition, CBase.Songs.GetVisibleSong(_Actsong).VideoGap); + CBase.Video.Skip(_PreviewVideoStream, startposition, song.VideoGap); _VideoFadeTimer.Stop(); _VideoFadeTimer.Reset(); _VideoFadeTimer.Start(); @@ -595,8 +586,8 @@ namespace VocaluxeLib.Menu.SongMenu CBase.Sound.FadeAndStop(stream, 0f, 0.75f); _Streams.Clear(); - CBase.Video.Close(_Video); - _Video = -1; + CBase.Video.Close(_PreviewVideoStream); + _PreviewVideoStream = -1; CBase.Drawing.RemoveTexture(ref _Vidtex); } diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index eed48eff..fd70a47b 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -81,7 +81,7 @@ namespace VocaluxeLib.Menu.SongMenu { base.Init(); - _Rect = _Theme.SongMenuTileBoard.TileRect; + Rect = _Theme.SongMenuTileBoard.TileRect; _NumW = _Theme.SongMenuTileBoard.NumW; _NumH = _Theme.SongMenuTileBoard.NumH; @@ -100,7 +100,7 @@ namespace VocaluxeLib.Menu.SongMenu for (int j = 0; j < _NumW; j++) { var rect = new SRectF(_Theme.SongMenuTileBoard.TileRect.X + j * (_TileW + _SpaceW), - _Theme.SongMenuTileBoard.TileRect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, _Rect.Z); + _Theme.SongMenuTileBoard.TileRect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, Rect.Z); var tile = new CStatic(_PartyModeID, _CoverTexture, Color, rect); _Tiles.Add(tile); } @@ -108,9 +108,6 @@ namespace VocaluxeLib.Menu.SongMenu _ScrollRect = new SRectF(0, 0, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), _Theme.SongMenuTileBoard.TileRect.Z); - _PreviewId = -1; - _Offset = 0; - _CoverBig = _Theme.SongMenuTileBoard.StaticCoverBig; _TextBG = _Theme.SongMenuTileBoard.StaticTextBG; _DuetIcon = _Theme.SongMenuTileBoard.StaticDuetIcon; @@ -121,6 +118,9 @@ namespace VocaluxeLib.Menu.SongMenu _Artist = _Theme.SongMenuTileBoard.TextArtist; _Title = _Theme.SongMenuTileBoard.TextTitle; _SongLength = _Theme.SongMenuTileBoard.TextSongLength; + + _PreviewId = -1; + _Offset = 0; } public override void Update(SScreenSongOptions songOptions) @@ -175,7 +175,7 @@ namespace VocaluxeLib.Menu.SongMenu _MedleyCalcIcon.Visible = song.Medley.Source == EMedleySource.Calculated; _MedleyTagIcon.Visible = song.Medley.Source == EMedleySource.Tag; - float time = CBase.Sound.GetLength(_SongStream); + float time = CBase.Sound.GetLength(_PreviewSongStream); if (Math.Abs(song.Finish) > 0.001) time = song.Finish; @@ -194,12 +194,8 @@ namespace VocaluxeLib.Menu.SongMenu _Artist.Text = category.Name; int num = category.GetNumSongsNotSung(); - // ReSharper disable ConvertIfStatementToConditionalTernaryExpression - if (num != 1) - // ReSharper restore ConvertIfStatementToConditionalTernaryExpression - _Title.Text = CBase.Language.Translate("TR_SCREENSONG_NUMSONGS").Replace("%v", num.ToString()); - else - _Title.Text = CBase.Language.Translate("TR_SCREENSONG_NUMSONG").Replace("%v", num.ToString()); + String songOrSongs = (num == 1) ? "TR_SCREENSONG_NUMSONG" : "TR_SCREENSONG_NUMSONGS"; + _Title.Text = CBase.Language.Translate(songOrSongs).Replace("%v", num.ToString()); } } @@ -212,7 +208,7 @@ namespace VocaluxeLib.Menu.SongMenu _PreviewId = -1; _UpdateList(0, true); //AfterCategoryChange(); - SetSelectedSong(_ActSong); + SetSelectedSong(_ActPlayingSongId); _AfterCategoryChange(); if (_PreviewId < 0) @@ -376,7 +372,7 @@ namespace VocaluxeLib.Menu.SongMenu bool sel = false; int lastselection = _ActualSelection; - if (!songOptions.Selection.RandomOnly || !CBase.Songs.IsInCategory() && songOptions.Selection.CategoryChangeAllowed) + if (!songOptions.Selection.RandomOnly || (!CBase.Songs.IsInCategory() && songOptions.Selection.CategoryChangeAllowed)) { foreach (CStatic tile in _Tiles) { @@ -457,7 +453,7 @@ namespace VocaluxeLib.Menu.SongMenu _TextBG.Draw(); - if (_Vidtex != null && _Video != -1) + if (_Vidtex != null && _PreviewVideoStream != -1) { if (_Vidtex.Color.A < 1) _CoverBig.Draw(1f, EAspect.Crop); @@ -597,9 +593,6 @@ namespace VocaluxeLib.Menu.SongMenu private void _AfterCategoryChange() { - _SelectSong(_PreviewId); - _UpdatePreview(); - foreach (CStatic tile in _Tiles) tile.Selected = false; @@ -660,17 +653,17 @@ namespace VocaluxeLib.Menu.SongMenu { _NumH = _Theme.SongMenuTileBoard.NumHsmall; _NumW = _Theme.SongMenuTileBoard.NumWsmall; - _Rect = _Theme.SongMenuTileBoard.TileRectSmall; + Rect = _Theme.SongMenuTileBoard.TileRectSmall; } else { _NumH = _Theme.SongMenuTileBoard.NumH; _NumW = _Theme.SongMenuTileBoard.NumW; - _Rect = _Theme.SongMenuTileBoard.TileRect; + Rect = _Theme.SongMenuTileBoard.TileRect; } - _TileW = (int)((_Rect.W - _SpaceW * (_NumW - 1)) / _NumW); - _TileH = (int)((_Rect.H - _SpaceH * (_NumH - 1)) / _NumH); + _TileW = (int)((Rect.W - _SpaceW * (_NumW - 1)) / _NumW); + _TileH = (int)((Rect.H - _SpaceH * (_NumH - 1)) / _NumH); _CoverTexture = CBase.Theme.GetSkinTexture(_Theme.CoverBackgroundName, _PartyModeID); _CoverBigTexture = CBase.Theme.GetSkinTexture(_Theme.CoverBigBackgroundName, _PartyModeID); @@ -680,13 +673,13 @@ namespace VocaluxeLib.Menu.SongMenu { for (int j = 0; j < _NumW; j++) { - var rect = new SRectF(_Rect.X + j * (_TileW + _SpaceW), _Rect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, _Rect.Z); + var rect = new SRectF(Rect.X + j * (_TileW + _SpaceW), Rect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, Rect.Z); var tile = new CStatic(_PartyModeID, _CoverTexture, Color, rect); _Tiles.Add(tile); } } - _ScrollRect = new SRectF(0, 0, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), _Rect.Z); + _ScrollRect = new SRectF(0, 0, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), Rect.Z); _UpdateList(true); } diff --git a/VocaluxeLib/Menu/SongMenu/ISongMenu.cs b/VocaluxeLib/Menu/SongMenu/ISongMenu.cs index 7f2cd6ec..5fecdc43 100644 --- a/VocaluxeLib/Menu/SongMenu/ISongMenu.cs +++ b/VocaluxeLib/Menu/SongMenu/ISongMenu.cs @@ -57,6 +57,6 @@ namespace VocaluxeLib.Menu.SongMenu bool IsSmallView(); void SetSmallView(bool smallView); - SRectF GetRect(); + SRectF Rect { get; } } } \ No newline at end of file From 83b72604a9a2a5cf31d053f250bb4f0954e9b53f Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sat, 19 Oct 2013 02:02:53 +0200 Subject: [PATCH 11/18] Remove confusing ActSongId --- .../Menu/SongMenu/CSongMenuFramework.cs | 34 +++++-------------- .../Menu/SongMenu/CSongMenuTileBoard.cs | 2 +- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 2b1971db..4f84bfae 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -122,15 +122,18 @@ namespace VocaluxeLib.Menu.SongMenu protected virtual int _PreviewId { get { return _PreviewIdInternal; } - set { _PreviewIdInternal = value; } + set + { + //Do this first, otherwhise song will restart + _PlaySong(value); + _PreviewIdInternal = value; + } } protected int _PreviewSongStream { get; private set; } protected int _PreviewVideoStream { get; private set; } - protected int _ActPlayingSongId { get; private set; } - public SRectF Rect { get; protected set; } public SColorF Color @@ -172,7 +175,6 @@ namespace VocaluxeLib.Menu.SongMenu _PartyModeID = partyModeID; _PreviewVideoStream = -1; _PreviewSongStream = -1; - _ActPlayingSongId = -1; _Locked = -1; _Theme = new SThemeSongMenu { @@ -371,9 +373,6 @@ namespace VocaluxeLib.Menu.SongMenu if (!_Initialized) return; - if (_ActPlayingSongId != _PreviewId) - _PlaySong(_PreviewId); - if (_Streams.Count <= 0 || _PreviewVideoStream == -1) return; @@ -523,31 +522,15 @@ namespace VocaluxeLib.Menu.SongMenu CBase.Songs.SetCategory(-1); } - public void ApplyVolume() - { - CBase.Sound.SetStreamVolume(_PreviewSongStream, CBase.Config.GetPreviewMusicVolume()); - } - private void _PlaySong(int nr) { - if (CBase.Songs.IsInCategory() && (CBase.Songs.GetNumSongsVisible() > 0) && (nr >= 0) && ((_ActPlayingSongId != nr) || (_Streams.Count == 0))) + if (CBase.Songs.IsInCategory() && (_PreviewId != nr || _Streams.Count == 0)) { - _Streams.ForEach(soundStream => CBase.Sound.FadeAndStop(soundStream, 0f, 1f)); - _Streams.Clear(); - - CBase.Video.Close(_PreviewVideoStream); - _PreviewVideoStream = -1; - - CBase.Drawing.RemoveTexture(ref _Vidtex); + _Reset(); CSong song = CBase.Songs.GetVisibleSong(nr); if (song == null) - { - _ActPlayingSongId = -1; return; - } - - _ActPlayingSongId = nr; int stream = CBase.Sound.Load(Path.Combine(song.Folder, song.MP3FileName), true); CBase.Sound.SetStreamVolumeMax(stream, _MaxVolume); @@ -563,6 +546,7 @@ namespace VocaluxeLib.Menu.SongMenu CBase.Sound.SetPosition(stream, startposition); CBase.Sound.Play(stream); + CBase.Sound.SetStreamVolumeMax(stream, CBase.Config.GetPreviewMusicVolume()); CBase.Sound.Fade(stream, 100f, 3f); _Streams.Add(stream); _PreviewSongStream = stream; diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index fd70a47b..eac8be4c 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -208,7 +208,7 @@ namespace VocaluxeLib.Menu.SongMenu _PreviewId = -1; _UpdateList(0, true); //AfterCategoryChange(); - SetSelectedSong(_ActPlayingSongId); + SetSelectedSong(_PreviewId); _AfterCategoryChange(); if (_PreviewId < 0) From 21f6213c1a7164862fe434fc3931e8f0e61a73df Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sat, 19 Oct 2013 02:04:58 +0200 Subject: [PATCH 12/18] Fix preview start after song end --- VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 4f84bfae..ee760202 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -537,9 +537,12 @@ namespace VocaluxeLib.Menu.SongMenu CBase.Sound.SetStreamVolume(stream, 0f); float startposition = song.PreviewStart; + float length = CBase.Sound.GetLength(stream); if (startposition < 0.001) - startposition = CBase.Sound.GetLength(stream) / 4f; + startposition = length / 4f; + else if (startposition > length - 5f) + startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f)); if (startposition >= 0.5f) startposition -= 0.5f; From 62e8d125c930a97aeefb57282fc6403f34927f7d Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sat, 19 Oct 2013 03:13:52 +0200 Subject: [PATCH 13/18] Workaround missing length even with prescan on gestreamer --- GstreamerHelper/GstreamerAudioStream.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/GstreamerHelper/GstreamerAudioStream.cpp b/GstreamerHelper/GstreamerAudioStream.cpp index 7fbf632a..ed8d2c4a 100644 --- a/GstreamerHelper/GstreamerAudioStream.cpp +++ b/GstreamerHelper/GstreamerAudioStream.cpp @@ -69,13 +69,12 @@ int GstreamerAudioStream::Load(const wchar_t* Media) return -1; } Running = true; + gst_element_set_state(Element, GST_STATE_NULL); g_object_set(Element, "uri", Media, NULL); g_object_set(Element, "audio-sink", SinkBin, NULL); g_object_set(Element, "flags", GST_PLAY_FLAG_AUDIO, NULL); gst_element_set_state(Element, GST_STATE_PAUSED); - //gst_bus_timed_pop_filtered(Bus, -1, GST_MESSAGE_ASYNC_DONE); - RefreshDuration(); return ID; } @@ -84,8 +83,15 @@ int GstreamerAudioStream::Load(const wchar_t* Media) int GstreamerAudioStream::Load(const wchar_t* Media, bool Prescan) { Load(Media); - if(Prescan) + if(Prescan){ gst_bus_timed_pop_filtered(Bus, -1, GST_MESSAGE_ASYNC_DONE); + //Workaround: Waiting for the stream to be loaded (Length>0) + for(int i=0;i<40;i++){ + if(GetLength()>0.f) + break; + Sleep(5); + } + } return ID; } @@ -127,10 +133,7 @@ void GstreamerAudioStream::Play(void) { PauseStreamAfterFade = false; Running = true; - GstStateChangeReturn ret; - if(Element) - ret = gst_element_set_state(Element, GST_STATE_PLAYING); - if(ret == GST_STATE_CHANGE_ASYNC) + if(gst_element_set_state(Element, GST_STATE_PLAYING) == GST_STATE_CHANGE_ASYNC) gst_bus_timed_pop_filtered(Bus, -1, GST_MESSAGE_ASYNC_DONE); SetStreamVolume(Volume * 100.0); } @@ -180,7 +183,7 @@ void GstreamerAudioStream::SetStreamVolumeMax(float MaxVolume) float GstreamerAudioStream::GetLength() { - if(Duration <= 0) + if(Duration <= 0.f) RefreshDuration(); return Duration; } @@ -191,7 +194,7 @@ void GstreamerAudioStream::RefreshDuration() { gint64 time = -1000; if(gst_element_query_duration(Element, GST_FORMAT_TIME, &time)) - Duration = (gfloat)((gdouble)(time/GST_SECOND)); + Duration = (gfloat)((gdouble)time/GST_SECOND); } } From 7c68e049f430f0413d77243956303fbf0b76a821 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sat, 19 Oct 2013 03:16:35 +0200 Subject: [PATCH 14/18] Bump version to 0.8.2 --- Vocaluxe/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Vocaluxe/Properties/AssemblyInfo.cs b/Vocaluxe/Properties/AssemblyInfo.cs index 96cfb9a6..840ed612 100644 --- a/Vocaluxe/Properties/AssemblyInfo.cs +++ b/Vocaluxe/Properties/AssemblyInfo.cs @@ -49,5 +49,5 @@ using System.Runtime.InteropServices; // Revision // -[assembly: AssemblyVersion("0.3.0.81")] -[assembly: AssemblyFileVersion("0.3.0.81")] \ No newline at end of file +[assembly: AssemblyVersion("0.3.0.82")] +[assembly: AssemblyFileVersion("0.3.0.82")] \ No newline at end of file From 960d511186820244cc16cbf287f175f2a6de88a1 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sun, 20 Oct 2013 13:55:43 +0200 Subject: [PATCH 15/18] Return only true if we got a new video frame (Decoder framework might need a redesign or at least some docu how it is supposed to work) --- Vocaluxe/Lib/Video/Acinerella/CDecoder.cs | 2 +- Vocaluxe/Screens/CScreenSong.cs | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs b/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs index 84f591e1..37b031fe 100644 --- a/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs +++ b/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs @@ -130,7 +130,7 @@ namespace Vocaluxe.Lib.Video.Acinerella else { videoTime = 0; - return true; + return false; //Check if this false is right. But should as we don't give a frame here } _UploadNewFrame(ref frame); videoTime = _LastShownTime; diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index b8da8624..026137e2 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -1017,9 +1017,6 @@ namespace Vocaluxe.Screens { //TODO: What's to do with multiple tags? //Flamefire: What? We only sorted by one tag, sorting by multiple tags (e.g. Album) will be by e.g. the first entry. That can be used here too as otherwhise it will confuse users because it jumps randomly - - //How can we get current letter? I think we have to save it - Or is there a better method? - //"Current letter"? The letter that was typed last? Doesn't matter as we are starting the search on current selected song ReadOnlyCollection songs = CSongs.VisibleSongs; int ct = songs.Count; int visibleID = -1; @@ -1032,8 +1029,6 @@ namespace Vocaluxe.Screens visibleID = _FindIndex(songs, start, element => element.Artist.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)); break; - //TODO: Does this make sense? Maybe we should deactivate this for years? You could only jump between 1 and 2 - //Keep it for consistency. Decades are reasonable though. case ESongSorting.TR_CONFIG_YEAR: case ESongSorting.TR_CONFIG_DECADE: if (curSelected >= 0 && curSelected < ct - 1 && songs[curSelected].Year.StartsWith(letter.ToString(), StringComparison.OrdinalIgnoreCase)) From 5a5d94d18b261d6397df2c6e5b7c231474dff0d8 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 21 Oct 2013 15:11:57 +0200 Subject: [PATCH 16/18] Add documentation for Video/IVideoDecoder.cs --- Vocaluxe/Lib/Video/IVideoDecoder.cs | 73 +++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/Vocaluxe/Lib/Video/IVideoDecoder.cs b/Vocaluxe/Lib/Video/IVideoDecoder.cs index 6c48a24e..cf17f822 100644 --- a/Vocaluxe/Lib/Video/IVideoDecoder.cs +++ b/Vocaluxe/Lib/Video/IVideoDecoder.cs @@ -23,31 +23,94 @@ namespace Vocaluxe.Lib.Video { interface IVideoDecoder { + /// + /// Initializes videodecoder. Got to be called before usage + /// + /// True on success, false if something went wrong. bool Init(); + + /// + /// Close all video streams + /// void CloseAll(); + /// + /// Loads the file with the given file path. + /// + /// Absolute file path of the video file + /// StreamID >=0 on success or -1 on failure int Load(string videoFileName); + + /// + /// Closes the stream with the given ID + /// + /// ID of the stream + /// true if stream was closed, false if stream doesn't exist or already closed bool Close(int streamID); + + /// + /// Gets the number of streams currently active + /// + /// int GetNumStreams(); + /// + /// Gets the length of the video in s + /// + /// Id of the stream + /// Length of the video in s float GetLength(int streamID); /// + /// Gets a frame of the video and sets the current video time /// - /// - /// - /// - /// - /// True if frame is valid + /// Id of the stream + /// Reference to already initialized video texture (from previous calls). If null, one will be created.
+ /// Returns the current video frame which might be outdated if time != current (internal) video position or unchanged (even null) if none is available. + /// The position in s of the video you want to get a frame of. If != current (internal) video position, it will seek to get to right position.
+ /// Note:Will be ignored for looped playback! + /// The actual position in s of the returned frame. Should be ~ time+VideoGap + /// True if frame is valid, false: frame and videoTime might be unchanged or invalid bool GetFrame(int streamID, ref CTexture frame, float time, out float videoTime); + /// + /// Seeks to given position + /// + /// Id of the stream + /// Position to seek to + /// New video gap -> Actual position will be start+gap + /// True on success bool Skip(int streamID, float start, float gap); + + /// + /// Set if the video should be looped + /// + /// Id of the stream + /// True if it should be looped void SetLoop(int streamID, bool loop); + + /// + /// Pauses the video (no new frames will be decoded) + /// + /// Id of the stream void Pause(int streamID); + + /// + /// Resumes a paused video + /// + /// Id of the stream void Resume(int streamID); + /// + /// Check if the given video is finished + /// + /// Id of the stream + /// True if all frames are shown bool Finished(int streamID); + /// + /// Do a step of the decoder in unthreaded decoders. Should be called once every frame. + /// void Update(); } } \ No newline at end of file From c4d0bcd72385ea9cf010f384e9588ebe467dd1ae Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 21 Oct 2013 15:31:20 +0200 Subject: [PATCH 17/18] Rework on the ffmpeg video decoder (Bg were videos flickering? Can't reproduce) --- Vocaluxe/Lib/Video/Acinerella/CDecoder.cs | 27 ++++++++--------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs b/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs index 37b031fe..e68593fe 100644 --- a/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs +++ b/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs @@ -23,7 +23,7 @@ namespace Vocaluxe.Lib.Video.Acinerella private float _FrameDuration; // frame time in s private float _LastDecodedTime; // time of last decoded frame - private float _LastShownTime; // current video position + private float _LastShownTime; // time if the last shown frame in s private float _Time; private float _Gap; @@ -106,12 +106,6 @@ namespace Vocaluxe.Lib.Video.Acinerella public bool GetFrame(ref CTexture frame, float time, out float videoTime) { - if (_Paused) - { - videoTime = 0; - return false; - } - if (Loop) { lock (_MutexSyncSignals) @@ -120,17 +114,17 @@ namespace Vocaluxe.Lib.Video.Acinerella _LoopTimer.Restart(); } } - else if (Math.Abs(_SetTime - time) > float.Epsilon) + else if (Math.Abs(_SetTime - time) >= 1f / 1000f) //Check 1 ms difference { lock (_MutexSyncSignals) { _SetTime = time; } } - else + else if (Math.Abs(_LastShownTime - time) < 1f / 1000 && frame != null) //Check 1 ms difference { - videoTime = 0; - return false; //Check if this false is right. But should as we don't give a frame here + videoTime = _LastShownTime; + return true; } _UploadNewFrame(ref frame); videoTime = _LastShownTime; @@ -168,11 +162,6 @@ namespace Vocaluxe.Lib.Video.Acinerella } _LastDecodedTime = _SkipTime; - lock (_MutexSyncSignals) - { - _LastShownTime = _LastDecodedTime; - } - lock (_MutexFramebuffer) { _Framebuffer.Clear(); @@ -408,13 +397,15 @@ namespace Vocaluxe.Lib.Video.Acinerella float now = _SetTime + _Gap; float maxEnd = now - _FrameDuration * 2; //Get only frames younger than 2 CFrame frame; + bool paused = _Paused; while ((frame = _Framebuffer.Get()) != null) { float frameEnd = frame.Time + _FrameDuration; //Don't show frames that are shown during or after now if (frameEnd >= now) break; //All following frames are after that one - + if (paused) // Don't modify anything + break; _Framebuffer.SetRead(); //Get the last(newest) possible frame and skip the rest to force in-order showing if (frameEnd <= maxEnd) @@ -438,4 +429,4 @@ namespace Vocaluxe.Lib.Video.Acinerella } #endregion Threading } -} +} \ No newline at end of file From a7115df8f53ac290739adac8475ff569f8cd0ed9 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Thu, 24 Oct 2013 19:44:03 +0200 Subject: [PATCH 18/18] Make use of mutex to ensure single instance (more robust and faster) --- Vocaluxe/Program.cs | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index fa626f04..1a445e91 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -22,6 +22,8 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; +using System.Threading; using System.Windows.Forms; using Vocaluxe.Base; using System.Runtime.ExceptionServices; @@ -32,6 +34,12 @@ namespace Vocaluxe { static class CMainProgram { +#if WIN + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool SetForegroundWindow(IntPtr hWnd); +#endif + private static CSplashScreen _SplashScreen; [STAThread, HandleProcessCorruptedStateExceptions] @@ -41,6 +49,9 @@ namespace Vocaluxe { AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; AppDomain.CurrentDomain.AssemblyResolve += _AssemblyResolver; + // Close program if there is another instance running + if (!_EnsureSingleInstance()) + return; try { _Run(args); @@ -61,14 +72,6 @@ namespace Vocaluxe private static void _Run(string[] args) { - // Close program if there is another instance running - if (!_EnsureSingleInstance()) - { - //TODO: put it into language file - MessageBox.Show("Another Instance of Vocaluxe is already runnning!"); - return; - } - Application.DoEvents(); try @@ -306,12 +309,29 @@ namespace Vocaluxe return null; } + private static readonly Mutex _Mutex = new Mutex(false, Application.ProductName + "-SingleInstanceMutex"); + private static bool _EnsureSingleInstance() { - Process currentProcess = Process.GetCurrentProcess(); - Process[] processes = Process.GetProcesses(); + // wait a few seconds in case that the instance is just shutting down + if (!_Mutex.WaitOne(TimeSpan.FromSeconds(2), false)) + { + //TODO: put it into language file + MessageBox.Show("Another Instance of Vocaluxe is already runnning!"); +#if WIN + Process currentProcess = Process.GetCurrentProcess(); + Process[] processes = Process.GetProcessesByName(currentProcess.ProcessName); - return processes.All(t => t.Id == currentProcess.Id || currentProcess.ProcessName != t.ProcessName); + foreach (var process in processes.Where(t => t.Id != currentProcess.Id)) + { + var wnd = process.MainWindowHandle; + if (wnd != IntPtr.Zero) + SetForegroundWindow(wnd); + } +#endif + return false; + } + return true; } } } \ No newline at end of file