commit
3f2a794952
22 files changed
+372
-402
No files matched your search
+11
-10
@@ -121,9 +121,9 @@ namespace VocaluxeLib
|
||||
|
||||
CTextureRef GetVideoTexture();
|
||||
|
||||
void LoadPreview(CSong song, float start = 0f);
|
||||
void PlayPreview(float start = -1f);
|
||||
void LoadPreview(CSong song, float start = -1f);
|
||||
void StopPreview();
|
||||
void SetPlayingPreview(bool playPreview);
|
||||
}
|
||||
|
||||
public interface IDrawing
|
||||
@@ -266,17 +266,18 @@ namespace VocaluxeLib
|
||||
public interface ISound
|
||||
{
|
||||
int Load(string soundFile, bool loop = false, bool prescan = false);
|
||||
void SetPosition(int soundStream, float newPosition);
|
||||
void Play(int soundStream);
|
||||
void Fade(int soundStream, int targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing);
|
||||
void Close(int soundStream);
|
||||
void SetPosition(int streamID, float newPosition);
|
||||
void Play(int streamID);
|
||||
void Fade(int streamID, int targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing);
|
||||
void Close(int streamID);
|
||||
|
||||
bool IsFinished(int soundStream);
|
||||
float GetPosition(int soundStream);
|
||||
float GetLength(int soundStream);
|
||||
bool IsFinished(int streamID);
|
||||
float GetPosition(int streamID);
|
||||
float GetLength(int streamID);
|
||||
|
||||
void SetStreamVolume(int soundStream, int volume);
|
||||
void SetStreamVolume(int streamID, int volume);
|
||||
void SetGlobalVolume(int volume);
|
||||
bool IsPaused(int streamID);
|
||||
}
|
||||
|
||||
public interface ICover
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
||||
else if (value >= CBase.Songs.GetNumCategories())
|
||||
{
|
||||
value = -1;
|
||||
CBase.BackgroundMusic.Stop();
|
||||
CBase.BackgroundMusic.SetPlayingPreview(false);
|
||||
}
|
||||
|
||||
_PreviewNrInternal = value;
|
||||
@@ -371,7 +371,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
||||
return;
|
||||
|
||||
CBase.BackgroundMusic.StopPreview();
|
||||
|
||||
CBase.Sound.SetGlobalVolume(CBase.Config.GetMusicVolume(EMusicType.Background));
|
||||
if (playBGagain)
|
||||
CBase.BackgroundMusic.Play();
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
||||
if (value == base._PreviewNr)
|
||||
{
|
||||
if (!CBase.BackgroundMusic.IsPlaying() && value != -1)
|
||||
CBase.BackgroundMusic.PlayPreview();
|
||||
CBase.BackgroundMusic.Play();
|
||||
return;
|
||||
}
|
||||
base._PreviewNr = value;
|
||||
|
||||
@@ -39,28 +39,32 @@ namespace VocaluxeLib.Utils.Player
|
||||
_VideoEnabled = value;
|
||||
if (_VideoEnabled)
|
||||
_LoadVideo();
|
||||
else if (_Video != null)
|
||||
CBase.Video.Close(ref _Video);
|
||||
else
|
||||
_CloseVideo();
|
||||
}
|
||||
}
|
||||
|
||||
public int SongID
|
||||
{
|
||||
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
|
||||
{
|
||||
if (_Song == null)
|
||||
return "";
|
||||
if (_Song.Artist != "" && _Song.Title != "")
|
||||
return _Song != null && !String.IsNullOrEmpty(_Song.Folder) && !String.IsNullOrEmpty(_Song.VideoFileName) &&
|
||||
File.Exists(Path.Combine(_Song.Folder, _Song.VideoFileName));
|
||||
}
|
||||
}
|
||||
|
||||
public override string ArtistAndTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Song != null && !String.IsNullOrEmpty(_Song.Artist) && !String.IsNullOrEmpty(_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; }
|
||||
}
|
||||
|
||||
public bool SongLoaded
|
||||
{
|
||||
get { return _StreamID != -1; }
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
if (_Video == null || _Song == null)
|
||||
@@ -110,49 +96,11 @@ namespace VocaluxeLib.Utils.Player
|
||||
public void Load(CSong song, float position = 0f, bool autoplay = false)
|
||||
{
|
||||
if (song == null)
|
||||
return;
|
||||
throw new ArgumentNullException("song");
|
||||
|
||||
Stop();
|
||||
|
||||
_Song = song;
|
||||
|
||||
Load(Path.Combine(song.Folder, song.MP3FileName), position, autoplay);
|
||||
Load(song.GetMP3(), position, autoplay);
|
||||
_LoadVideo();
|
||||
|
||||
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();
|
||||
_Song = song;
|
||||
}
|
||||
|
||||
private void _LoadVideo()
|
||||
@@ -160,11 +108,13 @@ namespace VocaluxeLib.Utils.Player
|
||||
if (_Song == null)
|
||||
return;
|
||||
|
||||
string videoFilePath = Path.Combine(_Song.Folder, _Song.VideoFileName);
|
||||
if (_Video != null || String.IsNullOrEmpty(videoFilePath))
|
||||
if (_Video != null || !SongHasVideo)
|
||||
return;
|
||||
string videoFilePath = Path.Combine(_Song.Folder, _Song.VideoFileName);
|
||||
_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);
|
||||
|
||||
if (IsPlaying)
|
||||
@@ -172,6 +122,57 @@ namespace VocaluxeLib.Utils.Player
|
||||
CBase.Video.Skip(_Video, Position, _Song.VideoGap);
|
||||
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/>.
|
||||
#endregion
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace VocaluxeLib.Utils.Player
|
||||
{
|
||||
public class CSoundPlayer
|
||||
{
|
||||
protected int _StreamID = -1;
|
||||
protected int _Volume = 100;
|
||||
protected float _StartPosition;
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current stream position or sets it
|
||||
/// </summary>
|
||||
public float Position
|
||||
{
|
||||
set
|
||||
{
|
||||
if (_StreamID == -1)
|
||||
if (!SoundLoaded)
|
||||
return;
|
||||
_StartPosition = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
if (_StreamID == -1)
|
||||
return -1;
|
||||
return CBase.Sound.GetPosition(_StreamID);
|
||||
CBase.Sound.SetPosition(_StreamID, value);
|
||||
}
|
||||
get { return !SoundLoaded ? -1 : CBase.Sound.GetPosition(_StreamID); }
|
||||
}
|
||||
|
||||
public float Length
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_StreamID == -1)
|
||||
return 0;
|
||||
return CBase.Sound.GetLength(_StreamID);
|
||||
}
|
||||
get { return !SoundLoaded ? -1 : CBase.Sound.GetLength(_StreamID); }
|
||||
}
|
||||
|
||||
public bool RepeatSong;
|
||||
public bool IsPlaying { get; protected set; }
|
||||
public bool IsPlaying { get; private set; }
|
||||
|
||||
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)
|
||||
@@ -74,95 +68,97 @@ namespace VocaluxeLib.Utils.Player
|
||||
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);
|
||||
if (position > 0f)
|
||||
Position = position;
|
||||
Loop = loop;
|
||||
if (autoplay)
|
||||
Play();
|
||||
}
|
||||
|
||||
public void Load(string file, float position = 0f, bool autoplay = false)
|
||||
{
|
||||
if (IsPlaying)
|
||||
Stop();
|
||||
Close();
|
||||
|
||||
_StreamID = CBase.Sound.Load(file, false, true);
|
||||
if (position > 0f)
|
||||
Position = position;
|
||||
if (autoplay)
|
||||
Play();
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (_StreamID == -1 || IsPlaying)
|
||||
if (_StreamID < 0)
|
||||
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.Fade(_StreamID, Volume, _FadeTime);
|
||||
CBase.Sound.Fade(_StreamID, 100, _FadeTime);
|
||||
CBase.Sound.Play(_StreamID);
|
||||
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)
|
||||
return;
|
||||
if (!SoundLoaded || CBase.Sound.IsPaused(_StreamID))
|
||||
return false;
|
||||
|
||||
if (IsPlaying)
|
||||
CBase.Sound.Fade(_StreamID, 0, _FadeTime, EStreamAction.Pause);
|
||||
else
|
||||
{
|
||||
CBase.Sound.Fade(_StreamID, Volume, _FadeTime);
|
||||
CBase.Sound.Play(_StreamID);
|
||||
}
|
||||
|
||||
IsPlaying = !IsPlaying;
|
||||
CBase.Sound.Fade(_StreamID, 0, _FadeTime, EStreamAction.Pause);
|
||||
IsPlaying = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
CBase.Sound.Fade(_StreamID, 0, _FadeTime, EStreamAction.Close);
|
||||
_StreamID = -1;
|
||||
|
||||
FilePath = "";
|
||||
IsPlaying = false;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (_StreamID == -1 || !IsPlaying)
|
||||
if (!IsPlaying)
|
||||
return;
|
||||
|
||||
bool finished = CBase.Sound.IsFinished(_StreamID);
|
||||
if (Loop)
|
||||
{
|
||||
if (finished)
|
||||
{
|
||||
// Restart
|
||||
Stop();
|
||||
Play();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
float len = CBase.Sound.GetLength(_StreamID);
|
||||
float timeToPlay = (len > 0f) ? len - CBase.Sound.GetPosition(_StreamID) : _FadeTime + 1f;
|
||||
|
||||
bool finished = CBase.Sound.IsFinished(_StreamID);
|
||||
if (timeToPlay <= _FadeTime || finished)
|
||||
{
|
||||
if (RepeatSong)
|
||||
{
|
||||
//Set to false for restarting
|
||||
IsPlaying = false;
|
||||
Play();
|
||||
}
|
||||
else
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void _ApplyVolume()
|
||||
{
|
||||
if (_StreamID == -1)
|
||||
return;
|
||||
|
||||
CBase.Sound.SetStreamVolume(_StreamID, Volume);
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace VocaluxeLib.Xml
|
||||
/// <param name="type">Type of the value</param>
|
||||
/// <param name="value">Object to write</param>
|
||||
/// <param name="isAttribute">When true, value will be written as an attribute to the currently open node, otherwhise it will create a new node</param>
|
||||
/// <param name="arrayItemName">>Name of the sub nodes for array types(Array,List,Dictionary), can be set by XmlArrayItemAttribute and defaults to the type name</param>
|
||||
/// <param name="arrayItemName">Name of the sub nodes for array types(Array,List,Dictionary), can be set by XmlArrayItemAttribute and defaults to the type name</param>
|
||||
/// <param name="nameAttribute">If set, an attribute 'name' with this value will be written</param>
|
||||
private void _WriteValue(XmlWriter writer, string name, Type type, object value, bool isAttribute, string arrayItemName = null, string nameAttribute = null)
|
||||
{
|
||||
@@ -165,8 +165,14 @@ namespace VocaluxeLib.Xml
|
||||
if (field.IsEmbeddedList)
|
||||
{
|
||||
IEnumerable values = (IEnumerable)value;
|
||||
bool empty = true;
|
||||
foreach (object subValue in values)
|
||||
{
|
||||
_WriteValue(writer, field.Name, field.SubType, subValue, field.IsAttribute);
|
||||
empty = false;
|
||||
}
|
||||
if (empty && _WriteDefaults)
|
||||
writer.WriteElementString(field.Name, "");
|
||||
}
|
||||
else if (field.IsByteArray)
|
||||
writer.WriteElementString(field.Name, Convert.ToBase64String((byte[])value));
|
||||
|
||||
Reference in new issue
Block a user