Some fixes and support for more than 2 voices

This commit is contained in:
Flamefire committed 2013-10-11 14:50:27 +02:00
1 parent 8890176e97
commit bf1c00b5d1
10 files changed
+144 -62

No files matched your search

+51 -10
View File
@@ -21,26 +21,65 @@ namespace VocaluxeLib.Songs
{
public class CNotes
{
public class CVoiceNames
{
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 CNotes(CNotes notes)
{
foreach (CVoice voice in notes._Voices)
_Voices.Add(new CVoice(voice));
VoiceNames = new CVoiceNames(notes.VoiceNames);
}
public CVoice[] Voices
{
get { return _Voices.ToArray(); }
}
public CNotes() {}
public int LinesCount
public int VoiceCount
{
get { return _Voices.Count; }
}
public CNotes(CNotes notes)
{
foreach (CVoice voice in notes._Voices)
_Voices.Add(new CVoice(voice));
}
public CVoice GetVoice(int index)
{
while (index >= _Voices.Count)
@@ -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)
+22 -34
View File
@@ -124,9 +124,6 @@ namespace VocaluxeLib.Songs
public float Gap;
public float VideoGap;
public string DuetPart1 = String.Empty;
public string DuetPart2 = String.Empty;
private readonly List<string> _Comment = new List<string>();
// Sorting
@@ -192,8 +189,6 @@ namespace VocaluxeLib.Songs
PreviewStart = song.PreviewStart;
ShortEnd = song.ShortEnd;
DuetPart1 = song.DuetPart1;
DuetPart2 = song.DuetPart2;
Encoding = song.Encoding;
Folder = song.Folder;
@@ -268,7 +263,7 @@ namespace VocaluxeLib.Songs
if (Folder == null)
return false;
foreach (string folder in CBase.Config.GetSongFolder())
foreach (string folder in CBase.Config.GetSongFolders())
{
if (!Folder.Contains(folder))
continue;
@@ -318,7 +313,7 @@ namespace VocaluxeLib.Songs
sr = null;
sr = new StreamReader(filePath, Encoding);
//Scip everything till encoding
//Skip everything till encoding
while (!sr.EndOfStream)
{
line = sr.ReadLine();
@@ -362,12 +357,12 @@ namespace VocaluxeLib.Songs
case "DUETSINGERP1":
case "P1":
if (value != "")
DuetPart1 = value;
Notes.VoiceNames[0] = value;
break;
case "DUETSINGERP2":
case "P2":
if (value != "")
DuetPart2 = value;
Notes.VoiceNames[1] = value;
break;
case "MP3":
if (File.Exists(Path.Combine(Folder, value)))
@@ -462,7 +457,7 @@ namespace VocaluxeLib.Songs
CalculateMedley = false;
break;
case "RELATIVE":
if (value.ToUpper() == "YES" && value.ToUpper() != "NO")
if (value.ToUpper() == "YES")
Relative = EOffOn.TR_CONFIG_ON;
break;
}
@@ -569,7 +564,7 @@ namespace VocaluxeLib.Songs
int currentPos = 0;
bool isNewSentence = false;
int player = 0;
int player = 1;
int fileLineNo = 0;
StreamReader sr = null;
@@ -611,14 +606,7 @@ namespace VocaluxeLib.Songs
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
if (!int.TryParse(chr.ToString(), out player))
{
CBase.Log.LogError("Error loading song. Line No.: " + fileLineNo + ". Wrong or missing number after \"P\": " + filePath);
return false;
@@ -652,14 +640,19 @@ namespace VocaluxeLib.Songs
if (Relative == EOffOn.TR_CONFIG_ON)
param1 += currentPos;
if (player != 2)
// one singer
_ParseNote(player, noteType, param1, param2, param3, paramS);
else
int curPlayer = 0;
int tmpPlayer = player;
//Evaluate as bitset
while (tmpPlayer > 0)
{
// both singer
_ParseNote(0, noteType, param1, param2, param3, paramS);
_ParseNote(1, noteType, param1, param2, param3, paramS);
if ((tmpPlayer & 1) != 0)
{
if (!_ParseNote(curPlayer, noteType, param1, param2, param3, paramS))
CBase.Log.LogError("Warning! Ignored note for player " + (curPlayer + 1) + " in song because it overlaps with other note. Line No.: " +
fileLineNo + ": " + filePath);
}
tmpPlayer >>= 1;
curPlayer++;
}
isNewSentence = false;
break;
@@ -789,15 +782,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 + "\".");
}
}
+2 -5
View File
@@ -90,11 +90,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.NoteType = ENoteType.Freestyle;
VisibleInTimeLine = FirstNoteBeat >= startBeat && LastNoteBeat <= endBeat;
}