Changed Note/Line adding to be sorted in all cases

This commit is contained in:
Flamefire committed 2013-02-23 17:33:21 +01:00
1 parent b44b57b158
commit f50ebd09e1
2 files changed
+111 -95

No files matched your search

+109 -76
View File
@@ -19,6 +19,11 @@ namespace Vocaluxe.Menu.SingNotes
{ {
} }
public int LinesCount
{
get { return _Lines.Count; }
}
public CNotes(CNotes notes) public CNotes(CNotes notes)
{ {
foreach (CLines lines in notes._Lines) foreach (CLines lines in notes._Lines)
@@ -270,10 +275,10 @@ namespace Vocaluxe.Menu.SingNotes
public class CLine public class CLine
{ {
private int _StartBeat; private int _StartBeat = int.MinValue;
private int _EndBeat; private int _EndBeat = int.MinValue;
private bool _PerfectLine; // for drawing perfect line effect private bool _PerfectLine = false; // for drawing perfect line effect
private bool _VisibleInTimeLine; private bool _VisibleInTimeLine = true;
private int _MinBeat = int.MaxValue; private int _MinBeat = int.MaxValue;
private int _MaxBeat = int.MinValue; private int _MaxBeat = int.MinValue;
@@ -282,10 +287,6 @@ namespace Vocaluxe.Menu.SingNotes
#region Constructors #region Constructors
public CLine() public CLine()
{ {
StartBeat = int.MinValue;
EndBeat = int.MaxValue;
_PerfectLine = false;
_VisibleInTimeLine = true;
} }
public CLine(CLine line) public CLine(CLine line)
@@ -338,18 +339,12 @@ namespace Vocaluxe.Menu.SingNotes
public int FirstNoteBeat public int FirstNoteBeat
{ {
get get { return _MinBeat; }
{
return _MinBeat;
}
} }
public int LastNoteBeat public int LastNoteBeat
{ {
get get { return _MaxBeat; }
{
return _MaxBeat;
}
} }
public string Lyrics public string Lyrics
@@ -385,10 +380,7 @@ namespace Vocaluxe.Menu.SingNotes
public CNote[] Notes public CNote[] Notes
{ {
get get { return _Notes.ToArray(); }
{
return _Notes.ToArray();
}
} }
public CNote FirstNote public CNote FirstNote
@@ -418,15 +410,11 @@ namespace Vocaluxe.Menu.SingNotes
get get
{ {
int Min = int.MaxValue; int Min = int.MaxValue;
int Max = int.MinValue;
foreach (CNote note in _Notes) foreach (CNote note in _Notes)
{ {
if (note.Tone < Min) if (note.Tone < Min)
Min = note.Tone; Min = note.Tone;
}
int Max = int.MinValue;
foreach (CNote note in _Notes)
{
if (note.Tone > Max) if (note.Tone > Max)
Max = note.Tone; Max = note.Tone;
} }
@@ -452,28 +440,57 @@ namespace Vocaluxe.Menu.SingNotes
return _PerfectLine; return _PerfectLine;
} }
public void AddNote(CNote Note) public int FindPreviousNote(int Beat)
{ {
_Notes.Add(Note); //If no notes -> No previous note
updateMinMaxBeat(Note); if (_Notes.Count == 0)
return -1;
int start = 0;
int 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;
if (_Notes[mid].StartBeat <= Beat)
start = mid;
else
end = mid;
}
return start;
} }
public bool InsertNote(CNote Note, int Index) public bool AddNote(CNote Note)
{ {
if (_Notes.Count >= Index) if (_Notes.Count == 0)
_Notes.Add(Note);
else
{ {
_Notes.Insert(Index, Note); int insPos = FindPreviousNote(Note.StartBeat);
//Flamefire: May be a performance hit as notes are also used for sung notes
//But for song loading this might be very helpful!
//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;
* */
_Notes.Insert(insPos + 1, Note);
}
updateMinMaxBeat(Note); updateMinMaxBeat(Note);
return true; return true;
} }
return false;
}
public bool DeleteNote(int Index) public bool DeleteNote(int Index)
{ {
if (_Notes.Count > Index) if (_Notes.Count > Index)
{ {
_Notes.RemoveAt(Index); _Notes.RemoveAt(Index);
if (Index == 0 || Index == _Notes.Count - 1)
updateMinMaxBeat(); updateMinMaxBeat();
return true; return true;
} }
@@ -485,9 +502,7 @@ namespace Vocaluxe.Menu.SingNotes
if (_Notes.Count > Index) if (_Notes.Count > Index)
{ {
_Notes.RemoveAt(Index); _Notes.RemoveAt(Index);
_Notes.Insert(Index, Note); return AddNote(Note);
updateMinMaxBeat();
return true;
} }
return false; return false;
} }
@@ -497,7 +512,7 @@ namespace Vocaluxe.Menu.SingNotes
if (_Notes.Count > 0) if (_Notes.Count > 0)
{ {
_Notes[_Notes.Count - 1].Duration++; _Notes[_Notes.Count - 1].Duration++;
updateMinMaxBeat(); _MaxBeat++;
} }
return false; return false;
} }
@@ -505,8 +520,7 @@ namespace Vocaluxe.Menu.SingNotes
public void DeleteAllNotes() public void DeleteAllNotes()
{ {
_Notes.Clear(); _Notes.Clear();
_MinBeat = int.MaxValue; updateMinMaxBeat();
_MaxBeat = int.MinValue;
} }
public void SetMedley(int StartBeat, int EndBeat) public void SetMedley(int StartBeat, int EndBeat)
@@ -534,12 +548,16 @@ namespace Vocaluxe.Menu.SingNotes
} }
private void updateMinMaxBeat() private void updateMinMaxBeat()
{
if (_Notes.Count > 0)
{
_MinBeat = _Notes[0].StartBeat;
_MaxBeat = _Notes[_Notes.Count - 1].EndBeat;
}
else
{ {
_MinBeat = int.MaxValue; _MinBeat = int.MaxValue;
_MaxBeat = int.MinValue; _MaxBeat = int.MinValue;
foreach (CNote note in _Notes)
{
updateMinMaxBeat(note);
} }
} }
@@ -631,28 +649,40 @@ namespace Vocaluxe.Menu.SingNotes
} }
#region Methods #region Methods
public void AddLine(CLine Line) //Find last line with StartBeat<=Beat
public int FindPreviousLine(int Beat)
{ {
AddLine(Line, false); //If no line -> No previous line
} if (_Lines.Count == 0)
public void AddLine(CLine Line, bool updateTimings) return -1;
int start = 0;
int 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)
{ {
_Lines.Add(Line); int mid = (start + end) / 2;
if (updateTimings) if (_Lines[mid].StartBeat <= Beat)
{ start = mid;
UpdateTimings(); else
end = mid;
} }
return start;
} }
public bool InsertLine(CLine Line, int Index) public void AddLine(CLine Line)
{ {
if (_Lines.Count >= Index) if (_Lines.Count == 0)
_Lines.Add(Line);
else
{ {
_Lines.Insert(Index, Line); int insPos = FindPreviousLine(Line.StartBeat);
UpdateTimings(); _Lines.Insert(insPos + 1, Line);
return true;
} }
return false;
} }
public bool DeleteLine(int Index) public bool DeleteLine(int Index)
@@ -671,34 +701,38 @@ namespace Vocaluxe.Menu.SingNotes
_Lines.Clear(); _Lines.Clear();
} }
public bool AddNote(CNote Note, int LineIndex, bool updateTimings) public bool AddNote(CNote Note, bool updateTimings = false)
{ {
if (_Lines.Count > LineIndex) int LineIndex = FindPreviousLine(Note.StartBeat);
if (LineIndex < 0)
{
//Note is before ALL lines
CLine Line = new CLine();
Line.StartBeat = Note.StartBeat;
Line.AddNote(Note);
_Lines.Insert(0, Line);
}
else
{
if (!_Lines[LineIndex].AddNote(Note))
return false;
}
if (updateTimings)
UpdateTimings();
return true;
}
public bool InsertNote(CNote Note, int LineIndex, bool updateTimings = false)
{
if (_Lines.Count > LineIndex && _Lines[LineIndex].StartBeat <= Note.StartBeat)
{ {
_Lines[LineIndex].AddNote(Note); _Lines[LineIndex].AddNote(Note);
if (updateTimings) if (updateTimings)
{
UpdateTimings(); UpdateTimings();
}
return true; return true;
} }
return false; return false;
} }
public bool AddNote(CNote Note, int LineIndex)
{
return AddNote(Note, LineIndex, true);
}
public bool InsertNote(CNote Note, int LineIndex, int NoteIndex)
{
if (_Lines.Count > LineIndex)
{
bool res = _Lines[LineIndex].InsertNote(Note, NoteIndex);
UpdateTimings();
return res;
}
return false;
}
public void UpdateTimings() public void UpdateTimings()
{ {
CNote LastNote, FirstNote; CNote LastNote, FirstNote;
@@ -719,7 +753,6 @@ namespace Vocaluxe.Menu.SingNotes
min = LastNote.EndBeat; min = LastNote.EndBeat;
max = FirstNote.StartBeat; max = FirstNote.StartBeat;
s = 0;
switch (max - min) switch (max - min)
{ {
case 0: case 0:
+2 -19
View File
@@ -780,21 +780,11 @@ namespace Vocaluxe.Menu.SongMenu
return true; return true;
} }
private void ParseNote(int Player, ENoteType NoteType, int Start, int Length, int Tone, string Text) private bool ParseNote(int Player, ENoteType NoteType, int Start, int Length, int Tone, string Text)
{ {
CNote note = new CNote(Start, Length, Tone, Text, NoteType); CNote note = new CNote(Start, Length, Tone, Text, NoteType);
CLines lines = this.Notes.GetLines(Player); CLines lines = this.Notes.GetLines(Player);
return lines.AddNote(note);
if (lines.LineCount == 0)
{
CLine line = new CLine();
line.AddNote(note);
lines.AddLine(line, false);
}
else
{
lines.AddNote(note, lines.LineCount - 1, false);
}
} }
private void NewSentence(int Player, int Start) private void NewSentence(int Player, int Start)
@@ -802,15 +792,8 @@ namespace Vocaluxe.Menu.SongMenu
CLines lines = Notes.GetLines(Player); CLines lines = Notes.GetLines(Player);
CLine line = new CLine(); CLine line = new CLine();
line.StartBeat = Start; line.StartBeat = Start;
if (lines.LineCount == 0)
{
lines.AddLine(line); lines.AddLine(line);
} }
else
{
lines.AddLine(line);
}
}
public void LoadSmallCover() public void LoadSmallCover()
{ {