Refactor background music to fix some possible issues and smooth out transitions
This commit is contained in:
1 parent
cd4c010f99
commit
df82690cd0
16 files changed
+333
-389
No files matched your search
@@ -73,7 +73,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
|||||||
private const int _FieldSpace = 10;
|
private const int _FieldSpace = 10;
|
||||||
private float _FieldSize = 100;
|
private float _FieldSize = 100;
|
||||||
|
|
||||||
private int _PreviewStream = -1;
|
|
||||||
private int _OldSelectedField = -1;
|
private int _OldSelectedField = -1;
|
||||||
|
|
||||||
private int[,] _Possibilities;
|
private int[,] _Possibilities;
|
||||||
@@ -267,8 +266,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
|||||||
{
|
{
|
||||||
base.OnShow();
|
base.OnShow();
|
||||||
|
|
||||||
_PreviewStream = -1;
|
|
||||||
|
|
||||||
if (_PartyMode.GameData.CurrentRoundNr == 1)
|
if (_PartyMode.GameData.CurrentRoundNr == 1)
|
||||||
{
|
{
|
||||||
_BuildWinnerPossibilities();
|
_BuildWinnerPossibilities();
|
||||||
@@ -334,13 +331,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnClose()
|
|
||||||
{
|
|
||||||
base.OnClose();
|
|
||||||
CBase.BackgroundMusic.SetDisabled(false);
|
|
||||||
CBase.Sound.Fade(_PreviewStream, 0, 0.5f, EStreamAction.Close);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void _CreateFields()
|
private void _CreateFields()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 25; i++)
|
for (int i = 0; i < 25; i++)
|
||||||
@@ -490,14 +480,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
|||||||
private void _StartPreview(int songID)
|
private void _StartPreview(int songID)
|
||||||
{
|
{
|
||||||
CSong song = CBase.Songs.GetSongByID(songID);
|
CSong song = CBase.Songs.GetSongByID(songID);
|
||||||
CBase.BackgroundMusic.SetDisabled(true);
|
CBase.BackgroundMusic.LoadPreview(song);
|
||||||
|
|
||||||
_PreviewStream = CBase.Sound.Load(song.GetMP3());
|
|
||||||
CBase.Sound.SetGlobalVolume(CBase.Config.GetMusicVolume(EMusicType.Preview));
|
|
||||||
CBase.Sound.SetPosition(_PreviewStream, song.Preview.StartTime);
|
|
||||||
CBase.Sound.SetStreamVolume(_PreviewStream, 0);
|
|
||||||
CBase.Sound.Play(_PreviewStream);
|
|
||||||
CBase.Sound.Fade(_PreviewStream, 100, 1f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _UpdatePlayerInformation()
|
private void _UpdatePlayerInformation()
|
||||||
@@ -525,8 +508,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
|||||||
if (_PartyMode.GameData.NumJokerRandom[teamNr] > 0)
|
if (_PartyMode.GameData.NumJokerRandom[teamNr] > 0)
|
||||||
{
|
{
|
||||||
_PartyMode.GameData.NumJokerRandom[teamNr]--;
|
_PartyMode.GameData.NumJokerRandom[teamNr]--;
|
||||||
if (!CBase.Sound.IsFinished(_PreviewStream))
|
|
||||||
CBase.Sound.Fade(_PreviewStream, 0, 1, EStreamAction.Close);
|
|
||||||
_FieldSelected(true);
|
_FieldSelected(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -537,8 +518,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
|||||||
{
|
{
|
||||||
_PartyMode.GameData.NumJokerRetry[teamNr]--;
|
_PartyMode.GameData.NumJokerRetry[teamNr]--;
|
||||||
_PartyMode.GameData.Team = teamNr;
|
_PartyMode.GameData.Team = teamNr;
|
||||||
if (!CBase.Sound.IsFinished(_PreviewStream))
|
|
||||||
CBase.Sound.Fade(_PreviewStream, 0, 1, EStreamAction.Close);
|
|
||||||
_Status = EStatus.JokerRetry;
|
_Status = EStatus.JokerRetry;
|
||||||
_OldSelectedField = _PartyMode.GameData.FieldNr;
|
_OldSelectedField = _PartyMode.GameData.FieldNr;
|
||||||
_PartyMode.GameData.FieldNr = -1;
|
_PartyMode.GameData.FieldNr = -1;
|
||||||
@@ -579,13 +558,11 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
|||||||
|
|
||||||
private void _NextRound()
|
private void _NextRound()
|
||||||
{
|
{
|
||||||
CBase.Sound.Fade(_PreviewStream, 0, 0.5f, EStreamAction.Close);
|
|
||||||
_PartyMode.Next();
|
_PartyMode.Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _EndParty()
|
private void _EndParty()
|
||||||
{
|
{
|
||||||
CBase.Sound.Fade(_PreviewStream, 0, 0.5f, EStreamAction.Close);
|
|
||||||
CBase.Graphics.FadeTo(EScreen.Party);
|
CBase.Graphics.FadeTo(EScreen.Party);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,7 +581,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
|||||||
|
|
||||||
private void _Back()
|
private void _Back()
|
||||||
{
|
{
|
||||||
CBase.Sound.Fade(_PreviewStream, 0, 0.5f, EStreamAction.Close);
|
|
||||||
_PartyMode.Back();
|
_PartyMode.Back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+114
-165
@@ -18,7 +18,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
|
||||||
using VocaluxeLib;
|
using VocaluxeLib;
|
||||||
using VocaluxeLib.Songs;
|
using VocaluxeLib.Songs;
|
||||||
using VocaluxeLib.Draw;
|
using VocaluxeLib.Draw;
|
||||||
@@ -30,12 +29,12 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
private static bool _Initialized;
|
private static bool _Initialized;
|
||||||
|
|
||||||
private static CSongPlayer _SongPlayer;
|
private static readonly CSongPlayer _BGPlayer = new CSongPlayer();
|
||||||
private static CSongPlayer _PreviewPlayer;
|
private static readonly CSongPlayer _PreviewPlayer = new CSongPlayer(true);
|
||||||
|
private static CSongPlayer _CurPlayer;
|
||||||
|
|
||||||
private static bool _OwnSongsAvailable;
|
private static bool _OwnSongsAvailable;
|
||||||
private static EBackgroundMusicSource _MusicSource;
|
private static EBackgroundMusicSource _MusicSource;
|
||||||
private static bool _VideoEnabled;
|
|
||||||
|
|
||||||
private static CPlaylistElement _CurrentPlaylistElement; //Currently played music
|
private static CPlaylistElement _CurrentPlaylistElement; //Currently played music
|
||||||
private static int _PreviousMusicIndex = -1;
|
private static int _PreviousMusicIndex = -1;
|
||||||
@@ -47,29 +46,20 @@ 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
|
||||||
{
|
{
|
||||||
get { return _PlaysPreview ? _PreviewPlayer.VideoEnabled : _SongPlayer.VideoEnabled; }
|
get { return _CurPlayer.VideoEnabled; }
|
||||||
set
|
set { _CurPlayer.VideoEnabled = value; }
|
||||||
{
|
|
||||||
if (_PlaysPreview)
|
|
||||||
_PreviewPlayer.VideoEnabled = value;
|
|
||||||
else
|
|
||||||
_SongPlayer.VideoEnabled = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool CanSing
|
public static bool CanSing
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_PlaysPreview)
|
if (IsPlayingPreview)
|
||||||
return false;
|
return false;
|
||||||
if (_BGMusicFiles.Contains(_CurrentPlaylistElement))
|
return !_BGMusicFiles.Contains(_CurrentPlaylistElement);
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,54 +71,63 @@ namespace Vocaluxe.Base
|
|||||||
if (Disabled == value)
|
if (Disabled == value)
|
||||||
return;
|
return;
|
||||||
_Disabled = value;
|
_Disabled = value;
|
||||||
Pause();
|
if (_Disabled)
|
||||||
|
Pause();
|
||||||
|
else
|
||||||
|
Play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Repeat the background song (preview songs are always repeating!)
|
||||||
|
/// </summary>
|
||||||
public static bool RepeatSong
|
public static bool RepeatSong
|
||||||
{
|
{
|
||||||
get { return _SongPlayer.RepeatSong; }
|
get { return _BGPlayer.Loop; }
|
||||||
set { _SongPlayer.RepeatSong = value; }
|
set { _BGPlayer.Loop = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int SongID
|
public static int SongID
|
||||||
{
|
{
|
||||||
get { return _SongPlayer.SongID; }
|
get { return _CurPlayer.SongID; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool SongHasVideo
|
public static bool SongHasVideo
|
||||||
{
|
{
|
||||||
get { return _SongPlayer.SongHasVideo; }
|
get { return _CurPlayer.SongHasVideo; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsPlaying
|
public static bool IsPlaying
|
||||||
{
|
{
|
||||||
get { return _PlaysPreview ? _PreviewPlayer.IsPlaying : _SongPlayer.IsPlaying; }
|
get { return _CurPlayer.IsPlaying; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsPlayingPreview
|
public static bool IsPlayingPreview
|
||||||
{
|
{
|
||||||
get { return _PlaysPreview; }
|
get { return _CurPlayer == _PreviewPlayer; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (IsPlayingPreview == value)
|
||||||
|
return;
|
||||||
|
Pause();
|
||||||
|
_CurPlayer = value ? _PreviewPlayer : _BGPlayer;
|
||||||
|
Play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ArtistAndTitle
|
public static string ArtistAndTitle
|
||||||
{
|
{
|
||||||
get
|
get { return _CurPlayer.ArtistAndTitle; }
|
||||||
{
|
|
||||||
if (_PlaysPreview)
|
|
||||||
return _PreviewPlayer.ArtistAndTitle;
|
|
||||||
return _BGMusicFiles.Contains(_CurrentPlaylistElement) ? Path.GetFileNameWithoutExtension(_CurrentPlaylistElement.MusicFilePath) : _SongPlayer.ArtistAndTitle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float Length
|
public static float Length
|
||||||
{
|
{
|
||||||
get { return _PlaysPreview ? _PreviewPlayer.Length : _SongPlayer.Length; }
|
get { return _CurPlayer.Length; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CTextureRef Cover
|
public static CTextureRef Cover
|
||||||
{
|
{
|
||||||
get { return _PlaysPreview ? _PreviewPlayer.Cover : _SongPlayer.Cover; }
|
get { return _CurPlayer.Cover; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//Use this to set whether own songs are available for access
|
//Use this to set whether own songs are available for access
|
||||||
@@ -160,21 +159,15 @@ namespace Vocaluxe.Base
|
|||||||
_MusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC;
|
_MusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC;
|
||||||
_AddBackgroundMusic();
|
_AddBackgroundMusic();
|
||||||
|
|
||||||
_SongPlayer = new CSongPlayer();
|
|
||||||
|
|
||||||
_PreviewPlayer = new CSongPlayer {RepeatSong = true};
|
|
||||||
|
|
||||||
_VideoEnabled = (CConfig.Config.Video.VideoBackgrounds == EOffOn.TR_CONFIG_ON && CConfig.Config.Video.VideosToBackground == EOffOn.TR_CONFIG_ON);
|
|
||||||
SetMusicSource(CConfig.Config.Sound.BackgroundMusicSource);
|
SetMusicSource(CConfig.Config.Sound.BackgroundMusicSource);
|
||||||
|
_CurPlayer = _BGPlayer;
|
||||||
_Initialized = true;
|
_Initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Close()
|
public static void Close()
|
||||||
{
|
{
|
||||||
if (_SongPlayer != null)
|
_BGPlayer.Close();
|
||||||
_SongPlayer.Stop();
|
_PreviewPlayer.Close();
|
||||||
if (_PreviewPlayer != null)
|
|
||||||
_PreviewPlayer.Stop();
|
|
||||||
|
|
||||||
_BGMusicFiles.Clear();
|
_BGMusicFiles.Clear();
|
||||||
_NotPlayedFiles.Clear();
|
_NotPlayedFiles.Clear();
|
||||||
@@ -185,124 +178,88 @@ namespace Vocaluxe.Base
|
|||||||
|
|
||||||
public static void Play()
|
public static void Play()
|
||||||
{
|
{
|
||||||
if (IsPlaying || (CConfig.Config.Sound.BackgroundMusic != EBackgroundMusicOffOn.TR_CONFIG_ON && !_PlaysPreview))
|
if (!IsPlayingPreview && CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_OFF)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_PlaysPreview)
|
if (IsPlayingPreview || _BGPlayer.SoundLoaded)
|
||||||
_PreviewPlayer.Play();
|
_CurPlayer.Play();
|
||||||
else if (CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON)
|
else
|
||||||
{
|
Next();
|
||||||
if (_SongPlayer.SongLoaded)
|
|
||||||
//Resume
|
|
||||||
_SongPlayer.TogglePause();
|
|
||||||
else
|
|
||||||
Next();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Stop()
|
public static void Stop()
|
||||||
{
|
{
|
||||||
if (!IsPlaying)
|
_CurPlayer.Stop();
|
||||||
return;
|
if (!IsPlayingPreview)
|
||||||
|
|
||||||
if (_PlaysPreview)
|
|
||||||
{
|
|
||||||
_PreviewPlayer.Stop();
|
|
||||||
_PlaysPreview = false;
|
|
||||||
Pause();
|
|
||||||
CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_SongPlayer.Stop();
|
|
||||||
_CurrentPlaylistElement = null;
|
_CurrentPlaylistElement = null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Pause()
|
public static void Pause()
|
||||||
{
|
{
|
||||||
if (_PlaysPreview)
|
_CurPlayer.Pause();
|
||||||
{
|
|
||||||
if (!_PreviewPlayer.SongLoaded)
|
|
||||||
return;
|
|
||||||
_PreviewPlayer.TogglePause();
|
|
||||||
}
|
|
||||||
else if (CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON)
|
|
||||||
{
|
|
||||||
if (!_SongPlayer.SongLoaded)
|
|
||||||
Next();
|
|
||||||
else
|
|
||||||
_SongPlayer.TogglePause();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Next()
|
public static void Next()
|
||||||
{
|
{
|
||||||
if (!_PlaysPreview)
|
if (IsPlayingPreview)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Stop(); //stop last song if any
|
||||||
|
if (_PreviousMusicIndex < _PreviousFiles.Count - 2)
|
||||||
{
|
{
|
||||||
Stop(); //stop last song if any
|
//We are in the previous list and next element exists
|
||||||
if (_PreviousMusicIndex < _PreviousFiles.Count - 2)
|
_PreviousMusicIndex++;
|
||||||
{
|
_CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex];
|
||||||
//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);
|
|
||||||
|
|
||||||
_PreviousFiles.Add(_CurrentPlaylistElement);
|
|
||||||
_PreviousMusicIndex = _PreviousFiles.Count - 1;
|
|
||||||
}
|
|
||||||
_StartSong();
|
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
|
_PreviousFiles.Add(_CurrentPlaylistElement);
|
||||||
|
_PreviousMusicIndex = _PreviousFiles.Count - 1;
|
||||||
|
}
|
||||||
|
_StartSong();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Previous()
|
public static void Previous()
|
||||||
{
|
{
|
||||||
if (!_PlaysPreview)
|
if (IsPlayingPreview)
|
||||||
{
|
return;
|
||||||
if (_PreviousMusicIndex < 0)
|
if (_PreviousMusicIndex < 0)
|
||||||
return;
|
return;
|
||||||
Debug.Assert(_CurrentPlaylistElement != null);
|
|
||||||
if (_SongPlayer.Position <= 1.5f && _PreviousMusicIndex > 0)
|
|
||||||
{
|
|
||||||
Stop(); //stop last song
|
|
||||||
_PreviousMusicIndex--;
|
|
||||||
|
|
||||||
_CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex];
|
if (_CurrentPlaylistElement == null || (_BGPlayer.Position <= 1.5f && _PreviousMusicIndex > 0))
|
||||||
}
|
{
|
||||||
_StartSong();
|
Stop(); //stop last song
|
||||||
|
_PreviousMusicIndex--;
|
||||||
|
|
||||||
|
_CurrentPlaylistElement = _PreviousFiles[_PreviousMusicIndex];
|
||||||
}
|
}
|
||||||
|
_StartSong();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Update()
|
public static void Update()
|
||||||
{
|
{
|
||||||
if (!IsPlaying && (!_SongPlayer.SongLoaded || !_PreviewPlayer.SongLoaded))
|
if (!IsPlaying)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_PlaysPreview)
|
_CurPlayer.Update();
|
||||||
_PreviewPlayer.Update();
|
if (!IsPlayingPreview && _BGPlayer.IsFinished)
|
||||||
else
|
Next();
|
||||||
{
|
|
||||||
_SongPlayer.Update();
|
|
||||||
if (_SongPlayer.IsFinished)
|
|
||||||
Next();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CTextureRef GetVideoTexture()
|
public static CTextureRef GetVideoTexture()
|
||||||
{
|
{
|
||||||
return _PlaysPreview ? _PreviewPlayer.GetVideoTexture() : _SongPlayer.GetVideoTexture();
|
return _CurPlayer.GetVideoTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetMusicSource(EBackgroundMusicSource source)
|
public static void SetMusicSource(EBackgroundMusicSource source)
|
||||||
@@ -328,54 +285,42 @@ namespace Vocaluxe.Base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadPreview(CSong song, float start = 0f)
|
public static void LoadPreview(CSong song, float start = -1f)
|
||||||
{
|
{
|
||||||
if (!_PlaysPreview)
|
|
||||||
Pause();
|
|
||||||
else
|
|
||||||
StopPreview();
|
|
||||||
|
|
||||||
if (song == null)
|
if (song == null)
|
||||||
return;
|
throw new ArgumentNullException("song");
|
||||||
|
|
||||||
// ReSharper disable CompareOfFloatsByEqualityOperator
|
if (!IsPlayingPreview)
|
||||||
if (start == 0f)
|
{
|
||||||
start = song.Preview.StartTime;
|
Pause();
|
||||||
// ReSharper restore CompareOfFloatsByEqualityOperator
|
_CurPlayer = _PreviewPlayer;
|
||||||
|
CSound.SetGlobalVolume(CConfig.PreviewMusicVolume);
|
||||||
|
}
|
||||||
|
|
||||||
_PlaysPreview = true;
|
_PreviewPlayer.Load(song);
|
||||||
CSound.SetGlobalVolume(CConfig.PreviewMusicVolume);
|
|
||||||
_PreviewPlayer.Load(song, start);
|
|
||||||
|
|
||||||
float startposition = song.Preview.StartTime;
|
|
||||||
|
|
||||||
float length = _PreviewPlayer.Length;
|
float length = _PreviewPlayer.Length;
|
||||||
|
if (length < 1)
|
||||||
|
length = 30; // If length is unknow or invalid assume a length of 30s
|
||||||
|
|
||||||
if (song.Preview.Source == EDataSource.None)
|
if (start < 0)
|
||||||
startposition = length / 4f;
|
start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime;
|
||||||
else if (startposition > length - 5f)
|
if (start > length - 5f)
|
||||||
startposition = Math.Max(0f, Math.Min(length / 4f, length - 5f));
|
start = Math.Max(0f, Math.Min(length / 4f, length - 5f));
|
||||||
|
if (start >= 0.5f)
|
||||||
|
start -= 0.5f;
|
||||||
|
|
||||||
if (startposition >= 0.5f)
|
_PreviewPlayer.Position = start;
|
||||||
startposition -= 0.5f;
|
|
||||||
|
|
||||||
_PreviewPlayer.Position = startposition;
|
|
||||||
|
|
||||||
Play();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void PlayPreview(float start = -1f)
|
|
||||||
{
|
|
||||||
if (start > -1f)
|
|
||||||
_PreviewPlayer.Position = start;
|
|
||||||
|
|
||||||
Play();
|
Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void StopPreview()
|
public static void StopPreview()
|
||||||
{
|
{
|
||||||
_PreviewPlayer.Stop();
|
if (!IsPlayingPreview)
|
||||||
_PlaysPreview = false;
|
return;
|
||||||
|
Stop();
|
||||||
|
_CurPlayer = _BGPlayer;
|
||||||
CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume);
|
CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,19 +332,23 @@ namespace Vocaluxe.Base
|
|||||||
Debug.Assert(_CurrentPlaylistElement != null);
|
Debug.Assert(_CurrentPlaylistElement != null);
|
||||||
|
|
||||||
//If current song same as loaded restart only
|
//If current song same as loaded restart only
|
||||||
if (_CurrentPlaylistElement.SongID == _SongPlayer.SongID && _SongPlayer.SongLoaded)
|
if (_BGPlayer.SoundLoaded && _CurrentPlaylistElement.MusicFilePath == _BGPlayer.FilePath)
|
||||||
_SongPlayer.Play();
|
{
|
||||||
|
_BGPlayer.Stop();
|
||||||
|
_BGPlayer.Play();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//otherwhise load
|
//otherwhise load
|
||||||
if (_BGMusicFiles.Contains(_CurrentPlaylistElement))
|
if (!_CurrentPlaylistElement.HasMetaData)
|
||||||
_SongPlayer.LoadFile(_CurrentPlaylistElement.MusicFilePath, 0f, true);
|
_BGPlayer.Load(_CurrentPlaylistElement.MusicFilePath, 0f, true);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Seek to #Start-Tag, if found
|
//Seek to #Start-Tag, if found
|
||||||
float start = 0f;
|
float start = 0f;
|
||||||
if (_CurrentPlaylistElement.Start > 0.001 && CConfig.Config.Sound.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
|
if (_CurrentPlaylistElement.Start > 0.001 && CConfig.Config.Sound.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
|
||||||
start = _CurrentPlaylistElement.Start;
|
start = _CurrentPlaylistElement.Start;
|
||||||
_SongPlayer.Load(CBase.Songs.GetSongByID(_CurrentPlaylistElement.SongID), start, true);
|
_BGPlayer.Load(_CurrentPlaylistElement.Song, start, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -224,6 +224,8 @@ namespace Vocaluxe.Base
|
|||||||
NextScreen.ProcessMouseMove(_Cursor.X, _Cursor.Y);
|
NextScreen.ProcessMouseMove(_Cursor.X, _Cursor.Y);
|
||||||
|
|
||||||
HidePopup(EPopupScreens.PopupPlayerControl);
|
HidePopup(EPopupScreens.PopupPlayerControl);
|
||||||
|
if (NextScreen.CurrentMusicType != EMusicType.Background && NextScreen.CurrentMusicType != EMusicType.Preview)
|
||||||
|
CBackgroundMusic.Disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_Fading != null)
|
if (_Fading != null)
|
||||||
@@ -277,6 +279,11 @@ namespace Vocaluxe.Base
|
|||||||
NextScreen = null;
|
NextScreen = null;
|
||||||
CurrentScreen.OnShowFinish();
|
CurrentScreen.OnShowFinish();
|
||||||
CSound.SetGlobalVolume(CConfig.GetVolumeByType(CurrentScreen.CurrentMusicType));
|
CSound.SetGlobalVolume(CConfig.GetVolumeByType(CurrentScreen.CurrentMusicType));
|
||||||
|
if (CurrentScreen.CurrentMusicType == EMusicType.Background || CurrentScreen.CurrentMusicType == EMusicType.Preview)
|
||||||
|
{
|
||||||
|
CBackgroundMusic.Disabled = false;
|
||||||
|
CBackgroundMusic.IsPlayingPreview = CurrentScreen.CurrentMusicType == EMusicType.Preview;
|
||||||
|
}
|
||||||
_Fading = null;
|
_Fading = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,7 +358,7 @@ namespace Vocaluxe.Base
|
|||||||
SKeyEvent inputKeyEvent = new SKeyEvent();
|
SKeyEvent inputKeyEvent = new SKeyEvent();
|
||||||
SMouseEvent inputMouseEvent = new SMouseEvent();
|
SMouseEvent inputMouseEvent = new SMouseEvent();
|
||||||
|
|
||||||
bool popupPlayerControlAllowed = CurrentScreen.CurrentMusicType == EMusicType.Background && !CBackgroundMusic.Disabled;
|
bool popupPlayerControlAllowed = CurrentScreen.CurrentMusicType == EMusicType.Background;
|
||||||
bool popupVolumeControlAllowed = CurrentScreen.CurrentMusicType != EMusicType.None;
|
bool popupVolumeControlAllowed = CurrentScreen.CurrentMusicType != EMusicType.None;
|
||||||
//Hide volume control for bg-music if bg-music is disabled
|
//Hide volume control for bg-music if bg-music is disabled
|
||||||
if (popupVolumeControlAllowed && CurrentScreen.CurrentMusicType == EMusicType.Background && CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_OFF)
|
if (popupVolumeControlAllowed && CurrentScreen.CurrentMusicType == EMusicType.Background && CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_OFF)
|
||||||
|
|||||||
+11
-6
@@ -355,21 +355,21 @@ namespace Vocaluxe.Base
|
|||||||
CBackgroundMusic.Stop();
|
CBackgroundMusic.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadPreview(CSong song, float start = 0f)
|
public void LoadPreview(CSong song, float start = -1f)
|
||||||
{
|
{
|
||||||
CBackgroundMusic.LoadPreview(song, start);
|
CBackgroundMusic.LoadPreview(song, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayPreview(float start = -1f)
|
|
||||||
{
|
|
||||||
CBackgroundMusic.PlayPreview(start);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void StopPreview()
|
public void StopPreview()
|
||||||
{
|
{
|
||||||
CBackgroundMusic.StopPreview();
|
CBackgroundMusic.StopPreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetPlayingPreview(bool playPreview)
|
||||||
|
{
|
||||||
|
CBackgroundMusic.IsPlayingPreview = playPreview;
|
||||||
|
}
|
||||||
|
|
||||||
public CTextureRef GetVideoTexture()
|
public CTextureRef GetVideoTexture()
|
||||||
{
|
{
|
||||||
return CBackgroundMusic.GetVideoTexture();
|
return CBackgroundMusic.GetVideoTexture();
|
||||||
@@ -877,6 +877,11 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
CSound.SetGlobalVolume(volume);
|
CSound.SetGlobalVolume(volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsPaused(int streamID)
|
||||||
|
{
|
||||||
|
return CSound.IsPaused(streamID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CBcover : ICover
|
class CBcover : ICover
|
||||||
|
|||||||
@@ -23,61 +23,70 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
class CPlaylistElement
|
class CPlaylistElement
|
||||||
{
|
{
|
||||||
private readonly CSong _Song;
|
public readonly CSong Song;
|
||||||
private readonly string _MusicFilePath = String.Empty;
|
private readonly string _MusicFilePath = String.Empty;
|
||||||
|
|
||||||
|
public bool HasMetaData
|
||||||
|
{
|
||||||
|
get { return Song != null; }
|
||||||
|
}
|
||||||
|
|
||||||
public int SongID
|
public int SongID
|
||||||
{
|
{
|
||||||
get { return (_Song == null) ? -1 : _Song.ID; }
|
get { return HasMetaData ? Song.ID : -1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string MusicFilePath
|
public string MusicFilePath
|
||||||
{
|
{
|
||||||
get { return _Song != null ? _Song.GetMP3() : _MusicFilePath; }
|
get { return HasMetaData ? Song.GetMP3() : _MusicFilePath; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string VideoFilePath
|
public string VideoFilePath
|
||||||
{
|
{
|
||||||
get { return _Song != null ? _Song.GetVideo() : string.Empty; }
|
get { return HasMetaData ? Song.GetVideo() : string.Empty; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Title
|
public string Title
|
||||||
{
|
{
|
||||||
get { return _Song != null ? _Song.Title : ""; }
|
get { return HasMetaData ? Song.Title : ""; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Artist
|
public string Artist
|
||||||
{
|
{
|
||||||
get { return _Song != null ? _Song.Artist : ""; }
|
get { return HasMetaData ? Song.Artist : ""; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public float Start
|
public float Start
|
||||||
{
|
{
|
||||||
get { return _Song != null ? _Song.Start : 0f; }
|
get { return HasMetaData ? Song.Start : 0f; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public float Finish
|
public float Finish
|
||||||
{
|
{
|
||||||
get { return _Song != null ? _Song.Finish : 0f; }
|
get { return HasMetaData ? Song.Finish : 0f; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public CTextureRef Cover
|
public CTextureRef Cover
|
||||||
{
|
{
|
||||||
get { return _Song != null ? _Song.CoverTextureSmall : CCover.NoCover; }
|
get { return HasMetaData ? Song.CoverTextureSmall : CCover.NoCover; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public float VideoGap
|
public float VideoGap
|
||||||
{
|
{
|
||||||
get { return _Song != null ? _Song.VideoGap : 0; }
|
get { return HasMetaData ? Song.VideoGap : 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPlaylistElement(CSong song)
|
public CPlaylistElement(CSong song)
|
||||||
{
|
{
|
||||||
_Song = song;
|
if (song == null)
|
||||||
|
throw new ArgumentNullException("song");
|
||||||
|
Song = song;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPlaylistElement(string filePath)
|
public CPlaylistElement(string filePath)
|
||||||
{
|
{
|
||||||
|
if (String.IsNullOrEmpty(filePath))
|
||||||
|
throw new ArgumentNullException("filePath");
|
||||||
_MusicFilePath = filePath;
|
_MusicFilePath = filePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace Vocaluxe.Lib.Video
|
|||||||
/// Loads the file with the given file path.
|
/// Loads the file with the given file path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="videoFileName">Absolute file path of the video file</param>
|
/// <param name="videoFileName">Absolute file path of the video file</param>
|
||||||
/// <returns>stream >=0 on success or -1 on failure</returns>
|
/// <returns>Loaded video stream or null on failure</returns>
|
||||||
CVideoStream Load(string videoFileName);
|
CVideoStream Load(string videoFileName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace Vocaluxe.Screens
|
|||||||
if (_Buttons[_ButtonPrevious].Selected)
|
if (_Buttons[_ButtonPrevious].Selected)
|
||||||
CBackgroundMusic.Previous();
|
CBackgroundMusic.Previous();
|
||||||
if (_Buttons[_ButtonPlay].Selected)
|
if (_Buttons[_ButtonPlay].Selected)
|
||||||
CBackgroundMusic.Pause();
|
CBackgroundMusic.Play();
|
||||||
if (_Buttons[_ButtonPause].Selected)
|
if (_Buttons[_ButtonPause].Selected)
|
||||||
CBackgroundMusic.Pause();
|
CBackgroundMusic.Pause();
|
||||||
if (_Buttons[_ButtonRepeat].Selected)
|
if (_Buttons[_ButtonRepeat].Selected)
|
||||||
@@ -140,7 +140,7 @@ namespace Vocaluxe.Screens
|
|||||||
if (_Buttons[_ButtonPrevious].Selected)
|
if (_Buttons[_ButtonPrevious].Selected)
|
||||||
CBackgroundMusic.Previous();
|
CBackgroundMusic.Previous();
|
||||||
if (_Buttons[_ButtonPlay].Selected)
|
if (_Buttons[_ButtonPlay].Selected)
|
||||||
CBackgroundMusic.Pause();
|
CBackgroundMusic.Play();
|
||||||
if (_Buttons[_ButtonPause].Selected)
|
if (_Buttons[_ButtonPause].Selected)
|
||||||
CBackgroundMusic.Pause();
|
CBackgroundMusic.Pause();
|
||||||
if (_Buttons[_ButtonRepeat].Selected)
|
if (_Buttons[_ButtonRepeat].Selected)
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ namespace Vocaluxe.Screens
|
|||||||
private bool _AvatarsChanged;
|
private bool _AvatarsChanged;
|
||||||
private bool _ProfilesChanged;
|
private bool _ProfilesChanged;
|
||||||
|
|
||||||
|
public override EMusicType CurrentMusicType
|
||||||
|
{
|
||||||
|
get { return EMusicType.Preview; }
|
||||||
|
}
|
||||||
|
|
||||||
#region public methods
|
#region public methods
|
||||||
public override void Init()
|
public override void Init()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -303,7 +303,6 @@ namespace Vocaluxe.Screens
|
|||||||
public override void OnShowFinish()
|
public override void OnShowFinish()
|
||||||
{
|
{
|
||||||
base.OnShowFinish();
|
base.OnShowFinish();
|
||||||
CBackgroundMusic.Disabled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
@@ -332,7 +331,6 @@ namespace Vocaluxe.Screens
|
|||||||
CRecord.Stop();
|
CRecord.Stop();
|
||||||
|
|
||||||
_DelayTest.Reset();
|
_DelayTest.Reset();
|
||||||
CBackgroundMusic.Disabled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _OnDeviceEvent()
|
private void _OnDeviceEvent()
|
||||||
|
|||||||
@@ -124,8 +124,6 @@ namespace Vocaluxe.Screens
|
|||||||
|
|
||||||
public override void OnShow()
|
public override void OnShow()
|
||||||
{
|
{
|
||||||
CBackgroundMusic.Disabled = false;
|
|
||||||
|
|
||||||
base.OnShow();
|
base.OnShow();
|
||||||
//-1 --> Show average
|
//-1 --> Show average
|
||||||
_Round = CGame.NumRounds > 1 ? -1 : 0;
|
_Round = CGame.NumRounds > 1 ? -1 : 0;
|
||||||
|
|||||||
@@ -413,7 +413,6 @@ namespace Vocaluxe.Screens
|
|||||||
public override void OnShowFinish()
|
public override void OnShowFinish()
|
||||||
{
|
{
|
||||||
base.OnShowFinish();
|
base.OnShowFinish();
|
||||||
CBackgroundMusic.Disabled = true;
|
|
||||||
|
|
||||||
CGame.Start();
|
CGame.Start();
|
||||||
_LoadNextSong();
|
_LoadNextSong();
|
||||||
|
|||||||
+11
-10
@@ -121,9 +121,9 @@ namespace VocaluxeLib
|
|||||||
|
|
||||||
CTextureRef GetVideoTexture();
|
CTextureRef GetVideoTexture();
|
||||||
|
|
||||||
void LoadPreview(CSong song, float start = 0f);
|
void LoadPreview(CSong song, float start = -1f);
|
||||||
void PlayPreview(float start = -1f);
|
|
||||||
void StopPreview();
|
void StopPreview();
|
||||||
|
void SetPlayingPreview(bool playPreview);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IDrawing
|
public interface IDrawing
|
||||||
@@ -266,17 +266,18 @@ namespace VocaluxeLib
|
|||||||
public interface ISound
|
public interface ISound
|
||||||
{
|
{
|
||||||
int Load(string soundFile, bool loop = false, bool prescan = false);
|
int Load(string soundFile, bool loop = false, bool prescan = false);
|
||||||
void SetPosition(int soundStream, float newPosition);
|
void SetPosition(int streamID, float newPosition);
|
||||||
void Play(int soundStream);
|
void Play(int streamID);
|
||||||
void Fade(int soundStream, int targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing);
|
void Fade(int streamID, int targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing);
|
||||||
void Close(int soundStream);
|
void Close(int streamID);
|
||||||
|
|
||||||
bool IsFinished(int soundStream);
|
bool IsFinished(int streamID);
|
||||||
float GetPosition(int soundStream);
|
float GetPosition(int streamID);
|
||||||
float GetLength(int soundStream);
|
float GetLength(int streamID);
|
||||||
|
|
||||||
void SetStreamVolume(int soundStream, int volume);
|
void SetStreamVolume(int streamID, int volume);
|
||||||
void SetGlobalVolume(int volume);
|
void SetGlobalVolume(int volume);
|
||||||
|
bool IsPaused(int streamID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ICover
|
public interface ICover
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
else if (value >= CBase.Songs.GetNumCategories())
|
else if (value >= CBase.Songs.GetNumCategories())
|
||||||
{
|
{
|
||||||
value = -1;
|
value = -1;
|
||||||
CBase.BackgroundMusic.Stop();
|
CBase.BackgroundMusic.SetPlayingPreview(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
_PreviewNrInternal = value;
|
_PreviewNrInternal = value;
|
||||||
@@ -371,7 +371,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
CBase.BackgroundMusic.StopPreview();
|
CBase.BackgroundMusic.StopPreview();
|
||||||
|
CBase.Sound.SetGlobalVolume(CBase.Config.GetMusicVolume(EMusicType.Background));
|
||||||
if (playBGagain)
|
if (playBGagain)
|
||||||
CBase.BackgroundMusic.Play();
|
CBase.BackgroundMusic.Play();
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
if (value == base._PreviewNr)
|
if (value == base._PreviewNr)
|
||||||
{
|
{
|
||||||
if (!CBase.BackgroundMusic.IsPlaying() && value != -1)
|
if (!CBase.BackgroundMusic.IsPlaying() && value != -1)
|
||||||
CBase.BackgroundMusic.PlayPreview();
|
CBase.BackgroundMusic.Play();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
base._PreviewNr = value;
|
base._PreviewNr = value;
|
||||||
|
|||||||
@@ -39,28 +39,32 @@ namespace VocaluxeLib.Utils.Player
|
|||||||
_VideoEnabled = value;
|
_VideoEnabled = value;
|
||||||
if (_VideoEnabled)
|
if (_VideoEnabled)
|
||||||
_LoadVideo();
|
_LoadVideo();
|
||||||
else if (_Video != null)
|
else
|
||||||
CBase.Video.Close(ref _Video);
|
_CloseVideo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int SongID
|
public int SongID
|
||||||
{
|
{
|
||||||
get { return _Song == null ? -1 : _Song.ID; }
|
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
|
public bool SongHasVideo
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_Song == null)
|
return _Song != null && !String.IsNullOrEmpty(_Song.Folder) && !String.IsNullOrEmpty(_Song.VideoFileName) &&
|
||||||
return "";
|
File.Exists(Path.Combine(_Song.Folder, _Song.VideoFileName));
|
||||||
if (_Song.Artist != "" && _Song.Title != "")
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ArtistAndTitle
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_Song != null && !String.IsNullOrEmpty(_Song.Artist) && !String.IsNullOrEmpty(_Song.Title))
|
||||||
return _Song.Artist + " - " + _Song.Title;
|
return _Song.Artist + " - " + _Song.Title;
|
||||||
return Path.GetFileNameWithoutExtension(_Song.MP3FileName);
|
return base.ArtistAndTitle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,26 +73,8 @@ namespace VocaluxeLib.Utils.Player
|
|||||||
get { return _Song == null ? CBase.Cover.GetNoCover() : _Song.CoverTextureBig; }
|
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(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 CSongPlayer(string file, bool loop = false, float position = 0f, bool autoplay = false)
|
|
||||||
: base(file, loop, position, autoplay)
|
|
||||||
{
|
|
||||||
_Song = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CTextureRef GetVideoTexture()
|
public CTextureRef GetVideoTexture()
|
||||||
{
|
{
|
||||||
if (_Video == null || _Song == null)
|
if (_Video == null || _Song == null)
|
||||||
@@ -110,49 +96,11 @@ namespace VocaluxeLib.Utils.Player
|
|||||||
public void Load(CSong song, float position = 0f, bool autoplay = false)
|
public void Load(CSong song, float position = 0f, bool autoplay = false)
|
||||||
{
|
{
|
||||||
if (song == null)
|
if (song == null)
|
||||||
return;
|
throw new ArgumentNullException("song");
|
||||||
|
|
||||||
Stop();
|
Load(song.GetMP3(), position, autoplay);
|
||||||
|
|
||||||
_Song = song;
|
|
||||||
|
|
||||||
Load(Path.Combine(song.Folder, song.MP3FileName), position, autoplay);
|
|
||||||
_LoadVideo();
|
_LoadVideo();
|
||||||
|
_Song = song;
|
||||||
if (autoplay)
|
|
||||||
Play();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LoadFile(string file, float position = 0f, bool autoplay = false)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(file))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Stop();
|
|
||||||
|
|
||||||
Load(file, position, autoplay);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Stop()
|
|
||||||
{
|
|
||||||
base.Stop();
|
|
||||||
|
|
||||||
_Song = null;
|
|
||||||
|
|
||||||
if (_Video != null)
|
|
||||||
CBase.Video.Close(ref _Video);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void TogglePause()
|
|
||||||
{
|
|
||||||
if (IsPlaying && _Video != null)
|
|
||||||
{
|
|
||||||
CBase.Video.Pause(_Video);
|
|
||||||
CBase.Video.Skip(_Video, CBase.Sound.GetPosition(_StreamID) + _FadeTime, _Song.VideoGap);
|
|
||||||
}
|
|
||||||
else if (_Video != null)
|
|
||||||
CBase.Video.Resume(_Video);
|
|
||||||
base.TogglePause();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _LoadVideo()
|
private void _LoadVideo()
|
||||||
@@ -160,11 +108,13 @@ namespace VocaluxeLib.Utils.Player
|
|||||||
if (_Song == null)
|
if (_Song == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string videoFilePath = Path.Combine(_Song.Folder, _Song.VideoFileName);
|
if (_Video != null || !SongHasVideo)
|
||||||
if (_Video != null || String.IsNullOrEmpty(videoFilePath))
|
|
||||||
return;
|
return;
|
||||||
|
string videoFilePath = Path.Combine(_Song.Folder, _Song.VideoFileName);
|
||||||
_Video = CBase.Video.Load(videoFilePath);
|
_Video = CBase.Video.Load(videoFilePath);
|
||||||
CBase.Video.Skip(_Video, 0f, _Song.VideoGap); //Use gap, otherwhise we will overwrite position in GetVideoTexture
|
if (_Video == null)
|
||||||
|
return;
|
||||||
|
|
||||||
_VideoFading = new CFading(0f, 1f, 3f);
|
_VideoFading = new CFading(0f, 1f, 3f);
|
||||||
|
|
||||||
if (IsPlaying)
|
if (IsPlaying)
|
||||||
@@ -172,6 +122,57 @@ namespace VocaluxeLib.Utils.Player
|
|||||||
CBase.Video.Skip(_Video, Position, _Song.VideoGap);
|
CBase.Video.Skip(_Video, Position, _Song.VideoGap);
|
||||||
CBase.Video.Resume(_Video);
|
CBase.Video.Resume(_Video);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
CBase.Video.Skip(_Video, 0f, _Song.VideoGap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Play()
|
||||||
|
{
|
||||||
|
if (!base.Play())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (_Video != null)
|
||||||
|
{
|
||||||
|
CBase.Video.Skip(_Video, Position, _Song.VideoGap);
|
||||||
|
CBase.Video.Resume(_Video);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Pause()
|
||||||
|
{
|
||||||
|
if (!base.Pause())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (_Video != null)
|
||||||
|
CBase.Video.Pause(_Video);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Stop()
|
||||||
|
{
|
||||||
|
if (!base.Stop())
|
||||||
|
return false;
|
||||||
|
if (_Video != null)
|
||||||
|
{
|
||||||
|
CBase.Video.Pause(_Video);
|
||||||
|
CBase.Video.Skip(_Video, 0f, _Song.VideoGap);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _CloseVideo()
|
||||||
|
{
|
||||||
|
if (_Video != null)
|
||||||
|
CBase.Video.Close(ref _Video);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Close()
|
||||||
|
{
|
||||||
|
base.Close();
|
||||||
|
|
||||||
|
_Song = null;
|
||||||
|
_CloseVideo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,58 +15,52 @@
|
|||||||
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace VocaluxeLib.Utils.Player
|
namespace VocaluxeLib.Utils.Player
|
||||||
{
|
{
|
||||||
public class CSoundPlayer
|
public class CSoundPlayer
|
||||||
{
|
{
|
||||||
protected int _StreamID = -1;
|
protected int _StreamID = -1;
|
||||||
protected int _Volume = 100;
|
|
||||||
protected float _StartPosition;
|
|
||||||
protected readonly float _FadeTime = CBase.Settings.GetSoundPlayerFadeTime();
|
protected readonly float _FadeTime = CBase.Settings.GetSoundPlayerFadeTime();
|
||||||
|
public string FilePath { get; private set; }
|
||||||
|
|
||||||
public int Volume
|
|
||||||
{
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_Volume = value;
|
|
||||||
_ApplyVolume();
|
|
||||||
}
|
|
||||||
get { return _Volume; }
|
|
||||||
}
|
|
||||||
public bool Loop;
|
public bool Loop;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current stream position or sets it
|
||||||
|
/// </summary>
|
||||||
public float Position
|
public float Position
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (_StreamID == -1)
|
if (!SoundLoaded)
|
||||||
return;
|
return;
|
||||||
_StartPosition = value;
|
CBase.Sound.SetPosition(_StreamID, value);
|
||||||
}
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_StreamID == -1)
|
|
||||||
return -1;
|
|
||||||
return CBase.Sound.GetPosition(_StreamID);
|
|
||||||
}
|
}
|
||||||
|
get { return !SoundLoaded ? -1 : CBase.Sound.GetPosition(_StreamID); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public float Length
|
public float Length
|
||||||
{
|
{
|
||||||
get
|
get { return !SoundLoaded ? -1 : CBase.Sound.GetLength(_StreamID); }
|
||||||
{
|
|
||||||
if (_StreamID == -1)
|
|
||||||
return 0;
|
|
||||||
return CBase.Sound.GetLength(_StreamID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RepeatSong;
|
public bool IsPlaying { get; private set; }
|
||||||
public bool IsPlaying { get; protected set; }
|
|
||||||
|
|
||||||
public bool IsFinished
|
public bool IsFinished
|
||||||
{
|
{
|
||||||
get { return !RepeatSong && CBase.Sound.IsFinished(_StreamID); }
|
get { return !Loop && CBase.Sound.IsFinished(_StreamID); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SoundLoaded
|
||||||
|
{
|
||||||
|
get { return _StreamID != -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual string ArtistAndTitle
|
||||||
|
{
|
||||||
|
get { return string.IsNullOrEmpty(FilePath) ? "" : Path.GetFileNameWithoutExtension(FilePath); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public CSoundPlayer(bool loop = false)
|
public CSoundPlayer(bool loop = false)
|
||||||
@@ -74,95 +68,97 @@ namespace VocaluxeLib.Utils.Player
|
|||||||
Loop = loop;
|
Loop = loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CSoundPlayer(string file, bool loop = false, float position = 0f, bool autoplay = false)
|
public void Load(string file, float position = -1f, bool autoplay = false)
|
||||||
{
|
{
|
||||||
_StreamID = CBase.Sound.Load(file, false, true);
|
Close();
|
||||||
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);
|
_StreamID = CBase.Sound.Load(file, false, true);
|
||||||
if (position > 0f)
|
if (_StreamID < 0)
|
||||||
Position = position;
|
|
||||||
if (autoplay)
|
|
||||||
Play();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Play()
|
|
||||||
{
|
|
||||||
if (_StreamID == -1 || IsPlaying)
|
|
||||||
return;
|
return;
|
||||||
|
FilePath = file;
|
||||||
|
if (position > 0f)
|
||||||
|
Position = position;
|
||||||
|
if (autoplay)
|
||||||
|
Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts or resumes the player
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>True if state changed, false if nothing loaded or already playing</returns>
|
||||||
|
public virtual bool Play()
|
||||||
|
{
|
||||||
|
if (!SoundLoaded || IsPlaying)
|
||||||
|
return false;
|
||||||
|
|
||||||
CBase.Sound.SetPosition(_StreamID, _StartPosition);
|
|
||||||
CBase.Sound.SetStreamVolume(_StreamID, 0);
|
CBase.Sound.SetStreamVolume(_StreamID, 0);
|
||||||
CBase.Sound.Fade(_StreamID, Volume, _FadeTime);
|
CBase.Sound.Fade(_StreamID, 100, _FadeTime);
|
||||||
CBase.Sound.Play(_StreamID);
|
CBase.Sound.Play(_StreamID);
|
||||||
IsPlaying = true;
|
IsPlaying = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void TogglePause()
|
/// <summary>
|
||||||
|
/// Pauses the player
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>True if state changed, false if nothing loaded or already paused</returns>
|
||||||
|
public virtual bool Pause()
|
||||||
{
|
{
|
||||||
if (_StreamID == -1)
|
if (!SoundLoaded || CBase.Sound.IsPaused(_StreamID))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
if (IsPlaying)
|
CBase.Sound.Fade(_StreamID, 0, _FadeTime, EStreamAction.Pause);
|
||||||
CBase.Sound.Fade(_StreamID, 0, _FadeTime, EStreamAction.Pause);
|
IsPlaying = false;
|
||||||
else
|
return true;
|
||||||
{
|
|
||||||
CBase.Sound.Fade(_StreamID, Volume, _FadeTime);
|
|
||||||
CBase.Sound.Play(_StreamID);
|
|
||||||
}
|
|
||||||
|
|
||||||
IsPlaying = !IsPlaying;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Stop()
|
/// <summary>
|
||||||
|
/// Stops the player (no playback and position is set to start)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>True if playback was stopped</returns>
|
||||||
|
public virtual bool Stop()
|
||||||
{
|
{
|
||||||
if (_StreamID == -1 || !IsPlaying)
|
if (!SoundLoaded)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CBase.Sound.Fade(_StreamID, 0, _FadeTime, EStreamAction.Stop);
|
||||||
|
IsPlaying = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Close()
|
||||||
|
{
|
||||||
|
if (!SoundLoaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CBase.Sound.Fade(_StreamID, 0, _FadeTime, EStreamAction.Close);
|
CBase.Sound.Fade(_StreamID, 0, _FadeTime, EStreamAction.Close);
|
||||||
_StreamID = -1;
|
_StreamID = -1;
|
||||||
|
FilePath = "";
|
||||||
IsPlaying = false;
|
IsPlaying = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
if (_StreamID == -1 || !IsPlaying)
|
if (!IsPlaying)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
bool finished = CBase.Sound.IsFinished(_StreamID);
|
||||||
|
if (Loop)
|
||||||
|
{
|
||||||
|
if (finished)
|
||||||
|
{
|
||||||
|
// Restart
|
||||||
|
Stop();
|
||||||
|
Play();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
float len = CBase.Sound.GetLength(_StreamID);
|
float len = CBase.Sound.GetLength(_StreamID);
|
||||||
float timeToPlay = (len > 0f) ? len - CBase.Sound.GetPosition(_StreamID) : _FadeTime + 1f;
|
float timeToPlay = (len > 0f) ? len - CBase.Sound.GetPosition(_StreamID) : _FadeTime + 1f;
|
||||||
|
|
||||||
bool finished = CBase.Sound.IsFinished(_StreamID);
|
|
||||||
if (timeToPlay <= _FadeTime || finished)
|
if (timeToPlay <= _FadeTime || finished)
|
||||||
{
|
Stop();
|
||||||
if (RepeatSong)
|
|
||||||
{
|
|
||||||
//Set to false for restarting
|
|
||||||
IsPlaying = false;
|
|
||||||
Play();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void _ApplyVolume()
|
|
||||||
{
|
|
||||||
if (_StreamID == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
CBase.Sound.SetStreamVolume(_StreamID, Volume);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user