Added preview-player which is used for playing preview in song-menu.
This commit is contained in:
1 parent
bd41de6dbe
commit
4c01396e46
10 files changed
+163
-47
No files matched your search
@@ -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
|
||||
|
||||
+45
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,6 +217,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Base\CBackgroundMusic.cs" />
|
||||
<Compile Include="Base\CPlaylistElement.cs" />
|
||||
<Compile Include="Base\CPreviewPlayer.cs" />
|
||||
<Compile Include="Base\CRecord.cs" />
|
||||
<Compile Include="COSFunctions.cs" />
|
||||
<Compile Include="Lib\Database\CCoverDB.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -135,6 +135,7 @@
|
||||
<Compile Include="PartyModes\IPartyMode.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Utils\CWavFile.cs" />
|
||||
<Compile Include="Utils\Player\CPreviewPlayer.cs" />
|
||||
<Compile Include="Utils\Player\CSongPlayer.cs" />
|
||||
<Compile Include="Utils\Player\CSoundPlayer.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in new issue
Block a user