From 3b545454575032875794251c10ddabc6d6a65870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Fri, 15 Jan 2016 20:55:32 +0100 Subject: [PATCH 1/5] Fixes #189 - Number of total songs in category --- Vocaluxe/Screens/CScreenSong.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 51aca1ce..5d49a606 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -684,7 +684,7 @@ namespace Vocaluxe.Screens { int song = _SongMenu.GetSelectedSongNr(); if (song >= 0 && song < CSongs.VisibleSongs.Count) - selectionText = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title + " ( "+(song+1)+" / "+CSongs.NumAllSongs+" )"; + selectionText = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title + " ( "+(song+1)+" / "+CSongs.NumSongsVisible+" )"; } else { From 750b93d6d56466e52486ae166dbd22df22c91bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Fri, 15 Jan 2016 21:01:40 +0100 Subject: [PATCH 2/5] Fixes #188 (Preview-Start was ignored) --- VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index ca1f9323..21e66baf 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -415,7 +415,7 @@ namespace VocaluxeLib.Menu.SongMenu if (song == null) return; - CBase.BackgroundMusic.LoadPreview(song); + CBase.BackgroundMusic.LoadPreview(song, song.Preview.StartTime); } protected void _ResetPreview(bool playBGagain = true) From d6fcd7b58c10057f1e461510c858d8d01ecaae30 Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sun, 31 Jan 2016 17:00:48 +0100 Subject: [PATCH 3/5] Fix: previewStart is sometimes ignored (closes #188) --- Vocaluxe/Base/CBackgroundMusic.cs | 44 ++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index ea7e9364..067c5217 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Threading.Tasks; using VocaluxeLib; using VocaluxeLib.Songs; using VocaluxeLib.Draw; @@ -47,6 +48,8 @@ namespace Vocaluxe.Base private static bool _BackgroundMusicAdded; private static bool _Disabled; + private static Task PreviewStartHelperTask; + public static bool VideoEnabled { get { return _CurPlayer.VideoEnabled; } @@ -249,6 +252,13 @@ namespace Vocaluxe.Base public static void Update() { + if (PreviewStartHelperTask != null && _PreviewPlayer.Length > 0) + { + PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext()); + PreviewStartHelperTask.Dispose(); + PreviewStartHelperTask = null; + } + if (!IsPlaying) return; @@ -299,31 +309,41 @@ namespace Vocaluxe.Base bool songChanged = _CurPlayer.SongID != song.ID; _PreviewPlayer.Load(song); + //Change song position only if song is changed or near to end if (songChanged || _CurPlayer.Position + 30 < _CurPlayer.Length) { - float length = _PreviewPlayer.Length; - if (length < 1) - length = 30; // If length is unknow or invalid assume a length of 30s + PreviewStartHelperTask = new Task(() => + { + float length = _PreviewPlayer.Length; + if (length < 1) + length = 30; // If length is unknow or invalid assume a length of 30s - if (start < 0) - start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime; - if (start > length - 5f) - start = Math.Max(0f, Math.Min(length / 4f, length - 5f)); - if (start >= 0.5f) - start -= 0.5f; + if (start < 0) + start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime; + if (start > length - 5f) + start = Math.Max(0f, Math.Min(length / 4f, length - 5f)); + if (start >= 0.5f) + start -= 0.5f; - _PreviewPlayer.Position = start; + _PreviewPlayer.Position = start; + Play(); + }); + _CurPlayer = _PreviewPlayer; } else { + PreviewStartHelperTask.Dispose(); + PreviewStartHelperTask = null; _PreviewPlayer.Position = _CurPlayer.Position; + _CurPlayer = _PreviewPlayer; + Play(); } - _CurPlayer = _PreviewPlayer; + - Play(); + } public static void StopPreview() From 6dc57285543868535c0c8f6289f02fc732626500 Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sun, 31 Jan 2016 17:06:17 +0100 Subject: [PATCH 4/5] Added a timeout-fallback to PreviewStartHelper for the case the length can't be determinated --- Vocaluxe/Base/CBackgroundMusic.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 067c5217..4537b419 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -49,6 +49,8 @@ namespace Vocaluxe.Base private static bool _Disabled; private static Task PreviewStartHelperTask; + private static int PreviewStartWaitCounter; + private const int PreviewStartWaitMaxTries = 10; public static bool VideoEnabled { @@ -252,11 +254,12 @@ namespace Vocaluxe.Base public static void Update() { - if (PreviewStartHelperTask != null && _PreviewPlayer.Length > 0) + if (PreviewStartHelperTask != null && ( _PreviewPlayer.Length > 0 || PreviewStartWaitCounter++ >= PreviewStartWaitMaxTries)) { PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext()); PreviewStartHelperTask.Dispose(); PreviewStartHelperTask = null; + PreviewStartWaitCounter = 0; } if (!IsPlaying) From 35ced0dcfb4af6edb73ef54dfd15d2465d29d07e Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sun, 31 Jan 2016 17:08:51 +0100 Subject: [PATCH 5/5] Renamed new variables to be consistent with the naming rules --- Vocaluxe/Base/CBackgroundMusic.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 4537b419..65165cf4 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -48,9 +48,9 @@ namespace Vocaluxe.Base private static bool _BackgroundMusicAdded; private static bool _Disabled; - private static Task PreviewStartHelperTask; - private static int PreviewStartWaitCounter; - private const int PreviewStartWaitMaxTries = 10; + private static Task _PreviewStartHelperTask; + private static int _PreviewStartWaitCounter; + private const int _PreviewStartWaitMaxTries = 10; public static bool VideoEnabled { @@ -254,12 +254,12 @@ namespace Vocaluxe.Base public static void Update() { - if (PreviewStartHelperTask != null && ( _PreviewPlayer.Length > 0 || PreviewStartWaitCounter++ >= PreviewStartWaitMaxTries)) + if (_PreviewStartHelperTask != null && ( _PreviewPlayer.Length > 0 || _PreviewStartWaitCounter++ >= _PreviewStartWaitMaxTries)) { - PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext()); - PreviewStartHelperTask.Dispose(); - PreviewStartHelperTask = null; - PreviewStartWaitCounter = 0; + _PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext()); + _PreviewStartHelperTask.Dispose(); + _PreviewStartHelperTask = null; + _PreviewStartWaitCounter = 0; } if (!IsPlaying) @@ -317,7 +317,7 @@ namespace Vocaluxe.Base //Change song position only if song is changed or near to end if (songChanged || _CurPlayer.Position + 30 < _CurPlayer.Length) { - PreviewStartHelperTask = new Task(() => + _PreviewStartHelperTask = new Task(() => { float length = _PreviewPlayer.Length; if (length < 1) @@ -337,8 +337,8 @@ namespace Vocaluxe.Base } else { - PreviewStartHelperTask.Dispose(); - PreviewStartHelperTask = null; + _PreviewStartHelperTask.Dispose(); + _PreviewStartHelperTask = null; _PreviewPlayer.Position = _CurPlayer.Position; _CurPlayer = _PreviewPlayer; Play();