Change preview-player. Now it's part of bg-music.

This commit is contained in:
Florian Küpper committed 2014-08-20 18:50:27 +02:00
1 parent 0a7006db43
commit c6e8854dda
12 files changed
+155 -189

No files matched your search

+108 -46
View File
@@ -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>
-2
View File
@@ -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
View File
@@ -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;
}
}
}
-69
View File
@@ -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;
}
}
}
-3
View File
@@ -566,9 +566,6 @@ namespace Vocaluxe.Screens
{
base.OnClose();
CRecord.Stop();
if (CGraphics.NextScreen != EScreens.ScreenSong && CPreviewPlayer.IsPlaying)
CPreviewPlayer.TogglePause();
}
public override bool Draw()
+1 -2
View File
@@ -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
-5
View File
@@ -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)
{
-1
View File
@@ -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" />
+1 -4
View File
@@ -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;
}
}
}
+7
View File
@@ -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
@@ -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
@@ -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)
{