From 3612b9244bd9992515975f7b493eae648b90ab87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Tue, 5 Aug 2014 10:54:34 +0200 Subject: [PATCH 01/18] Added sound- and song-player to VocaluxeLib. Use it for Background-Music. --- .../CPartyScreenTicTacToeMain.cs | 12 +- Vocaluxe/Base/CBackgroundMusic.cs | 189 ++++-------------- Vocaluxe/Base/CMain.cs | 29 ++- Vocaluxe/Base/CSettings.cs | 2 + Vocaluxe/Lib/Sound/Playback/IAudioStream.cs | 1 + Vocaluxe/Lib/Sound/Playback/IPlayback.cs | 9 +- VocaluxeLib/Enums.cs | 8 + VocaluxeLib/IBasic.cs | 8 +- .../Menu/SongMenu/CSongMenuFramework.cs | 2 +- VocaluxeLib/Utils/Player/CSongPlayer.cs | 182 +++++++++++++++++ VocaluxeLib/Utils/Player/CSoundPlayer.cs | 148 ++++++++++++++ VocaluxeLib/VocaluxeLib.csproj | 2 + 12 files changed, 423 insertions(+), 169 deletions(-) create mode 100644 VocaluxeLib/Utils/Player/CSongPlayer.cs create mode 100644 VocaluxeLib/Utils/Player/CSoundPlayer.cs diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs index 2131cd14..bdfbf120 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs @@ -379,7 +379,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe { base.OnClose(); CBase.BackgroundMusic.SetStatus(false); - CBase.Sound.FadeAndClose(_PreviewStream, 0f, 0.5f); + CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close); } private void _CreateFields() @@ -574,7 +574,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe { _GameData.NumJokerRandom[teamNr]--; if (!CBase.Sound.IsFinished(_PreviewStream)) - CBase.Sound.FadeAndClose(_PreviewStream, 0, 1); + CBase.Sound.Fade(_PreviewStream, 0, 1, EStreamAction.Close); _FieldSelected(true); } break; @@ -586,7 +586,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _GameData.NumJokerRetry[teamNr]--; _GameData.Team = teamNr; if (!CBase.Sound.IsFinished(_PreviewStream)) - CBase.Sound.FadeAndClose(_PreviewStream, 0, 1); + CBase.Sound.Fade(_PreviewStream, 0, 1, EStreamAction.Close); _Status = EStatus.JokerRetry; _OldSelectedField = _SelectedField; _SelectedField = -1; @@ -627,7 +627,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _NextRound() { - CBase.Sound.FadeAndClose(_PreviewStream, 0f, 0.5f); + CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close); _Data.ScreenMain.Rounds = _GameData.Rounds; _Data.ScreenMain.FadeToNameSelection = false; _Data.ScreenMain.FadeToSinging = true; @@ -640,7 +640,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _EndParty() { - CBase.Sound.FadeAndClose(_PreviewStream, 0f, 0.5f); + CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close); _FadeTo(EScreens.ScreenParty); } @@ -659,7 +659,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _Back() { - CBase.Sound.FadeAndClose(_PreviewStream, 0f, 0.5f); + CBase.Sound.Fade(_PreviewStream, 0f, 0.5f, EStreamAction.Close); _Data.ScreenMain.FadeToNameSelection = true; _Data.ScreenMain.FadeToSinging = false; _Data.ScreenMain.SingRoundNr = _SelectedField; diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index b4be306f..0e4dbc44 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -22,6 +22,7 @@ using System.IO; using VocaluxeLib; using VocaluxeLib.Songs; using VocaluxeLib.Draw; +using VocaluxeLib.Utils.Player; namespace Vocaluxe.Base { @@ -29,46 +30,30 @@ namespace Vocaluxe.Base { private static bool _Initialized; + private static CSongPlayer _SongPlayer; + private static bool _OwnSongsAvailable; private static EBackgroundMusicSource _MusicSource; private static bool _VideoEnabled; private static CPlaylistElement _CurrentPlaylistElement; //Currently played music - private static int _CurrentMusicStream = -1; //Current active music stream - private static int _PreviousMusicIndex; //Index of _CurrentPlaylistElement in _PreviousFiles (kept for performance) + private static int _PreviousMusicIndex = -1; private static readonly List _BGMusicFiles = new List(); //Background music files private static readonly List _NotPlayedFiles = new List(); //Not played files private static readonly List _PreviousFiles = new List(); //Played files - private static int _Video = -1; - private static CTexture _CurrentVideoTexture; - private static CFading _VideoFading; - private static bool _OwnMusicAdded; private static bool _BackgroundMusicAdded; private static bool _Disabled; public static bool VideoEnabled { - get { return _VideoEnabled; } - set - { - if (_VideoEnabled == value) - return; - _VideoEnabled = value; - if (_VideoEnabled) - _LoadVideo(); - else if (_Video != -1) - { - CVideo.Close(_Video); - CDraw.RemoveTexture(ref _CurrentVideoTexture); - _Video = -1; - } - } + get { return _SongPlayer.VideoEnabled; } + set { _SongPlayer.VideoEnabled = value; } } - public static bool CanSing { get; private set; } + public static bool CanSing { get { return _BGMusicFiles.Contains(_CurrentPlaylistElement) ? false : _SongPlayer.CanSing; } } public static bool Disabled { @@ -83,35 +68,33 @@ namespace Vocaluxe.Base } } - public static bool RepeatSong { get; set; } + public static bool RepeatSong { + get { return _SongPlayer.RepeatSong; } + set { _SongPlayer.RepeatSong = value; } + } public static int SongID { - get { return _CurrentPlaylistElement == null ? -1 : _CurrentPlaylistElement.SongID; } + get { return _SongPlayer.SongID; } } public static bool SongHasVideo { - get { return _CurrentPlaylistElement != null && File.Exists(_CurrentPlaylistElement.VideoFilePath); } + get { return _SongPlayer.SongHasVideo; } } - public static bool IsPlaying { get; private set; } + public static bool IsPlaying { get { return _SongPlayer.IsPlaying; } } public static string ArtistAndTitle { - get - { - if (_CurrentPlaylistElement == null) - return ""; - if (_CurrentPlaylistElement.Artist != "" && _CurrentPlaylistElement.Title != "") - return _CurrentPlaylistElement.Artist + " - " + _CurrentPlaylistElement.Title; - return Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath); + get { + return _BGMusicFiles.Contains(_CurrentPlaylistElement) ? Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath) :_SongPlayer.ArtistAndTitle; } } public static CTexture Cover { - get { return _CurrentPlaylistElement == null ? CCover.NoCover : _CurrentPlaylistElement.Cover; } + get { return _SongPlayer.Cover; } } //Use this to set whether own songs are available for access @@ -143,8 +126,9 @@ namespace Vocaluxe.Base _MusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC; _AddBackgroundMusic(); - _PreviousMusicIndex = -1; - IsPlaying = false; + _SongPlayer = new CSongPlayer(); + _SongPlayer.Volume = CConfig.BackgroundMusicVolume; + _VideoEnabled = (CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON && CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON); SetMusicSource(CConfig.BackgroundMusicSource); _Initialized = true; @@ -152,22 +136,12 @@ namespace Vocaluxe.Base public static void Close() { - if (_CurrentMusicStream >= 0) - { - CSound.Close(_CurrentMusicStream); - _CurrentMusicStream = -1; - } - if (_Video != -1) - { - CVideo.Close(_Video); - CDraw.RemoveTexture(ref _CurrentVideoTexture); - _Video = -1; - } + _SongPlayer.Close(); + _BGMusicFiles.Clear(); _NotPlayedFiles.Clear(); _PreviousFiles.Clear(); - IsPlaying = false; _Initialized = false; } @@ -176,15 +150,10 @@ namespace Vocaluxe.Base if (IsPlaying || CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF) return; - if (_CurrentMusicStream != -1) + if (_SongPlayer.SongLoaded) { //Resume - CSound.SetStreamVolume(_CurrentMusicStream, 0f); - CSound.Fade(_CurrentMusicStream, 100f, CSettings.BackgroundMusicFadeTime); - CSound.Play(_CurrentMusicStream); - if (_VideoEnabled && _Video != -1) - CVideo.Resume(_Video); - IsPlaying = true; + _SongPlayer.TogglePause(); } else Next(); @@ -195,17 +164,9 @@ namespace Vocaluxe.Base if (!IsPlaying) return; - if (_Video != -1) - { - CVideo.Close(_Video); - CDraw.RemoveTexture(ref _CurrentVideoTexture); - _Video = -1; - } - CSound.FadeAndClose(_CurrentMusicStream, 0f, CSettings.BackgroundMusicFadeTime); - _CurrentMusicStream = -1; + _SongPlayer.Stop(); _CurrentPlaylistElement = null; - IsPlaying = false; } public static void Pause() @@ -213,13 +174,7 @@ namespace Vocaluxe.Base if (!IsPlaying) return; - if (_Video != -1) - { - CVideo.Pause(_Video); - CVideo.Skip(_Video, CSound.GetPosition(_CurrentMusicStream) + CSettings.BackgroundMusicFadeTime, _CurrentPlaylistElement.VideoGap); - } - CSound.FadeAndPause(_CurrentMusicStream, 0f, CSettings.BackgroundMusicFadeTime); - IsPlaying = false; + _SongPlayer.TogglePause(); } public static void Next() @@ -248,68 +203,36 @@ namespace Vocaluxe.Base _PreviousMusicIndex = _PreviousFiles.Count - 1; } _StartSong(); - CanSing = !_IsBackgroundFile(_CurrentPlaylistElement); } public static void Previous() { if (_PreviousMusicIndex < 0) return; - Debug.Assert(_CurrentMusicStream != -1 && _CurrentPlaylistElement != null); - if (CSound.GetPosition(_CurrentMusicStream) <= 1.5f && _PreviousMusicIndex > 0) + Debug.Assert(_CurrentPlaylistElement != null); + if (_SongPlayer.Position <= 1.5f && _PreviousMusicIndex > 0) { Stop(); //stop last song _PreviousMusicIndex--; _CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex]; - CanSing = !_IsBackgroundFile(_CurrentPlaylistElement); } _StartSong(); } public static void Update() { - if (!IsPlaying) + if (!IsPlaying && !_SongPlayer.SongLoaded) return; - Debug.Assert(_CurrentMusicStream != -1 && _CurrentPlaylistElement != null); - float timeToPlay; - if (Math.Abs(_CurrentPlaylistElement.Finish) < 0.001) - { - //No End-Tag defined - float len = CSound.GetLength(_CurrentMusicStream); - timeToPlay = (len > 0f) ? len - CSound.GetPosition(_CurrentMusicStream) : CSettings.BackgroundMusicFadeTime + 1f; - } - else //End-Tag found - timeToPlay = _CurrentPlaylistElement.Finish - CSound.GetPosition(_CurrentMusicStream); - - bool finished = CSound.IsFinished(_CurrentMusicStream); - if (timeToPlay <= CSettings.BackgroundMusicFadeTime || finished) - { - if (RepeatSong) - _StartSong(); - else - Next(); - } + _SongPlayer.Update(); + if (_SongPlayer.IsFinished) + Next(); } public static CTexture GetVideoTexture() { - if (_Video == -1) - return null; - float vtime; - if (CVideo.GetFrame(_Video, ref _CurrentVideoTexture, CSound.GetPosition(_CurrentMusicStream), out vtime)) - { - if (_VideoFading != null) - { - bool finished; - _CurrentVideoTexture.Color.A = _VideoFading.GetValue(out finished); - if (finished) - _VideoFading = null; - } - return _CurrentVideoTexture; - } - return null; + return _SongPlayer.GetVideoTexture(); } public static void SetMusicSource(EBackgroundMusicSource source) @@ -341,32 +264,17 @@ namespace Vocaluxe.Base private static void _StartSong() { Debug.Assert(_CurrentPlaylistElement != null); - //If we have an active stream, reuse it - if (_CurrentMusicStream < 0) - { - //otherwhise load - _CurrentMusicStream = CSound.Load(_CurrentPlaylistElement.MusicFilePath); - if (_CurrentMusicStream < 0) - return; - CSound.SetStreamVolume(_CurrentMusicStream, 0f); - CSound.Fade(_CurrentMusicStream, 100f, CSettings.BackgroundMusicFadeTime); - } - //Seek to #Start-Tag, if found - if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) - CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start); - if (_VideoEnabled) - { - if (_Video != -1) - { - if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) - CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap + _CurrentPlaylistElement.Start); - else - CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap); - } - else - _LoadVideo(); - } + //If current song same as loaded restart only + if (_CurrentPlaylistElement.SongID == _SongPlayer.SongID) + _SongPlayer.Play(); + + //otherwhise load + //Seek to #Start-Tag, if found + float start = 0f; + if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) + start = _CurrentPlaylistElement.Start; + _SongPlayer.Load(CBase.Songs.GetSongByID(_CurrentPlaylistElement.SongID), start, true); } private static void _AddOwnMusic() @@ -419,16 +327,5 @@ namespace Vocaluxe.Base return _BGMusicFiles.Contains(element); } - private static void _LoadVideo() - { - if (_Video != -1 || String.IsNullOrEmpty(_CurrentPlaylistElement.VideoFilePath)) - return; - _Video = CVideo.Load(_CurrentPlaylistElement.VideoFilePath); - if (CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) - CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap + _CurrentPlaylistElement.Start); //Use gap, otherwhise we will overwrite position in GetVideoTexture - else - CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap); - _VideoFading = new CFading(0f, 1f, 3f); - } } } \ No newline at end of file diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index a47c74a7..3daec831 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -243,6 +243,11 @@ namespace Vocaluxe.Base { return CSettings.SlideShowFadeTime; } + + public float GetSoundPlayerFadeTime() + { + return CSettings.SoundPlayerFadeTime; + } } class CBtheme : ITheme @@ -774,6 +779,16 @@ namespace Vocaluxe.Base { CVideo.SetLoop(streamID, loop); } + + public void Pause(int streamID) + { + CVideo.Pause(streamID); + } + + public void Resume(int streamID) + { + CVideo.Resume(streamID); + } } class CBsound : ISound @@ -793,9 +808,14 @@ namespace Vocaluxe.Base CSound.Play(soundStream); } - public void Fade(int soundStream, float targetVolume, float duration) + public void Fade(int soundStream, float targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing) { - CSound.Fade(soundStream, targetVolume, duration); + CSound.Fade(soundStream, targetVolume, duration, afterFadeAction); + } + + public void Close(int soundStream) + { + CSound.Close(soundStream); } public bool IsFinished(int soundStream) @@ -813,11 +833,6 @@ namespace Vocaluxe.Base return CSound.GetLength(soundStream); } - public void FadeAndClose(int soundStream, float targetVolume, float duration) - { - CSound.FadeAndClose(soundStream, targetVolume, duration); - } - public void SetStreamVolume(int soundStream, float volume) { CSound.SetStreamVolume(soundStream, volume); diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index 3de72e98..a1326c55 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -145,6 +145,8 @@ namespace Vocaluxe.Base public const float BackgroundMusicFadeTime = 0.5f; public const float PauseResetTime = 1f; + public const float SoundPlayerFadeTime = 0.5f; + public const float SlideShowImageTime = 3500f; public const float SlideShowFadeTime = 500f; diff --git a/Vocaluxe/Lib/Sound/Playback/IAudioStream.cs b/Vocaluxe/Lib/Sound/Playback/IAudioStream.cs index 8ec763fe..15d88270 100644 --- a/Vocaluxe/Lib/Sound/Playback/IAudioStream.cs +++ b/Vocaluxe/Lib/Sound/Playback/IAudioStream.cs @@ -16,6 +16,7 @@ #endregion using System; +using VocaluxeLib; namespace Vocaluxe.Lib.Sound.Playback { diff --git a/Vocaluxe/Lib/Sound/Playback/IPlayback.cs b/Vocaluxe/Lib/Sound/Playback/IPlayback.cs index 04d9be75..a022d455 100644 --- a/Vocaluxe/Lib/Sound/Playback/IPlayback.cs +++ b/Vocaluxe/Lib/Sound/Playback/IPlayback.cs @@ -15,15 +15,10 @@ // along with Vocaluxe. If not, see . #endregion +using VocaluxeLib; + namespace Vocaluxe.Lib.Sound.Playback { - public enum EStreamAction - { - Nothing, - Pause, - Stop, - Close - } interface IPlayback { diff --git a/VocaluxeLib/Enums.cs b/VocaluxeLib/Enums.cs index 0df1d888..e7bf8270 100644 --- a/VocaluxeLib/Enums.cs +++ b/VocaluxeLib/Enums.cs @@ -288,6 +288,14 @@ namespace VocaluxeLib } #endregion Config + public enum EStreamAction + { + Nothing, + Pause, + Stop, + Close + } + public enum EProgramState { Start, diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index 9d84374d..4785d045 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -89,6 +89,8 @@ namespace VocaluxeLib float GetSlideShowImageTime(); float GetSlideShowFadeTime(); + + float GetSoundPlayerFadeTime(); } public interface ITheme @@ -253,6 +255,8 @@ namespace VocaluxeLib bool IsFinished(int streamID); bool Close(int streamID); void SetLoop(int streamID, bool loop = true); + void Resume(int streamID); + void Pause(int streamID); } public interface ISound @@ -260,12 +264,12 @@ namespace VocaluxeLib int Load(string soundFile, bool loop = false, bool prescan = false); void SetPosition(int soundStream, float newPosition); void Play(int soundStream); - void Fade(int soundStream, float targetVolume, float duration); + void Fade(int soundStream, float targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing); + void Close(int soundStream); bool IsFinished(int soundStream); float GetPosition(int soundStream); float GetLength(int soundStream); - void FadeAndClose(int soundStream, float targetVolume, float duration); void SetStreamVolume(int soundStream, float volume); } diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index e7f260f9..70705f1c 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -561,7 +561,7 @@ namespace VocaluxeLib.Menu.SongMenu protected void _Reset() { foreach (int stream in _Streams) - CBase.Sound.FadeAndClose(stream, 0f, 0.75f); + CBase.Sound.Fade(stream, 0f, 0.75f, EStreamAction.Close); _Streams.Clear(); CBase.Video.Close(_PreviewVideoStream); diff --git a/VocaluxeLib/Utils/Player/CSongPlayer.cs b/VocaluxeLib/Utils/Player/CSongPlayer.cs new file mode 100644 index 00000000..55da4687 --- /dev/null +++ b/VocaluxeLib/Utils/Player/CSongPlayer.cs @@ -0,0 +1,182 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; + +using VocaluxeLib.Draw; +using VocaluxeLib.Songs; + +namespace VocaluxeLib.Utils.Player +{ + public class CSongPlayer : CSoundPlayer + { + private CSong _Song; + private bool _VideoEnabled; + private int _Video = -1; + private CTexture _CurrentVideoTexture; + private CFading _VideoFading; + + public bool VideoEnabled + { + get { return _VideoEnabled; } + set + { + if (_VideoEnabled == value) + return; + _VideoEnabled = value; + if (_VideoEnabled) + _LoadVideo(); + else if (_Video != -1) + { + CBase.Video.Close(_Video); + CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture); + _Video = -1; + } + } + } + public bool CanSing { get; private set; } + public int SongID + { + get { return _Song == null ? -1 : _Song.ID; } + } + public bool SongHasVideo + { + get { return _Song != null && File.Exists(Path.Combine(_Song.Folder,_Song.VideoFileName)); } + } + + public string ArtistAndTitle + { + get + { + if (_Song == null) + return ""; + if (_Song.Artist != "" && _Song.Title != "") + return _Song.Artist + " - " + _Song.Title; + return Path.GetFileNameWithoutExtension(_Song.MP3FileName); + } + } + + public CTexture Cover + { + get { return _Song == null ? CBase.Cover.GetNoCover() : _Song.CoverTextureBig; } + } + + public bool SongLoaded + { + get { return _StreamID != -1; } + } + + public CSongPlayer(bool loop = false) : base(loop) { } + + public CSongPlayer(CSong song, bool loop = false, float position = 0f, bool autoplay = false) + : base(Path.Combine(song.Folder,song.MP3FileName), loop, position, autoplay) + { + _Song = song; + _LoadVideo(); + } + + public CTexture GetVideoTexture() + { + if (_Video == -1 || _Song == null) + return null; + float vtime; + if (CBase.Video.GetFrame(_Video, ref _CurrentVideoTexture, CBase.Sound.GetPosition(_StreamID), out vtime)) + { + if (_VideoFading != null) + { + bool finished; + _CurrentVideoTexture.Color.A = _VideoFading.GetValue(out finished); + if (finished) + _VideoFading = null; + } + return _CurrentVideoTexture; + } + return null; + } + + public void Load(CSong song, float position = 0f, bool autoplay = false) + { + if (song == null) + return; + + _Song = song; + _LoadVideo(); + base.Load(Path.Combine(song.Folder, song.MP3FileName), position, autoplay); + } + + public new void Close() + { + base.Close(); + + if (_Video != -1) + { + CBase.Video.Close(_Video); + CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture); + _Video = -1; + } + } + + public new void Play() + { + base.Play(); + + if (_VideoEnabled && _Video != -1) + CBase.Video.Resume(_Video); + } + + public new void Stop() + { + base.Stop(); + + if (_Video != -1) + { + CBase.Video.Close(_Video); + CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture); + _Video = -1; + } + } + + public new void TogglePause() + { + base.TogglePause(); + if (_Video != -1) + { + CBase.Video.Pause(_Video); + CBase.Video.Skip(_Video, CBase.Sound.GetPosition(_StreamID) + _FadeTime, _Song.VideoGap); + } + } + + public new void Update() + { + if (_StreamID == -1 || !IsPlaying) + return; + + float timeToPlay; + float len = CBase.Sound.GetLength(_StreamID); + timeToPlay = (len > 0f) ? len - CBase.Sound.GetPosition(_StreamID) : _FadeTime + 1f; + + bool finished = CBase.Sound.IsFinished(_StreamID); + if (timeToPlay <= _FadeTime || finished) + { + if (RepeatSong) + Play(); + else + Stop(); + } + } + + private void _LoadVideo() + { + if (_Song == null) + return; + + string videoFilePath = Path.Combine(_Song.Folder, _Song.VideoFileName); + if (_Video != -1 || String.IsNullOrEmpty(videoFilePath)) + return; + _Video = CBase.Video.Load(videoFilePath); + CBase.Video.Skip(_Video, 0f, _Song.VideoGap + _StartPosition); //Use gap, otherwhise we will overwrite position in GetVideoTexture + _VideoFading = new CFading(0f, 1f, 3f); + } + } +} diff --git a/VocaluxeLib/Utils/Player/CSoundPlayer.cs b/VocaluxeLib/Utils/Player/CSoundPlayer.cs new file mode 100644 index 00000000..59e858de --- /dev/null +++ b/VocaluxeLib/Utils/Player/CSoundPlayer.cs @@ -0,0 +1,148 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace VocaluxeLib.Utils.Player +{ + public class CSoundPlayer + { + protected int _StreamID = -1; + protected float _Volume; + protected float _StartPosition; + protected float _FadeTime = CBase.Settings.GetSoundPlayerFadeTime(); + + public float Volume + { + set + { + _Volume = value; + _ApplyVolume(); + } + get { return _Volume; } + } + public bool Loop; + + public float Position + { + set { + if(_StreamID == -1) + return; + CBase.Sound.SetPosition(_StreamID, value); + _StartPosition = value; + } + get { + if(_StreamID == -1) + return -1; + return CBase.Sound.GetPosition(_StreamID); + } + } + + public bool RepeatSong; + public bool IsPlaying { get; private set; } + + public bool IsFinished { get { return CBase.Sound.IsFinished(_StreamID); } } + + public CSoundPlayer(bool loop = false) + { + Loop = loop; + } + + public CSoundPlayer(string file, bool loop = false, float position = 0f, bool autoplay = false) + { + _StreamID = CBase.Sound.Load(file, false, true); + if(position > 0f) + Position = position; + Loop = loop; + if (autoplay) + Play(); + } + + public void Load(string file, float position = 0f, bool autoplay = false) + { + if (IsPlaying) + Stop(); + + _StreamID = CBase.Sound.Load(file, false, true); + if (position > 0f) + Position = position; + if (autoplay) + Play(); + } + + public void Play() + { + if (_StreamID == -1) + return; + + CBase.Sound.SetPosition(_StreamID, _StartPosition); + CBase.Sound.SetStreamVolume(_StreamID, 0f); + CBase.Sound.Fade(_StreamID, Volume, _FadeTime); + CBase.Sound.Play(_StreamID); + IsPlaying = true; + } + + public void TogglePause() + { + if (_StreamID == -1) + return; + + if(IsPlaying) + CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Pause); + else + { + CBase.Sound.Fade(_StreamID, Volume, _FadeTime); + CBase.Sound.Play(_StreamID); + } + + IsPlaying = !IsPlaying; + } + + public void Stop() + { + if (_StreamID == -1 || !IsPlaying) + return; + + CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Stop); + IsPlaying = false; + } + + public void Update() + { + if (_StreamID == -1 || !IsPlaying) + return; + + float timeToPlay; + float len = CBase.Sound.GetLength(_StreamID); + timeToPlay = (len > 0f) ? len - CBase.Sound.GetPosition(_StreamID) : _FadeTime + 1f; + + bool finished = CBase.Sound.IsFinished(_StreamID); + if (timeToPlay <= _FadeTime || finished) + { + if (RepeatSong) + Play(); + else + Stop(); + } + + } + + public void Close() + { + if (_StreamID == -1) + return; + + CBase.Sound.Close(_StreamID); + _StreamID = -1; + IsPlaying = false; + } + + private void _ApplyVolume() + { + if (_StreamID == -1) + return; + + CBase.Sound.SetStreamVolume(_StreamID, Volume); + } + } +} diff --git a/VocaluxeLib/VocaluxeLib.csproj b/VocaluxeLib/VocaluxeLib.csproj index 3e17ea26..a367e8e1 100644 --- a/VocaluxeLib/VocaluxeLib.csproj +++ b/VocaluxeLib/VocaluxeLib.csproj @@ -135,6 +135,8 @@ + + From 240f47090d819e84ad78a56499937b35aaeca413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Tue, 5 Aug 2014 11:41:20 +0200 Subject: [PATCH 02/18] Fix for background-music-files. --- Vocaluxe/Base/CBackgroundMusic.cs | 15 ++++++++++----- VocaluxeLib/Utils/Player/CSongPlayer.cs | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 0e4dbc44..fa48a565 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -270,11 +270,16 @@ namespace Vocaluxe.Base _SongPlayer.Play(); //otherwhise load - //Seek to #Start-Tag, if found - float start = 0f; - if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) - start = _CurrentPlaylistElement.Start; - _SongPlayer.Load(CBase.Songs.GetSongByID(_CurrentPlaylistElement.SongID), start, true); + if (_BGMusicFiles.Contains(_CurrentPlaylistElement)) + _SongPlayer.Load(_CurrentPlaylistElement.MusicFilePath, 0f, true); + else + { + //Seek to #Start-Tag, if found + float start = 0f; + if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) + start = _CurrentPlaylistElement.Start; + _SongPlayer.Load(CBase.Songs.GetSongByID(_CurrentPlaylistElement.SongID), start, true); + } } private static void _AddOwnMusic() diff --git a/VocaluxeLib/Utils/Player/CSongPlayer.cs b/VocaluxeLib/Utils/Player/CSongPlayer.cs index 55da4687..88e02bd4 100644 --- a/VocaluxeLib/Utils/Player/CSongPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSongPlayer.cs @@ -76,6 +76,12 @@ namespace VocaluxeLib.Utils.Player _LoadVideo(); } + public CSongPlayer(string file, bool loop = false, float position = 0f, bool autoplay = false) + : base(file, loop, position, autoplay) + { + _Song = null; + } + public CTexture GetVideoTexture() { if (_Video == -1 || _Song == null) @@ -105,6 +111,15 @@ namespace VocaluxeLib.Utils.Player base.Load(Path.Combine(song.Folder, song.MP3FileName), position, autoplay); } + public void Load(string file, float position = 0f, bool autoplay = false) + { + if (String.IsNullOrEmpty(file)) + return; + + _Song = null; + base.Load(file, position, autoplay); + } + public new void Close() { base.Close(); From 4c01396e461e9b3a415643f5574ee1bc4aee49ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sat, 9 Aug 2014 17:12:27 +0200 Subject: [PATCH 03/18] Added preview-player which is used for playing preview in song-menu. --- Vocaluxe/Base/CConfig.cs | 2 + Vocaluxe/Base/CMain.cs | 46 ++++++++++++- Vocaluxe/Base/CPreviewPlayer.cs | 69 +++++++++++++++++++ Vocaluxe/Vocaluxe.csproj | 1 + VocaluxeLib/CBasic.cs | 5 +- VocaluxeLib/IBasic.cs | 13 ++++ .../Menu/SongMenu/CSongMenuFramework.cs | 47 +++---------- .../Menu/SongMenu/CSongMenuTileBoard.cs | 16 +++-- VocaluxeLib/Utils/Player/CSoundPlayer.cs | 10 +++ VocaluxeLib/VocaluxeLib.csproj | 1 + 10 files changed, 163 insertions(+), 47 deletions(-) create mode 100644 Vocaluxe/Base/CPreviewPlayer.cs diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 2e73bc8e..fbf02ada 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -263,6 +263,8 @@ namespace Vocaluxe.Base xmlReader.TryGetEnumValue("//root/Sound/BackgroundMusicUseStart", ref BackgroundMusicUseStart); xmlReader.TryGetIntValueRange("//root/Sound/PreviewMusicVolume", ref _PreviewMusicVolume); xmlReader.TryGetIntValueRange("//root/Sound/GameMusicVolume", ref _GameMusicVolume); + + CPreviewPlayer.UpdateVolume(); #endregion Sound #region Game diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index bac2a91d..00650e9a 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -51,11 +51,12 @@ namespace Vocaluxe.Base private static readonly IDataBase _DataBase = new CBdataBase(); private static readonly IControllers _Controller = new CBcontrollers(); private static readonly IPlaylist _Playlist = new CBplaylist(); + private static readonly IPreviewPlayer _PreviewPlayer = new CBpreviewPlayer(); public static void Init() { CBase.Assign(_Config, _Settings, _Theme, _Log, _BackgroundMusic, _Draw, _Graphics, _Fonts, _Language, - _Game, _Profiles, _Record, _Songs, _Video, _Sound, _Cover, _DataBase, _Controller, _Playlist); + _Game, _Profiles, _Record, _Songs, _Video, _Sound, _Cover, _DataBase, _Controller, _Playlist, _PreviewPlayer); } } @@ -960,4 +961,47 @@ namespace Vocaluxe.Base return CPlaylists.GetSong(playlistID, songIndex); } } + + class CBpreviewPlayer : IPreviewPlayer + { + public void Play(float start = -1) + { + CPreviewPlayer.Play(); + } + + public void Load(CSong song, float start = 0f) + { + CPreviewPlayer.Load(song, start); + } + + public void Stop() + { + CPreviewPlayer.Stop(); + } + + public void Pause() + { + CPreviewPlayer.Pause(); + } + + public CTexture GetCover() + { + return CPreviewPlayer.Cover; + } + + public CTexture GetVideoTexture() + { + return CPreviewPlayer.VideoTexture; + } + + public bool IsPlaying() + { + return CPreviewPlayer.IsPlaying; + } + + public float GetLength() + { + return CPreviewPlayer.Length; + } + } } \ No newline at end of file diff --git a/Vocaluxe/Base/CPreviewPlayer.cs b/Vocaluxe/Base/CPreviewPlayer.cs new file mode 100644 index 00000000..3422b248 --- /dev/null +++ b/Vocaluxe/Base/CPreviewPlayer.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using VocaluxeLib.Utils.Player; +using VocaluxeLib.Draw; +using VocaluxeLib.Songs; + +namespace Vocaluxe.Base +{ + public static class CPreviewPlayer + { + private static CSongPlayer _Player = new CSongPlayer(true); + + public static CTexture VideoTexture + { + get { return _Player.GetVideoTexture(); } + } + + public static CTexture Cover + { + get { return _Player.Cover; } + } + + public static bool IsPlaying + { + get { return _Player.IsPlaying; } + } + + public static float Length + { + get { return _Player.Length; } + } + + public static void Load(CSong song, float start = 0f) + { + if (song == null) + return; + + if (start == 0f) + start = song.Preview.StartTime; + + _Player.Load(song, start); + } + + public static void Play(float start = -1) + { + if (start > -1) + _Player.Position = start; + _Player.Play(); + } + + public static void Pause() + { + _Player.TogglePause(); + } + + public static void Stop() + { + _Player.Stop(); + } + + public static void UpdateVolume() + { + _Player.Volume = CConfig.PreviewMusicVolume; + } + } +} diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index db1858e6..41753b7a 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -217,6 +217,7 @@ + diff --git a/VocaluxeLib/CBasic.cs b/VocaluxeLib/CBasic.cs index 7a588ee1..348f61de 100644 --- a/VocaluxeLib/CBasic.cs +++ b/VocaluxeLib/CBasic.cs @@ -38,10 +38,12 @@ namespace VocaluxeLib public static IDataBase DataBase; public static IControllers Controller; public static IPlaylist Playlist; + public static IPreviewPlayer PreviewPlayer; public static void Assign(IConfig config, ISettings settings, ITheme theme, ILog log, IBackgroundMusic backgroundMusic, IDrawing draw, IGraphics graphics, IFonts fonts, ILanguage language, IGame game, IProfiles profiles, IRecording record, - ISongs songs, IVideo video, ISound sound, ICover cover, IDataBase dataBase, IControllers controller, IPlaylist playlist) + ISongs songs, IVideo video, ISound sound, ICover cover, IDataBase dataBase, IControllers controller, IPlaylist playlist, + IPreviewPlayer previewPlayer) { Config = config; Settings = settings; @@ -62,6 +64,7 @@ namespace VocaluxeLib DataBase = dataBase; Controller = controller; Playlist = playlist; + PreviewPlayer = previewPlayer; } } } \ No newline at end of file diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index ab012974..a18b6811 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -315,4 +315,17 @@ namespace VocaluxeLib int GetSongCount(int playlistID); CPlaylistSong GetSong(int playlistID, int songIndex); } + + public interface IPreviewPlayer + { + void Play(float start = -1); + void Load(CSong song, float start = 0f); + void Stop(); + void Pause(); + CTexture GetCover(); + CTexture GetVideoTexture(); + bool IsPlaying(); + float GetLength(); + + } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index bcb6ceda..079c0cb6 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -121,12 +121,6 @@ namespace VocaluxeLib.Menu.SongMenu } } - protected int _PreviewSongStream { get; private set; } - - protected int _PreviewVideoStream { get; private set; } - private CFading _VideoFading; - protected CTexture _Vidtex; - private SColorF _ColorInternal; protected SColorF _Color { @@ -160,8 +154,6 @@ namespace VocaluxeLib.Menu.SongMenu { Visible = true; _PartyModeID = partyModeID; - _PreviewVideoStream = -1; - _PreviewSongStream = -1; _Theme = new SThemeSongMenu { SongMenuTileBoard = @@ -354,7 +346,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (!_Initialized) return; - + /* if (_PreviewSongStream == -1 || _PreviewVideoStream == -1) return; @@ -380,7 +372,7 @@ namespace VocaluxeLib.Menu.SongMenu _VideoFading = null; } } - } + }*/ } public virtual void OnShow() {} @@ -399,8 +391,8 @@ namespace VocaluxeLib.Menu.SongMenu if (!_Initialized || !Visible) return; - if (_PreviewVideoStream != -1) - CBase.Drawing.DrawTexture(_Vidtex, new SRectF(0, 0, 1280, 720, 0)); + if (CBase.PreviewPlayer.IsPlaying()) + CBase.Drawing.DrawTexture(CBase.PreviewPlayer.GetVideoTexture(), new SRectF(0, 0, 1280, 720, 0)); } public bool IsMouseOverSelectedSong(SMouseEvent mEvent) @@ -509,44 +501,23 @@ namespace VocaluxeLib.Menu.SongMenu if (song == null) return; - //TODO: Using prescan here causes Vocaluxe to hang a bit on loading the song but we need the length below - _PreviewSongStream = CBase.Sound.Load(Path.Combine(song.Folder, song.MP3FileName), true, true); + CBase.PreviewPlayer.Load(song); float startposition = song.Preview.StartTime; - float length = CBase.Sound.GetLength(_PreviewSongStream); + + float length = CBase.PreviewPlayer.GetLength(); if (song.Preview.Source == EDataSource.None) startposition = length / 4f; else if (startposition > length - 5f) startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f)); - CBase.Sound.SetPosition(_PreviewSongStream, startposition); - CBase.Sound.Play(_PreviewSongStream); - CBase.Sound.SetStreamVolume(_PreviewSongStream, 0f); - CBase.Sound.Fade(_PreviewSongStream, 100f, 3f); - - if (song.VideoFileName != "" && CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON) - { - _PreviewVideoStream = CBase.Video.Load(Path.Combine(song.Folder, song.VideoFileName)); - if (_PreviewVideoStream == -1) - return; - CBase.Video.SetLoop(_PreviewVideoStream); - CBase.Video.Skip(_PreviewVideoStream, startposition, song.VideoGap); - _VideoFading = new CFading(0f, 1f, 3f); - } + CBase.PreviewPlayer.Play(startposition); } protected void _ResetPreview() { - if (_PreviewSongStream >= 0) - CBase.Sound.Fade(_PreviewSongStream, 0f, 0.75f, EStreamAction.Close); - - _PreviewSongStream = -1; - - CBase.Video.Close(_PreviewVideoStream); - _PreviewVideoStream = -1; - - CBase.Drawing.RemoveTexture(ref _Vidtex); + CBase.PreviewPlayer.Stop(); } #region ThemeEdit diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 00a31e7e..f1449689 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -179,7 +179,7 @@ namespace VocaluxeLib.Menu.SongMenu if (songOptions.Selection.RandomOnly) _PreviewNr = _SelectionNr; - if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.Sound.GetLength(_PreviewSongStream) > 0) + if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.PreviewPlayer.GetLength() > 0) _UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr)); } @@ -244,7 +244,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (song == null) return; - float time = CBase.Sound.GetLength(_PreviewSongStream); + float time = CBase.PreviewPlayer.GetLength(); if (Math.Abs(song.Finish) > 0.001) time = song.Finish; @@ -462,18 +462,20 @@ namespace VocaluxeLib.Menu.SongMenu _TextBG.Draw(); - if (_Vidtex != null && _PreviewVideoStream != -1) + CTexture vidtex = CBase.PreviewPlayer.GetVideoTexture(); + + if (vidtex != null) { - if (_Vidtex.Color.A < 1) + if (vidtex.Color.A < 1) _CoverBig.Draw(EAspect.Crop); 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); + CHelper.SetRect(bounds, out rect, vidtex.OrigAspect, EAspect.Crop); 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); + CBase.Drawing.DrawTexture(vidtex, vidRect, vidtex.Color, vidRectBounds); + CBase.Drawing.DrawTextureReflection(vidtex, vidRect, vidtex.Color, vidRectBounds, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight); } else _CoverBig.Draw(EAspect.Crop); diff --git a/VocaluxeLib/Utils/Player/CSoundPlayer.cs b/VocaluxeLib/Utils/Player/CSoundPlayer.cs index 59e858de..533d4e21 100644 --- a/VocaluxeLib/Utils/Player/CSoundPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSoundPlayer.cs @@ -38,6 +38,16 @@ namespace VocaluxeLib.Utils.Player } } + public float Length + { + get + { + if (_StreamID == -1) + return 0; + return CBase.Sound.GetLength(_StreamID); + } + } + public bool RepeatSong; public bool IsPlaying { get; private set; } diff --git a/VocaluxeLib/VocaluxeLib.csproj b/VocaluxeLib/VocaluxeLib.csproj index a367e8e1..04e04f51 100644 --- a/VocaluxeLib/VocaluxeLib.csproj +++ b/VocaluxeLib/VocaluxeLib.csproj @@ -135,6 +135,7 @@ + From 04c2b85e2bc1b8911eceec64e769685ab2a2acbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sat, 9 Aug 2014 17:16:51 +0200 Subject: [PATCH 04/18] Close stream when finished (*-player) --- VocaluxeLib/Utils/Player/CSongPlayer.cs | 4 ++++ VocaluxeLib/Utils/Player/CSoundPlayer.cs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/VocaluxeLib/Utils/Player/CSongPlayer.cs b/VocaluxeLib/Utils/Player/CSongPlayer.cs index 88e02bd4..8238e35e 100644 --- a/VocaluxeLib/Utils/Player/CSongPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSongPlayer.cs @@ -106,6 +106,8 @@ namespace VocaluxeLib.Utils.Player if (song == null) return; + Close(); + _Song = song; _LoadVideo(); base.Load(Path.Combine(song.Folder, song.MP3FileName), position, autoplay); @@ -116,6 +118,8 @@ namespace VocaluxeLib.Utils.Player if (String.IsNullOrEmpty(file)) return; + Close(); + _Song = null; base.Load(file, position, autoplay); } diff --git a/VocaluxeLib/Utils/Player/CSoundPlayer.cs b/VocaluxeLib/Utils/Player/CSoundPlayer.cs index 533d4e21..499df3f1 100644 --- a/VocaluxeLib/Utils/Player/CSoundPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSoundPlayer.cs @@ -73,6 +73,8 @@ namespace VocaluxeLib.Utils.Player if (IsPlaying) Stop(); + Close(); + _StreamID = CBase.Sound.Load(file, false, true); if (position > 0f) Position = position; From 8e8fdc1277810df7f2ff4f59824c73b64f2cf728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sat, 9 Aug 2014 19:50:40 +0200 Subject: [PATCH 05/18] Play song-preview instead of bg-music (if enabled) on names-, score- and highscore-screen. --- Vocaluxe/Base/CGraphics.cs | 5 +++++ Vocaluxe/Base/CMain.cs | 14 ++++++++++++-- Vocaluxe/Base/CPreviewPlayer.cs | 2 +- Vocaluxe/Screens/CScreenNames.cs | 3 +++ Vocaluxe/Screens/CScreenScore.cs | 3 +++ Vocaluxe/Screens/CScreenSing.cs | 2 -- Vocaluxe/Screens/CScreenSong.cs | 9 +++++++-- VocaluxeLib/IBasic.cs | 6 +++++- VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs | 5 +++-- VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs | 4 ++++ VocaluxeLib/Utils/Player/CSongPlayer.cs | 6 +++++- VocaluxeLib/VocaluxeLib.csproj | 1 - 12 files changed, 48 insertions(+), 12 deletions(-) diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index 837cd713..cef1f480 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -60,6 +60,11 @@ namespace Vocaluxe.Base get { return _CurrentScreen; } } + public static EScreens NextScreen + { + get { return _NextScreen; } + } + #region public methods public static void Init() { diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 00650e9a..f97120ee 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -77,6 +77,11 @@ namespace Vocaluxe.Base return CConfig.BackgroundMusicVolume; } + public EOffOn GetBackgroundMusicStatus() + { + return CConfig.BackgroundMusic; + } + public int GetPreviewMusicVolume() { return CConfig.PreviewMusicVolume; @@ -436,6 +441,11 @@ namespace Vocaluxe.Base { return CGraphics.GlobalAlpha; } + + public EScreens GetNextScreen() + { + return CGraphics.NextScreen; + } } class CBlog : ILog @@ -979,9 +989,9 @@ namespace Vocaluxe.Base CPreviewPlayer.Stop(); } - public void Pause() + public void TogglePause() { - CPreviewPlayer.Pause(); + CPreviewPlayer.TogglePause(); } public CTexture GetCover() diff --git a/Vocaluxe/Base/CPreviewPlayer.cs b/Vocaluxe/Base/CPreviewPlayer.cs index 3422b248..2daf7e1d 100644 --- a/Vocaluxe/Base/CPreviewPlayer.cs +++ b/Vocaluxe/Base/CPreviewPlayer.cs @@ -51,7 +51,7 @@ namespace Vocaluxe.Base _Player.Play(); } - public static void Pause() + public static void TogglePause() { _Player.TogglePause(); } diff --git a/Vocaluxe/Screens/CScreenNames.cs b/Vocaluxe/Screens/CScreenNames.cs index 945e6731..07eaa297 100644 --- a/Vocaluxe/Screens/CScreenNames.cs +++ b/Vocaluxe/Screens/CScreenNames.cs @@ -566,6 +566,9 @@ namespace Vocaluxe.Screens { base.OnClose(); CRecord.Stop(); + + if (CGraphics.NextScreen != EScreens.ScreenSong && CPreviewPlayer.IsPlaying) + CPreviewPlayer.TogglePause(); } public override bool Draw() diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index db70f56e..1b1c133f 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -123,6 +123,9 @@ namespace Vocaluxe.Screens public override void OnShow() { + if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) + CPreviewPlayer.TogglePause(); + base.OnShow(); //-1 --> Show average _Round = CGame.NumRounds > 1 ? -1 : 0; diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index d9a44b1a..0a0cb301 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -537,8 +537,6 @@ namespace Vocaluxe.Screens _CloseSong(); if (_Webcam) CWebcam.Stop(); - CBackgroundMusic.Disabled = false; - CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume); } private void _CloseSong() diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index b70017d5..ffc83c4e 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -716,9 +716,14 @@ namespace Vocaluxe.Screens public override void OnClose() { base.OnClose(); - CBackgroundMusic.Disabled = false; - CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume); + _SongMenu.OnHide(); + + if (CGraphics.NextScreen != EScreens.ScreenNames || CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF) + { + CBackgroundMusic.Disabled = false; + CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume); + } } private void _HandlePartySongSelection(int songNr) diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index a18b6811..2158cf62 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -35,6 +35,8 @@ namespace VocaluxeLib void SetBackgroundMusicVolume(int newVolume); int GetBackgroundMusicVolume(); + EOffOn GetBackgroundMusicStatus(); + int GetPreviewMusicVolume(); EOffOn GetVideosToBackground(); @@ -150,6 +152,8 @@ namespace VocaluxeLib void FadeTo(EScreens nextScreen); float GetGlobalAlpha(); + + EScreens GetNextScreen(); } public interface ILog @@ -321,7 +325,7 @@ namespace VocaluxeLib void Play(float start = -1); void Load(CSong song, float start = 0f); void Stop(); - void Pause(); + void TogglePause(); CTexture GetCover(); CTexture GetVideoTexture(); bool IsPlaying(); diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 079c0cb6..82974e48 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -376,10 +376,11 @@ namespace VocaluxeLib.Menu.SongMenu } public virtual void OnShow() {} - + public virtual void OnHide() { - _ResetPreview(); + if(CBase.Graphics.GetNextScreen() != EScreens.ScreenNames || CBase.Config.GetBackgroundMusicStatus() == EOffOn.TR_CONFIG_OFF) + _ResetPreview(); } public abstract bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options); diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index f1449689..68e142e2 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -110,7 +110,11 @@ namespace VocaluxeLib.Menu.SongMenu set { if (value == base._PreviewNr) + { + if (!CBase.PreviewPlayer.IsPlaying()) + CBase.PreviewPlayer.Play(); return; + } base._PreviewNr = value; _UpdatePreview(); } diff --git a/VocaluxeLib/Utils/Player/CSongPlayer.cs b/VocaluxeLib/Utils/Player/CSongPlayer.cs index 8238e35e..8f1f2a5d 100644 --- a/VocaluxeLib/Utils/Player/CSongPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSongPlayer.cs @@ -159,11 +159,15 @@ namespace VocaluxeLib.Utils.Player public new void TogglePause() { base.TogglePause(); - if (_Video != -1) + if (!IsPlaying && _Video != -1) { CBase.Video.Pause(_Video); CBase.Video.Skip(_Video, CBase.Sound.GetPosition(_StreamID) + _FadeTime, _Song.VideoGap); } + else if(_Video != -1) + { + CBase.Video.Resume(_Video); + } } public new void Update() diff --git a/VocaluxeLib/VocaluxeLib.csproj b/VocaluxeLib/VocaluxeLib.csproj index 04e04f51..a367e8e1 100644 --- a/VocaluxeLib/VocaluxeLib.csproj +++ b/VocaluxeLib/VocaluxeLib.csproj @@ -135,7 +135,6 @@ - From 0a7006db43ba07aea1535166dd2eab7b3dee8bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sat, 9 Aug 2014 22:01:01 +0200 Subject: [PATCH 06/18] Small bugfix. --- VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 06dbdda1..d1221877 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -115,7 +115,10 @@ namespace VocaluxeLib.Menu.SongMenu _PlaySong(value); } else if (value >= CBase.Songs.GetNumCategories()) + { value = -1; + CBase.PreviewPlayer.Stop(); + } _PreviewNrInternal = value; } From c6e8854ddae3a0538c9f38c69cfb9ac13accbecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Mon, 18 Aug 2014 21:14:08 +0200 Subject: [PATCH 07/18] Change preview-player. Now it's part of bg-music. --- Vocaluxe/Base/CBackgroundMusic.cs | 154 ++++++++++++------ Vocaluxe/Base/CConfig.cs | 2 - Vocaluxe/Base/CMain.cs | 71 +++----- Vocaluxe/Base/CPreviewPlayer.cs | 69 -------- Vocaluxe/Screens/CScreenNames.cs | 3 - Vocaluxe/Screens/CScreenScore.cs | 3 +- Vocaluxe/Screens/CScreenSong.cs | 5 - Vocaluxe/Vocaluxe.csproj | 1 - VocaluxeLib/CBasic.cs | 5 +- VocaluxeLib/IBasic.cs | 7 + .../Menu/SongMenu/CSongMenuFramework.cs | 14 +- .../Menu/SongMenu/CSongMenuTileBoard.cs | 10 +- 12 files changed, 155 insertions(+), 189 deletions(-) delete mode 100644 Vocaluxe/Base/CPreviewPlayer.cs diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 65b2bc65..d4cf5f60 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -31,6 +31,7 @@ namespace Vocaluxe.Base private static bool _Initialized; private static CSongPlayer _SongPlayer; + private static CSongPlayer _PreviewPlayer; private static bool _OwnSongsAvailable; private static EBackgroundMusicSource _MusicSource; @@ -46,6 +47,7 @@ namespace Vocaluxe.Base private static bool _OwnMusicAdded; private static bool _BackgroundMusicAdded; private static bool _Disabled; + private static bool _PlaysPreview; public static bool VideoEnabled { @@ -83,18 +85,28 @@ namespace Vocaluxe.Base get { return _SongPlayer.SongHasVideo; } } - public static bool IsPlaying { get { return _SongPlayer.IsPlaying; } } + public static bool IsPlaying { get { return _PlaysPreview ? _PreviewPlayer.IsPlaying : _SongPlayer.IsPlaying; } } + + public static bool IsPlayingPreview { get { return _PlaysPreview; } } public static string ArtistAndTitle { - get { - return _BGMusicFiles.Contains(_CurrentPlaylistElement) ? Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath) :_SongPlayer.ArtistAndTitle; + get { + if (_PlaysPreview) + return _PreviewPlayer.ArtistAndTitle; + else + return _BGMusicFiles.Contains(_CurrentPlaylistElement) ? Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath) : _SongPlayer.ArtistAndTitle; } } + public static float Length + { + get { return _PlaysPreview ? _PreviewPlayer.Length : _SongPlayer.Length; } + } + public static CTexture Cover { - get { return _SongPlayer.Cover; } + get { return _PlaysPreview ? _PreviewPlayer.Cover : _SongPlayer.Cover; } } //Use this to set whether own songs are available for access @@ -129,6 +141,10 @@ namespace Vocaluxe.Base _SongPlayer = new CSongPlayer(); _SongPlayer.Volume = CConfig.BackgroundMusicVolume; + _PreviewPlayer = new CSongPlayer(); + _PreviewPlayer.Volume = CConfig.PreviewMusicVolume; + _PreviewPlayer.RepeatSong = true; + _VideoEnabled = (CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON && CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON); SetMusicSource(CConfig.BackgroundMusicSource); _Initialized = true; @@ -137,6 +153,7 @@ namespace Vocaluxe.Base public static void Close() { _SongPlayer.Close(); + _PreviewPlayer.Close(); _BGMusicFiles.Clear(); _NotPlayedFiles.Clear(); @@ -147,16 +164,17 @@ namespace Vocaluxe.Base public static void Play() { - if (IsPlaying || CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF) + if (IsPlaying || (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF && !_PlaysPreview)) return; - if (_SongPlayer.SongLoaded) - { - //Resume - _SongPlayer.TogglePause(); - } + if (_PlaysPreview) + _PreviewPlayer.TogglePause(); else - Next(); + if (_SongPlayer.SongLoaded) + //Resume + _SongPlayer.TogglePause(); + else + Next(); } public static void Stop() @@ -164,9 +182,17 @@ namespace Vocaluxe.Base if (!IsPlaying) return; - _SongPlayer.Stop(); - - _CurrentPlaylistElement = null; + if (_PlaysPreview) + { + _PreviewPlayer.Stop(); + _PlaysPreview = false; + Play(); + } + else + { + _SongPlayer.Stop(); + _CurrentPlaylistElement = null; + } } public static void Pause() @@ -174,65 +200,79 @@ namespace Vocaluxe.Base if (!IsPlaying) return; - _SongPlayer.TogglePause(); + if (_PlaysPreview) + _PreviewPlayer.TogglePause(); + else + _SongPlayer.TogglePause(); } public static void Next() { - Stop(); //stop last song if any - if (_PreviousMusicIndex < _PreviousFiles.Count - 2) + if (!_PlaysPreview) { - //We are in the previous list and next element exists - _PreviousMusicIndex++; - _CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex]; - } - else - { - //We are not in the previous list (anymore) - if (_NotPlayedFiles.Count == 0) + Stop(); //stop last song if any + if (_PreviousMusicIndex < _PreviousFiles.Count - 2) { - if (_PreviousFiles.Count == 0) - return; //No songs to play - _NotPlayedFiles.AddRange(_PreviousFiles); + //We are in the previous list and next element exists + _PreviousMusicIndex++; + _CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex]; } + else + { + //We are not in the previous list (anymore) + if (_NotPlayedFiles.Count == 0) + { + if (_PreviousFiles.Count == 0) + return; //No songs to play + _NotPlayedFiles.AddRange(_PreviousFiles); + } - _CurrentPlaylistElement = _NotPlayedFiles[CGame.Rand.Next(_NotPlayedFiles.Count)]; - _NotPlayedFiles.Remove(_CurrentPlaylistElement); + _CurrentPlaylistElement = _NotPlayedFiles[CGame.Rand.Next(_NotPlayedFiles.Count)]; + _NotPlayedFiles.Remove(_CurrentPlaylistElement); - _PreviousFiles.Add(_CurrentPlaylistElement); - _PreviousMusicIndex = _PreviousFiles.Count - 1; + _PreviousFiles.Add(_CurrentPlaylistElement); + _PreviousMusicIndex = _PreviousFiles.Count - 1; + } + _StartSong(); } - _StartSong(); } public static void Previous() { - if (_PreviousMusicIndex < 0) - return; - Debug.Assert(_CurrentPlaylistElement != null); - if (_SongPlayer.Position <= 1.5f && _PreviousMusicIndex > 0) + if (!_PlaysPreview) { - Stop(); //stop last song - _PreviousMusicIndex--; + if (_PreviousMusicIndex < 0) + return; + Debug.Assert(_CurrentPlaylistElement != null); + if (_SongPlayer.Position <= 1.5f && _PreviousMusicIndex > 0) + { + Stop(); //stop last song + _PreviousMusicIndex--; - _CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex]; + _CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex]; + } + _StartSong(); } - _StartSong(); } public static void Update() { - if (!IsPlaying && !_SongPlayer.SongLoaded) + if (!IsPlaying && (!_SongPlayer.SongLoaded || !_PreviewPlayer.SongLoaded) ) return; - _SongPlayer.Update(); - if (_SongPlayer.IsFinished) - Next(); + if (_PlaysPreview) + _PreviewPlayer.Update(); + else + { + _SongPlayer.Update(); + if (_SongPlayer.IsFinished) + Next(); + } } public static CTexture GetVideoTexture() { - return _SongPlayer.GetVideoTexture(); + return _PlaysPreview ? _PreviewPlayer.GetVideoTexture() : _SongPlayer.GetVideoTexture(); } public static void SetMusicSource(EBackgroundMusicSource source) @@ -258,6 +298,28 @@ namespace Vocaluxe.Base } } + public static void LoadPreview(CSong song, float start = 0f) + { + Stop(); + + if (song == null) + return; + + if (start == 0f) + start = song.Preview.StartTime; + + _PlaysPreview = true; + _PreviewPlayer.Load(song, start); + } + + public static void PlayPreview(float start = -1f) + { + if (start > -1f) + _PreviewPlayer.Position = start; + + Play(); + } + /// /// (Re-)Starts the _CurrentPlaylistElement /// diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index fbf02ada..2e73bc8e 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -263,8 +263,6 @@ namespace Vocaluxe.Base xmlReader.TryGetEnumValue("//root/Sound/BackgroundMusicUseStart", ref BackgroundMusicUseStart); xmlReader.TryGetIntValueRange("//root/Sound/PreviewMusicVolume", ref _PreviewMusicVolume); xmlReader.TryGetIntValueRange("//root/Sound/GameMusicVolume", ref _GameMusicVolume); - - CPreviewPlayer.UpdateVolume(); #endregion Sound #region Game diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index f97120ee..9e724f2f 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -51,12 +51,11 @@ namespace Vocaluxe.Base private static readonly IDataBase _DataBase = new CBdataBase(); private static readonly IControllers _Controller = new CBcontrollers(); private static readonly IPlaylist _Playlist = new CBplaylist(); - private static readonly IPreviewPlayer _PreviewPlayer = new CBpreviewPlayer(); public static void Init() { CBase.Assign(_Config, _Settings, _Theme, _Log, _BackgroundMusic, _Draw, _Graphics, _Fonts, _Language, - _Game, _Profiles, _Record, _Songs, _Video, _Sound, _Cover, _DataBase, _Controller, _Playlist, _PreviewPlayer); + _Game, _Profiles, _Record, _Songs, _Video, _Sound, _Cover, _DataBase, _Controller, _Playlist); } } @@ -346,11 +345,21 @@ namespace Vocaluxe.Base return CBackgroundMusic.VideoEnabled; } + public bool IsPlayingPreview() + { + return CBackgroundMusic.IsPlayingPreview; + } + public void SetDisabled(bool disabled) { CBackgroundMusic.Disabled = disabled; } + public float GetLength() + { + return CBackgroundMusic.Length; + } + public void Next() { CBackgroundMusic.Next(); @@ -371,6 +380,21 @@ namespace Vocaluxe.Base CBackgroundMusic.Play(); } + public void Stop() + { + CBackgroundMusic.Stop(); + } + + public void LoadPreview(CSong song, float start = 0f) + { + CBackgroundMusic.LoadPreview(song, start); + } + + public void PlayPreview(float start = -1f) + { + CBackgroundMusic.PlayPreview(start); + } + public CTexture GetVideoTexture() { return CBackgroundMusic.GetVideoTexture(); @@ -971,47 +995,4 @@ namespace Vocaluxe.Base return CPlaylists.GetSong(playlistID, songIndex); } } - - class CBpreviewPlayer : IPreviewPlayer - { - public void Play(float start = -1) - { - CPreviewPlayer.Play(); - } - - public void Load(CSong song, float start = 0f) - { - CPreviewPlayer.Load(song, start); - } - - public void Stop() - { - CPreviewPlayer.Stop(); - } - - public void TogglePause() - { - CPreviewPlayer.TogglePause(); - } - - public CTexture GetCover() - { - return CPreviewPlayer.Cover; - } - - public CTexture GetVideoTexture() - { - return CPreviewPlayer.VideoTexture; - } - - public bool IsPlaying() - { - return CPreviewPlayer.IsPlaying; - } - - public float GetLength() - { - return CPreviewPlayer.Length; - } - } } \ No newline at end of file diff --git a/Vocaluxe/Base/CPreviewPlayer.cs b/Vocaluxe/Base/CPreviewPlayer.cs deleted file mode 100644 index 2daf7e1d..00000000 --- a/Vocaluxe/Base/CPreviewPlayer.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using VocaluxeLib.Utils.Player; -using VocaluxeLib.Draw; -using VocaluxeLib.Songs; - -namespace Vocaluxe.Base -{ - public static class CPreviewPlayer - { - private static CSongPlayer _Player = new CSongPlayer(true); - - public static CTexture VideoTexture - { - get { return _Player.GetVideoTexture(); } - } - - public static CTexture Cover - { - get { return _Player.Cover; } - } - - public static bool IsPlaying - { - get { return _Player.IsPlaying; } - } - - public static float Length - { - get { return _Player.Length; } - } - - public static void Load(CSong song, float start = 0f) - { - if (song == null) - return; - - if (start == 0f) - start = song.Preview.StartTime; - - _Player.Load(song, start); - } - - public static void Play(float start = -1) - { - if (start > -1) - _Player.Position = start; - _Player.Play(); - } - - public static void TogglePause() - { - _Player.TogglePause(); - } - - public static void Stop() - { - _Player.Stop(); - } - - public static void UpdateVolume() - { - _Player.Volume = CConfig.PreviewMusicVolume; - } - } -} diff --git a/Vocaluxe/Screens/CScreenNames.cs b/Vocaluxe/Screens/CScreenNames.cs index 07eaa297..945e6731 100644 --- a/Vocaluxe/Screens/CScreenNames.cs +++ b/Vocaluxe/Screens/CScreenNames.cs @@ -566,9 +566,6 @@ namespace Vocaluxe.Screens { base.OnClose(); CRecord.Stop(); - - if (CGraphics.NextScreen != EScreens.ScreenSong && CPreviewPlayer.IsPlaying) - CPreviewPlayer.TogglePause(); } public override bool Draw() diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index 19ec84ef..bbf4aaf4 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -123,8 +123,7 @@ namespace Vocaluxe.Screens public override void OnShow() { - if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) - CPreviewPlayer.TogglePause(); + CBackgroundMusic.Disabled = false; base.OnShow(); //-1 --> Show average diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index ffc83c4e..94753053 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -662,11 +662,6 @@ namespace Vocaluxe.Screens _Texts[_TextCategory].Text = CSongs.GetCurrentCategoryName(); - if (CSongs.IsInCategory || CConfig.Tabs == EOffOn.TR_CONFIG_OFF) - CBackgroundMusic.Disabled = true; - else - CBackgroundMusic.Disabled = false; - string selectionText = ""; if (CSongs.IsInCategory) { diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index ca4e0c7b..b8276467 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -217,7 +217,6 @@ - diff --git a/VocaluxeLib/CBasic.cs b/VocaluxeLib/CBasic.cs index 348f61de..7a588ee1 100644 --- a/VocaluxeLib/CBasic.cs +++ b/VocaluxeLib/CBasic.cs @@ -38,12 +38,10 @@ namespace VocaluxeLib public static IDataBase DataBase; public static IControllers Controller; public static IPlaylist Playlist; - public static IPreviewPlayer PreviewPlayer; public static void Assign(IConfig config, ISettings settings, ITheme theme, ILog log, IBackgroundMusic backgroundMusic, IDrawing draw, IGraphics graphics, IFonts fonts, ILanguage language, IGame game, IProfiles profiles, IRecording record, - ISongs songs, IVideo video, ISound sound, ICover cover, IDataBase dataBase, IControllers controller, IPlaylist playlist, - IPreviewPlayer previewPlayer) + ISongs songs, IVideo video, ISound sound, ICover cover, IDataBase dataBase, IControllers controller, IPlaylist playlist) { Config = config; Settings = settings; @@ -64,7 +62,6 @@ namespace VocaluxeLib DataBase = dataBase; Controller = controller; Playlist = playlist; - PreviewPlayer = previewPlayer; } } } \ No newline at end of file diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index 2158cf62..e59634d7 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -119,16 +119,23 @@ namespace VocaluxeLib { bool IsDisabled(); bool IsPlaying(); + bool IsPlayingPreview(); bool SongHasVideo(); bool VideoEnabled(); + float GetLength(); void SetDisabled(bool disabled); void Next(); void Previous(); void Pause(); void Play(); + void Stop(); CTexture GetVideoTexture(); + + void LoadPreview(CSong song, float start = 0f); + void PlayPreview(float start = -1f); + } public interface IDrawing diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index d1221877..b2cd1f92 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -117,7 +117,7 @@ namespace VocaluxeLib.Menu.SongMenu else if (value >= CBase.Songs.GetNumCategories()) { value = -1; - CBase.PreviewPlayer.Stop(); + CBase.BackgroundMusic.Stop(); } _PreviewNrInternal = value; @@ -395,8 +395,8 @@ namespace VocaluxeLib.Menu.SongMenu if (!_Initialized || !Visible) return; - if (CBase.PreviewPlayer.IsPlaying()) - CBase.Drawing.DrawTexture(CBase.PreviewPlayer.GetVideoTexture(), new SRectF(0, 0, 1280, 720, 0)); + if (CBase.BackgroundMusic.IsPlaying()) + CBase.Drawing.DrawTexture(CBase.BackgroundMusic.GetVideoTexture(), new SRectF(0, 0, 1280, 720, 0)); } public bool IsMouseOverSelectedSong(SMouseEvent mEvent) @@ -506,23 +506,23 @@ namespace VocaluxeLib.Menu.SongMenu if (song == null) return; - CBase.PreviewPlayer.Load(song); + CBase.BackgroundMusic.LoadPreview(song); float startposition = song.Preview.StartTime; - float length = CBase.PreviewPlayer.GetLength(); + float length = CBase.BackgroundMusic.GetLength(); if (song.Preview.Source == EDataSource.None) startposition = length / 4f; else if (startposition > length - 5f) startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f)); - CBase.PreviewPlayer.Play(startposition); + CBase.BackgroundMusic.PlayPreview(startposition); } protected void _ResetPreview() { - CBase.PreviewPlayer.Stop(); + CBase.BackgroundMusic.Stop(); //Make sure we don't have a preview here otherwise a change won't be recognized //(e.g. leave a category with one song and set preview to 0 --> previewOld=previewNew=0 --> No change --> Old data shown diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index f58d337f..281d9d2e 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -111,8 +111,8 @@ namespace VocaluxeLib.Menu.SongMenu { if (value == base._PreviewNr) { - if (!CBase.PreviewPlayer.IsPlaying()) - CBase.PreviewPlayer.Play(); + if (!CBase.BackgroundMusic.IsPlaying()) + CBase.BackgroundMusic.PlayPreview(); return; } base._PreviewNr = value; @@ -183,7 +183,7 @@ namespace VocaluxeLib.Menu.SongMenu if (songOptions.Selection.RandomOnly) _PreviewNr = _SelectionNr; - if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.PreviewPlayer.GetLength() > 0) + if (_Length < 0 && CBase.Songs.IsInCategory() && CBase.BackgroundMusic.GetLength() > 0) _UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr)); } @@ -248,7 +248,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (song == null) return; - float time = CBase.PreviewPlayer.GetLength(); + float time = CBase.BackgroundMusic.GetLength(); if (Math.Abs(song.Finish) > 0.001) time = song.Finish; @@ -467,7 +467,7 @@ namespace VocaluxeLib.Menu.SongMenu _TextBG.Draw(); - CTexture vidtex = CBase.PreviewPlayer.GetVideoTexture(); + CTexture vidtex = CBase.BackgroundMusic.GetVideoTexture(); if (vidtex != null) { From d0958b69be87e295b2c35c7d2e95214eaa70b8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Wed, 20 Aug 2014 19:10:13 +0200 Subject: [PATCH 08/18] Some changes to preview-start. --- Vocaluxe/Base/CBackgroundMusic.cs | 13 +++++++++++++ VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs | 11 ----------- VocaluxeLib/Songs/CSongLoader.cs | 1 + 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index d4cf5f60..e65d5c78 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -310,6 +310,19 @@ namespace Vocaluxe.Base _PlaysPreview = true; _PreviewPlayer.Load(song, start); + + float startposition = song.Preview.StartTime; + + float length = _PreviewPlayer.Length; + + if (song.Preview.Source == EDataSource.None) + startposition = length / 4f; + else if (startposition > length - 5f) + startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f)); + + _PreviewPlayer.Position = startposition; + + Play(); } public static void PlayPreview(float start = -1f) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index b2cd1f92..e2ad5ae6 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -507,17 +507,6 @@ namespace VocaluxeLib.Menu.SongMenu return; CBase.BackgroundMusic.LoadPreview(song); - - float startposition = song.Preview.StartTime; - - float length = CBase.BackgroundMusic.GetLength(); - - if (song.Preview.Source == EDataSource.None) - startposition = length / 4f; - else if (startposition > length - 5f) - startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f)); - - CBase.BackgroundMusic.PlayPreview(startposition); } protected void _ResetPreview() diff --git a/VocaluxeLib/Songs/CSongLoader.cs b/VocaluxeLib/Songs/CSongLoader.cs index 334089d2..0e06ab45 100644 --- a/VocaluxeLib/Songs/CSongLoader.cs +++ b/VocaluxeLib/Songs/CSongLoader.cs @@ -416,6 +416,7 @@ namespace VocaluxeLib.Songs { //PreviewStart is not set or <=0 _Song.Preview.StartTime = (headerFlags & EHeaderFlags.MedleyStartBeat) != 0 ? CBase.Game.GetTimeFromBeats(_Song.Medley.StartBeat, _Song.BPM) : 0f; + _Song.Preview.Source = EDataSource.Calculated; } if ((headerFlags & EHeaderFlags.MedleyStartBeat) != 0 && (headerFlags & EHeaderFlags.MedleyEndBeat) != 0) From eef988fcdbe93123ab4d096d628e8618319d9a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Wed, 20 Aug 2014 19:14:20 +0200 Subject: [PATCH 09/18] Some code-cleanup. --- Vocaluxe/Base/CBackgroundMusic.cs | 2 +- VocaluxeLib/Utils/Player/CSongPlayer.cs | 21 +-------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index e65d5c78..51014f58 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -346,7 +346,7 @@ namespace Vocaluxe.Base //otherwhise load if (_BGMusicFiles.Contains(_CurrentPlaylistElement)) - _SongPlayer.Load(_CurrentPlaylistElement.MusicFilePath, 0f, true); + _SongPlayer.LoadFile(_CurrentPlaylistElement.MusicFilePath, 0f, true); else { //Seek to #Start-Tag, if found diff --git a/VocaluxeLib/Utils/Player/CSongPlayer.cs b/VocaluxeLib/Utils/Player/CSongPlayer.cs index 8f1f2a5d..3af9732d 100644 --- a/VocaluxeLib/Utils/Player/CSongPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSongPlayer.cs @@ -113,7 +113,7 @@ namespace VocaluxeLib.Utils.Player base.Load(Path.Combine(song.Folder, song.MP3FileName), position, autoplay); } - public void Load(string file, float position = 0f, bool autoplay = false) + public void LoadFile(string file, float position = 0f, bool autoplay = false) { if (String.IsNullOrEmpty(file)) return; @@ -170,25 +170,6 @@ namespace VocaluxeLib.Utils.Player } } - public new void Update() - { - if (_StreamID == -1 || !IsPlaying) - return; - - float timeToPlay; - float len = CBase.Sound.GetLength(_StreamID); - timeToPlay = (len > 0f) ? len - CBase.Sound.GetPosition(_StreamID) : _FadeTime + 1f; - - bool finished = CBase.Sound.IsFinished(_StreamID); - if (timeToPlay <= _FadeTime || finished) - { - if (RepeatSong) - Play(); - else - Stop(); - } - } - private void _LoadVideo() { if (_Song == null) From 6f617aa40b5ab7e9cf310164df755a0175dbcd4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Fri, 22 Aug 2014 17:51:47 +0200 Subject: [PATCH 10/18] Some improvements... --- Vocaluxe/Base/CBackgroundMusic.cs | 6 ++++++ Vocaluxe/Base/CMain.cs | 5 +++++ VocaluxeLib/IBasic.cs | 1 + VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs | 4 +++- VocaluxeLib/Songs/CSong.cs | 3 +++ VocaluxeLib/Songs/CSongLoader.cs | 2 +- 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 51014f58..954692e0 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -333,6 +333,12 @@ namespace Vocaluxe.Base Play(); } + public static void StopPreview() + { + _PreviewPlayer.Close(); + _PlaysPreview = false; + } + /// /// (Re-)Starts the _CurrentPlaylistElement /// diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 9e724f2f..c0629d36 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -395,6 +395,11 @@ namespace Vocaluxe.Base CBackgroundMusic.PlayPreview(start); } + public void StopPreview() + { + CBackgroundMusic.StopPreview(); + } + public CTexture GetVideoTexture() { return CBackgroundMusic.GetVideoTexture(); diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index e59634d7..699a4152 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -135,6 +135,7 @@ namespace VocaluxeLib void LoadPreview(CSong song, float start = 0f); void PlayPreview(float start = -1f); + void StopPreview(); } diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index e2ad5ae6..eaeee46b 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -500,7 +500,9 @@ namespace VocaluxeLib.Menu.SongMenu private void _PlaySong(int nr) { - _ResetPreview(); + _PreviewNrInternal = -1; + + CBase.BackgroundMusic.StopPreview(); CSong song = CBase.Songs.GetVisibleSong(nr); if (song == null) diff --git a/VocaluxeLib/Songs/CSong.cs b/VocaluxeLib/Songs/CSong.cs index 26d1d6fd..665beac4 100644 --- a/VocaluxeLib/Songs/CSong.cs +++ b/VocaluxeLib/Songs/CSong.cs @@ -458,7 +458,10 @@ namespace VocaluxeLib.Songs if (Preview.Source == EDataSource.None) { if (Medley.Source != EDataSource.None) + { Preview.StartTime = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM); + Preview.Source = EDataSource.Calculated; + } } } diff --git a/VocaluxeLib/Songs/CSongLoader.cs b/VocaluxeLib/Songs/CSongLoader.cs index 0e06ab45..cd4cf834 100644 --- a/VocaluxeLib/Songs/CSongLoader.cs +++ b/VocaluxeLib/Songs/CSongLoader.cs @@ -416,7 +416,7 @@ namespace VocaluxeLib.Songs { //PreviewStart is not set or <=0 _Song.Preview.StartTime = (headerFlags & EHeaderFlags.MedleyStartBeat) != 0 ? CBase.Game.GetTimeFromBeats(_Song.Medley.StartBeat, _Song.BPM) : 0f; - _Song.Preview.Source = EDataSource.Calculated; + _Song.Preview.Source = _Song.Preview.StartTime == 0 ? EDataSource.None : EDataSource.Calculated; } if ((headerFlags & EHeaderFlags.MedleyStartBeat) != 0 && (headerFlags & EHeaderFlags.MedleyEndBeat) != 0) From f926263706fb684a6eea232d7dee9a36dbdd669a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Fri, 22 Aug 2014 18:05:50 +0200 Subject: [PATCH 11/18] Fix video sync. --- Vocaluxe/Base/CBackgroundMusic.cs | 3 +++ VocaluxeLib/Utils/Player/CSongPlayer.cs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 954692e0..be900321 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -320,6 +320,9 @@ namespace Vocaluxe.Base else if (startposition > length - 5f) startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f)); + if (startposition >= 0.5f) + startposition -= 0.5f; + _PreviewPlayer.Position = startposition; Play(); diff --git a/VocaluxeLib/Utils/Player/CSongPlayer.cs b/VocaluxeLib/Utils/Player/CSongPlayer.cs index 3af9732d..fe2f9bb1 100644 --- a/VocaluxeLib/Utils/Player/CSongPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSongPlayer.cs @@ -67,6 +67,24 @@ namespace VocaluxeLib.Utils.Player get { return _StreamID != -1; } } + public float Position + { + get + { + if (_StreamID == -1) + return -1; + return CBase.Sound.GetPosition(_StreamID); + } + set + { + if (_StreamID == -1) + return; + CBase.Sound.SetPosition(_StreamID, value); + CBase.Video.Skip(_Video, value, _Song.VideoGap); + _StartPosition = value; + } + } + public CSongPlayer(bool loop = false) : base(loop) { } public CSongPlayer(CSong song, bool loop = false, float position = 0f, bool autoplay = false) From b30efb1913e176e64b619bc939c336fe85092945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Fri, 22 Aug 2014 21:01:24 +0200 Subject: [PATCH 12/18] some fixes. --- VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs | 2 +- VocaluxeLib/Utils/Player/CSoundPlayer.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 281d9d2e..f473ead7 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -111,7 +111,7 @@ namespace VocaluxeLib.Menu.SongMenu { if (value == base._PreviewNr) { - if (!CBase.BackgroundMusic.IsPlaying()) + if (!CBase.BackgroundMusic.IsPlaying() && value != -1) CBase.BackgroundMusic.PlayPreview(); return; } diff --git a/VocaluxeLib/Utils/Player/CSoundPlayer.cs b/VocaluxeLib/Utils/Player/CSoundPlayer.cs index 499df3f1..a3a86f51 100644 --- a/VocaluxeLib/Utils/Player/CSoundPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSoundPlayer.cs @@ -84,7 +84,7 @@ namespace VocaluxeLib.Utils.Player public void Play() { - if (_StreamID == -1) + if (_StreamID == -1 || IsPlaying) return; CBase.Sound.SetPosition(_StreamID, _StartPosition); From 6dda1a38d074fb3969a2dbe7c5eb547b784b4f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Fri, 22 Aug 2014 21:22:03 +0200 Subject: [PATCH 13/18] Added background-music-option: "Only selected song". bg-music is played on name/score/highscore screen with selected song. --- Output/Languages/English.xml | 1 + Vocaluxe/Base/CBackgroundMusic.cs | 2 +- Vocaluxe/Base/CConfig.cs | 6 +++--- Vocaluxe/Base/CGraphics.cs | 8 ++++---- Vocaluxe/Base/CMain.cs | 2 +- Vocaluxe/Screens/CScreenOptionsSound.cs | 6 +++--- Vocaluxe/Screens/CScreenSong.cs | 2 +- VocaluxeLib/Enums.cs | 7 +++++++ VocaluxeLib/IBasic.cs | 2 +- VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs | 2 +- 10 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Output/Languages/English.xml b/Output/Languages/English.xml index 1cafa62a..6554f2dc 100644 --- a/Output/Languages/English.xml +++ b/Output/Languages/English.xml @@ -76,6 +76,7 @@ Own Music and Background Music No own Music Only own Music + Only selected song All Only names and avatars Nothing diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index be900321..711c88bb 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -164,7 +164,7 @@ namespace Vocaluxe.Base public static void Play() { - if (IsPlaying || (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF && !_PlaysPreview)) + if (IsPlaying || (CConfig.BackgroundMusic != EBackgroundMusicOffOn.TR_CONFIG_ON && !_PlaysPreview)) return; if (_PlaysPreview) diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 2e73bc8e..5b42d5aa 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -97,7 +97,7 @@ namespace Vocaluxe.Base public static EBufferSize AudioBufferSize = EBufferSize.B2048; public static int AudioLatency; private static int _BackgroundMusicVolume = 30; - public static EOffOn BackgroundMusic = EOffOn.TR_CONFIG_ON; + public static EBackgroundMusicOffOn BackgroundMusic = EBackgroundMusicOffOn.TR_CONFIG_ON; public static EBackgroundMusicSource BackgroundMusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC; public static EOffOn BackgroundMusicUseStart = EOffOn.TR_CONFIG_ON; private static int _PreviewMusicVolume = 50; @@ -478,8 +478,8 @@ namespace Vocaluxe.Base writer.WriteComment("AudioLatency from -500 to 500 ms"); writer.WriteElementString("AudioLatency", AudioLatency.ToString()); - writer.WriteComment("Background Music: " + CHelper.ListStrings(Enum.GetNames(typeof(EOffOn)))); - writer.WriteElementString("BackgroundMusic", Enum.GetName(typeof(EOffOn), BackgroundMusic)); + writer.WriteComment("Background Music: " + CHelper.ListStrings(Enum.GetNames(typeof(EBackgroundMusicOffOn)))); + writer.WriteElementString("BackgroundMusic", Enum.GetName(typeof(EBackgroundMusicOffOn), BackgroundMusic)); writer.WriteComment("Background Music Volume from 0 to 100"); writer.WriteElementString("BackgroundMusicVolume", BackgroundMusicVolume.ToString()); diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index 6526ac02..69bf1c51 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -340,7 +340,7 @@ namespace Vocaluxe.Base bool popupVolumeControlAllowed = _CurrentScreen != EScreens.ScreenCredits && _CurrentScreen != EScreens.ScreenOptionsRecord; //Hide volume control for bg-music if bg-music is disabled if (popupVolumeControlAllowed && (_CurrentScreen != EScreens.ScreenSong || CSongs.Category == -1) - && _CurrentScreen != EScreens.ScreenSing && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF) + && _CurrentScreen != EScreens.ScreenSing && CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_OFF) popupVolumeControlAllowed = false; @@ -396,13 +396,13 @@ namespace Vocaluxe.Base if (popupPlayerControlAllowed && keyEvent.Key == Keys.Tab) { - if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) + if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON) ShowPopup(EPopupScreens.PopupPlayerControl); else HidePopup(EPopupScreens.PopupPlayerControl); } - if (popupPlayerControlAllowed && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) + if (popupPlayerControlAllowed && CConfig.BackgroundMusic != EBackgroundMusicOffOn.TR_CONFIG_OFF) { if (keyEvent.Key == Keys.MediaNextTrack) CBackgroundMusic.Next(); @@ -502,7 +502,7 @@ namespace Vocaluxe.Base bool isOverPopupPlayerControl = CHelper.IsInBounds(_PopupScreens[(int)EPopupScreens.PopupPlayerControl].ScreenArea, mouseEvent); if (popupPlayerControlAllowed && isOverPopupPlayerControl) { - if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) + if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON) ShowPopup(EPopupScreens.PopupPlayerControl); } diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index c0629d36..68bdb588 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -76,7 +76,7 @@ namespace Vocaluxe.Base return CConfig.BackgroundMusicVolume; } - public EOffOn GetBackgroundMusicStatus() + public EBackgroundMusicOffOn GetBackgroundMusicStatus() { return CConfig.BackgroundMusic; } diff --git a/Vocaluxe/Screens/CScreenOptionsSound.cs b/Vocaluxe/Screens/CScreenOptionsSound.cs index 502f4c28..0d711fd0 100644 --- a/Vocaluxe/Screens/CScreenOptionsSound.cs +++ b/Vocaluxe/Screens/CScreenOptionsSound.cs @@ -52,7 +52,7 @@ namespace Vocaluxe.Screens public override void LoadTheme(string xmlPath) { base.LoadTheme(xmlPath); - _SelectSlides[_SelectSlideBackgroundMusic].SetValues((int)CConfig.BackgroundMusic); + _SelectSlides[_SelectSlideBackgroundMusic].SetValues((int)CConfig.BackgroundMusic); _SelectSlides[_SelectSlideBackgroundMusicVolume].AddValues(new string[] {"0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "100"}); _SelectSlides[_SelectSlideBackgroundMusicVolume].Selection = CConfig.BackgroundMusicVolume / 5; @@ -150,14 +150,14 @@ namespace Vocaluxe.Screens { CConfig.GameMusicVolume = _SelectSlides[_SelectSlideGameMusicVolume].Selection * 5; CConfig.PreviewMusicVolume = _SelectSlides[_SelectSlidePreviewMusicVolume].Selection * 5; - CConfig.BackgroundMusic = (EOffOn)_SelectSlides[_SelectSlideBackgroundMusic].Selection; + CConfig.BackgroundMusic = (EBackgroundMusicOffOn)_SelectSlides[_SelectSlideBackgroundMusic].Selection; CConfig.BackgroundMusicSource = (EBackgroundMusicSource)_SelectSlides[_SelectSlideBackgroundMusicSource].Selection; CConfig.BackgroundMusicVolume = _SelectSlides[_SelectSlideBackgroundMusicVolume].Selection * 5; CConfig.SaveConfig(); CBackgroundMusic.SetMusicSource(CConfig.BackgroundMusicSource); CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume); - if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) + if (CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON) CBackgroundMusic.Play(); else CBackgroundMusic.Pause(); diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 94753053..d7722f9a 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -714,7 +714,7 @@ namespace Vocaluxe.Screens _SongMenu.OnHide(); - if (CGraphics.NextScreen != EScreens.ScreenNames || CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF) + if (CGraphics.NextScreen != EScreens.ScreenNames || CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_OFF) { CBackgroundMusic.Disabled = false; CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume); diff --git a/VocaluxeLib/Enums.cs b/VocaluxeLib/Enums.cs index e7bf8270..4db6424c 100644 --- a/VocaluxeLib/Enums.cs +++ b/VocaluxeLib/Enums.cs @@ -248,6 +248,13 @@ namespace VocaluxeLib // ReSharper restore InconsistentNaming } + public enum EBackgroundMusicOffOn + { + TR_CONFIG_OFF, + TR_CONFIG_ONLY_SONG, + TR_CONFIG_ON + } + public enum EPlayerInfo { // ReSharper disable InconsistentNaming diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index 699a4152..d88a4ea7 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -35,7 +35,7 @@ namespace VocaluxeLib void SetBackgroundMusicVolume(int newVolume); int GetBackgroundMusicVolume(); - EOffOn GetBackgroundMusicStatus(); + EBackgroundMusicOffOn GetBackgroundMusicStatus(); int GetPreviewMusicVolume(); diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index eaeee46b..9a11dde7 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -382,7 +382,7 @@ namespace VocaluxeLib.Menu.SongMenu public virtual void OnHide() { - if(CBase.Graphics.GetNextScreen() != EScreens.ScreenNames || CBase.Config.GetBackgroundMusicStatus() == EOffOn.TR_CONFIG_OFF) + if(CBase.Graphics.GetNextScreen() != EScreens.ScreenNames || CBase.Config.GetBackgroundMusicStatus() == EBackgroundMusicOffOn.TR_CONFIG_OFF) _ResetPreview(); } From 6c4fe011bf8a7274b1eeabc4742119ee0b0b9bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 24 Aug 2014 12:42:05 +0200 Subject: [PATCH 14/18] Some improvements. --- Vocaluxe/Base/CBackgroundMusic.cs | 19 +++--- Vocaluxe/Screens/CPopupScreenPlayerControl.cs | 11 ++++ .../Menu/SongMenu/CSongMenuFramework.cs | 11 ++-- .../Menu/SongMenu/CSongMenuTileBoard.cs | 2 +- VocaluxeLib/Utils/Player/CSongPlayer.cs | 61 +++++++------------ VocaluxeLib/Utils/Player/CSoundPlayer.cs | 17 +----- 6 files changed, 55 insertions(+), 66 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 711c88bb..6f050db8 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -51,8 +51,13 @@ namespace Vocaluxe.Base public static bool VideoEnabled { - get { return _SongPlayer.VideoEnabled; } - set { _SongPlayer.VideoEnabled = value; } + get { return _PlaysPreview ? _PreviewPlayer.VideoEnabled : _SongPlayer.VideoEnabled; } + set { + if(_PlaysPreview) + _PreviewPlayer.VideoEnabled = value; + else + _SongPlayer.VideoEnabled = value; + } } public static bool CanSing { get { return _BGMusicFiles.Contains(_CurrentPlaylistElement) ? false : _SongPlayer.CanSing; } } @@ -152,8 +157,8 @@ namespace Vocaluxe.Base public static void Close() { - _SongPlayer.Close(); - _PreviewPlayer.Close(); + _SongPlayer.Stop(); + _PreviewPlayer.Stop(); _BGMusicFiles.Clear(); _NotPlayedFiles.Clear(); @@ -168,7 +173,7 @@ namespace Vocaluxe.Base return; if (_PlaysPreview) - _PreviewPlayer.TogglePause(); + _PreviewPlayer.Play(); else if (_SongPlayer.SongLoaded) //Resume @@ -338,7 +343,7 @@ namespace Vocaluxe.Base public static void StopPreview() { - _PreviewPlayer.Close(); + _PreviewPlayer.Stop(); _PlaysPreview = false; } @@ -350,7 +355,7 @@ namespace Vocaluxe.Base Debug.Assert(_CurrentPlaylistElement != null); //If current song same as loaded restart only - if (_CurrentPlaylistElement.SongID == _SongPlayer.SongID) + if (_CurrentPlaylistElement.SongID == _SongPlayer.SongID && _SongPlayer.SongLoaded) _SongPlayer.Play(); //otherwhise load diff --git a/Vocaluxe/Screens/CPopupScreenPlayerControl.cs b/Vocaluxe/Screens/CPopupScreenPlayerControl.cs index 9ffe1779..208fc630 100644 --- a/Vocaluxe/Screens/CPopupScreenPlayerControl.cs +++ b/Vocaluxe/Screens/CPopupScreenPlayerControl.cs @@ -168,6 +168,17 @@ namespace Vocaluxe.Screens return true; } + public override void OnShow() + { + base.OnShow(); + _Buttons[_ButtonNext].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonPause].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonPlay].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonPrevious].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonRepeat].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonSing].Visible = !CBackgroundMusic.IsPlayingPreview; + } + public override bool UpdateGame() { _Statics[_StaticCover].Visible = !_VideoPreviewInt || !CBackgroundMusic.SongHasVideo; diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 9a11dde7..b4d0cff4 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -341,7 +341,7 @@ namespace VocaluxeLib.Menu.SongMenu public virtual void Init() { - _ResetPreview(); + _ResetPreview(false); _Initialized = true; } @@ -482,7 +482,7 @@ namespace VocaluxeLib.Menu.SongMenu if (categoryNr >= CBase.Songs.GetNumCategories()) return; - _ResetPreview(); + _ResetPreview(false); CBase.Songs.SetCategory(categoryNr); } @@ -511,9 +511,12 @@ namespace VocaluxeLib.Menu.SongMenu CBase.BackgroundMusic.LoadPreview(song); } - protected void _ResetPreview() + protected void _ResetPreview(bool playBGagain = true) { - CBase.BackgroundMusic.Stop(); + CBase.BackgroundMusic.StopPreview(); + + if (playBGagain) + CBase.BackgroundMusic.Play(); //Make sure we don't have a preview here otherwise a change won't be recognized //(e.g. leave a category with one song and set preview to 0 --> previewOld=previewNew=0 --> No change --> Old data shown diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index f473ead7..b33a1d16 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -467,7 +467,7 @@ namespace VocaluxeLib.Menu.SongMenu _TextBG.Draw(); - CTexture vidtex = CBase.BackgroundMusic.GetVideoTexture(); + CTexture vidtex = CBase.BackgroundMusic.IsPlayingPreview() ? CBase.BackgroundMusic.GetVideoTexture() : null; if (vidtex != null) { diff --git a/VocaluxeLib/Utils/Player/CSongPlayer.cs b/VocaluxeLib/Utils/Player/CSongPlayer.cs index fe2f9bb1..27b13176 100644 --- a/VocaluxeLib/Utils/Player/CSongPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSongPlayer.cs @@ -67,23 +67,6 @@ namespace VocaluxeLib.Utils.Player get { return _StreamID != -1; } } - public float Position - { - get - { - if (_StreamID == -1) - return -1; - return CBase.Sound.GetPosition(_StreamID); - } - set - { - if (_StreamID == -1) - return; - CBase.Sound.SetPosition(_StreamID, value); - CBase.Video.Skip(_Video, value, _Song.VideoGap); - _StartPosition = value; - } - } public CSongPlayer(bool loop = false) : base(loop) { } @@ -124,11 +107,15 @@ namespace VocaluxeLib.Utils.Player if (song == null) return; - Close(); + Stop(); _Song = song; + + base.Load(Path.Combine(song.Folder, song.MP3FileName), position, false); _LoadVideo(); - base.Load(Path.Combine(song.Folder, song.MP3FileName), position, autoplay); + + if (autoplay) + Play(); } public void LoadFile(string file, float position = 0f, bool autoplay = false) @@ -136,36 +123,24 @@ namespace VocaluxeLib.Utils.Player if (String.IsNullOrEmpty(file)) return; - Close(); + Stop(); - _Song = null; base.Load(file, position, autoplay); } - public new void Close() - { - base.Close(); - - if (_Video != -1) - { - CBase.Video.Close(_Video); - CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture); - _Video = -1; - } - } - public new void Play() { - base.Play(); - - if (_VideoEnabled && _Video != -1) - CBase.Video.Resume(_Video); + CBase.Sound.SetPosition(_StreamID, _StartPosition); + CBase.Video.Skip(_Video, _StartPosition, _Song.VideoGap); + TogglePause(); } public new void Stop() { base.Stop(); + _Song = null; + if (_Video != -1) { CBase.Video.Close(_Video); @@ -176,8 +151,7 @@ namespace VocaluxeLib.Utils.Player public new void TogglePause() { - base.TogglePause(); - if (!IsPlaying && _Video != -1) + if (IsPlaying && _Video != -1) { CBase.Video.Pause(_Video); CBase.Video.Skip(_Video, CBase.Sound.GetPosition(_StreamID) + _FadeTime, _Song.VideoGap); @@ -186,6 +160,7 @@ namespace VocaluxeLib.Utils.Player { CBase.Video.Resume(_Video); } + base.TogglePause(); } private void _LoadVideo() @@ -197,8 +172,14 @@ namespace VocaluxeLib.Utils.Player if (_Video != -1 || String.IsNullOrEmpty(videoFilePath)) return; _Video = CBase.Video.Load(videoFilePath); - CBase.Video.Skip(_Video, 0f, _Song.VideoGap + _StartPosition); //Use gap, otherwhise we will overwrite position in GetVideoTexture + CBase.Video.Skip(_Video, 0f, _Song.VideoGap); //Use gap, otherwhise we will overwrite position in GetVideoTexture _VideoFading = new CFading(0f, 1f, 3f); + + if (IsPlaying) + { + CBase.Video.Skip(_Video, Position, _Song.VideoGap); + CBase.Video.Resume(_Video); + } } } } diff --git a/VocaluxeLib/Utils/Player/CSoundPlayer.cs b/VocaluxeLib/Utils/Player/CSoundPlayer.cs index a3a86f51..b2b19b9e 100644 --- a/VocaluxeLib/Utils/Player/CSoundPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSoundPlayer.cs @@ -28,7 +28,6 @@ namespace VocaluxeLib.Utils.Player set { if(_StreamID == -1) return; - CBase.Sound.SetPosition(_StreamID, value); _StartPosition = value; } get { @@ -73,8 +72,6 @@ namespace VocaluxeLib.Utils.Player if (IsPlaying) Stop(); - Close(); - _StreamID = CBase.Sound.Load(file, false, true); if (position > 0f) Position = position; @@ -115,7 +112,9 @@ namespace VocaluxeLib.Utils.Player if (_StreamID == -1 || !IsPlaying) return; - CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Stop); + CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Close); + _StreamID = -1; + IsPlaying = false; } @@ -139,16 +138,6 @@ namespace VocaluxeLib.Utils.Player } - public void Close() - { - if (_StreamID == -1) - return; - - CBase.Sound.Close(_StreamID); - _StreamID = -1; - IsPlaying = false; - } - private void _ApplyVolume() { if (_StreamID == -1) From 74654d7fcf01c759b1d2cf26eb17944e8e06a6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 24 Aug 2014 13:09:57 +0200 Subject: [PATCH 15/18] More improvements and fixes (nearly stable now) --- Vocaluxe/Base/CBackgroundMusic.cs | 26 +++++++++------ Vocaluxe/Screens/CPopupScreenPlayerControl.cs | 4 +-- Vocaluxe/Screens/CScreenSong.cs | 2 +- .../Menu/SongMenu/CSongMenuFramework.cs | 32 +++---------------- 4 files changed, 23 insertions(+), 41 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 6f050db8..662a0c0d 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -67,11 +67,10 @@ namespace Vocaluxe.Base get { return _Disabled; } set { + if (Disabled == value) + return; _Disabled = value; - if (_Disabled) - Pause(); - else - Play(); + Pause(); } } @@ -191,7 +190,7 @@ namespace Vocaluxe.Base { _PreviewPlayer.Stop(); _PlaysPreview = false; - Play(); + Pause(); } else { @@ -202,13 +201,17 @@ namespace Vocaluxe.Base public static void Pause() { - if (!IsPlaying) - return; - if (_PlaysPreview) + { + if (!_PreviewPlayer.SongLoaded) + return; _PreviewPlayer.TogglePause(); + } else - _SongPlayer.TogglePause(); + if (!_SongPlayer.SongLoaded) + Next(); + else + _SongPlayer.TogglePause(); } public static void Next() @@ -305,7 +308,10 @@ namespace Vocaluxe.Base public static void LoadPreview(CSong song, float start = 0f) { - Stop(); + if (!_PlaysPreview) + Pause(); + else + StopPreview(); if (song == null) return; diff --git a/Vocaluxe/Screens/CPopupScreenPlayerControl.cs b/Vocaluxe/Screens/CPopupScreenPlayerControl.cs index 208fc630..e0c1cdf2 100644 --- a/Vocaluxe/Screens/CPopupScreenPlayerControl.cs +++ b/Vocaluxe/Screens/CPopupScreenPlayerControl.cs @@ -115,7 +115,7 @@ namespace Vocaluxe.Screens if (_Buttons[_ButtonPrevious].Selected) CBackgroundMusic.Previous(); if (_Buttons[_ButtonPlay].Selected) - CBackgroundMusic.Play(); + CBackgroundMusic.Pause(); if (_Buttons[_ButtonPause].Selected) CBackgroundMusic.Pause(); if (_Buttons[_ButtonRepeat].Selected) @@ -143,7 +143,7 @@ namespace Vocaluxe.Screens if (_Buttons[_ButtonPrevious].Selected) CBackgroundMusic.Previous(); if (_Buttons[_ButtonPlay].Selected) - CBackgroundMusic.Play(); + CBackgroundMusic.Pause(); if (_Buttons[_ButtonPause].Selected) CBackgroundMusic.Pause(); if (_Buttons[_ButtonRepeat].Selected) diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index d7722f9a..ace7503d 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -714,7 +714,7 @@ namespace Vocaluxe.Screens _SongMenu.OnHide(); - if (CGraphics.NextScreen != EScreens.ScreenNames || CConfig.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_OFF) + if (CGraphics.NextScreen != EScreens.ScreenNames) { CBackgroundMusic.Disabled = false; CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume); diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index b4d0cff4..c1bd939f 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -349,40 +349,13 @@ namespace VocaluxeLib.Menu.SongMenu { if (!_Initialized) return; - /* - if (_PreviewSongStream == -1 || _PreviewVideoStream == -1) - return; - - if (CBase.Video.IsFinished(_PreviewVideoStream) || CBase.Sound.IsFinished(_PreviewSongStream)) - { - CBase.Video.Close(_PreviewVideoStream); - _PreviewVideoStream = -1; - return; - } - - float time = CBase.Sound.GetPosition(_PreviewSongStream); - - float vtime; - if (CBase.Video.GetFrame(_PreviewVideoStream, ref _Vidtex, time, out vtime)) - { - if (_Vidtex != null) - { - if (_VideoFading != null) - { - bool finished; - _Vidtex.Color.A = _VideoFading.GetValue(out finished); - if (finished) - _VideoFading = null; - } - } - }*/ } public virtual void OnShow() {} public virtual void OnHide() { - if(CBase.Graphics.GetNextScreen() != EScreens.ScreenNames || CBase.Config.GetBackgroundMusicStatus() == EBackgroundMusicOffOn.TR_CONFIG_OFF) + if(CBase.Graphics.GetNextScreen() != EScreens.ScreenNames) _ResetPreview(); } @@ -513,6 +486,9 @@ namespace VocaluxeLib.Menu.SongMenu protected void _ResetPreview(bool playBGagain = true) { + if (_PreviewNrInternal == -1) + return; + CBase.BackgroundMusic.StopPreview(); if (playBGagain) From 942c8dca27135a3caabd9c26b59ad418916de607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 24 Aug 2014 14:34:51 +0200 Subject: [PATCH 16/18] Fix showing bg-video on start (if enabled) --- Vocaluxe/Screens/CScreenLoad.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Vocaluxe/Screens/CScreenLoad.cs b/Vocaluxe/Screens/CScreenLoad.cs index 5bcc054d..50c57008 100644 --- a/Vocaluxe/Screens/CScreenLoad.cs +++ b/Vocaluxe/Screens/CScreenLoad.cs @@ -152,6 +152,9 @@ namespace Vocaluxe.Screens { CBackgroundMusic.OwnSongsAvailable = true; + if (CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON || CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON) + CBackgroundMusic.VideoEnabled = true; + CBackgroundMusic.Play(); } From 46544aee8203226f81c3b424a28c9730a83abf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 24 Aug 2014 17:38:37 +0200 Subject: [PATCH 17/18] Fix repeating of bg-music. --- VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs | 2 -- VocaluxeLib/Utils/Player/CSongPlayer.cs | 1 + VocaluxeLib/Utils/Player/CSoundPlayer.cs | 8 ++++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index c1bd939f..7ab54122 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -475,8 +475,6 @@ namespace VocaluxeLib.Menu.SongMenu { _PreviewNrInternal = -1; - CBase.BackgroundMusic.StopPreview(); - CSong song = CBase.Songs.GetVisibleSong(nr); if (song == null) return; diff --git a/VocaluxeLib/Utils/Player/CSongPlayer.cs b/VocaluxeLib/Utils/Player/CSongPlayer.cs index 27b13176..a7fe62a0 100644 --- a/VocaluxeLib/Utils/Player/CSongPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSongPlayer.cs @@ -162,6 +162,7 @@ namespace VocaluxeLib.Utils.Player } base.TogglePause(); } + private void _LoadVideo() { diff --git a/VocaluxeLib/Utils/Player/CSoundPlayer.cs b/VocaluxeLib/Utils/Player/CSoundPlayer.cs index b2b19b9e..4bbbd602 100644 --- a/VocaluxeLib/Utils/Player/CSoundPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSoundPlayer.cs @@ -48,9 +48,9 @@ namespace VocaluxeLib.Utils.Player } public bool RepeatSong; - public bool IsPlaying { get; private set; } + public bool IsPlaying { get; protected set; } - public bool IsFinished { get { return CBase.Sound.IsFinished(_StreamID); } } + public bool IsFinished { get { return RepeatSong ? false : CBase.Sound.IsFinished(_StreamID); } } public CSoundPlayer(bool loop = false) { @@ -131,7 +131,11 @@ namespace VocaluxeLib.Utils.Player if (timeToPlay <= _FadeTime || finished) { if (RepeatSong) + { + //Set to false for restarting + IsPlaying = false; Play(); + } else Stop(); } From dd1fe4402ce38a389d9b25706a7d3005fc66add1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 24 Aug 2014 18:01:02 +0200 Subject: [PATCH 18/18] Draw color instead of texture when changing song (looks better) --- VocaluxeLib/Menu/CBackground.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index 7138d3f3..67ba0755 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -194,7 +194,7 @@ namespace VocaluxeLib.Menu if (!String.IsNullOrEmpty(_Theme.TextureName) && (_Theme.Type == EBackgroundTypes.Texture || - (_Theme.Type == EBackgroundTypes.Video && (CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF || !ok)))) + (_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF))) ok = _DrawTexture(); if (_Theme.Type == EBackgroundTypes.Color || _Theme.Type == EBackgroundTypes.Texture && !ok ||