Write decimals in international format

No warning on #RESOLUTION tag
This commit is contained in:
Flamefire committed 2013-10-14 21:55:26 +02:00
1 parent d41779b6f2
commit 1702859e79
4 files changed
+27 -21

No files matched your search

+1 -8
View File
@@ -53,7 +53,6 @@ namespace VocaluxeLib
public static string ListStrings(string[] str) public static string ListStrings(string[] str)
{ {
string result = string.Empty; string result = string.Empty;
for (int i = 0; i < str.Length; i++) for (int i = 0; i < str.Length; i++)
{ {
result += str[i]; result += str[i];
@@ -160,13 +159,7 @@ namespace VocaluxeLib
return files; return files;
} }
public static bool TryParse<T>(string value, out T result) public static bool TryParse<T>(string value, out T result, bool ignoreCase=false)
where T : struct
{
return TryParse(value, out result, false);
}
public static bool TryParse<T>(string value, out T result, bool ignoreCase)
where T : struct where T : struct
{ {
result = default(T); result = default(T);
+11
View File
@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -97,5 +98,15 @@ namespace VocaluxeLib
value = value.Substring(start, end - start + 1); value = value.Substring(start, end - start + 1);
return value; return value;
} }
/// <summary>
/// Converts value to a string in fixed point notation using invariant formating (english style decimal point)
/// </summary>
/// <param name="value">Value to be converted</param>
/// <returns>String representation of value</returns>
public static string ToInvariantString(this float value)
{
return value.ToString("F", NumberFormatInfo.InvariantInfo);
}
} }
} }
+4 -2
View File
@@ -321,13 +321,15 @@ namespace VocaluxeLib.Songs
_Song.Relative = true; _Song.Relative = true;
break; break;
case "RESOLUTION": case "RESOLUTION":
_LogWarning("#RESOLUTION tag is outdated and ignored. Test the song to see if note timing is still correct!"); case "NOTESGAP":
//Outdated/not used
_Song.UnknownTags.Add(line);
break; break;
default: default:
if (identifier.StartsWith("DUETSINGER")) if (identifier.StartsWith("DUETSINGER"))
{ {
identifier = identifier.Substring(10); identifier = identifier.Substring(10);
if (identifier.StartsWith("P")) // Possible fix for missing "P" if (identifier.StartsWith("P")) // fix for missing "P"
identifier = "P" + identifier; identifier = "P" + identifier;
} }
if (identifier.StartsWith("P")) if (identifier.StartsWith("P"))
+11 -11
View File
@@ -9,7 +9,7 @@ namespace VocaluxeLib.Songs
private class CSongWriter private class CSongWriter
{ {
private readonly CSong _Song; private readonly CSong _Song;
private TextWriter tw; private TextWriter _Tw;
public CSongWriter(CSong song) public CSongWriter(CSong song)
{ {
@@ -19,7 +19,7 @@ namespace VocaluxeLib.Songs
private void _WriteHeaderEntry(string id, string value) private void _WriteHeaderEntry(string id, string value)
{ {
if (!String.IsNullOrEmpty(value)) if (!String.IsNullOrEmpty(value))
tw.WriteLine("#" + id.ToUpper() + ":" + value); _Tw.WriteLine("#" + id.ToUpper() + ":" + value);
} }
private void _WriteHeaderEntry(string id, bool value) private void _WriteHeaderEntry(string id, bool value)
@@ -31,7 +31,7 @@ namespace VocaluxeLib.Songs
private void _WriteHeaderEntry(string id, float value, float def = 0f) private void _WriteHeaderEntry(string id, float value, float def = 0f)
{ {
if (Math.Abs(value - def) > 0.0001) if (Math.Abs(value - def) > 0.0001)
_WriteHeaderEntry(id, value.ToString()); _WriteHeaderEntry(id, value.ToInvariantString());
} }
private void _WriteHeaderEntry(string id, int value, int def = 0) private void _WriteHeaderEntry(string id, int value, int def = 0)
@@ -81,11 +81,11 @@ namespace VocaluxeLib.Songs
_WriteHeaderEntry("VIDEOASPECT", _Song.VideoAspect.ToString()); _WriteHeaderEntry("VIDEOASPECT", _Song.VideoAspect.ToString());
_WriteHeaderEntry("RELATIVE", _Song.Relative); _WriteHeaderEntry("RELATIVE", _Song.Relative);
_WriteHeaderEntry("BPM", _Song.BPM / _BPMFactor); _WriteHeaderEntry("BPM", _Song.BPM / _BPMFactor);
_WriteHeaderEntry("GAP", _Song.Gap * 1000f); _WriteHeaderEntry("GAP", (int)(_Song.Gap * 1000f));
if (_Song.Preview.Source == EDataSource.Tag) if (_Song.Preview.Source == EDataSource.Tag)
_WriteHeaderEntry("PREVIEWSTART", _Song.Preview.StartTime); _WriteHeaderEntry("PREVIEWSTART", _Song.Preview.StartTime);
_WriteHeaderEntry("START", _Song.Start); _WriteHeaderEntry("START", _Song.Start);
_WriteHeaderEntry("END", _Song.Finish * 1000f); _WriteHeaderEntry("END", (int)(_Song.Finish * 1000f));
if (_Song.ShortEnd.Source == EDataSource.Tag) if (_Song.ShortEnd.Source == EDataSource.Tag)
_WriteHeaderEntry("ENDSHORT", (int)(CBase.Game.GetTimeFromBeats(_Song.ShortEnd.EndBeat, _Song.BPM) + _Song.Gap) * 1000); _WriteHeaderEntry("ENDSHORT", (int)(CBase.Game.GetTimeFromBeats(_Song.ShortEnd.EndBeat, _Song.BPM) + _Song.Gap) * 1000);
if (!_Song._CalculateMedley) if (!_Song._CalculateMedley)
@@ -101,7 +101,7 @@ namespace VocaluxeLib.Songs
_WriteHeaderEntry("P" + i, _Song.Notes.VoiceNames[i]); _WriteHeaderEntry("P" + i, _Song.Notes.VoiceNames[i]);
} }
foreach (string addLine in _Song.UnknownTags) foreach (string addLine in _Song.UnknownTags)
tw.WriteLine(addLine); _Tw.WriteLine(addLine);
} }
private void _WriteNotes() private void _WriteNotes()
@@ -110,7 +110,7 @@ namespace VocaluxeLib.Songs
{ {
CVoice voice = _Song.Notes.GetVoice(i); CVoice voice = _Song.Notes.GetVoice(i);
if (_Song.Notes.VoiceCount > 1) if (_Song.Notes.VoiceCount > 1)
tw.WriteLine("P" + Math.Pow(2, i)); _Tw.WriteLine("P" + Math.Pow(2, i));
bool firstLine = true; bool firstLine = true;
int currentBeat = 0; int currentBeat = 0;
foreach (CSongLine line in voice.Lines) foreach (CSongLine line in voice.Lines)
@@ -123,7 +123,7 @@ namespace VocaluxeLib.Songs
lineTxt += " " + (line.FirstNoteBeat - currentBeat); lineTxt += " " + (line.FirstNoteBeat - currentBeat);
currentBeat = line.FirstNoteBeat; currentBeat = line.FirstNoteBeat;
} }
tw.WriteLine(lineTxt); _Tw.WriteLine(lineTxt);
} }
else else
firstLine = false; firstLine = false;
@@ -144,18 +144,18 @@ namespace VocaluxeLib.Songs
default: default:
throw new NotImplementedException("Note type " + note.Type); throw new NotImplementedException("Note type " + note.Type);
} }
tw.WriteLine(tag + " " + (note.StartBeat - currentBeat) + " " + note.Duration + " " + note.Tone + " " + note.Text); _Tw.WriteLine(tag + " " + (note.StartBeat - currentBeat) + " " + note.Duration + " " + note.Tone + " " + note.Text);
} }
} }
} }
tw.WriteLine("E"); _Tw.WriteLine("E");
} }
public bool SaveFile(string filePath) public bool SaveFile(string filePath)
{ {
try try
{ {
tw = new StreamWriter(filePath, false, _Song.Encoding); _Tw = new StreamWriter(filePath, false, _Song.Encoding);
_WriteHeader(); _WriteHeader();
_WriteNotes(); _WriteNotes();
} }