From 4c8244601972fd0aaf6433b4dcac2aa3191bae55 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sat, 19 Oct 2013 01:49:34 +0200 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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;