Merge branch 'develop' of github.com:Flamefire/Vocaluxe into sound-player

Conflicts:
	VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs
This commit is contained in:
Florian Küpper committed 2014-08-09 20:04:41 +02:00
commit 8722844646
48 files changed
+399 -521

No files matched your search

+34 -29
View File
@@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
@@ -63,8 +64,18 @@ namespace VocaluxeLib
return (int)result;
}
/// <summary>
/// Makes sure val is between min and max
/// Asserts that min&lt;=max
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="val"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns>Clamped value</returns>
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
{
Debug.Assert(min.CompareTo(max) <= 0);
if (val.CompareTo(min) < 0)
return min;
if (val.CompareTo(max) > 0)
@@ -72,6 +83,27 @@ namespace VocaluxeLib
return val;
}
/// <summary>
/// Makes sure val is between min and max but also handles the case where min&gt;max
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="val"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <param name="preferMin"></param>
/// <returns>Clamped value</returns>
public static T Clamp<T>(this T val, T min, T max, bool preferMin) where T : IComparable<T>
{
if (min.CompareTo(max) > 0)
{
if (preferMin)
max = min;
else
min = max;
}
return Clamp(val, min, max);
}
/// <summary>
/// Concat strings into one string with ", " as separator.
/// </summary>
@@ -88,32 +120,6 @@ namespace VocaluxeLib
return result;
}
public static int TryReadInt(StreamReader sr)
{
string value = String.Empty;
try
{
int tmp = sr.Peek();
//Check for ' ', ?, ?, \n, \r, E
while (tmp != 32 && tmp != 19 && tmp != 16 && tmp != 13 && tmp != 10 && tmp != 69)
{
if (sr.EndOfStream)
break;
var chr = (char)sr.Read();
value += chr.ToString();
tmp = sr.Peek();
}
}
catch (Exception)
{
return 0;
}
int result;
return Int32.TryParse(value, out result) ? result : 0;
}
public static void SetRect(SRectF bounds, out SRectF rect, float rectAspect, EAspect aspect)
{
var bounds2 = new RectangleF(bounds.X, bounds.Y, bounds.W, bounds.H);
@@ -279,13 +285,12 @@ namespace VocaluxeLib
/// </summary>
/// <param name="path">Path in which the file should be stored</param>
/// <param name="filename">filename (including extension)</param>
/// <param name="withPath">Whether the fullpath or only the filename should be returned</param>
/// <returns></returns>
public static string GetUniqueFileName(string path, string filename, bool withPath = true)
{
string ext = Path.GetExtension(filename);
filename = Path.GetFileNameWithoutExtension(filename);
if (filename == null)
filename = "1";
filename = Path.GetFileNameWithoutExtension(filename) ?? "1";
if (File.Exists(Path.Combine(path, filename + ext)))
{
int i = 1;
+43 -80
View File
@@ -57,49 +57,44 @@ namespace VocaluxeLib
}
}
public bool TryGetEnumValue<T>(string cast, ref T value)
public bool TryGetEnumValue<T>(string xPath, ref T value)
where T : struct
{
string val;
if (GetValue(cast, out val, Enum.GetName(typeof(T), value)))
if (GetValue(xPath, out val, Enum.GetName(typeof(T), value)))
return CHelper.TryParse(val, out value, true);
return false;
}
public bool TryGetIntValue(string cast, ref int value)
public bool TryGetIntValue(string xPath, ref int value)
{
string val;
if (GetValue(cast, out val, value.ToString()))
if (GetValue(xPath, out val, value.ToString()))
return int.TryParse(val, out value);
return false;
}
public bool TryGetIntValueRange(string cast, ref int value, int min = 0, int max = 100)
public bool TryGetIntValueRange(string xPath, ref int value, int min = 0, int max = 100)
{
bool result = TryGetIntValue(cast, ref value);
bool result = TryGetIntValue(xPath, ref value);
if (result)
{
if (value < min)
value = min;
else if (value > max)
value = max;
}
value = value.Clamp(min, max);
return result;
}
public bool TryGetFloatValue(string cast, ref float value)
public bool TryGetFloatValue(string xPath, ref float value)
{
string val;
return GetValue(cast, out val, value.ToString()) && CHelper.TryParse(val, out value);
return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value);
}
public bool GetValue(string cast, out string value, string defaultValue)
public bool GetValue(string xPath, out string value, string defaultValue)
{
int resultCt = 0;
string val = string.Empty;
_Navigator.MoveToFirstChild();
XPathNodeIterator iterator = _Navigator.Select(cast);
_Navigator.MoveToRoot();
XPathNodeIterator iterator = _Navigator.Select(xPath);
while (iterator.MoveNext())
{
@@ -116,77 +111,45 @@ namespace VocaluxeLib
return true;
}
public List<string> GetValues(string cast)
public List<string> GetNames(string xPath)
{
var values = new List<string>();
_Navigator.MoveToRoot();
_Navigator.MoveToFirstChild();
_Navigator.MoveToFirstChild();
while (_Navigator.Name != cast)
_Navigator.MoveToNext();
_Navigator.MoveToFirstChild();
values.Add(_Navigator.LocalName);
while (_Navigator.MoveToNext())
values.Add(_Navigator.LocalName);
return values;
}
public IEnumerable<string> GetAttributes(string cast, string attribute)
{
var values = new List<string>();
_Navigator.MoveToRoot();
_Navigator.MoveToFirstChild();
while (_Navigator.Name != cast)
_Navigator.MoveToNext();
_Navigator.MoveToFirstChild();
values.Add(_Navigator.LocalName);
while (_Navigator.MoveToNext())
values.Add(_Navigator.GetAttribute(attribute, ""));
return values;
}
public bool GetInnerValues(string cast, ref List<string> values)
{
_Navigator.MoveToRoot();
_Navigator.MoveToFirstChild();
_Navigator.MoveToFirstChild();
while (_Navigator.Name != cast)
_Navigator.MoveToNext();
_Navigator.MoveToFirstChild();
values.Add(_Navigator.Value);
while (_Navigator.MoveToNext())
values.Add(_Navigator.Value);
return true;
}
public bool ItemExists(string cast)
{
int results = 0;
_Navigator.MoveToFirstChild();
XPathNodeIterator iterator = _Navigator.Select(cast);
XPathNodeIterator iterator = _Navigator.Select(xPath);
while (iterator.MoveNext())
results++;
values.Add(iterator.Current.LocalName);
if (results == 0)
return false;
return values;
}
public IEnumerable<string> GetAttributes(string xPath, string attribute)
{
var values = new List<string>();
_Navigator.MoveToRoot();
XPathNodeIterator iterator = _Navigator.Select(xPath);
while (iterator.MoveNext())
values.Add(iterator.Current.GetAttribute(attribute, ""));
return values;
}
public bool GetValues(string xPath, ref List<string> values)
{
_Navigator.MoveToRoot();
XPathNodeIterator iterator = _Navigator.Select(xPath);
while (iterator.MoveNext())
values.Add(iterator.Current.Value);
return true;
}
public bool ItemExists(string xPath)
{
_Navigator.MoveToRoot();
return _Navigator.Select(xPath).MoveNext();
}
}
}
@@ -442,6 +442,7 @@ namespace VocaluxeLib.Menu.SongMenu
_SelectionNr = categoryNr;
else
_SelectionNr = -1;
_PreviewNr = _SelectionNr;
}
public virtual void UnloadTextures() {}
@@ -519,6 +520,11 @@ namespace VocaluxeLib.Menu.SongMenu
protected void _ResetPreview()
{
CBase.PreviewPlayer.Stop();
//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
//Use internal nr because this function gets called from withing setPreviewNr
_PreviewNrInternal = -1;
}
#region ThemeEdit
+20 -20
View File
@@ -57,8 +57,8 @@ namespace VocaluxeLib.Menu.SongMenu
private int _Offset;
private float _Length = -1f;
private int _LastKnownNumSongs;
private int _LastKnownCategory = -1;
private int _LastKnownElements;
private int _LastKnownCategory;
private bool _MouseWasInRect;
@@ -72,7 +72,7 @@ namespace VocaluxeLib.Menu.SongMenu
set
{
int max = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
base._SelectionNr = value.Clamp(-1, max - 1);
base._SelectionNr = value.Clamp(-1, max - 1, true);
//Update list in case we scrolled
_UpdateList();
@@ -267,17 +267,18 @@ namespace VocaluxeLib.Menu.SongMenu
public override void OnShow()
{
if (CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0 && !CBase.Songs.IsInCategory())
_EnterCategory(0);
else
_LastKnownElements = -1; //Force refresh of list
if (!CBase.Songs.IsInCategory())
{
if (CBase.Songs.IsInCategory())
SetSelectedSong(_SelectionNr < 0 ? 0 : _SelectionNr);
else
SetSelectedCategory(_SelectionNr < 0 ? 0 : _SelectionNr);
if ((CBase.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && CBase.Songs.GetNumCategories() > 0) || CBase.Songs.GetNumCategories() == 1)
_EnterCategory(0);
}
if (CBase.Songs.IsInCategory())
SetSelectedSong(_SelectionNr < 0 ? 0 : _SelectionNr);
else
SetSelectedCategory(_SelectionNr < 0 ? 0 : _SelectionNr);
_PreviewNr = _SelectionNr;
_AfterCategoryChange();
_UpdateListIfRequired();
}
public override bool HandleInput(ref SKeyEvent keyEvent, SScreenSongOptions options)
@@ -503,18 +504,16 @@ namespace VocaluxeLib.Menu.SongMenu
{
base._EnterCategory(categoryNr);
_PreviewNr = 0;
SetSelectedSong(0);
_AfterCategoryChange();
_UpdateListIfRequired();
}
protected override void _LeaveCategory()
{
base._LeaveCategory();
_PreviewNr = 0;
SetSelectedCategory(0);
_AfterCategoryChange();
_UpdateListIfRequired();
}
private void _NextCategory()
@@ -535,20 +534,21 @@ namespace VocaluxeLib.Menu.SongMenu
}
}
private void _AfterCategoryChange()
private void _UpdateListIfRequired()
{
if ((_LastKnownNumSongs == CBase.Songs.GetNumSongsVisible()) && (_LastKnownCategory == CBase.Songs.GetCurrentCategoryIndex()))
int curElements = CBase.Songs.IsInCategory() ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
if ((_LastKnownElements == curElements) && (_LastKnownCategory == CBase.Songs.GetCurrentCategoryIndex()))
return;
_LastKnownCategory = CBase.Songs.GetCurrentCategoryIndex();
_LastKnownNumSongs = CBase.Songs.GetNumSongsVisible();
_LastKnownElements = curElements;
CBase.Songs.UpdateRandomSongList();
_UpdateList(true);
}
private int _GetOffsetForPosition(int index, int rowNum = 0)
{
return (index / _NumW) * _NumW - (_NumW * rowNum.Clamp(0, _NumH - 1));
return (index / _NumW) * _NumW - (_NumW * rowNum.Clamp(0, _NumH - 1, true));
}
private void _UpdateList(bool force = false)
@@ -568,7 +568,7 @@ namespace VocaluxeLib.Menu.SongMenu
bool isInCategory = CBase.Songs.IsInCategory();
int itemCount = isInCategory ? CBase.Songs.GetNumSongsVisible() : CBase.Songs.GetNumCategories();
offset = offset.Clamp(0, _GetOffsetForPosition(itemCount, _NumH - 1));
offset = offset.Clamp(0, _GetOffsetForPosition(itemCount, _NumH - 1), true);
if (offset == _Offset && !force)
return;
+22 -1
View File
@@ -240,7 +240,7 @@ namespace VocaluxeLib.Songs
break;
case "LANGUAGE":
if (value.Length > 1)
_Song.Languages.Add(value);
_Song.Languages.Add(_UnifyLanguage(value));
else
_LogWarning("Invalid language");
break;
@@ -449,6 +449,27 @@ namespace VocaluxeLib.Songs
return true;
}
private static string _UnifyLanguage(string lang)
{
if (lang != "")
{
lang = Char.ToUpperInvariant(lang[0]) + lang.Substring(1).ToLowerInvariant();
switch (lang)
{
case "Englisch":
lang = "English";
break;
case "Deutsch":
lang = "German";
break;
case "Spanisch":
lang = "Spanish";
break;
}
}
return lang;
}
private enum ENoteReadMode
{
Normal,