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
+117 -151

No files matched your search

+70 -8
View File
@@ -31,6 +31,7 @@ namespace Vocaluxe.Base
private static bool _Initialized; private static bool _Initialized;
private static CSongPlayer _SongPlayer; private static CSongPlayer _SongPlayer;
private static CSongPlayer _PreviewPlayer;
private static bool _OwnSongsAvailable; private static bool _OwnSongsAvailable;
private static EBackgroundMusicSource _MusicSource; private static EBackgroundMusicSource _MusicSource;
@@ -46,6 +47,7 @@ namespace Vocaluxe.Base
private static bool _OwnMusicAdded; private static bool _OwnMusicAdded;
private static bool _BackgroundMusicAdded; private static bool _BackgroundMusicAdded;
private static bool _Disabled; private static bool _Disabled;
private static bool _PlaysPreview;
public static bool VideoEnabled public static bool VideoEnabled
{ {
@@ -83,18 +85,28 @@ namespace Vocaluxe.Base
get { return _SongPlayer.SongHasVideo; } 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 public static string ArtistAndTitle
{ {
get { get {
if (_PlaysPreview)
return _PreviewPlayer.ArtistAndTitle;
else
return _BGMusicFiles.Contains(_CurrentPlaylistElement) ? Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath) : _SongPlayer.ArtistAndTitle; 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 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 //Use this to set whether own songs are available for access
@@ -129,6 +141,10 @@ namespace Vocaluxe.Base
_SongPlayer = new CSongPlayer(); _SongPlayer = new CSongPlayer();
_SongPlayer.Volume = CConfig.BackgroundMusicVolume; _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); _VideoEnabled = (CConfig.VideoBackgrounds == EOffOn.TR_CONFIG_ON && CConfig.VideosToBackground == EOffOn.TR_CONFIG_ON);
SetMusicSource(CConfig.BackgroundMusicSource); SetMusicSource(CConfig.BackgroundMusicSource);
_Initialized = true; _Initialized = true;
@@ -137,6 +153,7 @@ namespace Vocaluxe.Base
public static void Close() public static void Close()
{ {
_SongPlayer.Close(); _SongPlayer.Close();
_PreviewPlayer.Close();
_BGMusicFiles.Clear(); _BGMusicFiles.Clear();
_NotPlayedFiles.Clear(); _NotPlayedFiles.Clear();
@@ -147,14 +164,15 @@ namespace Vocaluxe.Base
public static void Play() public static void Play()
{ {
if (IsPlaying || CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF) if (IsPlaying || (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_OFF && !_PlaysPreview))
return; return;
if (_PlaysPreview)
_PreviewPlayer.TogglePause();
else
if (_SongPlayer.SongLoaded) if (_SongPlayer.SongLoaded)
{
//Resume //Resume
_SongPlayer.TogglePause(); _SongPlayer.TogglePause();
}
else else
Next(); Next();
} }
@@ -164,20 +182,33 @@ namespace Vocaluxe.Base
if (!IsPlaying) if (!IsPlaying)
return; return;
if (_PlaysPreview)
{
_PreviewPlayer.Stop();
_PlaysPreview = false;
Play();
}
else
{
_SongPlayer.Stop(); _SongPlayer.Stop();
_CurrentPlaylistElement = null; _CurrentPlaylistElement = null;
} }
}
public static void Pause() public static void Pause()
{ {
if (!IsPlaying) if (!IsPlaying)
return; return;
if (_PlaysPreview)
_PreviewPlayer.TogglePause();
else
_SongPlayer.TogglePause(); _SongPlayer.TogglePause();
} }
public static void Next() public static void Next()
{
if (!_PlaysPreview)
{ {
Stop(); //stop last song if any Stop(); //stop last song if any
if (_PreviousMusicIndex < _PreviousFiles.Count - 2) if (_PreviousMusicIndex < _PreviousFiles.Count - 2)
@@ -204,8 +235,11 @@ namespace Vocaluxe.Base
} }
_StartSong(); _StartSong();
} }
}
public static void Previous() public static void Previous()
{
if (!_PlaysPreview)
{ {
if (_PreviousMusicIndex < 0) if (_PreviousMusicIndex < 0)
return; return;
@@ -219,20 +253,26 @@ namespace Vocaluxe.Base
} }
_StartSong(); _StartSong();
} }
}
public static void Update() public static void Update()
{ {
if (!IsPlaying && !_SongPlayer.SongLoaded) if (!IsPlaying && (!_SongPlayer.SongLoaded || !_PreviewPlayer.SongLoaded) )
return; return;
if (_PlaysPreview)
_PreviewPlayer.Update();
else
{
_SongPlayer.Update(); _SongPlayer.Update();
if (_SongPlayer.IsFinished) if (_SongPlayer.IsFinished)
Next(); Next();
} }
}
public static CTexture GetVideoTexture() public static CTexture GetVideoTexture()
{ {
return _SongPlayer.GetVideoTexture(); return _PlaysPreview ? _PreviewPlayer.GetVideoTexture() : _SongPlayer.GetVideoTexture();
} }
public static void SetMusicSource(EBackgroundMusicSource source) 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> /// <summary>
/// (Re-)Starts the _CurrentPlaylistElement /// (Re-)Starts the _CurrentPlaylistElement
/// </summary> /// </summary>
-2
View File
@@ -263,8 +263,6 @@ namespace Vocaluxe.Base
xmlReader.TryGetEnumValue("//root/Sound/BackgroundMusicUseStart", ref BackgroundMusicUseStart); xmlReader.TryGetEnumValue("//root/Sound/BackgroundMusicUseStart", ref BackgroundMusicUseStart);
xmlReader.TryGetIntValueRange("//root/Sound/PreviewMusicVolume", ref _PreviewMusicVolume); xmlReader.TryGetIntValueRange("//root/Sound/PreviewMusicVolume", ref _PreviewMusicVolume);
xmlReader.TryGetIntValueRange("//root/Sound/GameMusicVolume", ref _GameMusicVolume); xmlReader.TryGetIntValueRange("//root/Sound/GameMusicVolume", ref _GameMusicVolume);
CPreviewPlayer.UpdateVolume();
#endregion Sound #endregion Sound
#region Game #region Game
+26 -45
View File
@@ -51,12 +51,11 @@ namespace Vocaluxe.Base
private static readonly IDataBase _DataBase = new CBdataBase(); private static readonly IDataBase _DataBase = new CBdataBase();
private static readonly IControllers _Controller = new CBcontrollers(); private static readonly IControllers _Controller = new CBcontrollers();
private static readonly IPlaylist _Playlist = new CBplaylist(); private static readonly IPlaylist _Playlist = new CBplaylist();
private static readonly IPreviewPlayer _PreviewPlayer = new CBpreviewPlayer();
public static void Init() public static void Init()
{ {
CBase.Assign(_Config, _Settings, _Theme, _Log, _BackgroundMusic, _Draw, _Graphics, _Fonts, _Language, 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; return CBackgroundMusic.VideoEnabled;
} }
public bool IsPlayingPreview()
{
return CBackgroundMusic.IsPlayingPreview;
}
public void SetDisabled(bool disabled) public void SetDisabled(bool disabled)
{ {
CBackgroundMusic.Disabled = disabled; CBackgroundMusic.Disabled = disabled;
} }
public float GetLength()
{
return CBackgroundMusic.Length;
}
public void Next() public void Next()
{ {
CBackgroundMusic.Next(); CBackgroundMusic.Next();
@@ -371,6 +380,21 @@ namespace Vocaluxe.Base
CBackgroundMusic.Play(); 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() public CTexture GetVideoTexture()
{ {
return CBackgroundMusic.GetVideoTexture(); return CBackgroundMusic.GetVideoTexture();
@@ -971,47 +995,4 @@ namespace Vocaluxe.Base
return CPlaylists.GetSong(playlistID, songIndex); 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(); base.OnClose();
CRecord.Stop(); CRecord.Stop();
if (CGraphics.NextScreen != EScreens.ScreenSong && CPreviewPlayer.IsPlaying)
CPreviewPlayer.TogglePause();
} }
public override bool Draw() public override bool Draw()
+1 -2
View File
@@ -123,8 +123,7 @@ namespace Vocaluxe.Screens
public override void OnShow() public override void OnShow()
{ {
if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON) CBackgroundMusic.Disabled = false;
CPreviewPlayer.TogglePause();
base.OnShow(); base.OnShow();
//-1 --> Show average //-1 --> Show average
-5
View File
@@ -662,11 +662,6 @@ namespace Vocaluxe.Screens
_Texts[_TextCategory].Text = CSongs.GetCurrentCategoryName(); _Texts[_TextCategory].Text = CSongs.GetCurrentCategoryName();
if (CSongs.IsInCategory || CConfig.Tabs == EOffOn.TR_CONFIG_OFF)
CBackgroundMusic.Disabled = true;
else
CBackgroundMusic.Disabled = false;
string selectionText = ""; string selectionText = "";
if (CSongs.IsInCategory) if (CSongs.IsInCategory)
{ {
-1
View File
@@ -217,7 +217,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="Base\CBackgroundMusic.cs" /> <Compile Include="Base\CBackgroundMusic.cs" />
<Compile Include="Base\CPlaylistElement.cs" /> <Compile Include="Base\CPlaylistElement.cs" />
<Compile Include="Base\CPreviewPlayer.cs" />
<Compile Include="Base\CRecord.cs" /> <Compile Include="Base\CRecord.cs" />
<Compile Include="Base\CVideoPlayer.cs" /> <Compile Include="Base\CVideoPlayer.cs" />
<Compile Include="COSFunctions.cs" /> <Compile Include="COSFunctions.cs" />
+1 -4
View File
@@ -38,12 +38,10 @@ namespace VocaluxeLib
public static IDataBase DataBase; public static IDataBase DataBase;
public static IControllers Controller; public static IControllers Controller;
public static IPlaylist Playlist; public static IPlaylist Playlist;
public static IPreviewPlayer PreviewPlayer;
public static void Assign(IConfig config, ISettings settings, ITheme theme, ILog log, IBackgroundMusic backgroundMusic, 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, 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; Config = config;
Settings = settings; Settings = settings;
@@ -64,7 +62,6 @@ namespace VocaluxeLib
DataBase = dataBase; DataBase = dataBase;
Controller = controller; Controller = controller;
Playlist = playlist; Playlist = playlist;
PreviewPlayer = previewPlayer;
} }
} }
} }
+7
View File
@@ -119,16 +119,23 @@ namespace VocaluxeLib
{ {
bool IsDisabled(); bool IsDisabled();
bool IsPlaying(); bool IsPlaying();
bool IsPlayingPreview();
bool SongHasVideo(); bool SongHasVideo();
bool VideoEnabled(); bool VideoEnabled();
float GetLength();
void SetDisabled(bool disabled); void SetDisabled(bool disabled);
void Next(); void Next();
void Previous(); void Previous();
void Pause(); void Pause();
void Play(); void Play();
void Stop();
CTexture GetVideoTexture(); CTexture GetVideoTexture();
void LoadPreview(CSong song, float start = 0f);
void PlayPreview(float start = -1f);
} }
public interface IDrawing public interface IDrawing
@@ -117,7 +117,7 @@ namespace VocaluxeLib.Menu.SongMenu
else if (value >= CBase.Songs.GetNumCategories()) else if (value >= CBase.Songs.GetNumCategories())
{ {
value = -1; value = -1;
CBase.PreviewPlayer.Stop(); CBase.BackgroundMusic.Stop();
} }
_PreviewNrInternal = value; _PreviewNrInternal = value;
@@ -395,8 +395,8 @@ namespace VocaluxeLib.Menu.SongMenu
if (!_Initialized || !Visible) if (!_Initialized || !Visible)
return; return;
if (CBase.PreviewPlayer.IsPlaying()) if (CBase.BackgroundMusic.IsPlaying())
CBase.Drawing.DrawTexture(CBase.PreviewPlayer.GetVideoTexture(), new SRectF(0, 0, 1280, 720, 0)); CBase.Drawing.DrawTexture(CBase.BackgroundMusic.GetVideoTexture(), new SRectF(0, 0, 1280, 720, 0));
} }
public bool IsMouseOverSelectedSong(SMouseEvent mEvent) public bool IsMouseOverSelectedSong(SMouseEvent mEvent)
@@ -506,23 +506,23 @@ namespace VocaluxeLib.Menu.SongMenu
if (song == null) if (song == null)
return; return;
CBase.PreviewPlayer.Load(song); CBase.BackgroundMusic.LoadPreview(song);
float startposition = song.Preview.StartTime; float startposition = song.Preview.StartTime;
float length = CBase.PreviewPlayer.GetLength(); float length = CBase.BackgroundMusic.GetLength();
if (song.Preview.Source == EDataSource.None) if (song.Preview.Source == EDataSource.None)
startposition = length / 4f; startposition = length / 4f;
else if (startposition > length - 5f) else if (startposition > length - 5f)
startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f)); startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f));
CBase.PreviewPlayer.Play(startposition); CBase.BackgroundMusic.PlayPreview(startposition);
} }
protected void _ResetPreview() 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 //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 //(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 (value == base._PreviewNr)
{ {
if (!CBase.PreviewPlayer.IsPlaying()) if (!CBase.BackgroundMusic.IsPlaying())
CBase.PreviewPlayer.Play(); CBase.BackgroundMusic.PlayPreview();
return; return;
} }
base._PreviewNr = value; base._PreviewNr = value;
@@ -183,7 +183,7 @@ namespace VocaluxeLib.Menu.SongMenu
if (songOptions.Selection.RandomOnly) if (songOptions.Selection.RandomOnly)
_PreviewNr = _SelectionNr; _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)); _UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr));
} }
@@ -248,7 +248,7 @@ namespace VocaluxeLib.Menu.SongMenu
{ {
if (song == null) if (song == null)
return; return;
float time = CBase.PreviewPlayer.GetLength(); float time = CBase.BackgroundMusic.GetLength();
if (Math.Abs(song.Finish) > 0.001) if (Math.Abs(song.Finish) > 0.001)
time = song.Finish; time = song.Finish;
@@ -467,7 +467,7 @@ namespace VocaluxeLib.Menu.SongMenu
_TextBG.Draw(); _TextBG.Draw();
CTexture vidtex = CBase.PreviewPlayer.GetVideoTexture(); CTexture vidtex = CBase.BackgroundMusic.GetVideoTexture();
if (vidtex != null) if (vidtex != null)
{ {