Change preview-player. Now it's part of bg-music.
This commit is contained in:
1 parent
0a7006db43
commit
c6e8854dda
12 files changed
+155
-189
No files matched your search
@@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// (Re-)Starts the _CurrentPlaylistElement
|
||||
/// </summary>
|
||||
|
||||
@@ -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
|
||||
|
||||
+26
-45
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -566,9 +566,6 @@ namespace Vocaluxe.Screens
|
||||
{
|
||||
base.OnClose();
|
||||
CRecord.Stop();
|
||||
|
||||
if (CGraphics.NextScreen != EScreens.ScreenSong && CPreviewPlayer.IsPlaying)
|
||||
CPreviewPlayer.TogglePause();
|
||||
}
|
||||
|
||||
public override bool Draw()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -217,7 +217,6 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Base\CBackgroundMusic.cs" />
|
||||
<Compile Include="Base\CPlaylistElement.cs" />
|
||||
<Compile Include="Base\CPreviewPlayer.cs" />
|
||||
<Compile Include="Base\CRecord.cs" />
|
||||
<Compile Include="Base\CVideoPlayer.cs" />
|
||||
<Compile Include="COSFunctions.cs" />
|
||||
|
||||
Reference in new issue
Block a user