Apply R# clean-up for reliability (#877)
* Apply R# clean-up for reliability - Migrate to NUnit4 Assert.That - Update dependencise versions - Fix LangVersion to 9.0 (until net core migration) - Reformat code - Apply 'var' style (easier for refactoring) - Remove redundant parentheses - Add braces on every condition blocks (1 line) - Uses new null checking patterns - Uses AutoProperties when possible - Uses string scalar type instead of class - Clean usings - Add .orig files in git ignore - Rename some properties to respect defined conventions and US format definition - ID -> Id - BPM -> Bpm - Finish -> End * Update R# settings according to the clean-up made
This commit is contained in:
1 parent
b9b0f7c8df
commit
6ffa63b923
236 files changed
+14194
-7278
No files matched your search
@@ -41,7 +41,9 @@ namespace VocaluxeLib.Songs
|
||||
Duration = duration;
|
||||
Tone = tone;
|
||||
if (Duration < 1)
|
||||
{
|
||||
throw new Exception("Note to short. All notes should be at least 1 beat long!");
|
||||
}
|
||||
}
|
||||
#endregion Constructors
|
||||
|
||||
@@ -62,7 +64,9 @@ namespace VocaluxeLib.Songs
|
||||
set
|
||||
{
|
||||
if (value > 0)
|
||||
{
|
||||
_Duration = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,13 +76,18 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
// Always return 0 for Rap notes
|
||||
if (IsRapNote)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _Tone;
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((value >= CBase.Settings.GetToneMin()) && (value <= CBase.Settings.GetToneMax()))
|
||||
if (value >= CBase.Settings.GetToneMin() && value <= CBase.Settings.GetToneMax())
|
||||
{
|
||||
_Tone = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,4 +113,4 @@ namespace VocaluxeLib.Songs
|
||||
public abstract bool IsNoteType(params ENoteType[] noteTypes);
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,15 +16,14 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using VocaluxeLib.Draw;
|
||||
using System.Linq;
|
||||
using VocaluxeLib.Draw;
|
||||
|
||||
namespace VocaluxeLib.Songs
|
||||
{
|
||||
public class CCategory
|
||||
{
|
||||
public readonly string Name;
|
||||
private CTextureRef _CoverTextureSmall;
|
||||
private CTextureRef _CoverTextureBig;
|
||||
public readonly List<CSongPointer> Songs = new List<CSongPointer>();
|
||||
|
||||
@@ -33,20 +32,18 @@ namespace VocaluxeLib.Songs
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public CTextureRef CoverTextureSmall
|
||||
{
|
||||
get { return _CoverTextureSmall; }
|
||||
|
||||
set { _CoverTextureSmall = value; }
|
||||
}
|
||||
public CTextureRef CoverTextureSmall { get; set; }
|
||||
|
||||
public CTextureRef CoverTextureBig
|
||||
{
|
||||
get { return _CoverTextureBig ?? _CoverTextureSmall; }
|
||||
get { return _CoverTextureBig ?? CoverTextureSmall; }
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_CoverTextureBig = value;
|
||||
}
|
||||
}
|
||||
@@ -59,7 +56,10 @@ namespace VocaluxeLib.Songs
|
||||
public CSong GetSong(int numInCategory)
|
||||
{
|
||||
if (numInCategory >= 0 && numInCategory < Songs.Count)
|
||||
return CBase.Songs.GetSongByID(Songs[numInCategory].SongID);
|
||||
{
|
||||
return CBase.Songs.GetSongById(Songs[numInCategory].SongId);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ namespace VocaluxeLib.Songs
|
||||
#region Properties
|
||||
public int FirstNoteBeat
|
||||
{
|
||||
get { return (NoteCount == 0) ? int.MaxValue : _Notes[0].StartBeat; }
|
||||
get { return NoteCount == 0 ? int.MaxValue : _Notes[0].StartBeat; }
|
||||
}
|
||||
|
||||
public int LastNoteBeat
|
||||
{
|
||||
get { return (NoteCount == 0) ? int.MinValue : _Notes[NoteCount - 1].EndBeat; }
|
||||
get { return NoteCount == 0 ? int.MinValue : _Notes[NoteCount - 1].EndBeat; }
|
||||
}
|
||||
|
||||
public int NoteCount
|
||||
@@ -64,9 +64,12 @@ namespace VocaluxeLib.Songs
|
||||
get
|
||||
{
|
||||
if (_Notes.Count == 0)
|
||||
{
|
||||
return 0;
|
||||
int min = _Notes.Min(note => note.Tone);
|
||||
int max = _Notes.Max(note => note.Tone);
|
||||
}
|
||||
|
||||
var min = _Notes.Min(note => note.Tone);
|
||||
var max = _Notes.Max(note => note.Tone);
|
||||
|
||||
return min - (max - min) / 4;
|
||||
}
|
||||
@@ -83,35 +86,52 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
//If no notes -> No previous note
|
||||
if (_Notes.Count == 0)
|
||||
{
|
||||
return -1;
|
||||
int start = 0;
|
||||
int end = _Notes.Count - 1;
|
||||
}
|
||||
|
||||
var start = 0;
|
||||
var end = _Notes.Count - 1;
|
||||
//Ensure that start.StartBeat<=Beat && end.StartBeat>Beat
|
||||
if (_Notes[0].StartBeat > beat)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_Notes[end].StartBeat <= beat)
|
||||
{
|
||||
return end;
|
||||
}
|
||||
|
||||
//Binary search
|
||||
while (end - start > 1)
|
||||
{
|
||||
int mid = (start + end) / 2;
|
||||
var mid = (start + end) / 2;
|
||||
if (_Notes[mid].StartBeat <= beat)
|
||||
{
|
||||
start = mid;
|
||||
}
|
||||
else
|
||||
{
|
||||
end = mid;
|
||||
}
|
||||
}
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
public virtual bool AddNote(T note)
|
||||
{
|
||||
if (_Notes.Count == 0)
|
||||
{
|
||||
_Notes.Add(note);
|
||||
}
|
||||
else
|
||||
{
|
||||
int insPos = FindPreviousNote(note.StartBeat);
|
||||
var insPos = FindPreviousNote(note.StartBeat);
|
||||
_Notes.Insert(insPos + 1, note);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -122,6 +142,7 @@ namespace VocaluxeLib.Songs
|
||||
_Notes.RemoveAt(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -132,13 +153,16 @@ namespace VocaluxeLib.Songs
|
||||
_Notes.RemoveAt(index);
|
||||
return AddNote(note);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void IncLastNoteLength()
|
||||
{
|
||||
if (_Notes.Count > 0)
|
||||
{
|
||||
_Notes[NoteCount - 1].Duration++;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteAllNotes()
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
private readonly List<string> _Names = new List<string>();
|
||||
|
||||
public CVoiceNames() {}
|
||||
public CVoiceNames() { }
|
||||
|
||||
public CVoiceNames(CVoiceNames names)
|
||||
{
|
||||
@@ -37,7 +37,10 @@ namespace VocaluxeLib.Songs
|
||||
get
|
||||
{
|
||||
if (IsSet(index))
|
||||
{
|
||||
return _Names[index];
|
||||
}
|
||||
|
||||
return "Part " + (index + 1);
|
||||
}
|
||||
set
|
||||
@@ -61,12 +64,15 @@ namespace VocaluxeLib.Songs
|
||||
private readonly List<CVoice> _Voices = new List<CVoice>();
|
||||
public readonly CVoiceNames VoiceNames = new CVoiceNames();
|
||||
|
||||
public CNotes() {}
|
||||
public CNotes() { }
|
||||
|
||||
public CNotes(CNotes notes)
|
||||
{
|
||||
foreach (CVoice voice in notes._Voices)
|
||||
foreach (var voice in notes._Voices)
|
||||
{
|
||||
_Voices.Add(new CVoice(voice));
|
||||
}
|
||||
|
||||
VoiceNames = new CVoiceNames(notes.VoiceNames);
|
||||
}
|
||||
|
||||
@@ -85,10 +91,14 @@ namespace VocaluxeLib.Songs
|
||||
if (add)
|
||||
{
|
||||
while (index >= _Voices.Count)
|
||||
{
|
||||
_Voices.Add(new CVoice());
|
||||
}
|
||||
}
|
||||
else if (index >= _Voices.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _Voices[index];
|
||||
}
|
||||
@@ -96,7 +106,9 @@ namespace VocaluxeLib.Songs
|
||||
public int GetPoints(int index)
|
||||
{
|
||||
if (index >= _Voices.Count)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _Voices[index].Points;
|
||||
}
|
||||
@@ -104,7 +116,9 @@ namespace VocaluxeLib.Songs
|
||||
public int GetNumLinesWithPoints(int index)
|
||||
{
|
||||
if (index >= _Voices.Count)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _Voices[index].NumLinesWithPoints;
|
||||
}
|
||||
@@ -117,7 +131,9 @@ namespace VocaluxeLib.Songs
|
||||
public bool ReplaceVoiceAt(int index, CVoice voice)
|
||||
{
|
||||
if (index >= _Voices.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_Voices[index] = voice;
|
||||
return true;
|
||||
@@ -127,13 +143,17 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
_Voices.Clear();
|
||||
if (resetVoices)
|
||||
{
|
||||
VoiceNames.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMedley(int startBeat, int endBeat)
|
||||
{
|
||||
foreach (CVoice voice in _Voices)
|
||||
foreach (var voice in _Voices)
|
||||
{
|
||||
voice.SetMedley(startBeat, endBeat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+110
-60
@@ -27,13 +27,13 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
public class CSongPointer
|
||||
{
|
||||
public readonly int SongID;
|
||||
public readonly int SongId;
|
||||
public string SortString;
|
||||
public bool IsSung;
|
||||
|
||||
public CSongPointer(int id, string sortString)
|
||||
{
|
||||
SongID = id;
|
||||
SongId = id;
|
||||
SortString = sortString;
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ namespace VocaluxeLib.Songs
|
||||
MP3 = 4,
|
||||
Instrumental = 5,
|
||||
Vocals = 6,
|
||||
BPM = 8,
|
||||
Bpm = 8,
|
||||
MedleyStartBeat = 16,
|
||||
MedleyEndBeat = 32
|
||||
}
|
||||
@@ -93,17 +93,17 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
public Encoding Encoding = new UTF8Encoding();
|
||||
public bool ManualEncoding;
|
||||
public string Folder = String.Empty;
|
||||
public string FolderName = String.Empty;
|
||||
public string FileName = String.Empty;
|
||||
public string Folder = string.Empty;
|
||||
public string FolderName = string.Empty;
|
||||
public string FileName = string.Empty;
|
||||
public bool Relative;
|
||||
|
||||
public string MP3FileName = String.Empty;
|
||||
public string InstrumentalFileName = String.Empty;
|
||||
public string VocalsFileName = String.Empty;
|
||||
public string CoverFileName = String.Empty;
|
||||
public string MP3FileName = string.Empty;
|
||||
public string InstrumentalFileName = string.Empty;
|
||||
public string VocalsFileName = string.Empty;
|
||||
public string CoverFileName = string.Empty;
|
||||
public readonly List<string> BackgroundFileNames = new List<string>();
|
||||
public string VideoFileName = String.Empty;
|
||||
public string VideoFileName = string.Empty;
|
||||
|
||||
public EAspect VideoAspect = EAspect.Automatic;
|
||||
|
||||
@@ -114,7 +114,10 @@ namespace VocaluxeLib.Songs
|
||||
get
|
||||
{
|
||||
if (_CoverTextureSmall == null)
|
||||
{
|
||||
LoadSmallCover();
|
||||
}
|
||||
|
||||
return _CoverTextureSmall;
|
||||
}
|
||||
|
||||
@@ -127,11 +130,11 @@ namespace VocaluxeLib.Songs
|
||||
set { _CoverTextureBig = value; }
|
||||
}
|
||||
|
||||
public string Title = String.Empty;
|
||||
public string Artist = String.Empty;
|
||||
public string Title = string.Empty;
|
||||
public string Artist = string.Empty;
|
||||
|
||||
public string TitleSorting = String.Empty;
|
||||
public string ArtistSorting = String.Empty;
|
||||
public string TitleSorting = string.Empty;
|
||||
public string ArtistSorting = string.Empty;
|
||||
|
||||
public string Creator = "";
|
||||
public string Version = "";
|
||||
@@ -146,9 +149,9 @@ namespace VocaluxeLib.Songs
|
||||
/// <summary>
|
||||
/// End of the song in s (ms in txt)
|
||||
/// </summary>
|
||||
public float Finish;
|
||||
public float End;
|
||||
|
||||
public float BPM = 1f;
|
||||
public float Bpm = 1f;
|
||||
/// <summary>
|
||||
/// Gap of the mp3 in s (ms in txt)
|
||||
/// </summary>
|
||||
@@ -161,7 +164,7 @@ namespace VocaluxeLib.Songs
|
||||
private string _Comment = "";
|
||||
|
||||
// Sorting
|
||||
public int ID;
|
||||
public int Id;
|
||||
private readonly bool _Visible = true;
|
||||
private readonly int _CatIndex = -1;
|
||||
private readonly bool _Selected;
|
||||
@@ -179,7 +182,7 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
public readonly List<string> Languages = new List<string>();
|
||||
|
||||
public int DataBaseSongID = -1;
|
||||
public int DataBaseSongId = -1;
|
||||
public DateTime DateAdded = DateTime.Today;
|
||||
public int NumPlayed;
|
||||
public int NumPlayedSession;
|
||||
@@ -191,11 +194,16 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
get
|
||||
{
|
||||
var gms = new List<EGameMode> {IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL};
|
||||
var gms = new List<EGameMode> { IsDuet ? EGameMode.TR_GAMEMODE_DUET : EGameMode.TR_GAMEMODE_NORMAL };
|
||||
if (Medley.Source != EDataSource.None)
|
||||
{
|
||||
gms.Add(EGameMode.TR_GAMEMODE_MEDLEY);
|
||||
}
|
||||
|
||||
if (ShortEnd.Source != EDataSource.None)
|
||||
{
|
||||
gms.Add(EGameMode.TR_GAMEMODE_SHORTSONG);
|
||||
}
|
||||
|
||||
return gms;
|
||||
}
|
||||
@@ -212,7 +220,7 @@ namespace VocaluxeLib.Songs
|
||||
}
|
||||
|
||||
//No point creating a song without a text file --> Use factory method LoadSong
|
||||
private CSong() {}
|
||||
private CSong() { }
|
||||
|
||||
public CSong(CSong song)
|
||||
{
|
||||
@@ -255,15 +263,15 @@ namespace VocaluxeLib.Songs
|
||||
UnknownTags = new List<string>(song.UnknownTags);
|
||||
|
||||
Start = song.Start;
|
||||
Finish = song.Finish;
|
||||
End = song.End;
|
||||
|
||||
BPM = song.BPM;
|
||||
Bpm = song.Bpm;
|
||||
Gap = song.Gap;
|
||||
VideoGap = song.VideoGap;
|
||||
|
||||
_Comment = song._Comment;
|
||||
|
||||
ID = song.ID;
|
||||
Id = song.Id;
|
||||
_Visible = song._Visible;
|
||||
_CatIndex = song._CatIndex;
|
||||
_Selected = song._Selected;
|
||||
@@ -276,7 +284,7 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
Languages = new List<string>(song.Languages);
|
||||
|
||||
DataBaseSongID = song.DataBaseSongID;
|
||||
DataBaseSongId = song.DataBaseSongId;
|
||||
DateAdded = song.DateAdded;
|
||||
NumPlayed = song.NumPlayed;
|
||||
NumPlayedSession = song.NumPlayedSession;
|
||||
@@ -300,9 +308,11 @@ namespace VocaluxeLib.Songs
|
||||
public bool ReloadSong(bool reloadNotes)
|
||||
{
|
||||
var loader = new CSongLoader(this);
|
||||
bool retValue = loader.ReadHeader();
|
||||
var retValue = loader.ReadHeader();
|
||||
if (!retValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
retValue = loader.ReadNotes(reloadNotes);
|
||||
return retValue;
|
||||
@@ -352,12 +362,18 @@ namespace VocaluxeLib.Songs
|
||||
public void LoadSmallCover()
|
||||
{
|
||||
if (_CoverTextureSmall != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (CoverFileName != "")
|
||||
{
|
||||
if (CBase.DataBase.GetCover(Path.Combine(Folder, CoverFileName), ref _CoverTextureSmall, CBase.Config.GetCoverSize()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_CoverTextureSmall = CBase.Cover.GenerateCover(Title, ECoverGeneratorType.Song, null);
|
||||
}
|
||||
|
||||
@@ -365,33 +381,39 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
if (CoverFileName == "")
|
||||
{
|
||||
IEnumerable<string> files = CHelper.ListImageFiles(Folder);
|
||||
foreach (String file in files)
|
||||
var files = CHelper.ListImageFiles(Folder);
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (file.ContainsIgnoreCase("[CO]") &&
|
||||
(file.ContainsIgnoreCase(Title) || file.ContainsIgnoreCase(Artist)))
|
||||
{
|
||||
CoverFileName = file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (BackgroundFileNames.Count == 0)
|
||||
{
|
||||
IEnumerable<string> files = CHelper.ListImageFiles(Folder);
|
||||
foreach (String file in files)
|
||||
var files = CHelper.ListImageFiles(Folder);
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (file.ContainsIgnoreCase("[BG]") &&
|
||||
(file.ContainsIgnoreCase(Title) || file.ContainsIgnoreCase(Artist)))
|
||||
{
|
||||
BackgroundFileNames.Add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void _CheckDuet()
|
||||
{
|
||||
for (int i = 0; i < Notes.VoiceCount; i++)
|
||||
for (var i = 0; i < Notes.VoiceCount; i++)
|
||||
{
|
||||
if (!Notes.VoiceNames.IsSet(i))
|
||||
{
|
||||
CLog.Error("Warning: Can't find #P" + (i + 1) + "-tag for duets in \"" + Artist + " - " + Title + "\".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,42 +426,56 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
private List<SSeries> _GetSeries()
|
||||
{
|
||||
CVoice voice = Notes.GetVoice(0);
|
||||
var voice = Notes.GetVoice(0);
|
||||
|
||||
if (voice.NumLines == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// build sentences list
|
||||
List<string> sentences = voice.Lines.Select(line => line.Points != 0 ? line.Lyrics : String.Empty).ToList();
|
||||
var sentences = voice.Lines.Select(line => line.Points != 0 ? line.Lyrics : string.Empty).ToList();
|
||||
|
||||
// find equal sentences series
|
||||
var series = new List<SSeries>();
|
||||
for (int i = 0; i < voice.NumLines - 1; i++)
|
||||
for (var i = 0; i < voice.NumLines - 1; i++)
|
||||
{
|
||||
for (int j = i + 1; j < voice.NumLines; j++)
|
||||
for (var j = i + 1; j < voice.NumLines; j++)
|
||||
{
|
||||
if (sentences[i] != sentences[j] || sentences[i] == "")
|
||||
{
|
||||
continue;
|
||||
var tempSeries = new SSeries {Start = i, End = i};
|
||||
}
|
||||
|
||||
var tempSeries = new SSeries { Start = i, End = i };
|
||||
|
||||
int max;
|
||||
if (j + j - i > voice.NumLines)
|
||||
{
|
||||
max = voice.NumLines - 1 - j;
|
||||
}
|
||||
else
|
||||
{
|
||||
max = j - i - 1;
|
||||
}
|
||||
|
||||
for (int k = 1; k <= max; k++)
|
||||
for (var k = 1; k <= max; k++)
|
||||
{
|
||||
if (sentences[i + k] == sentences[j + k] && sentences[i + k] != "")
|
||||
{
|
||||
tempSeries.End = i + k;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tempSeries.Length = tempSeries.End - tempSeries.Start + 1;
|
||||
series.Add(tempSeries);
|
||||
}
|
||||
}
|
||||
|
||||
return series;
|
||||
}
|
||||
|
||||
@@ -452,21 +488,27 @@ namespace VocaluxeLib.Songs
|
||||
}
|
||||
|
||||
if (!_CalculateMedley || Medley.Source != EDataSource.None)
|
||||
return;
|
||||
|
||||
List<SSeries> series = _GetSeries();
|
||||
if (series == null)
|
||||
return;
|
||||
|
||||
// search for longest series
|
||||
int longest = 0;
|
||||
for (int i = 0; i < series.Count; i++)
|
||||
{
|
||||
if (series[i].Length > series[longest].Length)
|
||||
longest = i;
|
||||
return;
|
||||
}
|
||||
|
||||
CVoice voice = Notes.GetVoice(0);
|
||||
var series = _GetSeries();
|
||||
if (series == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// search for longest series
|
||||
var longest = 0;
|
||||
for (var i = 0; i < series.Count; i++)
|
||||
{
|
||||
if (series[i].Length > series[longest].Length)
|
||||
{
|
||||
longest = i;
|
||||
}
|
||||
}
|
||||
|
||||
var voice = Notes.GetVoice(0);
|
||||
|
||||
// set medley vars
|
||||
if (series.Count > 0 && series[longest].Length > CBase.Settings.GetMedleyMinSeriesLength())
|
||||
@@ -474,15 +516,15 @@ 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.EndBeat, BPM) - CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) < CBase.Settings.GetMedleyMinDuration();
|
||||
var foundEnd = CBase.Game.GetTimeFromBeats(Medley.EndBeat, Bpm) - CBase.Game.GetTimeFromBeats(Medley.StartBeat, Bpm) < CBase.Settings.GetMedleyMinDuration();
|
||||
|
||||
// set end if duration < MedleyMinDuration
|
||||
|
||||
if (!foundEnd)
|
||||
{
|
||||
for (int i = series[longest].End + 1; i < voice.NumLines - 1; i++)
|
||||
for (var i = series[longest].End + 1; i < voice.NumLines - 1; i++)
|
||||
{
|
||||
if (CBase.Game.GetTimeFromBeats(voice.Lines[i].LastNoteBeat, BPM) - CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM) <
|
||||
if (CBase.Game.GetTimeFromBeats(voice.Lines[i].LastNoteBeat, Bpm) - CBase.Game.GetTimeFromBeats(Medley.StartBeat, Bpm) <
|
||||
CBase.Settings.GetMedleyMinDuration())
|
||||
{
|
||||
foundEnd = true;
|
||||
@@ -504,10 +546,13 @@ namespace VocaluxeLib.Songs
|
||||
private void _CheckPreview()
|
||||
{
|
||||
if (Preview.Source != EDataSource.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Medley.Source != EDataSource.None)
|
||||
{
|
||||
Preview.StartTime = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM);
|
||||
Preview.StartTime = CBase.Game.GetTimeFromBeats(Medley.StartBeat, Bpm);
|
||||
Preview.Source = EDataSource.Calculated;
|
||||
}
|
||||
}
|
||||
@@ -515,28 +560,33 @@ namespace VocaluxeLib.Songs
|
||||
private void _FindShortEnd()
|
||||
{
|
||||
if (ShortEnd.Source != EDataSource.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<SSeries> series = _GetSeries();
|
||||
var series = _GetSeries();
|
||||
if (series == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CVoice voice = Notes.GetVoice(0);
|
||||
var voice = Notes.GetVoice(0);
|
||||
|
||||
//Calculate length of singing
|
||||
int stop = (voice.Lines[voice.Lines.Length - 1].LastNoteBeat - voice.Lines[0].FirstNote.StartBeat) / 2 + voice.Lines[0].FirstNote.StartBeat;
|
||||
var stop = (voice.Lines[voice.Lines.Length - 1].LastNoteBeat - voice.Lines[0].FirstNote.StartBeat) / 2 + voice.Lines[0].FirstNote.StartBeat;
|
||||
|
||||
//Check if stop is in series
|
||||
for (int i = 0; i < series.Count; i++)
|
||||
for (var i = 0; i < series.Count; i++)
|
||||
{
|
||||
if (voice.Lines[series[i].Start].FirstNoteBeat < stop && voice.Lines[series[i].End].LastNoteBeat > stop)
|
||||
{
|
||||
if (stop < (voice.Lines[series[i].Start].FirstNoteBeat + ((voice.Lines[series[i].End].LastNoteBeat - voice.Lines[series[i].Start].FirstNoteBeat) / 2)))
|
||||
if (stop < voice.Lines[series[i].Start].FirstNoteBeat + (voice.Lines[series[i].End].LastNoteBeat - voice.Lines[series[i].Start].FirstNoteBeat) / 2)
|
||||
{
|
||||
ShortEnd.EndBeat = voice.Lines[series[i].Start - 1].LastNote.EndBeat;
|
||||
ShortEnd.Source = EDataSource.Calculated;
|
||||
return;
|
||||
}
|
||||
|
||||
ShortEnd.EndBeat = voice.Lines[series[i].End].LastNote.EndBeat;
|
||||
ShortEnd.Source = EDataSource.Calculated;
|
||||
return;
|
||||
@@ -544,7 +594,7 @@ namespace VocaluxeLib.Songs
|
||||
}
|
||||
|
||||
//Check if stop is in line
|
||||
foreach (CSongLine line in voice.Lines)
|
||||
foreach (var line in voice.Lines)
|
||||
{
|
||||
if (line.FirstNoteBeat < stop && line.LastNoteBeat > stop)
|
||||
{
|
||||
@@ -558,4 +608,4 @@ namespace VocaluxeLib.Songs
|
||||
ShortEnd.Source = EDataSource.Calculated;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,8 +33,11 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
public CSongLine(CSongLine line)
|
||||
{
|
||||
foreach (CSongNote note in line._Notes)
|
||||
foreach (var note in line._Notes)
|
||||
{
|
||||
_Notes.Add(new CSongNote(note));
|
||||
}
|
||||
|
||||
_StartBeat = line._StartBeat;
|
||||
_EndBeat = line._EndBeat;
|
||||
VisibleInTimeLine = line.VisibleInTimeLine;
|
||||
@@ -50,7 +53,9 @@ namespace VocaluxeLib.Songs
|
||||
set
|
||||
{
|
||||
if (value <= FirstNoteBeat)
|
||||
{
|
||||
_StartBeat = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,13 +65,15 @@ namespace VocaluxeLib.Songs
|
||||
set
|
||||
{
|
||||
if (value >= LastNoteBeat)
|
||||
{
|
||||
_EndBeat = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Lyrics
|
||||
{
|
||||
get { return _Notes.Aggregate(String.Empty, (current, note) => current + note.Text); }
|
||||
get { return _Notes.Aggregate(string.Empty, (current, note) => current + note.Text); }
|
||||
}
|
||||
#endregion Properties
|
||||
|
||||
@@ -74,31 +81,42 @@ namespace VocaluxeLib.Songs
|
||||
public override bool AddNote(CSongNote note)
|
||||
{
|
||||
if (_Notes.Count == 0)
|
||||
{
|
||||
_Notes.Add(note);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Insert AFTER this note
|
||||
int insPos = FindPreviousNote(note.StartBeat);
|
||||
var insPos = FindPreviousNote(note.StartBeat);
|
||||
//Check for overlapping notes
|
||||
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;
|
||||
}
|
||||
|
||||
public void SetMedley(int startBeat, int endBeat)
|
||||
{
|
||||
foreach (CSongNote note in _Notes.Where(note => note.StartBeat < startBeat || note.EndBeat > endBeat))
|
||||
foreach (var note in _Notes.Where(note => note.StartBeat < startBeat || note.EndBeat > endBeat))
|
||||
{
|
||||
note.Type = ENoteType.Freestyle;
|
||||
}
|
||||
|
||||
VisibleInTimeLine = FirstNoteBeat >= startBeat && LastNoteBeat <= endBeat;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using VocaluxeLib.Log;
|
||||
|
||||
namespace VocaluxeLib.Songs
|
||||
@@ -31,7 +30,7 @@ namespace VocaluxeLib.Songs
|
||||
/// <summary>
|
||||
/// Factor the bpm given in the txt is multiplied with
|
||||
/// </summary>
|
||||
private const int _BPMFactor = 4;
|
||||
private const int _BpmFactor = 4;
|
||||
|
||||
private class CSongLoader
|
||||
{
|
||||
@@ -46,38 +45,48 @@ namespace VocaluxeLib.Songs
|
||||
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)))
|
||||
foreach (var 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);
|
||||
var pos = _Song.FolderName.IndexOf("\\", StringComparison.Ordinal);
|
||||
if (pos >= 0)
|
||||
{
|
||||
_Song.FolderName = _Song.FolderName.Substring(0, pos);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
_Song.FileName = Path.GetFileName(filePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public bool ReadHeader(bool useSetEncoding = false)
|
||||
{
|
||||
string filePath = Path.Combine(_Song.Folder, _Song.FileName);
|
||||
var filePath = Path.Combine(_Song.Folder, _Song.FileName);
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_Song.Languages.Clear();
|
||||
_Song.Genres.Clear();
|
||||
@@ -101,52 +110,61 @@ namespace VocaluxeLib.Songs
|
||||
sr = new StreamReader(filePath, _Song.Encoding, true);
|
||||
while (!sr.EndOfStream)
|
||||
{
|
||||
string line = sr.ReadLine();
|
||||
var line = sr.ReadLine();
|
||||
_LineNr++;
|
||||
if (line == "")
|
||||
{
|
||||
continue;
|
||||
if (!line[0].Equals('#'))
|
||||
break;
|
||||
}
|
||||
|
||||
int pos = line.IndexOf(":", StringComparison.Ordinal);
|
||||
if (!line[0].Equals('#'))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var pos = line.IndexOf(":", StringComparison.Ordinal);
|
||||
|
||||
if (pos <= 1)
|
||||
{
|
||||
_Song.UnknownTags.Add(line);
|
||||
continue;
|
||||
}
|
||||
string identifier = line.Substring(1, pos - 1).Trim().ToUpper();
|
||||
|
||||
var identifier = line.Substring(1, pos - 1).Trim().ToUpper();
|
||||
if (identifier.Contains(" "))
|
||||
{
|
||||
_Song.UnknownTags.Add(line);
|
||||
continue;
|
||||
}
|
||||
string value = line.Substring(pos + 1).Trim();
|
||||
|
||||
var value = line.Substring(pos + 1).Trim();
|
||||
|
||||
if (value == "")
|
||||
{
|
||||
_Song.UnknownTags.Add(line);
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Empty value skipped", CLog.Params(_Song.FileName));
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Empty value skipped", CLog.Params(_Song.FileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (identifier)
|
||||
{
|
||||
case "ENCODING":
|
||||
Encoding newEncoding = value.GetEncoding();
|
||||
var newEncoding = value.GetEncoding();
|
||||
_Song.ManualEncoding = true;
|
||||
if (!newEncoding.Equals(sr.CurrentEncoding))
|
||||
{
|
||||
if (useSetEncoding)
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Duplicate encoding ignored", CLog.Params(_Song.FileName));
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Duplicate encoding ignored", CLog.Params(_Song.FileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
sr.Dispose();
|
||||
sr = null;
|
||||
_Song.Encoding = newEncoding;
|
||||
return ReadHeader(true);
|
||||
}
|
||||
|
||||
break;
|
||||
case "TITLE":
|
||||
_Song.Title = value;
|
||||
@@ -190,6 +208,7 @@ namespace VocaluxeLib.Songs
|
||||
CLog.CSongLog.Error("[{SongFileName}] Can't find audio file: {AudioFile}", CLog.Params(_Song.FileName, Path.Combine(_Song.Folder, value)));
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case "INSTRUMENTAL":
|
||||
if (File.Exists(Path.Combine(_Song.Folder, value)))
|
||||
@@ -199,9 +218,11 @@ namespace VocaluxeLib.Songs
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Error("[{SongFileName}] Can't find instrumental audio file: {AudioFile}", CLog.Params(_Song.FileName, Path.Combine(_Song.Folder, value)));
|
||||
CLog.CSongLog.Error("[{SongFileName}] Can't find instrumental audio file: {AudioFile}",
|
||||
CLog.Params(_Song.FileName, Path.Combine(_Song.Folder, value)));
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case "VOCALS":
|
||||
if (File.Exists(Path.Combine(_Song.Folder, value)))
|
||||
@@ -211,36 +232,56 @@ namespace VocaluxeLib.Songs
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Error("[{SongFileName}] Can't find vocal audio file: {AudioFile}", CLog.Params(_Song.FileName, Path.Combine(_Song.Folder, value)));
|
||||
CLog.CSongLog.Error("[{SongFileName}] Can't find vocal audio file: {AudioFile}",
|
||||
CLog.Params(_Song.FileName, Path.Combine(_Song.Folder, value)));
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case "BPM":
|
||||
if (CHelper.TryParse(value, out _Song.BPM))
|
||||
if (CHelper.TryParse(value, out _Song.Bpm))
|
||||
{
|
||||
_Song.BPM *= _BPMFactor;
|
||||
headerFlags |= EHeaderFlags.BPM;
|
||||
_Song.Bpm *= _BpmFactor;
|
||||
headerFlags |= EHeaderFlags.Bpm;
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid BPM value: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "EDITION":
|
||||
if (value.Length > 1)
|
||||
{
|
||||
_Song.Editions.Add(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid edition: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "GENRE":
|
||||
if (value.Length > 1)
|
||||
{
|
||||
_Song.Genres.Add(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid genre: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "TAGS":
|
||||
if (value.Length > 1)
|
||||
{
|
||||
_Song.Tags.AddRange(value.Split(','));
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid tags: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "ALBUM":
|
||||
_Song.Album = value;
|
||||
@@ -248,68 +289,121 @@ namespace VocaluxeLib.Songs
|
||||
case "YEAR":
|
||||
int num;
|
||||
if (value.Length == 4 && int.TryParse(value, out num) && num > 0)
|
||||
{
|
||||
_Song.Year = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid year: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "LANGUAGE":
|
||||
if (value.Length > 1)
|
||||
{
|
||||
_Song.Languages.Add(_UnifyLanguage(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid language: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "COMMENT":
|
||||
if (!String.IsNullOrEmpty(_Song._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
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid gap: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "COVER":
|
||||
if (File.Exists(Path.Combine(_Song.Folder, value)))
|
||||
{
|
||||
_Song.CoverFileName = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Can't find cover file: {MissingFile}", CLog.Params(_Song.FileName, Path.Combine(_Song.Folder, value)));
|
||||
}
|
||||
|
||||
break;
|
||||
case "BACKGROUND":
|
||||
if (File.Exists(Path.Combine(_Song.Folder, value)))
|
||||
{
|
||||
_Song.BackgroundFileNames.Add(value);
|
||||
}
|
||||
else
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Can't find background file: {MissingFile}", CLog.Params(_Song.FileName, Path.Combine(_Song.Folder, value)));
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Can't find background file: {MissingFile}",
|
||||
CLog.Params(_Song.FileName, Path.Combine(_Song.Folder, value)));
|
||||
}
|
||||
|
||||
break;
|
||||
case "VIDEO":
|
||||
if (File.Exists(Path.Combine(_Song.Folder, value)))
|
||||
{
|
||||
_Song.VideoFileName = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Can't find video file: {MissingFile}", CLog.Params(_Song.FileName, Path.Combine(_Song.Folder, value)));
|
||||
}
|
||||
|
||||
break;
|
||||
case "VIDEOGAP":
|
||||
if (!CHelper.TryParse(value, out _Song.VideoGap))
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid videogap: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "VIDEOASPECT":
|
||||
if (!CHelper.TryParse(value, out _Song.VideoAspect, true))
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid videoaspect: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "START":
|
||||
if (!CHelper.TryParse(value, out _Song.Start))
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid start: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "END":
|
||||
if (CHelper.TryParse(value, out _Song.Finish))
|
||||
_Song.Finish /= 1000f;
|
||||
if (CHelper.TryParse(value, out _Song.End))
|
||||
{
|
||||
_Song.End /= 1000f;
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid end: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "PREVIEWSTART":
|
||||
if (CHelper.TryParse(value, out _Song.Preview.StartTime) && _Song.Preview.StartTime >= 0f)
|
||||
{
|
||||
_Song.Preview.Source = EDataSource.Tag;
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid previewstart: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "PREVIEW":
|
||||
if (CHelper.TryParse(value, out _Song.Preview.StartTime) && _Song.Preview.StartTime >= 0f)
|
||||
@@ -319,40 +413,62 @@ namespace VocaluxeLib.Songs
|
||||
_Song.Preview.Source = EDataSource.Tag;
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid previewstart: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "MEDLEYSTARTBEAT":
|
||||
if (int.TryParse(value, out _Song.Medley.StartBeat))
|
||||
{
|
||||
headerFlags |= EHeaderFlags.MedleyStartBeat;
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid medleystartbeat: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "MEDLEYENDBEAT":
|
||||
if (int.TryParse(value, out _Song.Medley.EndBeat))
|
||||
{
|
||||
headerFlags |= EHeaderFlags.MedleyEndBeat;
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid medleyendbeat: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
|
||||
break;
|
||||
case "ENDSHORT":
|
||||
if ((headerFlags & EHeaderFlags.BPM) != 0)
|
||||
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.EndBeat = (int)CBase.Game.GetBeatFromTime(endTime / 1000f, _Song.Bpm, _Song.Gap);
|
||||
_Song.ShortEnd.Source = EDataSource.Tag;
|
||||
}
|
||||
else
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Invalid shortendbeat: {Value}", CLog.Params(_Song.FileName, value));
|
||||
}
|
||||
}
|
||||
|
||||
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":
|
||||
@@ -364,15 +480,20 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
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())
|
||||
foreach (var curPlayer in player.GetSetBits())
|
||||
{
|
||||
_Song.Notes.VoiceNames[curPlayer] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -388,32 +509,32 @@ namespace VocaluxeLib.Songs
|
||||
if (sr.EndOfStream)
|
||||
{
|
||||
//No other data then header
|
||||
CLog.CSongLog.Error("[{SongFileName}] Lyrics/Notes missing", CLog.Params(_Song.FileName));
|
||||
CLog.CSongLog.Error("[{SongFileName}] Lyrics/Notes missing", CLog.Params(_Song.FileName));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.Title) == 0)
|
||||
{
|
||||
CLog.CSongLog.Error("[{SongFileName}] Title tag missing", CLog.Params(_Song.FileName));
|
||||
CLog.CSongLog.Error("[{SongFileName}] Title tag missing", CLog.Params(_Song.FileName));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.Artist) == 0)
|
||||
{
|
||||
CLog.CSongLog.Error("[{SongFileName}] Artist tag missing", CLog.Params(_Song.FileName));
|
||||
CLog.CSongLog.Error("[{SongFileName}] Artist tag missing", CLog.Params(_Song.FileName));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.MP3) == 0)
|
||||
{
|
||||
CLog.CSongLog.Error("[{SongFileName}] MP3 or AUDIO tag missing", CLog.Params(_Song.FileName));
|
||||
CLog.CSongLog.Error("[{SongFileName}] MP3 or AUDIO tag missing", CLog.Params(_Song.FileName));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((headerFlags & EHeaderFlags.BPM) == 0)
|
||||
if ((headerFlags & EHeaderFlags.Bpm) == 0)
|
||||
{
|
||||
CLog.CSongLog.Error("[{SongFileName}] BPM tag missing", CLog.Params(_Song.FileName));
|
||||
CLog.CSongLog.Error("[{SongFileName}] Bpm tag missing", CLog.Params(_Song.FileName));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -422,7 +543,8 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
if (_Song.Medley.StartBeat > _Song.Medley.EndBeat)
|
||||
{
|
||||
CLog.CSongLog.Error("[{SongFileName}] MedleyStartBeat is bigger than MedleyEndBeat in file: {StartBeat} > {EndBeat}", CLog.Params(_Song.FileName, _Song.Medley.StartBeat > _Song.Medley.EndBeat));
|
||||
CLog.CSongLog.Error("[{SongFileName}] MedleyStartBeat is bigger than MedleyEndBeat in file: {StartBeat} > {EndBeat}",
|
||||
CLog.Params(_Song.FileName, _Song.Medley.StartBeat > _Song.Medley.EndBeat));
|
||||
headerFlags = headerFlags - EHeaderFlags.MedleyStartBeat - EHeaderFlags.MedleyEndBeat;
|
||||
}
|
||||
}
|
||||
@@ -430,7 +552,7 @@ namespace VocaluxeLib.Songs
|
||||
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;
|
||||
_Song.Preview.StartTime = (headerFlags & EHeaderFlags.MedleyStartBeat) != 0 ? CBase.Game.GetTimeFromBeats(_Song.Medley.StartBeat, _Song.Bpm) : 0f;
|
||||
// ReSharper disable CompareOfFloatsByEqualityOperator
|
||||
_Song.Preview.Source = _Song.Preview.StartTime == 0 ? EDataSource.None : EDataSource.Calculated;
|
||||
// ReSharper restore CompareOfFloatsByEqualityOperator
|
||||
@@ -447,22 +569,30 @@ namespace VocaluxeLib.Songs
|
||||
catch (Exception e)
|
||||
{
|
||||
if (sr != null)
|
||||
{
|
||||
sr.Dispose();
|
||||
}
|
||||
|
||||
CLog.CSongLog.Error(e, "[{SongFileName}] Error reading txt header with Message: {ExceptionMessage}", CLog.Params(e.Message, _Song.FileName));
|
||||
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);
|
||||
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))
|
||||
if (string.IsNullOrEmpty(_Song.ArtistSorting))
|
||||
{
|
||||
_Song.ArtistSorting = _Song.Artist;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(_Song.TitleSorting))
|
||||
if (string.IsNullOrEmpty(_Song.TitleSorting))
|
||||
{
|
||||
_Song.TitleSorting = _Song.Title;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -485,6 +615,7 @@ namespace VocaluxeLib.Songs
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return lang;
|
||||
}
|
||||
|
||||
@@ -511,15 +642,25 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = "";
|
||||
int skippedNotesCt = ZeroLengthNoteCt + OverlapNoteCt + NoTextNoteCt;
|
||||
var result = "";
|
||||
var skippedNotesCt = ZeroLengthNoteCt + OverlapNoteCt + NoTextNoteCt;
|
||||
if (skippedNotesCt > 0)
|
||||
result += "Skipped " + skippedNotesCt + " notes (0-Length: " + ZeroLengthNoteCt + ", Overlapping: " + OverlapNoteCt + ", No text: " + NoTextNoteCt + ")\r\n";
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
var adjustedBreakCt = AjustedBreakCt + NoLengthBreakCt;
|
||||
if (adjustedBreakCt > 0)
|
||||
{
|
||||
result += "Adjusted " + adjustedBreakCt + " line breaks (Overlapping previous note: " + AjustedBreakCt + ", No length: " + NoLengthBreakCt + ")\r\n";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -539,25 +680,27 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
//Skip loading if already done and no reload is forced
|
||||
if (_Song.NotesLoaded && !forceReload)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
string filePath = Path.Combine(_Song.Folder, _Song.FileName);
|
||||
var filePath = Path.Combine(_Song.Folder, _Song.FileName);
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
CLog.CSongLog.Error("[{SongFileName}] The file songfile does not exist", CLog.Params(_Song.FileName));
|
||||
CLog.CSongLog.Error("[{SongFileName}] The file songfile does not exist", CLog.Params(_Song.FileName));
|
||||
return false;
|
||||
}
|
||||
|
||||
int currentBeat = 0; //Used for relative songs
|
||||
var 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
|
||||
var endFound = false; // True if end tag was found
|
||||
|
||||
int player = 1;
|
||||
var player = 1;
|
||||
_LineNr = 0;
|
||||
|
||||
char[] trimChars = {' ', ':'};
|
||||
char[] splitChars = {' '};
|
||||
char[] trimChars = { ' ', ':' };
|
||||
char[] splitChars = { ' ' };
|
||||
|
||||
var changesMade = new CAutoChanges();
|
||||
|
||||
@@ -571,15 +714,17 @@ namespace VocaluxeLib.Songs
|
||||
//Search for Note Beginning
|
||||
while (!sr.EndOfStream && !endFound)
|
||||
{
|
||||
string line = sr.ReadLine();
|
||||
var line = sr.ReadLine();
|
||||
_LineNr++;
|
||||
|
||||
if (String.IsNullOrEmpty(line))
|
||||
if (string.IsNullOrEmpty(line))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
char tag = line[0];
|
||||
var tag = line[0];
|
||||
//Remove tag and potential space
|
||||
line = (line.Length >= 2 && line[1] == ' ') ? line.Substring(2) : line.Substring(1);
|
||||
line = line.Length >= 2 && line[1] == ' ' ? line.Substring(2) : line.Substring(1);
|
||||
|
||||
int beat, length;
|
||||
switch (tag)
|
||||
@@ -597,6 +742,7 @@ namespace VocaluxeLib.Songs
|
||||
CLog.CSongLog.Error("[{SongFileName}] Wrong or missing number after \"P\" (in line {LineNr})", CLog.Params(_Song.FileName, _LineNr));
|
||||
return false;
|
||||
}
|
||||
|
||||
currentBeat = 0;
|
||||
lastNote = null;
|
||||
break;
|
||||
@@ -605,7 +751,7 @@ namespace VocaluxeLib.Songs
|
||||
case 'R':
|
||||
case 'G':
|
||||
case 'F':
|
||||
string[] noteData = line.Split(splitChars, 4);
|
||||
var noteData = line.Split(splitChars, 4);
|
||||
if (noteData.Length < 4)
|
||||
{
|
||||
if (noteData.Length == 3)
|
||||
@@ -614,36 +760,46 @@ namespace VocaluxeLib.Songs
|
||||
changesMade.NoTextNoteCt++;
|
||||
continue;
|
||||
}
|
||||
|
||||
CLog.CSongLog.Error("[{SongFileName}] Invalid note found (in line {LineNr}): {noteData}", CLog.Params(_Song.FileName, _LineNr, noteData));
|
||||
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))
|
||||
{
|
||||
CLog.CSongLog.Error("[{SongFileName}] Invalid note found (non-numeric values) (in line {LineNr}): {noteData}", CLog.Params(_Song.FileName, _LineNr, noteData));
|
||||
CLog.CSongLog.Error("[{SongFileName}] Invalid note found (non-numeric values) (in line {LineNr}): {noteData}",
|
||||
CLog.Params(_Song.FileName, _LineNr, noteData));
|
||||
sr.Dispose();
|
||||
return false;
|
||||
}
|
||||
string text = noteData[3].TrimMultipleWs();
|
||||
|
||||
var text = noteData[3].TrimMultipleWs();
|
||||
if (text == "")
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Ignored note without text (in line {LineNr})", CLog.Params(_Song.FileName, _LineNr));
|
||||
changesMade.NoTextNoteCt++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_CurrentReadMode == ENoteReadMode.ZeroBased)
|
||||
{
|
||||
length++;
|
||||
}
|
||||
|
||||
if (length < 1)
|
||||
{
|
||||
changesMade.ZeroLengthNoteCt++;
|
||||
if (_CurrentReadMode == ENoteReadMode.Normal && changesMade.ZeroLengthNoteCt > _MaxZeroNoteCt && changesMade.OverlapNoteCt <= _MaxOverlapNoteCt)
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Found more than {MaxZeroNoteCt} notes with length < 1. Trying alternative read mode.", CLog.Params(_Song.FileName, _MaxZeroNoteCt));
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Found more than {MaxZeroNoteCt} notes with length < 1. Trying alternative read mode.",
|
||||
CLog.Params(_Song.FileName, _MaxZeroNoteCt));
|
||||
_CurrentReadMode = ENoteReadMode.ZeroBased;
|
||||
sr.Dispose();
|
||||
return ReadNotes(true);
|
||||
}
|
||||
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Ignored note with length < 1 (in line {LineNr})", CLog.Params(_Song.FileName, _LineNr));
|
||||
}
|
||||
else
|
||||
@@ -651,9 +807,13 @@ namespace VocaluxeLib.Songs
|
||||
ENoteType noteType;
|
||||
|
||||
if (tag.Equals('*'))
|
||||
{
|
||||
noteType = ENoteType.Golden;
|
||||
}
|
||||
else if (tag.Equals('F'))
|
||||
{
|
||||
noteType = ENoteType.Freestyle;
|
||||
}
|
||||
else if (tag.Equals('R'))
|
||||
{
|
||||
noteType = ENoteType.Rap;
|
||||
@@ -665,13 +825,17 @@ namespace VocaluxeLib.Songs
|
||||
_Song.IsRap = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
noteType = ENoteType.Normal;
|
||||
}
|
||||
|
||||
if (_Song.Relative)
|
||||
{
|
||||
beat += currentBeat;
|
||||
}
|
||||
|
||||
bool ignored = false;
|
||||
foreach (int curPlayer in player.GetSetBits())
|
||||
var ignored = false;
|
||||
foreach (var 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);
|
||||
@@ -683,28 +847,36 @@ namespace VocaluxeLib.Songs
|
||||
changesMade.OverlapNoteCt++;
|
||||
if (changesMade.OverlapNoteCt > _MaxOverlapNoteCt && _CurrentReadMode == ENoteReadMode.ZeroBased)
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Found more than {MaxOverlapNoteCt} overlapping notes. Using standard mode.", CLog.Params(_Song.FileName, _MaxOverlapNoteCt));
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Found more than {MaxOverlapNoteCt} overlapping notes. Using standard mode.",
|
||||
CLog.Params(_Song.FileName, _MaxOverlapNoteCt));
|
||||
_CurrentReadMode = ENoteReadMode.OneBased;
|
||||
sr.Dispose();
|
||||
return ReadNotes(true);
|
||||
}
|
||||
}
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Ignored note for player {CurrentPlayerNumber} because it overlaps with other note (in line {LineNr})", CLog.Params(_Song.FileName, (curPlayer + 1), _LineNr));
|
||||
|
||||
CLog.CSongLog.Warning(
|
||||
"[{SongFileName}] Ignored note for player {CurrentPlayerNumber} because it overlaps with other note (in line {LineNr})",
|
||||
CLog.Params(_Song.FileName, curPlayer + 1, _LineNr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case '-':
|
||||
string[] lineBreakData = line.Split(splitChars);
|
||||
var lineBreakData = line.Split(splitChars);
|
||||
if (lineBreakData.Length < 1)
|
||||
{
|
||||
CLog.CSongLog.Error("[{SongFileName}] Invalid line break found (No beat) (in line {LineNr}): {LineBreakData}", CLog.Params(_Song.FileName, _LineNr, lineBreakData));
|
||||
CLog.CSongLog.Error("[{SongFileName}] Invalid line break found (No beat) (in line {LineNr}): {LineBreakData}",
|
||||
CLog.Params(_Song.FileName, _LineNr, lineBreakData));
|
||||
sr.Dispose();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!int.TryParse(lineBreakData[0], out beat))
|
||||
{
|
||||
CLog.CSongLog.Error("[{SongFileName}] Invalid line break found (Non-numeric value) (in line {LineNr}): {LineBreakData}", CLog.Params(_Song.FileName, _LineNr, lineBreakData));
|
||||
CLog.CSongLog.Error("[{SongFileName}] Invalid line break found (Non-numeric value) (in line {LineNr}): {LineBreakData}",
|
||||
CLog.Params(_Song.FileName, _LineNr, lineBreakData));
|
||||
sr.Dispose();
|
||||
return false;
|
||||
}
|
||||
@@ -714,21 +886,28 @@ namespace VocaluxeLib.Songs
|
||||
beat += currentBeat;
|
||||
if (lineBreakData.Length < 2 || !int.TryParse(lineBreakData[1], out length))
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Missing line break length (in line {LineNr}):{LineBreakData}", CLog.Params(_Song.FileName, _LineNr, lineBreakData));
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Missing line break length (in line {LineNr}):{LineBreakData}",
|
||||
CLog.Params(_Song.FileName, _LineNr, lineBreakData));
|
||||
changesMade.NoLengthBreakCt++;
|
||||
currentBeat = beat;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentBeat += length;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastNote != null && beat <= lastNote.EndBeat)
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Line break is before previous note end. Adjusted. (in line {LineNr})", CLog.Params(_Song.FileName, _LineNr));
|
||||
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Line break is before previous note end. Adjusted. (in line {LineNr})",
|
||||
CLog.Params(_Song.FileName, _LineNr));
|
||||
|
||||
changesMade.AjustedBreakCt++;
|
||||
if (_Song.Relative)
|
||||
{
|
||||
currentBeat += lastNote.EndBeat - beat + 1;
|
||||
}
|
||||
|
||||
beat = lastNote.EndBeat + 1;
|
||||
}
|
||||
|
||||
@@ -739,12 +918,16 @@ namespace VocaluxeLib.Songs
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (int curPlayer in player.GetSetBits())
|
||||
foreach (var curPlayer in player.GetSetBits())
|
||||
{
|
||||
if (!_NewSentence(curPlayer, beat))
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Ignored line break for player {CurPlayerNr} (Overlapping or duplicate) (in line {LineNr})", CLog.Params(_Song.FileName, (curPlayer + 1) , _LineNr));
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Ignored line break for player {CurPlayerNr} (Overlapping or duplicate) (in line {LineNr})",
|
||||
CLog.Params(_Song.FileName, curPlayer + 1, _LineNr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
CLog.CSongLog.Error("[{SongFileName}] Unexpected or missing character ({Tag})", CLog.Params(_Song.FileName, tag));
|
||||
@@ -752,12 +935,16 @@ namespace VocaluxeLib.Songs
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _Song.Notes.VoiceCount; i++)
|
||||
for (var i = 0; i < _Song.Notes.VoiceCount; i++)
|
||||
{
|
||||
CVoice voice = _Song.Notes.GetVoice(i);
|
||||
int emptyLines = voice.RemoveEmptyLines();
|
||||
var voice = _Song.Notes.GetVoice(i);
|
||||
var emptyLines = voice.RemoveEmptyLines();
|
||||
if (emptyLines > 0)
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Removed {NumEmptyLines} empty lines from P .This often indicates a problem with the line breaks in the file", CLog.Params(_Song.FileName, emptyLines));
|
||||
{
|
||||
CLog.CSongLog.Warning("[{SongFileName}] Removed {NumEmptyLines} empty lines from P .This often indicates a problem with the line breaks in the file",
|
||||
CLog.Params(_Song.FileName, emptyLines));
|
||||
}
|
||||
|
||||
voice.UpdateTimings();
|
||||
}
|
||||
}
|
||||
@@ -765,9 +952,13 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
CLog.CSongLog.Error(e, "[{SongFileName}] An unhandled exception occured: {ExceptionMessage}", CLog.Params(_Song.FileName, e.Message));
|
||||
if (sr != null)
|
||||
{
|
||||
sr.Dispose();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
sr.Dispose();
|
||||
try
|
||||
{
|
||||
@@ -776,7 +967,9 @@ namespace VocaluxeLib.Songs
|
||||
_Song._FindShortEnd();
|
||||
_Song.NotesLoaded = true;
|
||||
if (_Song.IsDuet)
|
||||
{
|
||||
_Song._CheckDuet();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -786,27 +979,28 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
if (changesMade.IsModified)
|
||||
{
|
||||
CLog.Warning("Automatic changes have been made to {FilePath} Please check result!\r\n{ChangesMade}" , CLog.Params(filePath, changesMade));
|
||||
CLog.Warning("Automatic changes have been made to {FilePath} Please check result!\r\n{ChangesMade}", CLog.Params(filePath, changesMade));
|
||||
if (CBase.Config.GetSaveModifiedSongs() == EOffOn.TR_CONFIG_ON)
|
||||
{
|
||||
string name = Path.GetFileNameWithoutExtension(_Song.FileName);
|
||||
var 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, true);
|
||||
var voice = _Song.Notes.GetVoice(player, true);
|
||||
return voice.AddNote(note, false);
|
||||
}
|
||||
|
||||
private bool _NewSentence(int player, int start)
|
||||
{
|
||||
CVoice voice = _Song.Notes.GetVoice(player, true);
|
||||
var voice = _Song.Notes.GetVoice(player, true);
|
||||
return voice.AddLine(start);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,56 +36,79 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
private void _WriteHeaderEntry(string id, string value)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(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)
|
||||
}
|
||||
|
||||
foreach (var 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("LENGTH", _Song.Length);
|
||||
_WriteHeaderEntry("SOURCE", _Song.Source);
|
||||
if (!String.IsNullOrEmpty(_Song._Comment))
|
||||
if (!string.IsNullOrEmpty(_Song._Comment))
|
||||
{
|
||||
string comment = _Song._Comment.Replace("\r\n", "\n").Replace('\r', '\n');
|
||||
char[] splitChar = {'\n'};
|
||||
var 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);
|
||||
_WriteHeaderEntry("TAGS", String.Join(",", _Song.Tags.ToArray()));
|
||||
@@ -98,30 +121,48 @@ namespace VocaluxeLib.Songs
|
||||
_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("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));
|
||||
_WriteHeaderEntry("END", (int)(_Song.End * 1000f));
|
||||
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)
|
||||
{
|
||||
_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++)
|
||||
|
||||
for (var 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)
|
||||
|
||||
foreach (var addLine in _Song.UnknownTags)
|
||||
{
|
||||
_Tw.WriteLine(addLine);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -134,47 +175,67 @@ namespace VocaluxeLib.Songs
|
||||
private int _GetBreakBeat(int firstPossibleBeat, int firstNoteBeat)
|
||||
{
|
||||
int breakBeat;
|
||||
int diff = firstNoteBeat - firstPossibleBeat;
|
||||
float timeDiff = CBase.Game.GetTimeFromBeats(diff, _Song.BPM);
|
||||
var diff = firstNoteBeat - firstPossibleBeat;
|
||||
var timeDiff = CBase.Game.GetTimeFromBeats(diff, _Song.Bpm);
|
||||
if (timeDiff > 4f)
|
||||
breakBeat = firstPossibleBeat + (int)CBase.Game.GetBeatFromTime(2f, _Song.BPM, 0f);
|
||||
{
|
||||
breakBeat = firstPossibleBeat + (int)CBase.Game.GetBeatFromTime(2f, _Song.Bpm, 0f);
|
||||
}
|
||||
else if (timeDiff > 2f)
|
||||
breakBeat = firstPossibleBeat + (int)CBase.Game.GetBeatFromTime(1f, _Song.BPM, 0f);
|
||||
{
|
||||
breakBeat = firstPossibleBeat + (int)CBase.Game.GetBeatFromTime(1f, _Song.Bpm, 0f);
|
||||
}
|
||||
else if (diff < 2)
|
||||
{
|
||||
breakBeat = firstPossibleBeat;
|
||||
}
|
||||
else if (diff < 9)
|
||||
{
|
||||
breakBeat = firstNoteBeat - 2;
|
||||
}
|
||||
else if (diff < 13)
|
||||
{
|
||||
breakBeat = firstNoteBeat - 3;
|
||||
}
|
||||
else if (diff < 17)
|
||||
{
|
||||
breakBeat = firstNoteBeat - 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
breakBeat = firstPossibleBeat + 12;
|
||||
}
|
||||
|
||||
return breakBeat;
|
||||
}
|
||||
|
||||
private void _WriteNotes()
|
||||
{
|
||||
for (int i = 0; i < _Song.Notes.VoiceCount; i++)
|
||||
for (var i = 0; i < _Song.Notes.VoiceCount; i++)
|
||||
{
|
||||
CVoice voice = _Song.Notes.GetVoice(i);
|
||||
var voice = _Song.Notes.GetVoice(i);
|
||||
if (_Song.Notes.VoiceCount > 1)
|
||||
{
|
||||
_Tw.WriteLine("P" + Math.Pow(2, i));
|
||||
int currentBeat = 0;
|
||||
}
|
||||
|
||||
var currentBeat = 0;
|
||||
CSongLine lastLine = null;
|
||||
foreach (CSongLine line in voice.Lines)
|
||||
foreach (var line in voice.Lines)
|
||||
{
|
||||
if (lastLine != null)
|
||||
{
|
||||
string lineTxt = "- " + (_GetBreakBeat(lastLine.EndBeat + 1, line.FirstNoteBeat) - currentBeat);
|
||||
var lineTxt = "- " + (_GetBreakBeat(lastLine.EndBeat + 1, line.FirstNoteBeat) - currentBeat);
|
||||
if (_Song.Relative)
|
||||
{
|
||||
lineTxt += " " + (line.FirstNoteBeat - currentBeat);
|
||||
currentBeat = line.FirstNoteBeat;
|
||||
}
|
||||
|
||||
_Tw.WriteLine(lineTxt);
|
||||
}
|
||||
foreach (CSongNote note in line.Notes)
|
||||
|
||||
foreach (var note in line.Notes)
|
||||
{
|
||||
string tag;
|
||||
switch (note.Type)
|
||||
@@ -197,11 +258,14 @@ namespace VocaluxeLib.Songs
|
||||
default:
|
||||
throw new NotImplementedException("Note type " + note.Type);
|
||||
}
|
||||
|
||||
_Tw.WriteLine(tag + " " + (note.StartBeat - currentBeat) + " " + note.Duration + " " + note.Tone + " " + note.Text);
|
||||
}
|
||||
|
||||
lastLine = line;
|
||||
}
|
||||
}
|
||||
|
||||
_Tw.WriteLine("E");
|
||||
}
|
||||
|
||||
@@ -226,8 +290,11 @@ namespace VocaluxeLib.Songs
|
||||
finally
|
||||
{
|
||||
if (_Tw != null)
|
||||
{
|
||||
_Tw.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,16 +66,17 @@ namespace VocaluxeLib.Songs
|
||||
#region Methods
|
||||
public void CheckPerfect()
|
||||
{
|
||||
bool result = HitNote != null;
|
||||
var result = HitNote != null;
|
||||
if (result)
|
||||
{
|
||||
result = (StartBeat == HitNote.StartBeat);
|
||||
result &= (EndBeat == HitNote.EndBeat);
|
||||
result &= (Tone == HitNote.Tone);
|
||||
result = StartBeat == HitNote.StartBeat;
|
||||
result &= EndBeat == HitNote.EndBeat;
|
||||
result &= Tone == HitNote.Tone;
|
||||
}
|
||||
|
||||
Perfect = result;
|
||||
}
|
||||
|
||||
public override bool IsNoteType(params ENoteType[] noteTypes)
|
||||
{
|
||||
return HitNote != null && noteTypes.Contains(HitNote.Type);
|
||||
@@ -84,7 +85,7 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
public override int PointsForBeat
|
||||
{
|
||||
get { return (HitNote == null) ? 0 : HitNote.PointsForBeat; }
|
||||
get { return HitNote == null ? 0 : HitNote.PointsForBeat; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+72
-18
@@ -25,12 +25,14 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
private readonly List<CSongLine> _Lines = new List<CSongLine>();
|
||||
|
||||
public CVoice() {}
|
||||
public CVoice() { }
|
||||
|
||||
public CVoice(CVoice voice)
|
||||
{
|
||||
foreach (CSongLine line in voice._Lines)
|
||||
foreach (var line in voice._Lines)
|
||||
{
|
||||
_Lines.Add(new CSongLine(line));
|
||||
}
|
||||
}
|
||||
|
||||
public CSongLine[] Lines
|
||||
@@ -50,9 +52,11 @@ namespace VocaluxeLib.Songs
|
||||
get
|
||||
{
|
||||
if (_Lines.Count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int result = _Lines[_Lines.Count - 1].EndBeat - _Lines[0].StartBeat;
|
||||
var result = _Lines[_Lines.Count - 1].EndBeat - _Lines[0].StartBeat;
|
||||
return result > 0 ? result : 0;
|
||||
}
|
||||
}
|
||||
@@ -77,59 +81,91 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
//If no line -> No previous line
|
||||
if (_Lines.Count == 0)
|
||||
{
|
||||
return -1;
|
||||
int start = 0;
|
||||
int end = _Lines.Count - 1;
|
||||
}
|
||||
|
||||
var start = 0;
|
||||
var end = _Lines.Count - 1;
|
||||
//Ensure that start.StartBeat<=Beat && end.StartBeat>Beat
|
||||
if (_Lines[0].StartBeat > beat)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_Lines[end].StartBeat <= beat)
|
||||
{
|
||||
return end;
|
||||
}
|
||||
|
||||
//Binary search
|
||||
while (end - start > 1)
|
||||
{
|
||||
int mid = (start + end) / 2;
|
||||
var mid = (start + end) / 2;
|
||||
if (_Lines[mid].StartBeat <= beat)
|
||||
{
|
||||
start = mid;
|
||||
}
|
||||
else
|
||||
{
|
||||
end = mid;
|
||||
}
|
||||
}
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
public bool AddLine(CSongLine line, bool updateTimings = true)
|
||||
{
|
||||
if (_Lines.Count == 0)
|
||||
{
|
||||
_Lines.Add(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
int insPos = FindPreviousLine(line.StartBeat);
|
||||
var 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);
|
||||
var 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};
|
||||
}
|
||||
|
||||
var line = new CSongLine { StartBeat = startBeat };
|
||||
if (insPos >= 0)
|
||||
{
|
||||
CSongLine prevLine = _Lines[insPos];
|
||||
var 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)
|
||||
{
|
||||
@@ -138,6 +174,7 @@ namespace VocaluxeLib.Songs
|
||||
prevLine.DeleteNote(prevLine.NoteCount - 1);
|
||||
}
|
||||
}
|
||||
|
||||
_Lines.Insert(insPos + 1, line);
|
||||
return true;
|
||||
}
|
||||
@@ -150,6 +187,7 @@ namespace VocaluxeLib.Songs
|
||||
UpdateTimings();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -160,9 +198,12 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
public bool AddNote(CSongNote note, bool updateTimings = true)
|
||||
{
|
||||
int lineIndex = FindPreviousLine(note.StartBeat);
|
||||
var 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
|
||||
@@ -170,7 +211,9 @@ namespace VocaluxeLib.Songs
|
||||
{
|
||||
//Add to first line
|
||||
if (!_Lines[0].AddNote(note))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -182,10 +225,16 @@ namespace VocaluxeLib.Songs
|
||||
else
|
||||
{
|
||||
if (!_Lines[lineIndex].AddNote(note))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (updateTimings)
|
||||
{
|
||||
UpdateTimings();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -206,18 +255,21 @@ namespace VocaluxeLib.Songs
|
||||
public void UpdateTimings()
|
||||
{
|
||||
if (_Lines.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_Lines[0].StartBeat = -10000;
|
||||
|
||||
for (int i = 1; i < _Lines.Count; i++)
|
||||
for (var i = 1; i < _Lines.Count; i++)
|
||||
{
|
||||
CSongNote lastNote = _Lines[i - 1].LastNote;
|
||||
CSongNote firstNote = _Lines[i].FirstNote;
|
||||
var lastNote = _Lines[i - 1].LastNote;
|
||||
var firstNote = _Lines[i].FirstNote;
|
||||
|
||||
if ((lastNote != null) && (firstNote != null))
|
||||
if (lastNote != null && firstNote != null)
|
||||
{
|
||||
int min = lastNote.EndBeat;
|
||||
int max = firstNote.StartBeat;
|
||||
var min = lastNote.EndBeat;
|
||||
var max = firstNote.StartBeat;
|
||||
|
||||
int s;
|
||||
switch (max - min)
|
||||
@@ -264,8 +316,10 @@ namespace VocaluxeLib.Songs
|
||||
|
||||
public void SetMedley(int startBeat, int endBeat)
|
||||
{
|
||||
foreach (CSongLine line in _Lines)
|
||||
foreach (var line in _Lines)
|
||||
{
|
||||
line.SetMedley(startBeat, endBeat);
|
||||
}
|
||||
}
|
||||
#endregion Methods
|
||||
|
||||
|
||||
Reference in new issue
Block a user