Merge branch 'Font_Rewrite' into Automatic_Covers

This commit is contained in:
Flamefire committed 2014-09-10 17:19:25 +02:00
commit eaa709813d
40 files changed
+1238 -845

No files matched your search

+87
View File
@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
namespace VocaluxeLib
{
public interface IFontObserver
{
void FontChanged();
}
public class CFont
{
private string _Name;
private EStyle _Style;
private float _Height;
private readonly List<IFontObserver> _Observers = new List<IFontObserver>();
public string Name
{
get { return _Name; }
set
{
if (_Name == value)
return;
_Name = value;
foreach (IFontObserver observer in _Observers)
observer.FontChanged();
}
}
public EStyle Style
{
get { return _Style; }
set
{
if (_Style == value)
return;
_Style = value;
foreach (IFontObserver observer in _Observers)
observer.FontChanged();
}
}
public float Height
{
get { return _Height; }
set
{
if (Math.Abs(_Height - value) < 0.001)
return;
_Height = value;
foreach (IFontObserver observer in _Observers)
observer.FontChanged();
}
}
public CFont()
{
_Name = "Normal";
_Style = EStyle.Normal;
_Height = 25f;
}
public CFont(CFont font)
{
_Name = font.Name;
_Style = font.Style;
_Height = font.Height;
}
public CFont(string fontFamily, EStyle style, float h)
{
_Name = fontFamily;
_Style = style;
_Height = h;
}
public void AddObserver(IFontObserver observer)
{
if (!_Observers.Contains(observer))
_Observers.Add(observer);
}
public void RemoveObserver(IFontObserver observer)
{
_Observers.Remove(observer);
}
}
}
+6
View File
@@ -64,6 +64,12 @@ namespace VocaluxeLib
return (int)result;
}
public static bool InRange<T>(this T val, T min, T max) where T : IComparable<T>
{
Debug.Assert(min.CompareTo(max) <= 0);
return val.CompareTo(min) >= 0 && val.CompareTo(max) <= 0;
}
/// <summary>
/// Makes sure val is between min and max
/// Asserts that min&lt;=max
+16 -11
View File
@@ -88,20 +88,25 @@ namespace VocaluxeLib
return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value);
}
/// <summary>
/// Gets a normalized (0&lt;=x&lt;=1) float value
/// </summary>
/// <param name="xPath"></param>
/// <param name="value"></param>
/// <returns>True if exists and is normalized</returns>
public bool TryGetNormalizedFloatValue(string xPath, ref float value)
{
string val;
return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value) && value.InRange(0f, 1f);
}
public bool TryGetColorFromRGBA(string xPath, ref SColorF value)
{
bool result = true;
result &= TryGetFloatValue(xPath + "/R", ref value.R);
result &= TryGetFloatValue(xPath + "/G", ref value.G);
result &= TryGetFloatValue(xPath + "/B", ref value.B);
result &= TryGetFloatValue(xPath + "/A", ref value.A);
if (result)
{
value.R = value.R.Clamp(0f, 1f);
value.G = value.G.Clamp(0f, 1f);
value.B = value.B.Clamp(0f, 1f);
value.A = value.A.Clamp(0f, 1f);
}
result &= TryGetNormalizedFloatValue(xPath + "/R", ref value.R);
result &= TryGetNormalizedFloatValue(xPath + "/G", ref value.G);
result &= TryGetNormalizedFloatValue(xPath + "/B", ref value.B);
result &= TryGetNormalizedFloatValue(xPath + "/A", ref value.A);
return result;
}
+15
View File
@@ -248,6 +248,13 @@ namespace VocaluxeLib
// ReSharper restore InconsistentNaming
}
public enum EBackgroundMusicOffOn
{
TR_CONFIG_OFF,
TR_CONFIG_ONLY_SONG,
TR_CONFIG_ON
}
public enum EPlayerInfo
{
// ReSharper disable InconsistentNaming
@@ -288,6 +295,14 @@ namespace VocaluxeLib
}
#endregion Config
public enum EStreamAction
{
Nothing,
Pause,
Stop,
Close
}
public enum EProgramState
{
Start,
+34 -9
View File
@@ -35,6 +35,8 @@ namespace VocaluxeLib
void SetBackgroundMusicVolume(int newVolume);
int GetBackgroundMusicVolume();
EBackgroundMusicOffOn GetBackgroundMusicStatus();
int GetPreviewMusicVolume();
EOffOn GetVideosToBackground();
@@ -89,6 +91,8 @@ namespace VocaluxeLib
float GetSlideShowImageTime();
float GetSlideShowFadeTime();
float GetSoundPlayerFadeTime();
}
public interface ITheme
@@ -115,16 +119,24 @@ namespace VocaluxeLib
{
bool IsDisabled();
bool IsPlaying();
bool IsPlayingPreview();
bool SongHasVideo();
bool VideoEnabled();
float GetLength();
void SetDisabled(bool disabled);
void Next();
void Previous();
void Pause();
void Play();
void Stop();
CTexture GetVideoTexture();
void LoadPreview(CSong song, float start = 0f);
void PlayPreview(float start = -1f);
void StopPreview();
}
public interface IDrawing
@@ -148,6 +160,8 @@ namespace VocaluxeLib
void FadeTo(EScreens nextScreen);
float GetGlobalAlpha();
EScreens GetNextScreen();
}
public interface ILog
@@ -159,15 +173,11 @@ namespace VocaluxeLib
public interface IFonts
{
void SetFont(string fontName);
void SetStyle(EStyle fontStyle);
RectangleF GetTextBounds(CText text);
RectangleF GetTextBounds(CText text, float textHeight);
void DrawText(string text, float textHeight, float x, float y, float z, SColorF color);
void DrawTextReflection(string text, float textHeight, float x, float y, float z, SColorF color, float reflectionSpace, float reflectionHeight);
void DrawText(string text, float textHeight, float x, float y, float z, SColorF color, float begin, float end);
void DrawText(string text, CFont font, float x, float y, float z, SColorF color);
void DrawTextReflection(string text, CFont font, float x, float y, float z, SColorF color, float reflectionSpace, float reflectionHeight);
void DrawText(string text, CFont font, float x, float y, float z, SColorF color, float begin, float end);
}
public interface ILanguage
@@ -255,6 +265,8 @@ namespace VocaluxeLib
bool IsFinished(int streamID);
bool Close(int streamID);
void SetLoop(int streamID, bool loop = true);
void Resume(int streamID);
void Pause(int streamID);
}
public interface ISound
@@ -262,12 +274,12 @@ namespace VocaluxeLib
int Load(string soundFile, bool loop = false, bool prescan = false);
void SetPosition(int soundStream, float newPosition);
void Play(int soundStream);
void Fade(int soundStream, float targetVolume, float duration);
void Fade(int soundStream, float targetVolume, float duration, EStreamAction afterFadeAction = EStreamAction.Nothing);
void Close(int soundStream);
bool IsFinished(int soundStream);
float GetPosition(int soundStream);
float GetLength(int soundStream);
void FadeAndClose(int soundStream, float targetVolume, float duration);
void SetStreamVolume(int soundStream, float volume);
}
@@ -311,4 +323,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 TogglePause();
CTexture GetCover();
CTexture GetVideoTexture();
bool IsPlaying();
float GetLength();
}
}
+1 -1
View File
@@ -194,7 +194,7 @@ namespace VocaluxeLib.Menu
if (!String.IsNullOrEmpty(_Theme.TextureName) &&
(_Theme.Type == EBackgroundTypes.Texture ||
(_Theme.Type == EBackgroundTypes.Video && (CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF || !ok))))
(_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF)))
ok = _DrawTexture();
if (_Theme.Type == EBackgroundTypes.Color || _Theme.Type == EBackgroundTypes.Texture && !ok ||
+5 -8
View File
@@ -205,10 +205,7 @@ namespace VocaluxeLib.Menu
private void _SetText(CSongNote note)
{
_Text.Text = note.Text;
_Text.Style = EStyle.Bold;
if (note.Type == ENoteType.Freestyle)
_Text.Style = EStyle.BoldItalic;
_Text.Font.Style = (note.Type == ENoteType.Freestyle)? EStyle.BoldItalic:EStyle.Bold;
}
public void Clear()
@@ -350,11 +347,11 @@ namespace VocaluxeLib.Menu
p = 1f - p;
float ty = _Text.Y;
float th = _Text.Height;
float th = _Text.Font.Height;
float tz = _Text.Z;
SRectF normalRect = _Text.Rect;
_Text.Height += _Text.Height * p * 0.4f;
_Text.Font.Height *= 1f+ p * 0.4f;
_Text.X -= (_Text.Rect.W - normalRect.W) / 2f;
_Text.Y -= (_Text.Rect.H - normalRect.H) / 2f;
_Text.Z -= 0.1f;
@@ -364,7 +361,7 @@ namespace VocaluxeLib.Menu
_Text.Draw();
_Text.Y = ty;
_Text.Height = th;
_Text.Font.Height = th;
_Text.Z = tz;
}
}
@@ -456,7 +453,7 @@ namespace VocaluxeLib.Menu
else
{
float y = _Text.Y;
_Text.Y -= _Text.Height * 0.1f * p;
_Text.Y -= _Text.Font.Height * 0.1f * p;
_Text.Draw();
_Text.Y = y;
}
+46 -68
View File
@@ -28,9 +28,12 @@ namespace VocaluxeLib.Menu
public string Text;
public string ColorName;
public string SelColorName; //for Buttons
public string FontFamily;
public EStyle FontStyle;
public float FontHeight;
}
public class CText : IMenuElement
public class CText : IMenuElement, IFontObserver
{
private SThemeText _Theme;
private bool _ThemeLoaded;
@@ -82,20 +85,6 @@ namespace VocaluxeLib.Menu
set { _Z = value; }
}
private float _Height;
public float Height
{
get { return _Height; }
set
{
if (Math.Abs(_Height - value) > 0.01)
{
_Height = value;
_PositionNeedsUpdate = true;
}
}
}
private float _MaxWidth;
public float MaxWidth
{
@@ -138,29 +127,17 @@ namespace VocaluxeLib.Menu
}
}
private EStyle _Style = EStyle.Normal;
public EStyle Style
{
get { return _Style; }
set
{
if (_Style != value)
{
_Style = value;
_PositionNeedsUpdate = true;
}
}
}
private string _Font = String.Empty;
public string Font
private CFont _Font = new CFont();
public CFont Font
{
get { return _Font; }
set
{
if (_Font != value)
if (!_Font.Equals(value))
{
_Font.RemoveObserver(this);
_Font = value;
_Font.AddObserver(this);
_PositionNeedsUpdate = true;
}
}
@@ -199,10 +176,16 @@ namespace VocaluxeLib.Menu
_Text = translation;
if (_EditMode)
_Text += "|";
//Reset height, it might have been reduced in _UpdatePosition
Font.Height = _Theme.FontHeight;
_PositionNeedsUpdate = true;
}
}
}
public string TranslatedText
{
get { return _Text; }
}
public int PartyModeID
{
@@ -246,7 +229,7 @@ namespace VocaluxeLib.Menu
{
_PartyModeID = partyModeID;
_TranslationID = _PartyModeID;
_Font = "Normal";
_Font.AddObserver(this);
}
public CText(CText text)
@@ -257,12 +240,10 @@ namespace VocaluxeLib.Menu
_X = text._X;
_Y = text._Y;
_Z = text._Z;
_Height = text._Height;
_MaxWidth = text._MaxWidth;
_Align = text._Align;
_ResizeAlign = text._ResizeAlign;
_Style = text._Style;
_Font = text._Font;
Font = text.Font; //Use setter to set observer
Color = new SColorF(text.Color);
SelColor = new SColorF(text.SelColor);
@@ -277,24 +258,23 @@ namespace VocaluxeLib.Menu
_EditMode = text._EditMode;
}
public CText(float x, float y, float z, float h, float mw, EAlignment align, EStyle style, string font, SColorF col, string text, int partyModeID = -1, float rheight = 0,
float rspace = 0)
public CText(float x, float y, float z, float h, float mw, EAlignment align, EStyle style, string fontFamily, SColorF col, string text, int partyModeID = -1,
float rheight = 0,
float rspace = 0) : this(partyModeID)
{
_Theme = new SThemeText();
_Theme = new SThemeText {FontFamily = fontFamily, FontStyle = style, FontHeight = h, Text = text};
_ThemeLoaded = false;
_ButtonText = false;
_PartyModeID = partyModeID;
_TranslationID = _PartyModeID;
X = x;
Y = y;
Z = z;
Height = h;
MaxWidth = mw;
Align = align;
ResizeAlign = EHAlignment.Center;
Style = style;
Font = font;
_Font.Name = fontFamily;
_Font.Style = style;
_Font.Height = h;
Color = col;
SelColor = new SColorF(col);
@@ -323,7 +303,6 @@ namespace VocaluxeLib.Menu
if (!buttonText)
_ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Z", ref _Z);
_ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref _Height);
xmlReader.TryGetFloatValue(item + "/MaxW", ref _MaxWidth);
if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty))
@@ -350,8 +329,10 @@ namespace VocaluxeLib.Menu
_ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Align", ref _Align);
xmlReader.TryGetEnumValue(item + "/ResizeAlign", ref _ResizeAlign);
_ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Style", ref _Style);
_ThemeLoaded &= xmlReader.GetValue(item + "/Font", out _Font, "Normal");
_ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref _Theme.FontHeight);
_ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Style", ref _Theme.FontStyle);
_ThemeLoaded &= xmlReader.GetValue(item + "/Font", out _Theme.FontFamily);
Font = new CFont(_Theme.FontFamily, _Theme.FontStyle, _Theme.FontHeight);
_ThemeLoaded &= xmlReader.GetValue(item + "/Text", out _Theme.Text, String.Empty);
@@ -388,7 +369,7 @@ namespace VocaluxeLib.Menu
}
writer.WriteComment("<H>: Text height");
writer.WriteElementString("H", Height.ToString("#0"));
writer.WriteElementString("H", _Theme.FontHeight.ToString("#0"));
writer.WriteComment("<MaxW>: Maximum text width (if exists)");
if (MaxWidth > 0)
@@ -425,10 +406,10 @@ namespace VocaluxeLib.Menu
writer.WriteElementString("ResizeAlign", Enum.GetName(typeof(EHAlignment), ResizeAlign));
writer.WriteComment("<Style>: Text style: " + CHelper.ListStrings(Enum.GetNames(typeof(EStyle))));
writer.WriteElementString("Style", Enum.GetName(typeof(EStyle), Style));
writer.WriteElementString("Style", Enum.GetName(typeof(EStyle), _Theme.FontStyle));
writer.WriteComment("<Font>: Text font name");
writer.WriteElementString("Font", Font);
writer.WriteElementString("Font", _Theme.FontFamily);
writer.WriteComment("<Text>: Nothing or translation tag");
writer.WriteElementString("Text", CBase.Language.TranslationExists(_Theme.Text) ? _Theme.Text : string.Empty);
@@ -463,16 +444,13 @@ namespace VocaluxeLib.Menu
// Update Text
Text = Text;
CBase.Fonts.SetFont(Font);
CBase.Fonts.SetStyle(Style);
SColorF currentColor = (Selected) ? SelColor : Color;
var color = new SColorF(currentColor.R, currentColor.G, currentColor.B, currentColor.A * Alpha);
CBase.Fonts.DrawText(_Text, Rect.H, Rect.X, Rect.Y, Z, color);
CBase.Fonts.DrawText(_Text, Font, Rect.X, Rect.Y, Z, color);
if (ReflectionHeight > 0)
CBase.Fonts.DrawTextReflection(_Text, Rect.H, Rect.X, Rect.Y, Z, color, ReflectionSpace, ReflectionHeight);
CBase.Fonts.DrawTextReflection(_Text, Font, Rect.X, Rect.Y, Z, color, ReflectionSpace, ReflectionHeight);
if (Selected && (CBase.Settings.GetProgramState() == EProgramState.EditTheme))
CBase.Drawing.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(Rect.X, Rect.Y, Rect.W, Rect.H, Z));
@@ -480,13 +458,10 @@ namespace VocaluxeLib.Menu
public void Draw(float begin, float end)
{
CBase.Fonts.SetFont(Font);
CBase.Fonts.SetStyle(Style);
SColorF currentColor = (Selected) ? SelColor : Color;
var color = new SColorF(currentColor.R, currentColor.G, currentColor.B, currentColor.A * Alpha);
CBase.Fonts.DrawText(Text, Rect.H, Rect.X, Rect.Y, Z, color, begin, end);
CBase.Fonts.DrawText(Text, Font, Rect.X, Rect.Y, Z, color, begin, end);
if (ReflectionHeight > 0)
{
@@ -543,9 +518,10 @@ namespace VocaluxeLib.Menu
public void ResizeElement(int stepW, int stepH)
{
Height += stepH;
if (Height <= 0)
Height = 1;
_Theme.FontHeight += stepH;
if (_Theme.FontHeight <= 0)
_Theme.FontHeight = 1;
_Font.Height = _Theme.FontHeight;
}
#endregion ThemeEdit
@@ -554,10 +530,7 @@ namespace VocaluxeLib.Menu
if (_Text == "")
return;
CBase.Fonts.SetFont(Font);
CBase.Fonts.SetStyle(Style);
float h = Height;
float h = Font.Height;
float y = Y;
RectangleF bounds = CBase.Fonts.GetTextBounds(this);
@@ -578,8 +551,8 @@ namespace VocaluxeLib.Menu
y += step * 0.75f;
break;
}
bounds = CBase.Fonts.GetTextBounds(this, h);
Font.Height = h;
bounds = CBase.Fonts.GetTextBounds(this);
}
float x = X;
@@ -600,5 +573,10 @@ namespace VocaluxeLib.Menu
_PositionNeedsUpdate = false;
}
public void FontChanged()
{
_PositionNeedsUpdate = true;
}
}
}
+18 -75
View File
@@ -115,18 +115,15 @@ namespace VocaluxeLib.Menu.SongMenu
_PlaySong(value);
}
else if (value >= CBase.Songs.GetNumCategories())
{
value = -1;
CBase.BackgroundMusic.Stop();
}
_PreviewNrInternal = value;
}
}
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 +157,6 @@ namespace VocaluxeLib.Menu.SongMenu
{
Visible = true;
_PartyModeID = partyModeID;
_PreviewVideoStream = -1;
_PreviewSongStream = -1;
_Theme = new SThemeSongMenu
{
SongMenuTileBoard =
@@ -346,7 +341,7 @@ namespace VocaluxeLib.Menu.SongMenu
public virtual void Init()
{
_ResetPreview();
_ResetPreview(false);
_Initialized = true;
}
@@ -354,40 +349,14 @@ namespace VocaluxeLib.Menu.SongMenu
{
if (!_Initialized)
return;
if (_PreviewSongStream == -1 || _PreviewVideoStream == -1)
return;
if (CBase.Video.IsFinished(_PreviewVideoStream) || CBase.Sound.IsFinished(_PreviewSongStream))
{
CBase.Video.Close(_PreviewVideoStream);
_PreviewVideoStream = -1;
return;
}
float time = CBase.Sound.GetPosition(_PreviewSongStream);
float vtime;
if (CBase.Video.GetFrame(_PreviewVideoStream, ref _Vidtex, time, out vtime))
{
if (_Vidtex != null)
{
if (_VideoFading != null)
{
bool finished;
_Vidtex.Color.A = _VideoFading.GetValue(out finished);
if (finished)
_VideoFading = null;
}
}
}
}
public virtual void OnShow() {}
public virtual void OnHide()
{
_ResetPreview();
if(CBase.Graphics.GetNextScreen() != EScreens.ScreenNames)
_ResetPreview();
}
public abstract bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options);
@@ -399,8 +368,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.BackgroundMusic.IsPlaying())
CBase.Drawing.DrawTexture(CBase.BackgroundMusic.GetVideoTexture(), new SRectF(0, 0, 1280, 720, 0));
}
public bool IsMouseOverSelectedSong(SMouseEvent mEvent)
@@ -486,7 +455,7 @@ namespace VocaluxeLib.Menu.SongMenu
if (categoryNr >= CBase.Songs.GetNumCategories())
return;
_ResetPreview();
_ResetPreview(false);
CBase.Songs.SetCategory(categoryNr);
}
@@ -504,50 +473,24 @@ namespace VocaluxeLib.Menu.SongMenu
private void _PlaySong(int nr)
{
_ResetPreview();
_PreviewNrInternal = -1;
CSong song = CBase.Songs.GetVisibleSong(nr);
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);
float startposition = song.Preview.StartTime;
float length = CBase.Sound.GetLength(_PreviewSongStream);
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.BackgroundMusic.LoadPreview(song);
}
protected void _ResetPreview()
protected void _ResetPreview(bool playBGagain = true)
{
if (_PreviewSongStream >= 0)
CBase.Sound.FadeAndClose(_PreviewSongStream, 0f, 0.75f);
if (_PreviewNrInternal == -1)
return;
_PreviewSongStream = -1;
CBase.BackgroundMusic.StopPreview();
CBase.Video.Close(_PreviewVideoStream);
_PreviewVideoStream = -1;
CBase.Drawing.RemoveTexture(ref _Vidtex);
if (playBGagain)
CBase.BackgroundMusic.Play();
//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
@@ -110,7 +110,11 @@ namespace VocaluxeLib.Menu.SongMenu
set
{
if (value == base._PreviewNr)
{
if (!CBase.BackgroundMusic.IsPlaying() && value != -1)
CBase.BackgroundMusic.PlayPreview();
return;
}
base._PreviewNr = value;
_UpdatePreview();
}
@@ -179,7 +183,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.BackgroundMusic.GetLength() > 0)
_UpdateLength(CBase.Songs.GetVisibleSong(_PreviewNr));
}
@@ -244,7 +248,7 @@ namespace VocaluxeLib.Menu.SongMenu
{
if (song == null)
return;
float time = CBase.Sound.GetLength(_PreviewSongStream);
float time = CBase.BackgroundMusic.GetLength();
if (Math.Abs(song.Finish) > 0.001)
time = song.Finish;
@@ -463,18 +467,20 @@ namespace VocaluxeLib.Menu.SongMenu
_TextBG.Draw();
if (_Vidtex != null && _PreviewVideoStream != -1)
CTexture vidtex = CBase.BackgroundMusic.IsPlayingPreview() ? CBase.BackgroundMusic.GetVideoTexture() : null;
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);
+1 -3
View File
@@ -32,11 +32,9 @@ namespace VocaluxeLib.PartyModes
public override void LoadTheme(string xmlPath)
{
_Warning = GetNewText();
_Warning.Height = 100f;
_Warning.Font.Height = 100f;
_Warning.X = 150;
_Warning.Y = 300;
_Warning.Font = "Normal";
_Warning.Style = EStyle.Normal;
_Warning.Color = new SColorF(1f, 0f, 0f, 1f);
_Warning.SelColor = new SColorF(1f, 0f, 0f, 1f);
_Warning.Text = "SOMETHING WENT WRONG!";
+3
View File
@@ -458,7 +458,10 @@ namespace VocaluxeLib.Songs
if (Preview.Source == EDataSource.None)
{
if (Medley.Source != EDataSource.None)
{
Preview.StartTime = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM);
Preview.Source = EDataSource.Calculated;
}
}
}
+1
View File
@@ -416,6 +416,7 @@ namespace VocaluxeLib.Songs
{
//PreviewStart is not set or <=0
_Song.Preview.StartTime = (headerFlags & EHeaderFlags.MedleyStartBeat) != 0 ? CBase.Game.GetTimeFromBeats(_Song.Medley.StartBeat, _Song.BPM) : 0f;
_Song.Preview.Source = _Song.Preview.StartTime == 0 ? EDataSource.None : EDataSource.Calculated;
}
if ((headerFlags & EHeaderFlags.MedleyStartBeat) != 0 && (headerFlags & EHeaderFlags.MedleyEndBeat) != 0)
+185
View File
@@ -0,0 +1,185 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using VocaluxeLib.Draw;
using VocaluxeLib.Songs;
namespace VocaluxeLib.Utils.Player
{
public class CSongPlayer : CSoundPlayer
{
private CSong _Song;
private bool _VideoEnabled;
private int _Video = -1;
private CTexture _CurrentVideoTexture;
private CFading _VideoFading;
public bool VideoEnabled
{
get { return _VideoEnabled; }
set
{
if (_VideoEnabled == value)
return;
_VideoEnabled = value;
if (_VideoEnabled)
_LoadVideo();
else if (_Video != -1)
{
CBase.Video.Close(_Video);
CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture);
_Video = -1;
}
}
}
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
{
get
{
if (_Song == null)
return "";
if (_Song.Artist != "" && _Song.Title != "")
return _Song.Artist + " - " + _Song.Title;
return Path.GetFileNameWithoutExtension(_Song.MP3FileName);
}
}
public CTexture Cover
{
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 CTexture GetVideoTexture()
{
if (_Video == -1 || _Song == null)
return null;
float vtime;
if (CBase.Video.GetFrame(_Video, ref _CurrentVideoTexture, CBase.Sound.GetPosition(_StreamID), out vtime))
{
if (_VideoFading != null)
{
bool finished;
_CurrentVideoTexture.Color.A = _VideoFading.GetValue(out finished);
if (finished)
_VideoFading = null;
}
return _CurrentVideoTexture;
}
return null;
}
public void Load(CSong song, float position = 0f, bool autoplay = false)
{
if (song == null)
return;
Stop();
_Song = song;
base.Load(Path.Combine(song.Folder, song.MP3FileName), position, false);
_LoadVideo();
if (autoplay)
Play();
}
public void LoadFile(string file, float position = 0f, bool autoplay = false)
{
if (String.IsNullOrEmpty(file))
return;
Stop();
base.Load(file, position, autoplay);
}
public new void Play()
{
CBase.Sound.SetPosition(_StreamID, _StartPosition);
CBase.Video.Skip(_Video, _StartPosition, _Song.VideoGap);
TogglePause();
}
public new void Stop()
{
base.Stop();
_Song = null;
if (_Video != -1)
{
CBase.Video.Close(_Video);
CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture);
_Video = -1;
}
}
public new void TogglePause()
{
if (IsPlaying && _Video != -1)
{
CBase.Video.Pause(_Video);
CBase.Video.Skip(_Video, CBase.Sound.GetPosition(_StreamID) + _FadeTime, _Song.VideoGap);
}
else if(_Video != -1)
{
CBase.Video.Resume(_Video);
}
base.TogglePause();
}
private void _LoadVideo()
{
if (_Song == null)
return;
string videoFilePath = Path.Combine(_Song.Folder, _Song.VideoFileName);
if (_Video != -1 || String.IsNullOrEmpty(videoFilePath))
return;
_Video = CBase.Video.Load(videoFilePath);
CBase.Video.Skip(_Video, 0f, _Song.VideoGap); //Use gap, otherwhise we will overwrite position in GetVideoTexture
_VideoFading = new CFading(0f, 1f, 3f);
if (IsPlaying)
{
CBase.Video.Skip(_Video, Position, _Song.VideoGap);
CBase.Video.Resume(_Video);
}
}
}
}
+153
View File
@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace VocaluxeLib.Utils.Player
{
public class CSoundPlayer
{
protected int _StreamID = -1;
protected float _Volume;
protected float _StartPosition;
protected float _FadeTime = CBase.Settings.GetSoundPlayerFadeTime();
public float Volume
{
set
{
_Volume = value;
_ApplyVolume();
}
get { return _Volume; }
}
public bool Loop;
public float Position
{
set {
if(_StreamID == -1)
return;
_StartPosition = value;
}
get {
if(_StreamID == -1)
return -1;
return CBase.Sound.GetPosition(_StreamID);
}
}
public float Length
{
get
{
if (_StreamID == -1)
return 0;
return CBase.Sound.GetLength(_StreamID);
}
}
public bool RepeatSong;
public bool IsPlaying { get; protected set; }
public bool IsFinished { get { return RepeatSong ? false : CBase.Sound.IsFinished(_StreamID); } }
public CSoundPlayer(bool loop = false)
{
Loop = loop;
}
public CSoundPlayer(string file, bool loop = false, float position = 0f, 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();
_StreamID = CBase.Sound.Load(file, false, true);
if (position > 0f)
Position = position;
if (autoplay)
Play();
}
public void Play()
{
if (_StreamID == -1 || IsPlaying)
return;
CBase.Sound.SetPosition(_StreamID, _StartPosition);
CBase.Sound.SetStreamVolume(_StreamID, 0f);
CBase.Sound.Fade(_StreamID, Volume, _FadeTime);
CBase.Sound.Play(_StreamID);
IsPlaying = true;
}
public void TogglePause()
{
if (_StreamID == -1)
return;
if(IsPlaying)
CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Pause);
else
{
CBase.Sound.Fade(_StreamID, Volume, _FadeTime);
CBase.Sound.Play(_StreamID);
}
IsPlaying = !IsPlaying;
}
public void Stop()
{
if (_StreamID == -1 || !IsPlaying)
return;
CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Close);
_StreamID = -1;
IsPlaying = false;
}
public void Update()
{
if (_StreamID == -1 || !IsPlaying)
return;
float timeToPlay;
float len = CBase.Sound.GetLength(_StreamID);
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);
}
}
}
+3
View File
@@ -77,6 +77,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CFading.cs" />
<Compile Include="CFont.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="IBasic.cs" />
@@ -135,6 +136,8 @@
<Compile Include="PartyModes\IPartyMode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils\CWavFile.cs" />
<Compile Include="Utils\Player\CSongPlayer.cs" />
<Compile Include="Utils\Player\CSoundPlayer.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>