From 1702859e790f79e2d4b2d7fed76f0991d719ef73 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 14 Oct 2013 21:55:26 +0200 Subject: [PATCH] Write decimals in international format No warning on #RESOLUTION tag --- VocaluxeLib/CHelper.cs | 9 +-------- VocaluxeLib/Extensions.cs | 11 +++++++++++ VocaluxeLib/Songs/CSongLoader.cs | 6 ++++-- VocaluxeLib/Songs/CSongWriter.cs | 22 +++++++++++----------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/VocaluxeLib/CHelper.cs b/VocaluxeLib/CHelper.cs index 7b441caa..bd06cecb 100644 --- a/VocaluxeLib/CHelper.cs +++ b/VocaluxeLib/CHelper.cs @@ -53,7 +53,6 @@ namespace VocaluxeLib public static string ListStrings(string[] str) { string result = string.Empty; - for (int i = 0; i < str.Length; i++) { result += str[i]; @@ -160,13 +159,7 @@ namespace VocaluxeLib return files; } - public static bool TryParse(string value, out T result) - where T : struct - { - return TryParse(value, out result, false); - } - - public static bool TryParse(string value, out T result, bool ignoreCase) + public static bool TryParse(string value, out T result, bool ignoreCase=false) where T : struct { result = default(T); diff --git a/VocaluxeLib/Extensions.cs b/VocaluxeLib/Extensions.cs index a035f869..d6c78529 100644 --- a/VocaluxeLib/Extensions.cs +++ b/VocaluxeLib/Extensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; @@ -97,5 +98,15 @@ namespace VocaluxeLib value = value.Substring(start, end - start + 1); return value; } + + /// + /// Converts value to a string in fixed point notation using invariant formating (english style decimal point) + /// + /// Value to be converted + /// String representation of value + public static string ToInvariantString(this float value) + { + return value.ToString("F", NumberFormatInfo.InvariantInfo); + } } } \ No newline at end of file diff --git a/VocaluxeLib/Songs/CSongLoader.cs b/VocaluxeLib/Songs/CSongLoader.cs index ec93c156..597398d4 100644 --- a/VocaluxeLib/Songs/CSongLoader.cs +++ b/VocaluxeLib/Songs/CSongLoader.cs @@ -321,13 +321,15 @@ namespace VocaluxeLib.Songs _Song.Relative = true; break; 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; default: if (identifier.StartsWith("DUETSINGER")) { identifier = identifier.Substring(10); - if (identifier.StartsWith("P")) // Possible fix for missing "P" + if (identifier.StartsWith("P")) // fix for missing "P" identifier = "P" + identifier; } if (identifier.StartsWith("P")) diff --git a/VocaluxeLib/Songs/CSongWriter.cs b/VocaluxeLib/Songs/CSongWriter.cs index 9ecf29a1..906c358f 100644 --- a/VocaluxeLib/Songs/CSongWriter.cs +++ b/VocaluxeLib/Songs/CSongWriter.cs @@ -9,7 +9,7 @@ namespace VocaluxeLib.Songs private class CSongWriter { private readonly CSong _Song; - private TextWriter tw; + private TextWriter _Tw; public CSongWriter(CSong song) { @@ -19,7 +19,7 @@ namespace VocaluxeLib.Songs private void _WriteHeaderEntry(string id, string value) { if (!String.IsNullOrEmpty(value)) - tw.WriteLine("#" + id.ToUpper() + ":" + value); + _Tw.WriteLine("#" + id.ToUpper() + ":" + 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) { 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) @@ -81,11 +81,11 @@ namespace VocaluxeLib.Songs _WriteHeaderEntry("VIDEOASPECT", _Song.VideoAspect.ToString()); _WriteHeaderEntry("RELATIVE", _Song.Relative); _WriteHeaderEntry("BPM", _Song.BPM / _BPMFactor); - _WriteHeaderEntry("GAP", _Song.Gap * 1000f); + _WriteHeaderEntry("GAP", (int)(_Song.Gap * 1000f)); if (_Song.Preview.Source == EDataSource.Tag) _WriteHeaderEntry("PREVIEWSTART", _Song.Preview.StartTime); _WriteHeaderEntry("START", _Song.Start); - _WriteHeaderEntry("END", _Song.Finish * 1000f); + _WriteHeaderEntry("END", (int)(_Song.Finish * 1000f)); if (_Song.ShortEnd.Source == EDataSource.Tag) _WriteHeaderEntry("ENDSHORT", (int)(CBase.Game.GetTimeFromBeats(_Song.ShortEnd.EndBeat, _Song.BPM) + _Song.Gap) * 1000); if (!_Song._CalculateMedley) @@ -101,7 +101,7 @@ namespace VocaluxeLib.Songs _WriteHeaderEntry("P" + i, _Song.Notes.VoiceNames[i]); } foreach (string addLine in _Song.UnknownTags) - tw.WriteLine(addLine); + _Tw.WriteLine(addLine); } private void _WriteNotes() @@ -110,7 +110,7 @@ namespace VocaluxeLib.Songs { CVoice voice = _Song.Notes.GetVoice(i); if (_Song.Notes.VoiceCount > 1) - tw.WriteLine("P" + Math.Pow(2, i)); + _Tw.WriteLine("P" + Math.Pow(2, i)); bool firstLine = true; int currentBeat = 0; foreach (CSongLine line in voice.Lines) @@ -123,7 +123,7 @@ namespace VocaluxeLib.Songs lineTxt += " " + (line.FirstNoteBeat - currentBeat); currentBeat = line.FirstNoteBeat; } - tw.WriteLine(lineTxt); + _Tw.WriteLine(lineTxt); } else firstLine = false; @@ -144,18 +144,18 @@ namespace VocaluxeLib.Songs default: 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) { try { - tw = new StreamWriter(filePath, false, _Song.Encoding); + _Tw = new StreamWriter(filePath, false, _Song.Encoding); _WriteHeader(); _WriteNotes(); }