Merge branch 'develop' into Better_Rounds_Handling
Conflicts: Vocaluxe/Base/CGame.cs Vocaluxe/Screens/CScreenNames.cs
This commit is contained in:
commit
f8b80a5911
53 files changed
+2014
-1281
No files matched your search
@@ -15,6 +15,8 @@
|
||||
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace VocaluxeLib.Songs
|
||||
{
|
||||
/// <summary>
|
||||
@@ -38,12 +40,17 @@ namespace VocaluxeLib.Songs
|
||||
StartBeat = startBeat;
|
||||
Duration = duration;
|
||||
Tone = tone;
|
||||
if (Duration < 1)
|
||||
throw new Exception("Note to short. All notes should be at least 1 beat long!");
|
||||
}
|
||||
#endregion Constructors
|
||||
|
||||
#region Properties
|
||||
public int StartBeat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Last beat of this note. First valid beat for a note after that is at EndBeat+1
|
||||
/// </summary>
|
||||
public int EndBeat
|
||||
{
|
||||
get { return StartBeat + _Duration - 1; }
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using VocaluxeLib.Draw;
|
||||
using System.Linq;
|
||||
|
||||
namespace VocaluxeLib.Songs
|
||||
{
|
||||
@@ -50,6 +51,11 @@ namespace VocaluxeLib.Songs
|
||||
}
|
||||
}
|
||||
|
||||
public int GetNumSongsNotSung()
|
||||
{
|
||||
return Songs.Count(sp => !sp.IsSung);
|
||||
}
|
||||
|
||||
public CCategory(string name, CTexture coverSmall, CTexture coverBig)
|
||||
{
|
||||
Name = name;
|
||||
|
||||
@@ -74,7 +74,11 @@ namespace VocaluxeLib.Songs
|
||||
#endregion Properties
|
||||
|
||||
#region Methods
|
||||
//Find last note with StartBeat<=Beat
|
||||
/// <summary>
|
||||
/// Find last note with StartBeat<=Beat
|
||||
/// </summary>
|
||||
/// <param name="beat"></param>
|
||||
/// <returns>Note index of last note with StartBeat<=Beat or -1 if all notes start after beat</returns>
|
||||
public int FindPreviousNote(int beat)
|
||||
{
|
||||
//If no notes -> No previous note
|
||||
|
||||
+51
-10
@@ -21,24 +21,63 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
public class CNotes
|
||||
{
|
||||
private readonly List<CVoice> _Voices = new List<CVoice>();
|
||||
|
||||
public CVoice[] Voices
|
||||
public class CVoiceNames
|
||||
{
|
||||
get { return _Voices.ToArray(); }
|
||||
private readonly List<string> _Names = new List<string>();
|
||||
|
||||
public CVoiceNames() {}
|
||||
|
||||
public CVoiceNames(CVoiceNames names)
|
||||
{
|
||||
_Names.AddRange(names._Names);
|
||||
}
|
||||
|
||||
public string this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsSet(index))
|
||||
return _Names[index];
|
||||
return "Part " + (index + 1);
|
||||
}
|
||||
set
|
||||
{
|
||||
_Names.EnsureSize(index + 1, null);
|
||||
_Names[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSet(int index)
|
||||
{
|
||||
return _Names.Count > index && !string.IsNullOrEmpty(_Names[index]);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_Names.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly List<CVoice> _Voices = new List<CVoice>();
|
||||
public readonly CVoiceNames VoiceNames = new CVoiceNames();
|
||||
|
||||
public CNotes() {}
|
||||
|
||||
public int LinesCount
|
||||
{
|
||||
get { return _Voices.Count; }
|
||||
}
|
||||
|
||||
public CNotes(CNotes notes)
|
||||
{
|
||||
foreach (CVoice voice in notes._Voices)
|
||||
_Voices.Add(new CVoice(voice));
|
||||
VoiceNames = new CVoiceNames(notes.VoiceNames);
|
||||
}
|
||||
|
||||
public IEnumerable<CVoice> Voices
|
||||
{
|
||||
get { return _Voices; }
|
||||
}
|
||||
|
||||
public int VoiceCount
|
||||
{
|
||||
get { return _Voices.Count; }
|
||||
}
|
||||
|
||||
public CVoice GetVoice(int index)
|
||||
@@ -79,9 +118,11 @@ namespace VocaluxeLib.Songs
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
public void Reset(bool resetVoices = false)
|
||||
{
|
||||
_Voices.Clear();
|
||||
if (resetVoices)
|
||||
VoiceNames.Reset();
|
||||
}
|
||||
|
||||
public void SetMedley(int startBeat, int endBeat)
|
||||
|
||||
+126
-574
@@ -20,7 +20,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using VocaluxeLib.Draw;
|
||||
|
||||
namespace VocaluxeLib.Songs
|
||||
@@ -45,12 +44,11 @@ namespace VocaluxeLib.Songs
|
||||
Artist = 2,
|
||||
MP3 = 4,
|
||||
BPM = 8,
|
||||
PreviewStart = 16,
|
||||
MedleyStartBeat = 32,
|
||||
MedleyEndBeat = 64
|
||||
MedleyStartBeat = 16,
|
||||
MedleyEndBeat = 32
|
||||
}
|
||||
|
||||
public enum EMedleySource
|
||||
public enum EDataSource
|
||||
{
|
||||
None = 0,
|
||||
Calculated,
|
||||
@@ -59,30 +57,43 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
public struct SMedley
|
||||
{
|
||||
public EMedleySource Source;
|
||||
public EDataSource Source;
|
||||
public int StartBeat;
|
||||
public int EndBeat;
|
||||
public float FadeInTime;
|
||||
public float FadeOutTime;
|
||||
}
|
||||
|
||||
public class CSong
|
||||
public struct SShortEnd
|
||||
{
|
||||
public EDataSource Source;
|
||||
public int EndBeat;
|
||||
}
|
||||
|
||||
public struct SPreview
|
||||
{
|
||||
public EDataSource Source;
|
||||
public float StartTime;
|
||||
}
|
||||
|
||||
public partial class CSong
|
||||
{
|
||||
private CTexture _CoverTextureSmall;
|
||||
private CTexture _CoverTextureBig;
|
||||
|
||||
public SMedley Medley;
|
||||
|
||||
public bool CalculateMedley = true;
|
||||
public float PreviewStart;
|
||||
private bool _CalculateMedley = true;
|
||||
public SPreview Preview;
|
||||
|
||||
public int ShortEnd;
|
||||
public SShortEnd ShortEnd;
|
||||
|
||||
public Encoding Encoding = Encoding.Default;
|
||||
public bool ManualEncoding;
|
||||
public string Folder = String.Empty;
|
||||
public string FolderName = String.Empty;
|
||||
public string FileName = String.Empty;
|
||||
public EOffOn Relative = EOffOn.TR_CONFIG_OFF;
|
||||
public bool Relative;
|
||||
|
||||
public string MP3FileName = String.Empty;
|
||||
public string CoverFileName = String.Empty;
|
||||
@@ -117,17 +128,31 @@ namespace VocaluxeLib.Songs
|
||||
public string TitleSorting = String.Empty;
|
||||
public string ArtistSorting = String.Empty;
|
||||
|
||||
public string Creator = "";
|
||||
public string Version = "";
|
||||
public string Source = "";
|
||||
public readonly List<String> UnknownTags = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Start of the song in s (s in txt)
|
||||
/// </summary>
|
||||
public float Start;
|
||||
/// <summary>
|
||||
/// End of the song in s (ms in txt)
|
||||
/// </summary>
|
||||
public float Finish;
|
||||
|
||||
public float BPM = 1f;
|
||||
/// <summary>
|
||||
/// Gap of the mp3 in s (ms in txt)
|
||||
/// </summary>
|
||||
public float Gap;
|
||||
/// <summary>
|
||||
/// Gap of the video in s (s in txt)
|
||||
/// </summary>
|
||||
public float VideoGap;
|
||||
|
||||
public string DuetPart1 = String.Empty;
|
||||
public string DuetPart2 = String.Empty;
|
||||
|
||||
private readonly List<string> _Comment = new List<string>();
|
||||
private string _Comment = "";
|
||||
|
||||
// Sorting
|
||||
public int ID;
|
||||
@@ -136,14 +161,15 @@ namespace VocaluxeLib.Songs
|
||||
private readonly bool _Selected;
|
||||
public bool IsDuet
|
||||
{
|
||||
get { return Notes.Voices.Length > 1; }
|
||||
get { return Notes.VoiceCount > 1; }
|
||||
}
|
||||
|
||||
public readonly List<string> Edition = new List<string>();
|
||||
public readonly List<string> Genre = new List<string>();
|
||||
public readonly List<string> Editions = new List<string>();
|
||||
public readonly List<string> Genres = new List<string>();
|
||||
public string Album = "";
|
||||
public string Year = "";
|
||||
|
||||
public readonly List<string> Language = new List<string>();
|
||||
public readonly List<string> Languages = new List<string>();
|
||||
|
||||
public int DataBaseSongID = -1;
|
||||
public string DateAdded = "";
|
||||
@@ -152,50 +178,47 @@ namespace VocaluxeLib.Songs
|
||||
// Notes
|
||||
public readonly CNotes Notes = new CNotes();
|
||||
|
||||
public EGameMode[] AvailableGameModes
|
||||
public IList<EGameMode> AvailableGameModes
|
||||
{
|
||||
get
|
||||
{
|
||||
var gms = new List<EGameMode> {IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL};
|
||||
if (Medley.Source != EMedleySource.None)
|
||||
if (Medley.Source != EDataSource.None)
|
||||
gms.Add(EGameMode.TR_GAMEMODE_MEDLEY);
|
||||
gms.Add(EGameMode.TR_GAMEMODE_SHORTSONG);
|
||||
if (ShortEnd.Source != EDataSource.None)
|
||||
gms.Add(EGameMode.TR_GAMEMODE_SHORTSONG);
|
||||
|
||||
return gms.ToArray();
|
||||
return gms;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the requested game mode is available
|
||||
/// </summary>
|
||||
/// <param name="gameMode"></param>
|
||||
/// <returns>true if the requested game mode is available</returns>
|
||||
public bool IsGameModeAvailable(EGameMode gameMode)
|
||||
{
|
||||
return AvailableGameModes.Any(gm => gm == gameMode);
|
||||
}
|
||||
|
||||
//No point creating a song without a text file --> Use factory method LoadSong
|
||||
private CSong() {}
|
||||
|
||||
public static CSong LoadSong(string filePath)
|
||||
{
|
||||
var song = new CSong();
|
||||
return song.ReadHeader(filePath) ? song : null;
|
||||
}
|
||||
|
||||
public CSong(CSong song)
|
||||
{
|
||||
_CoverTextureSmall = song._CoverTextureSmall;
|
||||
_CoverTextureBig = song._CoverTextureBig;
|
||||
|
||||
Medley = new SMedley
|
||||
{
|
||||
Source = song.Medley.Source,
|
||||
StartBeat = song.Medley.StartBeat,
|
||||
EndBeat = song.Medley.EndBeat,
|
||||
FadeInTime = song.Medley.FadeInTime,
|
||||
FadeOutTime = song.Medley.FadeOutTime
|
||||
};
|
||||
Medley = song.Medley;
|
||||
|
||||
CalculateMedley = song.CalculateMedley;
|
||||
PreviewStart = song.PreviewStart;
|
||||
_CalculateMedley = song._CalculateMedley;
|
||||
Preview = song.Preview;
|
||||
|
||||
ShortEnd = song.ShortEnd;
|
||||
DuetPart1 = song.DuetPart1;
|
||||
DuetPart2 = song.DuetPart2;
|
||||
|
||||
Encoding = song.Encoding;
|
||||
ManualEncoding = song.ManualEncoding;
|
||||
Folder = song.Folder;
|
||||
FolderName = song.FolderName;
|
||||
FileName = song.FileName;
|
||||
@@ -211,6 +234,13 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
Artist = song.Artist;
|
||||
Title = song.Title;
|
||||
ArtistSorting = song.ArtistSorting;
|
||||
TitleSorting = song.TitleSorting;
|
||||
|
||||
Creator = song.Creator;
|
||||
Version = song.Version;
|
||||
Source = song.Source;
|
||||
UnknownTags = new List<string>(song.UnknownTags);
|
||||
|
||||
Start = song.Start;
|
||||
Finish = song.Finish;
|
||||
@@ -219,28 +249,19 @@ namespace VocaluxeLib.Songs
|
||||
Gap = song.Gap;
|
||||
VideoGap = song.VideoGap;
|
||||
|
||||
_Comment = new List<string>();
|
||||
foreach (string value in song._Comment)
|
||||
_Comment.Add(value);
|
||||
_Comment = song._Comment;
|
||||
|
||||
ID = song.ID;
|
||||
_Visible = song._Visible;
|
||||
_CatIndex = song._CatIndex;
|
||||
_Selected = song._Selected;
|
||||
|
||||
Edition = new List<string>();
|
||||
foreach (string value in song.Edition)
|
||||
Edition.Add(value);
|
||||
|
||||
Genre = new List<string>();
|
||||
foreach (string value in song.Genre)
|
||||
Genre.Add(value);
|
||||
|
||||
Editions = new List<string>(song.Editions);
|
||||
Genres = new List<string>(song.Genres);
|
||||
Album = song.Album;
|
||||
Year = song.Year;
|
||||
|
||||
Language = new List<string>();
|
||||
foreach (string value in song.Language)
|
||||
Language.Add(value);
|
||||
Languages = new List<string>(song.Languages);
|
||||
|
||||
DataBaseSongID = song.DataBaseSongID;
|
||||
DateAdded = song.DateAdded;
|
||||
@@ -249,6 +270,25 @@ namespace VocaluxeLib.Songs
|
||||
Notes = new CNotes(song.Notes);
|
||||
}
|
||||
|
||||
public static CSong LoadSong(string filePath)
|
||||
{
|
||||
var song = new CSong();
|
||||
var loader = new CSongLoader(song);
|
||||
return loader.InitPaths(filePath) && loader.ReadHeader() ? song : null;
|
||||
}
|
||||
|
||||
public bool LoadNotes()
|
||||
{
|
||||
var loader = new CSongLoader(this);
|
||||
return loader.ReadNotes();
|
||||
}
|
||||
|
||||
public bool Save(string filePath)
|
||||
{
|
||||
var writer = new CSongWriter(this);
|
||||
return writer.SaveFile(filePath);
|
||||
}
|
||||
|
||||
public string GetMP3()
|
||||
{
|
||||
return Path.Combine(Folder, MP3FileName);
|
||||
@@ -259,494 +299,6 @@ namespace VocaluxeLib.Songs
|
||||
return Path.Combine(Folder, VideoFileName);
|
||||
}
|
||||
|
||||
public bool ReadHeader(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
return false;
|
||||
|
||||
Folder = Path.GetDirectoryName(filePath);
|
||||
if (Folder == null)
|
||||
return false;
|
||||
|
||||
foreach (string folder in CBase.Config.GetSongFolder())
|
||||
{
|
||||
if (!Folder.Contains(folder))
|
||||
continue;
|
||||
if (Folder.Length == folder.Length)
|
||||
FolderName = "Songs";
|
||||
else
|
||||
{
|
||||
FolderName = Folder.Substring(folder.Length + 1, Folder.Length - folder.Length - 1);
|
||||
|
||||
int pos = FolderName.IndexOf("\\", StringComparison.Ordinal);
|
||||
if (pos >= 0)
|
||||
FolderName = FolderName.Substring(0, pos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
FileName = Path.GetFileName(filePath);
|
||||
|
||||
var headerFlags = new EHeaderFlags();
|
||||
StreamReader sr = null;
|
||||
try
|
||||
{
|
||||
sr = new StreamReader(filePath, Encoding.Default, true);
|
||||
|
||||
while (!sr.EndOfStream)
|
||||
{
|
||||
string line = sr.ReadLine();
|
||||
if (line == "")
|
||||
continue;
|
||||
if (!line[0].ToString().Equals("#"))
|
||||
break;
|
||||
|
||||
int pos = line.IndexOf(":", StringComparison.Ordinal);
|
||||
|
||||
if (pos <= 0)
|
||||
continue;
|
||||
string identifier = line.Substring(1, pos - 1).Trim().ToUpper();
|
||||
string value = line.Substring(pos + 1, line.Length - pos - 1).Trim();
|
||||
|
||||
if (value != "")
|
||||
{
|
||||
switch (identifier)
|
||||
{
|
||||
case "ENCODING":
|
||||
Encoding = CEncoding.GetEncoding(value);
|
||||
sr.Dispose();
|
||||
sr = null;
|
||||
sr = new StreamReader(filePath, Encoding);
|
||||
|
||||
//Scip everything till encoding
|
||||
while (!sr.EndOfStream)
|
||||
{
|
||||
line = sr.ReadLine();
|
||||
if (line == "")
|
||||
continue;
|
||||
if (!line[0].ToString().Equals("#"))
|
||||
break;
|
||||
|
||||
pos = line.IndexOf(":", StringComparison.Ordinal);
|
||||
|
||||
if (pos > 0)
|
||||
{
|
||||
identifier = line.Substring(1, pos - 1).Trim().ToUpper();
|
||||
if (identifier == "ENCODING")
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "TITLE":
|
||||
if (value != "")
|
||||
{
|
||||
Title = value;
|
||||
headerFlags |= EHeaderFlags.Title;
|
||||
}
|
||||
break;
|
||||
case "ARTIST":
|
||||
if (value != "")
|
||||
{
|
||||
Artist = value;
|
||||
headerFlags |= EHeaderFlags.Artist;
|
||||
}
|
||||
break;
|
||||
case "TITLE-ON-SORTING":
|
||||
if (value != "")
|
||||
TitleSorting = value;
|
||||
break;
|
||||
case "ARTIST-ON-SORTING":
|
||||
if (value != "")
|
||||
ArtistSorting = value;
|
||||
break;
|
||||
case "DUETSINGERP1":
|
||||
case "P1":
|
||||
if (value != "")
|
||||
DuetPart1 = value;
|
||||
break;
|
||||
case "DUETSINGERP2":
|
||||
case "P2":
|
||||
if (value != "")
|
||||
DuetPart2 = value;
|
||||
break;
|
||||
case "MP3":
|
||||
if (File.Exists(Path.Combine(Folder, value)))
|
||||
{
|
||||
MP3FileName = value;
|
||||
headerFlags |= EHeaderFlags.MP3;
|
||||
}
|
||||
else
|
||||
{
|
||||
CBase.Log.LogError("Can't find audio file: " + Path.Combine(Folder, value));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case "BPM":
|
||||
if (CHelper.TryParse(value, out BPM))
|
||||
{
|
||||
BPM *= 4;
|
||||
headerFlags |= EHeaderFlags.BPM;
|
||||
}
|
||||
break;
|
||||
case "EDITION":
|
||||
if (value.Length > 1)
|
||||
Edition.Add(value);
|
||||
break;
|
||||
case "GENRE":
|
||||
if (value.Length > 1)
|
||||
Genre.Add(value);
|
||||
break;
|
||||
case "YEAR":
|
||||
int num;
|
||||
if (value.Length == 4 && int.TryParse(value, out num) && num != 0)
|
||||
Year = value;
|
||||
break;
|
||||
case "LANGUAGE":
|
||||
if (value.Length > 1)
|
||||
Language.Add(value);
|
||||
break;
|
||||
case "COMMENT":
|
||||
if (value.Length > 1)
|
||||
_Comment.Add(value);
|
||||
break;
|
||||
case "GAP":
|
||||
if (CHelper.TryParse(value, out Gap))
|
||||
Gap /= 1000f;
|
||||
break;
|
||||
case "COVER":
|
||||
if (File.Exists(Path.Combine(Folder, value)))
|
||||
CoverFileName = value;
|
||||
break;
|
||||
case "BACKGROUND":
|
||||
if (File.Exists(Path.Combine(Folder, value)))
|
||||
BackgroundFileName = value;
|
||||
break;
|
||||
case "VIDEO":
|
||||
if (File.Exists(Path.Combine(Folder, value)))
|
||||
VideoFileName = value;
|
||||
else
|
||||
CBase.Log.LogError("Can't find video file: " + Path.Combine(Folder, value));
|
||||
break;
|
||||
case "VIDEOGAP":
|
||||
CHelper.TryParse(value, out VideoGap);
|
||||
break;
|
||||
case "VIDEOASPECT":
|
||||
CHelper.TryParse(value, out VideoAspect, true);
|
||||
break;
|
||||
case "START":
|
||||
CHelper.TryParse(value, out Start);
|
||||
break;
|
||||
case "END":
|
||||
if (CHelper.TryParse(value, out Finish))
|
||||
Finish /= 1000f;
|
||||
break;
|
||||
case "PREVIEWSTART":
|
||||
if (CHelper.TryParse(value, out PreviewStart))
|
||||
{
|
||||
if (PreviewStart < 0f)
|
||||
PreviewStart = 0f;
|
||||
else
|
||||
headerFlags |= EHeaderFlags.PreviewStart;
|
||||
}
|
||||
break;
|
||||
case "MEDLEYSTARTBEAT":
|
||||
if (int.TryParse(value, out Medley.StartBeat))
|
||||
headerFlags |= EHeaderFlags.MedleyStartBeat;
|
||||
break;
|
||||
case "MEDLEYENDBEAT":
|
||||
if (int.TryParse(value, out Medley.EndBeat))
|
||||
headerFlags |= EHeaderFlags.MedleyEndBeat;
|
||||
break;
|
||||
case "CALCMEDLEY":
|
||||
if (value.ToUpper() == "OFF")
|
||||
CalculateMedley = false;
|
||||
break;
|
||||
case "RELATIVE":
|
||||
if (value.ToUpper() == "YES" && value.ToUpper() != "NO")
|
||||
Relative = EOffOn.TR_CONFIG_ON;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} //end of while
|
||||
|
||||
if (sr.EndOfStream)
|
||||
{
|
||||
//No other data then header
|
||||
CBase.Log.LogError("Lyrics/Notes missing: " + filePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.Title) == 0)
|
||||
{
|
||||
CBase.Log.LogError("Title tag missing: " + filePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.Artist) == 0)
|
||||
{
|
||||
CBase.Log.LogError("Artist tag missing: " + filePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.MP3) == 0)
|
||||
{
|
||||
CBase.Log.LogError("MP3 tag missing: " + filePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.BPM) == 0)
|
||||
{
|
||||
CBase.Log.LogError("BPM tag missing: " + filePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
#region check medley tags
|
||||
if ((headerFlags & EHeaderFlags.MedleyStartBeat) != 0 && (headerFlags & EHeaderFlags.MedleyEndBeat) != 0)
|
||||
{
|
||||
if (Medley.StartBeat > Medley.EndBeat)
|
||||
{
|
||||
CBase.Log.LogError("MedleyStartBeat is bigger than MedleyEndBeat in file: " + filePath);
|
||||
headerFlags = headerFlags - EHeaderFlags.MedleyStartBeat - EHeaderFlags.MedleyEndBeat;
|
||||
}
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.PreviewStart) == 0 || Math.Abs(PreviewStart) < float.Epsilon)
|
||||
{
|
||||
//PreviewStart is not set or <=0
|
||||
PreviewStart = (headerFlags & EHeaderFlags.MedleyStartBeat) != 0 ? CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) : 0f;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.MedleyStartBeat) != 0 && (headerFlags & EHeaderFlags.MedleyEndBeat) != 0)
|
||||
{
|
||||
Medley.Source = EMedleySource.Tag;
|
||||
Medley.FadeInTime = CBase.Settings.GetDefaultMedleyFadeInTime();
|
||||
Medley.FadeOutTime = CBase.Settings.GetDefaultMedleyFadeOutTime();
|
||||
}
|
||||
#endregion check medley tags
|
||||
|
||||
Encoding = sr.CurrentEncoding;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (sr != null)
|
||||
sr.Dispose();
|
||||
CBase.Log.LogError("Error reading txt header in file \"" + filePath + "\": " + e.Message);
|
||||
return false;
|
||||
}
|
||||
sr.Dispose();
|
||||
_CheckFiles();
|
||||
|
||||
CBase.DataBase.GetDataBaseSongInfos(Artist, Title, out NumPlayed, out DateAdded, out DataBaseSongID);
|
||||
|
||||
//Before saving this tags to .txt: Check, if ArtistSorting and Artist are equal, then don't save this tag.
|
||||
if (ArtistSorting == "")
|
||||
ArtistSorting = Artist;
|
||||
|
||||
if (TitleSorting == "")
|
||||
TitleSorting = Title;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ReadNotes()
|
||||
{
|
||||
return _ReadNotes(Path.Combine(Folder, FileName));
|
||||
}
|
||||
|
||||
private bool _ReadNotes(string filePath, bool forceReload = false)
|
||||
{
|
||||
//Skip loading if already done and no reload is forced
|
||||
if (NotesLoaded && !forceReload)
|
||||
return true;
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
CBase.Log.LogError("Error loading song. The file does not exist: " + filePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
char tempC = char.MinValue;
|
||||
int currentPos = 0;
|
||||
bool isNewSentence = false;
|
||||
|
||||
int player = 0;
|
||||
int fileLineNo = 0;
|
||||
|
||||
StreamReader sr = null;
|
||||
try
|
||||
{
|
||||
sr = new StreamReader(filePath, Encoding, true);
|
||||
|
||||
Notes.Reset();
|
||||
|
||||
//Search for Note Beginning
|
||||
while (!sr.EndOfStream)
|
||||
{
|
||||
sr.ReadLine();
|
||||
fileLineNo++;
|
||||
|
||||
tempC = (char)sr.Peek();
|
||||
if ((tempC == '#') || (tempC == '\r') || (tempC == '\n'))
|
||||
continue;
|
||||
if ((tempC == ':') || (tempC == 'F') || (tempC == '*') || (tempC == 'P'))
|
||||
{
|
||||
tempC = (char)sr.Read();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (sr.EndOfStream)
|
||||
{
|
||||
CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo + ". No lyrics/notes found: " + filePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
int param2;
|
||||
int param1;
|
||||
switch (tempC)
|
||||
{
|
||||
case 'P':
|
||||
char chr;
|
||||
while ((chr = (char)sr.Read()) == ' ') {}
|
||||
|
||||
int.TryParse(chr.ToString(), out param1);
|
||||
if (param1 == 1)
|
||||
player = 0;
|
||||
else if (param1 == 2)
|
||||
player = 1;
|
||||
else if (param1 == 3)
|
||||
player = 2;
|
||||
else
|
||||
{
|
||||
CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo + ". Wrong or missing number after \"P\": " + filePath);
|
||||
return false;
|
||||
}
|
||||
sr.ReadLine();
|
||||
break;
|
||||
case ':':
|
||||
case '*':
|
||||
case 'F':
|
||||
sr.Read();
|
||||
param1 = CHelper.TryReadInt(sr);
|
||||
|
||||
sr.Read();
|
||||
param2 = CHelper.TryReadInt(sr);
|
||||
|
||||
sr.Read();
|
||||
int param3 = CHelper.TryReadInt(sr);
|
||||
|
||||
sr.Read();
|
||||
string paramS = sr.ReadLine();
|
||||
|
||||
ENoteType noteType;
|
||||
|
||||
if (tempC.CompareTo('*') == 0)
|
||||
noteType = ENoteType.Golden;
|
||||
else if (tempC.CompareTo('F') == 0)
|
||||
noteType = ENoteType.Freestyle;
|
||||
else
|
||||
noteType = ENoteType.Normal;
|
||||
|
||||
if (Relative == EOffOn.TR_CONFIG_ON)
|
||||
param1 += currentPos;
|
||||
|
||||
if (player != 2)
|
||||
// one singer
|
||||
_ParseNote(player, noteType, param1, param2, param3, paramS);
|
||||
else
|
||||
{
|
||||
// both singer
|
||||
_ParseNote(0, noteType, param1, param2, param3, paramS);
|
||||
_ParseNote(1, noteType, param1, param2, param3, paramS);
|
||||
}
|
||||
isNewSentence = false;
|
||||
break;
|
||||
case '-':
|
||||
if (isNewSentence)
|
||||
{
|
||||
CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo + ". Double sentence break: " + filePath);
|
||||
return false;
|
||||
}
|
||||
sr.Read();
|
||||
param1 = CHelper.TryReadInt(sr);
|
||||
|
||||
if (Relative == EOffOn.TR_CONFIG_ON)
|
||||
{
|
||||
param1 += currentPos;
|
||||
sr.Read();
|
||||
param2 = CHelper.TryReadInt(sr);
|
||||
currentPos += param2;
|
||||
}
|
||||
|
||||
if (player != 2)
|
||||
// one singer
|
||||
_NewSentence(player, param1);
|
||||
else
|
||||
{
|
||||
// both singer
|
||||
_NewSentence(0, param1);
|
||||
_NewSentence(1, param1);
|
||||
}
|
||||
|
||||
isNewSentence = true;
|
||||
sr.ReadLine();
|
||||
break;
|
||||
default:
|
||||
CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo + ". Unexpected or missing character (" + tempC + "): " + filePath);
|
||||
return false;
|
||||
}
|
||||
int c;
|
||||
do
|
||||
{
|
||||
c = sr.Read();
|
||||
} while (!sr.EndOfStream && (c == 19 || c == 16 || c == 13 || c == 10));
|
||||
tempC = (char)c;
|
||||
fileLineNo++;
|
||||
} while (!sr.EndOfStream && (tempC != 'E'));
|
||||
|
||||
foreach (CVoice voice in Notes.Voices)
|
||||
voice.UpdateTimings();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo + ". An unhandled exception occured (" + e.Message + "): " + filePath);
|
||||
if (sr != null)
|
||||
sr.Dispose();
|
||||
return false;
|
||||
}
|
||||
sr.Dispose();
|
||||
try
|
||||
{
|
||||
_FindRefrain();
|
||||
_FindShortEnd();
|
||||
NotesLoaded = true;
|
||||
if (IsDuet)
|
||||
_CheckDuet();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CBase.Log.LogError("Error loading song. An unhandled exception occured (" + e.Message + "): " + filePath);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool _ParseNote(int player, ENoteType noteType, int start, int length, int tone, string text)
|
||||
{
|
||||
var note = new CSongNote(start, length, tone, text, noteType);
|
||||
CVoice voice = Notes.GetVoice(player);
|
||||
return voice.AddNote(note);
|
||||
}
|
||||
|
||||
private void _NewSentence(int player, int start)
|
||||
{
|
||||
CVoice voice = Notes.GetVoice(player);
|
||||
var line = new CSongLine {StartBeat = start};
|
||||
voice.AddLine(line);
|
||||
}
|
||||
|
||||
public void LoadSmallCover()
|
||||
{
|
||||
if (_CoverTextureSmall != null)
|
||||
@@ -765,11 +317,13 @@ namespace VocaluxeLib.Songs
|
||||
if (CoverFileName == "")
|
||||
{
|
||||
List<string> files = CHelper.ListFiles(Folder, "*.jpg");
|
||||
files.AddRange(CHelper.ListFiles(Folder, "*.jpeg"));
|
||||
files.AddRange(CHelper.ListFiles(Folder, "*.png"));
|
||||
files.AddRange(CHelper.ListFiles(Folder, "*.gif"));
|
||||
foreach (String file in files)
|
||||
{
|
||||
if (Regex.IsMatch(file, @".[CO].", RegexOptions.IgnoreCase) &&
|
||||
(Regex.IsMatch(file, @"" + Regex.Escape(Title), RegexOptions.IgnoreCase) || Regex.IsMatch(file, @"" + Regex.Escape(Artist), RegexOptions.IgnoreCase)))
|
||||
if (file.ContainsIgnoreCase("[CO]") &&
|
||||
(file.ContainsIgnoreCase(Title) || file.ContainsIgnoreCase(Artist)))
|
||||
CoverFileName = file;
|
||||
}
|
||||
}
|
||||
@@ -777,11 +331,13 @@ namespace VocaluxeLib.Songs
|
||||
if (BackgroundFileName == "")
|
||||
{
|
||||
List<string> files = CHelper.ListFiles(Folder, "*.jpg");
|
||||
files.AddRange(CHelper.ListFiles(Folder, "*.jpeg"));
|
||||
files.AddRange(CHelper.ListFiles(Folder, "*.png"));
|
||||
files.AddRange(CHelper.ListFiles(Folder, "*.gif"));
|
||||
foreach (String file in files)
|
||||
{
|
||||
if (Regex.IsMatch(file, @".[BG].", RegexOptions.IgnoreCase) &&
|
||||
(Regex.IsMatch(file, @"" + Regex.Escape(Title), RegexOptions.IgnoreCase) || Regex.IsMatch(file, @"" + Regex.Escape(Artist), RegexOptions.IgnoreCase)))
|
||||
if (file.ContainsIgnoreCase("[BG]") &&
|
||||
(file.ContainsIgnoreCase(Title) || file.ContainsIgnoreCase(Artist)))
|
||||
BackgroundFileName = file;
|
||||
}
|
||||
}
|
||||
@@ -789,15 +345,10 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
private void _CheckDuet()
|
||||
{
|
||||
if (DuetPart1 == "")
|
||||
for (int i = 0; i < Notes.VoiceCount; i++)
|
||||
{
|
||||
DuetPart1 = "Part 1";
|
||||
CBase.Log.LogError("Warning: Can't find #P1-tag for duets in \"" + Artist + " - " + Title + "\".");
|
||||
}
|
||||
if (DuetPart2 == "")
|
||||
{
|
||||
DuetPart2 = "Part 2";
|
||||
CBase.Log.LogError("Warning: Can't find #P2-tag for duets in \"" + Artist + " - " + Title + "\".");
|
||||
if (!Notes.VoiceNames.IsSet(i))
|
||||
CBase.Log.LogError("Warning: Can't find #P" + (i + 1) + "-tag for duets in \"" + Artist + " - " + Title + "\".");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -853,14 +404,11 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
if (IsDuet)
|
||||
{
|
||||
Medley.Source = EMedleySource.None;
|
||||
Medley.Source = EDataSource.None;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Medley.Source == EMedleySource.Tag)
|
||||
return;
|
||||
|
||||
if (!CalculateMedley)
|
||||
if (!_CalculateMedley)
|
||||
return;
|
||||
|
||||
List<SSeries> series = _GetSeries();
|
||||
@@ -883,41 +431,44 @@ namespace VocaluxeLib.Songs
|
||||
Medley.StartBeat = voice.Lines[series[longest].Start].FirstNoteBeat;
|
||||
Medley.EndBeat = voice.Lines[series[longest].End].LastNoteBeat;
|
||||
|
||||
bool foundEnd = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) + CBase.Settings.GetMedleyMinDuration() >
|
||||
CBase.Game.GetTimeFromBeats(Medley.EndBeat, BPM);
|
||||
bool foundEnd = CBase.Game.GetTimeFromBeats(Medley.EndBeat, BPM) - CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) < CBase.Settings.GetMedleyMinDuration();
|
||||
|
||||
// set end if duration > MedleyMinDuration
|
||||
// set end if duration < MedleyMinDuration
|
||||
|
||||
if (!foundEnd)
|
||||
{
|
||||
for (int i = series[longest].Start + 1; i < voice.NumLines - 1; i++)
|
||||
for (int i = series[longest].End + 1; i < voice.NumLines - 1; i++)
|
||||
{
|
||||
if (CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) + CBase.Settings.GetMedleyMinDuration() >
|
||||
CBase.Game.GetTimeFromBeats(voice.Lines[i].LastNoteBeat, BPM))
|
||||
if (CBase.Game.GetTimeFromBeats(voice.Lines[i].LastNoteBeat, BPM) - CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) <
|
||||
CBase.Settings.GetMedleyMinDuration())
|
||||
{
|
||||
foundEnd = true;
|
||||
Medley.EndBeat = voice.Lines[i].LastNoteBeat;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (foundEnd)
|
||||
{
|
||||
Medley.Source = EMedleySource.Calculated;
|
||||
Medley.Source = EDataSource.Calculated;
|
||||
Medley.FadeInTime = CBase.Settings.GetDefaultMedleyFadeInTime();
|
||||
Medley.FadeOutTime = CBase.Settings.GetDefaultMedleyFadeOutTime();
|
||||
}
|
||||
}
|
||||
|
||||
if (Math.Abs(PreviewStart) < 0.001)
|
||||
if (Preview.Source == EDataSource.None)
|
||||
{
|
||||
if (Medley.Source == EMedleySource.Calculated)
|
||||
PreviewStart = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM);
|
||||
if (Medley.Source != EDataSource.None)
|
||||
Preview.StartTime = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM);
|
||||
}
|
||||
}
|
||||
|
||||
private void _FindShortEnd()
|
||||
{
|
||||
if (ShortEnd.Source != EDataSource.None)
|
||||
return;
|
||||
|
||||
List<SSeries> series = _GetSeries();
|
||||
if (series == null)
|
||||
return;
|
||||
@@ -934,10 +485,10 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
if (stop < (voice.Lines[series[i].Start].FirstNoteBeat + ((voice.Lines[series[i].End].LastNoteBeat - voice.Lines[series[i].Start].FirstNoteBeat) / 2)))
|
||||
{
|
||||
ShortEnd = voice.Lines[series[i].Start - 1].LastNote.EndBeat;
|
||||
ShortEnd.EndBeat = voice.Lines[series[i].Start - 1].LastNote.EndBeat;
|
||||
return;
|
||||
}
|
||||
ShortEnd = voice.Lines[series[i].End].LastNote.EndBeat;
|
||||
ShortEnd.EndBeat = voice.Lines[series[i].End].LastNote.EndBeat;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -947,12 +498,13 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
if (line.FirstNoteBeat < stop && line.LastNoteBeat > stop)
|
||||
{
|
||||
ShortEnd = line.LastNoteBeat;
|
||||
ShortEnd.EndBeat = line.LastNoteBeat;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ShortEnd = stop;
|
||||
ShortEnd.EndBeat = stop;
|
||||
ShortEnd.Source = EDataSource.Calculated;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
public class CSongLine : CLineBase<CSongNote>
|
||||
{
|
||||
private int _StartBeat = int.MinValue;
|
||||
private int _StartBeat = int.MaxValue;
|
||||
private int _EndBeat = int.MinValue;
|
||||
|
||||
#region Constructors
|
||||
@@ -46,7 +46,7 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
public int StartBeat
|
||||
{
|
||||
get { return _StartBeat; }
|
||||
get { return Math.Min(_StartBeat, FirstNoteBeat); }
|
||||
set
|
||||
{
|
||||
if (value <= FirstNoteBeat)
|
||||
@@ -56,7 +56,7 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
public int EndBeat
|
||||
{
|
||||
get { return _EndBeat; }
|
||||
get { return Math.Min(_EndBeat, LastNoteBeat); }
|
||||
set
|
||||
{
|
||||
if (value >= LastNoteBeat)
|
||||
@@ -77,12 +77,19 @@ namespace VocaluxeLib.Songs
|
||||
_Notes.Add(note);
|
||||
else
|
||||
{
|
||||
//Insert AFTER this note
|
||||
int insPos = FindPreviousNote(note.StartBeat);
|
||||
//Check for overlapping notes
|
||||
if (insPos >= 0 && _Notes[insPos].EndBeat > note.StartBeat)
|
||||
return false;
|
||||
if (insPos < _Notes.Count - 1 && _Notes[insPos + 1].StartBeat > note.EndBeat)
|
||||
return false;
|
||||
if (insPos >= 0) //Check note before
|
||||
{
|
||||
if (_Notes[insPos].EndBeat >= note.StartBeat)
|
||||
return false;
|
||||
}
|
||||
if (insPos < _Notes.Count - 1) //Check note after
|
||||
{
|
||||
if (_Notes[insPos + 1].StartBeat <= note.EndBeat)
|
||||
return false;
|
||||
}
|
||||
_Notes.Insert(insPos + 1, note);
|
||||
}
|
||||
return true;
|
||||
@@ -90,11 +97,8 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
public void SetMedley(int startBeat, int endBeat)
|
||||
{
|
||||
foreach (CSongNote note in _Notes)
|
||||
{
|
||||
if (note.StartBeat < startBeat || note.EndBeat > endBeat)
|
||||
note.NoteType = ENoteType.Freestyle;
|
||||
}
|
||||
foreach (CSongNote note in _Notes.Where(note => note.StartBeat < startBeat || note.EndBeat > endBeat))
|
||||
note.Type = ENoteType.Freestyle;
|
||||
|
||||
VisibleInTimeLine = FirstNoteBeat >= startBeat && LastNoteBeat <= endBeat;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,740 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace VocaluxeLib.Songs
|
||||
{
|
||||
/// <summary>
|
||||
/// Part of CSong that is required for note loading
|
||||
/// </summary>
|
||||
public partial class CSong
|
||||
{
|
||||
/// <summary>
|
||||
/// Factor the bpm given in the txt is multiplied with
|
||||
/// </summary>
|
||||
private const int _BPMFactor = 4;
|
||||
|
||||
private class CSongLoader
|
||||
{
|
||||
private readonly CSong _Song;
|
||||
private int _LineNr;
|
||||
|
||||
public CSongLoader(CSong song)
|
||||
{
|
||||
_Song = song;
|
||||
}
|
||||
|
||||
public bool InitPaths(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
return false;
|
||||
|
||||
_Song.Folder = Path.GetDirectoryName(filePath);
|
||||
if (_Song.Folder == null)
|
||||
return false;
|
||||
|
||||
foreach (string folder in CBase.Config.GetSongFolders().Where(folder => _Song.Folder.StartsWith(folder)))
|
||||
{
|
||||
if (_Song.Folder.Length == folder.Length)
|
||||
_Song.FolderName = "Songs";
|
||||
else
|
||||
{
|
||||
_Song.FolderName = _Song.Folder.Substring(folder.Length + 1);
|
||||
|
||||
int pos = _Song.FolderName.IndexOf("\\", StringComparison.Ordinal);
|
||||
if (pos >= 0)
|
||||
_Song.FolderName = _Song.FolderName.Substring(0, pos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
_Song.FileName = Path.GetFileName(filePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs a given message with file name and line#
|
||||
/// </summary>
|
||||
/// <param name="msg">Message</param>
|
||||
/// <param name="error">True prepends "Error: "; False prepends "Warning: "</param>
|
||||
/// <param name="withLineNr">Adds line#</param>
|
||||
private void _LogMsg(string msg, bool error, bool withLineNr)
|
||||
{
|
||||
msg = (error ? "Error: " : "Warning: ") + msg;
|
||||
if (withLineNr)
|
||||
msg += " in line #" + _LineNr;
|
||||
CBase.Log.LogError(msg + " (" + Path.Combine(_Song.Folder, _Song.FileName) + ")");
|
||||
}
|
||||
|
||||
private void _LogError(string msg, bool withLineNr = true)
|
||||
{
|
||||
_LogMsg(msg, true, withLineNr);
|
||||
}
|
||||
|
||||
private void _LogWarning(string msg, bool withLineNr = true)
|
||||
{
|
||||
_LogMsg(msg, false, withLineNr);
|
||||
}
|
||||
|
||||
public bool ReadHeader(bool useSetEncoding = false)
|
||||
{
|
||||
string filePath = Path.Combine(_Song.Folder, _Song.FileName);
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
return false;
|
||||
|
||||
_Song.Languages.Clear();
|
||||
_Song.Genres.Clear();
|
||||
_Song.UnknownTags.Clear();
|
||||
_Song._Comment = "";
|
||||
_Song.ManualEncoding = false;
|
||||
_Song.Medley.Source = EDataSource.None;
|
||||
_Song._CalculateMedley = true;
|
||||
_Song.Preview.Source = EDataSource.None;
|
||||
_Song.ShortEnd.Source = EDataSource.None;
|
||||
|
||||
var headerFlags = new EHeaderFlags();
|
||||
StreamReader sr = null;
|
||||
_LineNr = 0;
|
||||
try
|
||||
{
|
||||
sr = new StreamReader(filePath, _Song.Encoding, true);
|
||||
while (!sr.EndOfStream)
|
||||
{
|
||||
string line = sr.ReadLine();
|
||||
_LineNr++;
|
||||
if (line == "")
|
||||
continue;
|
||||
if (!line[0].Equals('#'))
|
||||
break;
|
||||
|
||||
int pos = line.IndexOf(":", StringComparison.Ordinal);
|
||||
|
||||
if (pos <= 1)
|
||||
{
|
||||
_Song.UnknownTags.Add(line);
|
||||
continue;
|
||||
}
|
||||
string identifier = line.Substring(1, pos - 1).Trim().ToUpper();
|
||||
if (identifier.Contains(" "))
|
||||
{
|
||||
_Song.UnknownTags.Add(line);
|
||||
continue;
|
||||
}
|
||||
string value = line.Substring(pos + 1).Trim();
|
||||
|
||||
if (value == "")
|
||||
{
|
||||
_Song.UnknownTags.Add(line);
|
||||
_LogWarning("Empty value skipped");
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (identifier)
|
||||
{
|
||||
case "ENCODING":
|
||||
Encoding newEncoding = value.GetEncoding();
|
||||
_Song.ManualEncoding = true;
|
||||
if (!newEncoding.Equals(sr.CurrentEncoding))
|
||||
{
|
||||
if (useSetEncoding)
|
||||
{
|
||||
_LogWarning("Duplicate encoding ignored");
|
||||
continue;
|
||||
}
|
||||
sr.Dispose();
|
||||
sr = null;
|
||||
_Song.Encoding = newEncoding;
|
||||
return ReadHeader(true);
|
||||
}
|
||||
break;
|
||||
case "TITLE":
|
||||
_Song.Title = value;
|
||||
headerFlags |= EHeaderFlags.Title;
|
||||
break;
|
||||
case "ARTIST":
|
||||
_Song.Artist = value;
|
||||
headerFlags |= EHeaderFlags.Artist;
|
||||
break;
|
||||
case "TITLE-ON-SORTING":
|
||||
_Song.TitleSorting = value;
|
||||
break;
|
||||
case "ARTIST-ON-SORTING":
|
||||
_Song.ArtistSorting = value;
|
||||
break;
|
||||
case "CREATOR":
|
||||
case "AUTHOR":
|
||||
case "AUTOR":
|
||||
_Song.Creator = value;
|
||||
break;
|
||||
case "VERSION":
|
||||
_Song.Version = value;
|
||||
break;
|
||||
case "SOURCE":
|
||||
case "YOUTUBE":
|
||||
_Song.Source = value;
|
||||
break;
|
||||
case "MP3":
|
||||
if (File.Exists(Path.Combine(_Song.Folder, value)))
|
||||
{
|
||||
_Song.MP3FileName = value;
|
||||
headerFlags |= EHeaderFlags.MP3;
|
||||
}
|
||||
else
|
||||
{
|
||||
_LogError("Can't find audio file: " + Path.Combine(_Song.Folder, value));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case "BPM":
|
||||
if (CHelper.TryParse(value, out _Song.BPM))
|
||||
{
|
||||
_Song.BPM *= _BPMFactor;
|
||||
headerFlags |= EHeaderFlags.BPM;
|
||||
}
|
||||
else
|
||||
_LogWarning("Invalid BPM value");
|
||||
break;
|
||||
case "EDITION":
|
||||
if (value.Length > 1)
|
||||
_Song.Editions.Add(value);
|
||||
else
|
||||
_LogWarning("Invalid edition");
|
||||
break;
|
||||
case "GENRE":
|
||||
if (value.Length > 1)
|
||||
_Song.Genres.Add(value);
|
||||
else
|
||||
_LogWarning("Invalid genre");
|
||||
break;
|
||||
case "ALBUM":
|
||||
_Song.Album = value;
|
||||
break;
|
||||
case "YEAR":
|
||||
int num;
|
||||
if (value.Length == 4 && int.TryParse(value, out num) && num > 0)
|
||||
_Song.Year = value;
|
||||
else
|
||||
_LogWarning("Invalid year");
|
||||
break;
|
||||
case "LANGUAGE":
|
||||
if (value.Length > 1)
|
||||
_Song.Languages.Add(value);
|
||||
else
|
||||
_LogWarning("Invalid language");
|
||||
break;
|
||||
case "COMMENT":
|
||||
if (!String.IsNullOrEmpty(_Song._Comment))
|
||||
_Song._Comment += "\r\n";
|
||||
_Song._Comment += value;
|
||||
break;
|
||||
case "GAP":
|
||||
if (CHelper.TryParse(value, out _Song.Gap))
|
||||
_Song.Gap /= 1000f;
|
||||
else
|
||||
_LogWarning("Invalid gap");
|
||||
break;
|
||||
case "COVER":
|
||||
if (File.Exists(Path.Combine(_Song.Folder, value)))
|
||||
_Song.CoverFileName = value;
|
||||
else
|
||||
_LogWarning("Can't find cover file: " + Path.Combine(_Song.Folder, value));
|
||||
break;
|
||||
case "BACKGROUND":
|
||||
if (File.Exists(Path.Combine(_Song.Folder, value)))
|
||||
_Song.BackgroundFileName = value;
|
||||
else
|
||||
_LogWarning("Can't find background file: " + Path.Combine(_Song.Folder, value));
|
||||
break;
|
||||
case "VIDEO":
|
||||
if (File.Exists(Path.Combine(_Song.Folder, value)))
|
||||
_Song.VideoFileName = value;
|
||||
else
|
||||
_LogWarning("Can't find video file: " + Path.Combine(_Song.Folder, value));
|
||||
break;
|
||||
case "VIDEOGAP":
|
||||
if (!CHelper.TryParse(value, out _Song.VideoGap))
|
||||
_LogWarning("Invalid videogap");
|
||||
break;
|
||||
case "VIDEOASPECT":
|
||||
if (!CHelper.TryParse(value, out _Song.VideoAspect, true))
|
||||
_LogWarning("Invalid videoaspect");
|
||||
break;
|
||||
case "START":
|
||||
if (!CHelper.TryParse(value, out _Song.Start))
|
||||
_LogWarning("Invalid start");
|
||||
break;
|
||||
case "END":
|
||||
if (CHelper.TryParse(value, out _Song.Finish))
|
||||
_Song.Finish /= 1000f;
|
||||
else
|
||||
_LogWarning("Invalid end");
|
||||
break;
|
||||
case "PREVIEWSTART":
|
||||
if (CHelper.TryParse(value, out _Song.Preview.StartTime) && _Song.Preview.StartTime >= 0f)
|
||||
_Song.Preview.Source = EDataSource.Tag;
|
||||
else
|
||||
_LogWarning("Invalid previewstart");
|
||||
break;
|
||||
case "PREVIEW":
|
||||
if (CHelper.TryParse(value, out _Song.Preview.StartTime) && _Song.Preview.StartTime >= 0f)
|
||||
{
|
||||
//This is stored in ms not like PREVIEWSTART!
|
||||
_Song.Preview.StartTime /= 1000f;
|
||||
_Song.Preview.Source = EDataSource.Tag;
|
||||
}
|
||||
else
|
||||
_LogWarning("Invalid previewstart");
|
||||
break;
|
||||
case "MEDLEYSTARTBEAT":
|
||||
if (int.TryParse(value, out _Song.Medley.StartBeat))
|
||||
headerFlags |= EHeaderFlags.MedleyStartBeat;
|
||||
else
|
||||
_LogWarning("Invalid medleystartbeat");
|
||||
break;
|
||||
case "MEDLEYENDBEAT":
|
||||
if (int.TryParse(value, out _Song.Medley.EndBeat))
|
||||
headerFlags |= EHeaderFlags.MedleyEndBeat;
|
||||
else
|
||||
_LogWarning("Invalid medleyendbeat");
|
||||
break;
|
||||
case "ENDSHORT":
|
||||
if ((headerFlags & EHeaderFlags.BPM) != 0)
|
||||
{
|
||||
int endTime;
|
||||
if (int.TryParse(value, out endTime) || endTime < 0)
|
||||
{
|
||||
_Song.ShortEnd.EndBeat = (int)CBase.Game.GetBeatFromTime(endTime / 1000f, _Song.BPM, _Song.Gap);
|
||||
_Song.ShortEnd.Source = EDataSource.Tag;
|
||||
}
|
||||
else
|
||||
_LogWarning("Invalid medleyendbeat");
|
||||
}
|
||||
break;
|
||||
case "CALCMEDLEY":
|
||||
if (value.ToUpper() == "OFF")
|
||||
_Song._CalculateMedley = false;
|
||||
break;
|
||||
case "RELATIVE":
|
||||
if (value.ToUpper() == "YES")
|
||||
_Song.Relative = true;
|
||||
break;
|
||||
case "RESOLUTION":
|
||||
case "NOTESGAP":
|
||||
//Outdated/not used
|
||||
_Song.UnknownTags.Add(line);
|
||||
break;
|
||||
default:
|
||||
if (identifier.StartsWith("DUETSINGER"))
|
||||
{
|
||||
identifier = identifier.Substring(10);
|
||||
if (identifier.StartsWith("P")) // fix for missing "P"
|
||||
identifier = "P" + identifier;
|
||||
}
|
||||
if (identifier.StartsWith("P"))
|
||||
{
|
||||
int player;
|
||||
if (int.TryParse(identifier.Substring(1).Trim(), out player))
|
||||
{
|
||||
foreach (int curPlayer in player.GetSetBits())
|
||||
_Song.Notes.VoiceNames[curPlayer] = value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_Song.UnknownTags.Add(line);
|
||||
_LogWarning("Unknown tag: #" + identifier);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
} //end of while
|
||||
|
||||
if (sr.EndOfStream)
|
||||
{
|
||||
//No other data then header
|
||||
_LogError("Lyrics/Notes missing", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.Title) == 0)
|
||||
{
|
||||
_LogError("Title tag missing", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.Artist) == 0)
|
||||
{
|
||||
_LogError("Artist tag missing", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.MP3) == 0)
|
||||
{
|
||||
_LogError("MP3 tag missing", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.BPM) == 0)
|
||||
{
|
||||
_LogError("BPM tag missing", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
#region check medley tags
|
||||
if ((headerFlags & EHeaderFlags.MedleyStartBeat) != 0 && (headerFlags & EHeaderFlags.MedleyEndBeat) != 0)
|
||||
{
|
||||
if (_Song.Medley.StartBeat > _Song.Medley.EndBeat)
|
||||
{
|
||||
_LogError("MedleyStartBeat is bigger than MedleyEndBeat in file", false);
|
||||
headerFlags = headerFlags - EHeaderFlags.MedleyStartBeat - EHeaderFlags.MedleyEndBeat;
|
||||
}
|
||||
}
|
||||
|
||||
if (_Song.Preview.Source == EDataSource.None)
|
||||
{
|
||||
//PreviewStart is not set or <=0
|
||||
_Song.Preview.StartTime = (headerFlags & EHeaderFlags.MedleyStartBeat) != 0 ? CBase.Game.GetTimeFromBeats(_Song.Medley.StartBeat, _Song.BPM) : 0f;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.MedleyStartBeat) != 0 && (headerFlags & EHeaderFlags.MedleyEndBeat) != 0)
|
||||
{
|
||||
_Song.Medley.Source = EDataSource.Tag;
|
||||
_Song.Medley.FadeInTime = CBase.Settings.GetDefaultMedleyFadeInTime();
|
||||
_Song.Medley.FadeOutTime = CBase.Settings.GetDefaultMedleyFadeOutTime();
|
||||
}
|
||||
#endregion check medley tags
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (sr != null)
|
||||
sr.Dispose();
|
||||
_LogError("Error reading txt header" + e.Message, false);
|
||||
return false;
|
||||
}
|
||||
_Song.Encoding = sr.CurrentEncoding;
|
||||
sr.Dispose();
|
||||
_Song._CheckFiles();
|
||||
|
||||
CBase.DataBase.GetDataBaseSongInfos(_Song.Artist, _Song.Title, out _Song.NumPlayed, out _Song.DateAdded, out _Song.DataBaseSongID);
|
||||
|
||||
//Before saving this tags to .txt: Check, if ArtistSorting and Artist are equal, then don't save this tag.
|
||||
if (String.IsNullOrEmpty(_Song.ArtistSorting))
|
||||
_Song.ArtistSorting = _Song.Artist;
|
||||
|
||||
if (String.IsNullOrEmpty(_Song.TitleSorting))
|
||||
_Song.TitleSorting = _Song.Title;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private enum ENoteReadMode
|
||||
{
|
||||
Normal,
|
||||
ZeroBased,
|
||||
OneBased
|
||||
}
|
||||
|
||||
private class CAutoChanges
|
||||
{
|
||||
public int ZeroLengthNoteCt;
|
||||
public int OverlapNoteCt;
|
||||
public int NoTextNoteCt;
|
||||
public int NoLengthBreakCt;
|
||||
public int AjustedBreakCt;
|
||||
public int InvalidPosBreakCt;
|
||||
|
||||
public bool IsModified
|
||||
{
|
||||
get { return ZeroLengthNoteCt + OverlapNoteCt + NoTextNoteCt + NoLengthBreakCt + AjustedBreakCt + InvalidPosBreakCt > 0; }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = "";
|
||||
int skippedNotesCt = ZeroLengthNoteCt + OverlapNoteCt + NoTextNoteCt;
|
||||
if (skippedNotesCt > 0)
|
||||
result += "Skipped " + skippedNotesCt + " notes (0-Length: " + ZeroLengthNoteCt + ", Overlapping: " + OverlapNoteCt + ", No text: " + NoTextNoteCt + ")\r\n";
|
||||
if (InvalidPosBreakCt > 0)
|
||||
result += "Skipped " + InvalidPosBreakCt + " line breaks (Invalid position)\r\n";
|
||||
int adjustedBreakCt = AjustedBreakCt + NoLengthBreakCt;
|
||||
if (adjustedBreakCt > 0)
|
||||
result += "Adjusted " + adjustedBreakCt + " line breaks (Overlapping previous note: " + AjustedBreakCt + ", No length: " + NoLengthBreakCt + ")\r\n";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private ENoteReadMode _CurrentReadMode = ENoteReadMode.Normal;
|
||||
private const int _MaxZeroNoteCt = 1;
|
||||
private const int _MaxOverlapNoteCt = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Read notes. First try to read notes normally (assume standard)<br/>
|
||||
/// If there are more than _MaxZeroNoteCt with length < 1, try to read notes adding 1 to length<br/>
|
||||
/// Then if there are more than _MaxOverlapNoteCt fallback to first version ignoring notes with length < 1
|
||||
/// </summary>
|
||||
/// <param name="forceReload"></param>
|
||||
/// <returns></returns>
|
||||
public bool ReadNotes(bool forceReload = false)
|
||||
{
|
||||
//Skip loading if already done and no reload is forced
|
||||
if (_Song.NotesLoaded && !forceReload)
|
||||
return true;
|
||||
|
||||
string filePath = Path.Combine(_Song.Folder, _Song.FileName);
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
_LogError("The file does not exist", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
int currentBeat = 0; //Used for relative songs
|
||||
CSongNote lastNote = null; //Holds last parsed note. Get's reset on player change
|
||||
bool endFound = false; // True if end tag was found
|
||||
|
||||
int player = 1;
|
||||
_LineNr = 0;
|
||||
|
||||
char[] trimChars = {' ', ':'};
|
||||
char[] splitChars = {' '};
|
||||
|
||||
var changesMade = new CAutoChanges();
|
||||
|
||||
StreamReader sr = null;
|
||||
try
|
||||
{
|
||||
sr = new StreamReader(filePath, _Song.Encoding, true);
|
||||
|
||||
_Song.Notes.Reset();
|
||||
|
||||
//Search for Note Beginning
|
||||
while (!sr.EndOfStream && !endFound)
|
||||
{
|
||||
string line = sr.ReadLine();
|
||||
_LineNr++;
|
||||
|
||||
if (String.IsNullOrEmpty(line))
|
||||
continue;
|
||||
|
||||
char tag = line[0];
|
||||
//Remove tag and potential space
|
||||
line = (line.Length >= 2 && line[1] == ' ') ? line.Substring(2) : line.Substring(1);
|
||||
|
||||
int beat, length;
|
||||
switch (tag)
|
||||
{
|
||||
case '#':
|
||||
continue;
|
||||
case 'E':
|
||||
endFound = true;
|
||||
break;
|
||||
case 'P':
|
||||
line = line.Trim(trimChars);
|
||||
|
||||
if (!int.TryParse(line, out player))
|
||||
{
|
||||
_LogError("Wrong or missing number after \"P\"");
|
||||
return false;
|
||||
}
|
||||
currentBeat = 0;
|
||||
lastNote = null;
|
||||
break;
|
||||
case ':':
|
||||
case '*':
|
||||
case 'F':
|
||||
string[] noteData = line.Split(splitChars, 4);
|
||||
if (noteData.Length < 4)
|
||||
{
|
||||
if (noteData.Length == 3)
|
||||
{
|
||||
_LogWarning("Ignored note without text");
|
||||
changesMade.NoTextNoteCt++;
|
||||
continue;
|
||||
}
|
||||
_LogError("Invalid note found");
|
||||
sr.Dispose();
|
||||
return false;
|
||||
}
|
||||
int tone;
|
||||
if (!int.TryParse(noteData[0], out beat) || !int.TryParse(noteData[1], out length) || !int.TryParse(noteData[2], out tone))
|
||||
{
|
||||
_LogError("Invalid note found (non-numeric values)");
|
||||
sr.Dispose();
|
||||
return false;
|
||||
}
|
||||
string text = noteData[3].TrimMultipleWs();
|
||||
if (text == "")
|
||||
{
|
||||
_LogWarning("Ignored note without text");
|
||||
changesMade.NoTextNoteCt++;
|
||||
continue;
|
||||
}
|
||||
if (_CurrentReadMode == ENoteReadMode.ZeroBased)
|
||||
length++;
|
||||
if (length < 1)
|
||||
{
|
||||
changesMade.ZeroLengthNoteCt++;
|
||||
if (_CurrentReadMode == ENoteReadMode.Normal && changesMade.ZeroLengthNoteCt > _MaxZeroNoteCt && changesMade.OverlapNoteCt <= _MaxOverlapNoteCt)
|
||||
{
|
||||
_LogWarning("Found more than " + _MaxZeroNoteCt + " note with length < 1. Trying alternative read mode.");
|
||||
_CurrentReadMode = ENoteReadMode.ZeroBased;
|
||||
sr.Dispose();
|
||||
return ReadNotes(true);
|
||||
}
|
||||
_LogWarning("Ignored note with length < 1");
|
||||
}
|
||||
else
|
||||
{
|
||||
ENoteType noteType;
|
||||
|
||||
if (tag.Equals('*'))
|
||||
noteType = ENoteType.Golden;
|
||||
else if (tag.Equals('F'))
|
||||
noteType = ENoteType.Freestyle;
|
||||
else
|
||||
noteType = ENoteType.Normal;
|
||||
|
||||
if (_Song.Relative)
|
||||
beat += currentBeat;
|
||||
|
||||
bool ignored = false;
|
||||
foreach (int curPlayer in player.GetSetBits())
|
||||
{
|
||||
//Create the note here as we want independent instances in the lines. Otherwhise we can't modify them later
|
||||
lastNote = new CSongNote(beat, length, tone, text, noteType);
|
||||
if (!_AddNote(curPlayer, lastNote))
|
||||
{
|
||||
if (!ignored)
|
||||
{
|
||||
ignored = true;
|
||||
changesMade.OverlapNoteCt++;
|
||||
if (changesMade.OverlapNoteCt > _MaxOverlapNoteCt && _CurrentReadMode == ENoteReadMode.ZeroBased)
|
||||
{
|
||||
_LogWarning("Found more than " + _MaxOverlapNoteCt + " overlapping notes. Using standard mode.");
|
||||
_CurrentReadMode = ENoteReadMode.OneBased;
|
||||
sr.Dispose();
|
||||
return ReadNotes(true);
|
||||
}
|
||||
}
|
||||
_LogWarning("Ignored note for player " + (curPlayer + 1) + " because it overlaps with other note");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
string[] lineBreakData = line.Split(splitChars);
|
||||
if (lineBreakData.Length < 1)
|
||||
{
|
||||
_LogError("Invalid line break found (No beat)");
|
||||
sr.Dispose();
|
||||
return false;
|
||||
}
|
||||
if (!int.TryParse(lineBreakData[0], out beat))
|
||||
{
|
||||
_LogError("Invalid line break found (Non-numeric value)");
|
||||
sr.Dispose();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_Song.Relative)
|
||||
{
|
||||
beat += currentBeat;
|
||||
if (lineBreakData.Length < 2 || !int.TryParse(lineBreakData[1], out length))
|
||||
{
|
||||
_LogWarning("Missing line break length");
|
||||
changesMade.NoLengthBreakCt++;
|
||||
currentBeat = beat;
|
||||
}
|
||||
else
|
||||
currentBeat += length;
|
||||
}
|
||||
|
||||
if (lastNote != null && beat <= lastNote.EndBeat)
|
||||
{
|
||||
_LogWarning("Line break is before previous note end. Adjusted.");
|
||||
changesMade.AjustedBreakCt++;
|
||||
if (_Song.Relative)
|
||||
currentBeat += lastNote.EndBeat - beat + 1;
|
||||
beat = lastNote.EndBeat + 1;
|
||||
}
|
||||
|
||||
if (beat < 1)
|
||||
{
|
||||
_LogWarning("Ignored line break because position is < 1");
|
||||
changesMade.InvalidPosBreakCt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (int curPlayer in player.GetSetBits())
|
||||
{
|
||||
if (!_NewSentence(curPlayer, beat))
|
||||
_LogWarning("Ignored line break for player " + (curPlayer + 1) + " (Overlapping or duplicate)");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
_LogError("Unexpected or missing character (" + tag + ")");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _Song.Notes.VoiceCount; i++)
|
||||
{
|
||||
CVoice voice = _Song.Notes.GetVoice(i);
|
||||
int emptyLines = voice.RemoveEmptyLines();
|
||||
if (emptyLines > 0)
|
||||
_LogWarning("Removed " + emptyLines + " empty lines from P" + ". This often indicates a problem with the line breaks in the file", false);
|
||||
voice.UpdateTimings();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_LogError("An unhandled exception occured (" + e.Message + ")");
|
||||
if (sr != null)
|
||||
sr.Dispose();
|
||||
return false;
|
||||
}
|
||||
sr.Dispose();
|
||||
try
|
||||
{
|
||||
_Song._FindRefrain();
|
||||
_Song._FindShortEnd();
|
||||
_Song.NotesLoaded = true;
|
||||
if (_Song.IsDuet)
|
||||
_Song._CheckDuet();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_LogError("An unhandled exception occured (" + e.Message + ")", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (changesMade.IsModified)
|
||||
{
|
||||
string msg = "Automatic changes have been made to " + filePath + " Please check result!\r\n" + changesMade;
|
||||
CBase.Log.LogError("Warning: " + msg);
|
||||
if (CBase.Config.GetSaveModifiedSongs() == EOffOn.TR_CONFIG_ON)
|
||||
{
|
||||
string name = Path.GetFileNameWithoutExtension(_Song.FileName);
|
||||
_Song.Save(Path.Combine(_Song.Folder, name + ".fix"));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool _AddNote(int player, CSongNote note)
|
||||
{
|
||||
CVoice voice = _Song.Notes.GetVoice(player);
|
||||
return voice.AddNote(note, false);
|
||||
}
|
||||
|
||||
private bool _NewSentence(int player, int start)
|
||||
{
|
||||
CVoice voice = _Song.Notes.GetVoice(player);
|
||||
return voice.AddLine(start);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,20 +25,20 @@ namespace VocaluxeLib.Songs
|
||||
#region Contructors
|
||||
public CSongNote(CSongNote note) : base(note)
|
||||
{
|
||||
NoteType = note.NoteType;
|
||||
Type = note.Type;
|
||||
Text = note.Text;
|
||||
}
|
||||
|
||||
public CSongNote(int startBeat, int duration, int tone, string text, ENoteType noteType)
|
||||
: base(startBeat, duration, tone)
|
||||
{
|
||||
NoteType = noteType;
|
||||
Type = noteType;
|
||||
Text = text;
|
||||
}
|
||||
#endregion Constructors
|
||||
|
||||
#region Properties
|
||||
public ENoteType NoteType { get; set; }
|
||||
public ENoteType Type { get; set; }
|
||||
|
||||
public string Text { get; set; }
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (NoteType)
|
||||
switch (Type)
|
||||
{
|
||||
case ENoteType.Normal:
|
||||
return 1;
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace VocaluxeLib.Songs
|
||||
{
|
||||
public partial class CSong
|
||||
{
|
||||
private class CSongWriter
|
||||
{
|
||||
private readonly CSong _Song;
|
||||
private TextWriter _Tw;
|
||||
|
||||
public CSongWriter(CSong song)
|
||||
{
|
||||
_Song = song;
|
||||
}
|
||||
|
||||
private void _WriteHeaderEntry(string id, string value)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(value))
|
||||
_Tw.WriteLine("#" + id.ToUpper() + ":" + value);
|
||||
}
|
||||
|
||||
private void _WriteHeaderEntry(string id, bool value)
|
||||
{
|
||||
if (value)
|
||||
_WriteHeaderEntry(id, "YES");
|
||||
}
|
||||
|
||||
private void _WriteHeaderEntry(string id, float value, float def = 0f)
|
||||
{
|
||||
if (Math.Abs(value - def) > 0.0001)
|
||||
_WriteHeaderEntry(id, value.ToInvariantString());
|
||||
}
|
||||
|
||||
private void _WriteHeaderEntry(string id, int value, int def = 0)
|
||||
{
|
||||
if (value != def)
|
||||
_WriteHeaderEntry(id, value.ToString());
|
||||
}
|
||||
|
||||
private void _WriteHeaderEntrys(string id, ICollection<string> value)
|
||||
{
|
||||
if (value == null || value.Count <= 0)
|
||||
return;
|
||||
foreach (String val in value)
|
||||
_WriteHeaderEntry(id, val);
|
||||
}
|
||||
|
||||
private void _WriteHeader()
|
||||
{
|
||||
if (_Song.ManualEncoding)
|
||||
_WriteHeaderEntry("ENCODING", _Song.Encoding.GetEncodingName());
|
||||
_WriteHeaderEntry("CREATOR", _Song.Creator);
|
||||
_WriteHeaderEntry("VERSION", _Song.Version);
|
||||
_WriteHeaderEntry("SOURCE", _Song.Source);
|
||||
if (!String.IsNullOrEmpty(_Song._Comment))
|
||||
{
|
||||
string comment = _Song._Comment.Replace("\r\n", "\n").Replace('\r', '\n');
|
||||
char[] splitChar = {'\n'};
|
||||
_WriteHeaderEntrys("COMMENT", comment.Split(splitChar));
|
||||
}
|
||||
_WriteHeaderEntry("TITLE", _Song.Title);
|
||||
_WriteHeaderEntry("ARTIST", _Song.Artist);
|
||||
if (!_Song.Title.Equals(_Song.TitleSorting))
|
||||
_WriteHeaderEntry("TITLE-ON-SORTING", _Song.TitleSorting);
|
||||
if (!_Song.Artist.Equals(_Song.ArtistSorting))
|
||||
_WriteHeaderEntry("ARTIST-ON-SORTING", _Song.ArtistSorting);
|
||||
_WriteHeaderEntrys("EDITION", _Song.Editions);
|
||||
_WriteHeaderEntrys("GENRE", _Song.Genres);
|
||||
_WriteHeaderEntrys("LANGUAGE", _Song.Languages);
|
||||
_WriteHeaderEntry("ALBUM", _Song.Album);
|
||||
_WriteHeaderEntry("YEAR", _Song.Year);
|
||||
_WriteHeaderEntry("MP3", _Song.MP3FileName);
|
||||
_WriteHeaderEntry("COVER", _Song.CoverFileName);
|
||||
_WriteHeaderEntry("BACKGROUND", _Song.BackgroundFileName);
|
||||
_WriteHeaderEntry("VIDEO", _Song.VideoFileName);
|
||||
_WriteHeaderEntry("VIDEOGAP", _Song.VideoGap);
|
||||
if (_Song.VideoAspect != EAspect.Crop)
|
||||
_WriteHeaderEntry("VIDEOASPECT", _Song.VideoAspect.ToString());
|
||||
_WriteHeaderEntry("RELATIVE", _Song.Relative);
|
||||
_WriteHeaderEntry("BPM", _Song.BPM / _BPMFactor);
|
||||
_WriteHeaderEntry("GAP", (int)(_Song.Gap * 1000f));
|
||||
if (_Song.Preview.Source == EDataSource.Tag)
|
||||
_WriteHeaderEntry("PREVIEWSTART", _Song.Preview.StartTime);
|
||||
_WriteHeaderEntry("START", _Song.Start);
|
||||
_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)
|
||||
_WriteHeaderEntry("CALCMEDLEY", "OFF");
|
||||
if (_Song.Medley.Source == EDataSource.Tag)
|
||||
{
|
||||
_WriteHeaderEntry("MEDLEYSTARTBEAT", _Song.Medley.StartBeat);
|
||||
_WriteHeaderEntry("MEDLEYENDBEAT", _Song.Medley.EndBeat);
|
||||
}
|
||||
for (int i = 0; i < _Song.Notes.VoiceCount; i++)
|
||||
{
|
||||
if (_Song.Notes.VoiceNames.IsSet(i))
|
||||
_WriteHeaderEntry("P" + i, _Song.Notes.VoiceNames[i]);
|
||||
}
|
||||
foreach (string addLine in _Song.UnknownTags)
|
||||
_Tw.WriteLine(addLine);
|
||||
}
|
||||
|
||||
private void _WriteNotes()
|
||||
{
|
||||
for (int i = 0; i < _Song.Notes.VoiceCount; i++)
|
||||
{
|
||||
CVoice voice = _Song.Notes.GetVoice(i);
|
||||
if (_Song.Notes.VoiceCount > 1)
|
||||
_Tw.WriteLine("P" + Math.Pow(2, i));
|
||||
bool firstLine = true;
|
||||
int currentBeat = 0;
|
||||
foreach (CSongLine line in voice.Lines)
|
||||
{
|
||||
if (!firstLine)
|
||||
{
|
||||
string lineTxt = "- " + (line.StartBeat - currentBeat);
|
||||
if (_Song.Relative)
|
||||
{
|
||||
lineTxt += " " + (line.FirstNoteBeat - currentBeat);
|
||||
currentBeat = line.FirstNoteBeat;
|
||||
}
|
||||
_Tw.WriteLine(lineTxt);
|
||||
}
|
||||
else
|
||||
firstLine = false;
|
||||
foreach (CSongNote note in line.Notes)
|
||||
{
|
||||
string tag;
|
||||
switch (note.Type)
|
||||
{
|
||||
case ENoteType.Normal:
|
||||
tag = ":";
|
||||
break;
|
||||
case ENoteType.Golden:
|
||||
tag = "*";
|
||||
break;
|
||||
case ENoteType.Freestyle:
|
||||
tag = "F";
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("Note type " + note.Type);
|
||||
}
|
||||
_Tw.WriteLine(tag + " " + (note.StartBeat - currentBeat) + " " + note.Duration + " " + note.Tone + " " + note.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
_Tw.WriteLine("E");
|
||||
}
|
||||
|
||||
public bool SaveFile(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
_Tw = new StreamWriter(filePath, false, _Song.Encoding);
|
||||
_WriteHeader();
|
||||
_WriteNotes();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CBase.Log.LogError("Unhandled exception while writing " + filePath + ": " + e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ namespace VocaluxeLib.Songs
|
||||
}
|
||||
|
||||
#region Properties
|
||||
public double Points;
|
||||
public new double Points;
|
||||
// for drawing player notes
|
||||
public bool Hit
|
||||
{
|
||||
|
||||
+85
-14
@@ -15,6 +15,7 @@
|
||||
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -67,7 +68,11 @@ namespace VocaluxeLib.Songs
|
||||
}
|
||||
|
||||
#region Methods
|
||||
//Find last line with StartBeat<=Beat
|
||||
/// <summary>
|
||||
/// Find last line with StartBeat<=Beat
|
||||
/// </summary>
|
||||
/// <param name="beat"></param>
|
||||
/// <returns></returns>
|
||||
public int FindPreviousLine(int beat)
|
||||
{
|
||||
//If no line -> No previous line
|
||||
@@ -92,15 +97,49 @@ namespace VocaluxeLib.Songs
|
||||
return start;
|
||||
}
|
||||
|
||||
public void AddLine(CSongLine line)
|
||||
public bool AddLine(CSongLine line, bool updateTimings = true)
|
||||
{
|
||||
if (_Lines.Count == 0)
|
||||
_Lines.Add(line);
|
||||
else
|
||||
{
|
||||
int insPos = FindPreviousLine(line.StartBeat);
|
||||
//Check if previous line ends before this one
|
||||
if (insPos >= 0 && _Lines[insPos].LastNoteBeat > line.StartBeat)
|
||||
return false;
|
||||
//Check if next line starts before this one ends
|
||||
if (insPos + 1 < _Lines.Count && _Lines[insPos + 1].FirstNoteBeat < line.LastNoteBeat)
|
||||
return false;
|
||||
_Lines.Insert(insPos + 1, line);
|
||||
}
|
||||
if (updateTimings)
|
||||
UpdateTimings();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AddLine(int startBeat)
|
||||
{
|
||||
int insPos = FindPreviousLine(startBeat);
|
||||
//Check for actual notes (startbeat may be lower than first note)
|
||||
while (insPos >= 0 && _Lines[insPos].NoteCount > 0 && _Lines[insPos].FirstNoteBeat > startBeat)
|
||||
insPos--;
|
||||
CSongLine line = new CSongLine {StartBeat = startBeat};
|
||||
if (insPos >= 0)
|
||||
{
|
||||
CSongLine prevLine = _Lines[insPos];
|
||||
//We already have a line break here
|
||||
if (prevLine.StartBeat == startBeat && (prevLine.NoteCount==0 || prevLine.FirstNoteBeat == startBeat))
|
||||
return false;
|
||||
//Maybe we have to split the previous line
|
||||
while (prevLine.NoteCount > 0 && prevLine.LastNote.StartBeat >= startBeat)
|
||||
{
|
||||
//throw new Exception("This should not happen on song loading!");
|
||||
line.AddNote(prevLine.LastNote);
|
||||
prevLine.DeleteNote(prevLine.NoteCount - 1);
|
||||
}
|
||||
}
|
||||
_Lines.Insert(insPos + 1, line);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeleteLine(int index)
|
||||
@@ -119,15 +158,26 @@ namespace VocaluxeLib.Songs
|
||||
_Lines.Clear();
|
||||
}
|
||||
|
||||
public bool AddNote(CSongNote note, bool updateTimings = false)
|
||||
public bool AddNote(CSongNote note, bool updateTimings = true)
|
||||
{
|
||||
int lineIndex = FindPreviousLine(note.StartBeat);
|
||||
if (lineIndex + 1 < _Lines.Count && _Lines[lineIndex + 1].FirstNoteBeat < note.EndBeat) //First note in next line starts before this one ends
|
||||
return false;
|
||||
if (lineIndex < 0)
|
||||
{
|
||||
//Note is before ALL lines
|
||||
var line = new CSongLine {StartBeat = note.StartBeat};
|
||||
line.AddNote(note);
|
||||
_Lines.Insert(0, line);
|
||||
if (_Lines.Count > 0)
|
||||
{
|
||||
//Add to first line
|
||||
if (!_Lines[0].AddNote(note))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var line = new CSongLine();
|
||||
line.AddNote(note);
|
||||
_Lines.Add(line);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -139,24 +189,27 @@ namespace VocaluxeLib.Songs
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool InsertNote(CSongNote note, int lineIndex, bool updateTimings = false)
|
||||
/*Check this first for consistency (next line might be affected)
|
||||
* public bool InsertNote(CSongNote note, int lineIndex, bool updateTimings = false)
|
||||
{
|
||||
if (_Lines.Count > lineIndex && _Lines[lineIndex].StartBeat <= note.StartBeat)
|
||||
{
|
||||
_Lines[lineIndex].AddNote(note);
|
||||
if (!_Lines[lineIndex].AddNote(note))
|
||||
return false;
|
||||
if (updateTimings)
|
||||
UpdateTimings();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
public void UpdateTimings()
|
||||
{
|
||||
CSongNote lastNote;
|
||||
|
||||
if (_Lines.Count > 0)
|
||||
_Lines[0].StartBeat = -10000;
|
||||
if (_Lines.Count == 0)
|
||||
return;
|
||||
_Lines[0].StartBeat = -10000;
|
||||
|
||||
for (int i = 1; i < _Lines.Count; i++)
|
||||
{
|
||||
@@ -191,11 +244,24 @@ namespace VocaluxeLib.Songs
|
||||
_Lines[i].StartBeat = s;
|
||||
_Lines[i - 1].EndBeat = min;
|
||||
}
|
||||
else if (firstNote != null)
|
||||
{
|
||||
_Lines[i - 1].EndBeat = Math.Min(_Lines[i - 1].StartBeat, firstNote.StartBeat - 2);
|
||||
_Lines[i].StartBeat = Math.Max(_Lines[i - 1].EndBeat, firstNote.StartBeat - 2);
|
||||
}
|
||||
else if (lastNote != null)
|
||||
{
|
||||
_Lines[i - 1].EndBeat = lastNote.EndBeat;
|
||||
_Lines[i].StartBeat = Math.Max(lastNote.EndBeat, _Lines[i].StartBeat); //Prefer current setting
|
||||
}
|
||||
else
|
||||
{
|
||||
//No note
|
||||
_Lines[i - 1].EndBeat = _Lines[i - 1].StartBeat; //Assume at least startbeats were set right
|
||||
}
|
||||
}
|
||||
|
||||
lastNote = _Lines[_Lines.Count - 1].LastNote;
|
||||
if (lastNote != null)
|
||||
_Lines[_Lines.Count - 1].EndBeat = lastNote.EndBeat;
|
||||
_Lines[_Lines.Count - 1].EndBeat = Math.Max(_Lines[_Lines.Count - 1].LastNoteBeat, _Lines[_Lines.Count - 1].StartBeat); //Use note or (when not set) start beat
|
||||
}
|
||||
|
||||
public void SetMedley(int startBeat, int endBeat)
|
||||
@@ -204,5 +270,10 @@ namespace VocaluxeLib.Songs
|
||||
line.SetMedley(startBeat, endBeat);
|
||||
}
|
||||
#endregion Methods
|
||||
|
||||
public int RemoveEmptyLines()
|
||||
{
|
||||
return _Lines.RemoveAll(line => line.NoteCount == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user