some performance changes in CNotes.cs (thx to rayo)

This commit is contained in:
Alexander Eckart committed 2012-03-17 11:20:54 +01:00
1 parent 3420cc0972
commit ee70a8fa6b
1 file changed
+36 -30
+36 -30
View File
@@ -245,6 +245,8 @@ namespace Vocaluxe.Lib.Song
private int _EndBeat;
private bool _PerfectLine; // for drawing perfect line effect
private int _MinBeat = int.MaxValue;
private int _MaxBeat = int.MinValue;
private List<CNote> _Notes;
#region Constructors
@@ -263,14 +265,7 @@ namespace Vocaluxe.Lib.Song
get { return _StartBeat; }
set
{
int min = int.MaxValue;
foreach (CNote note in _Notes)
{
if (note.StartBeat < min)
min = note.StartBeat;
}
if (value <= min)
if (value <= _MinBeat)
_StartBeat = value;
}
}
@@ -280,14 +275,7 @@ namespace Vocaluxe.Lib.Song
get { return _EndBeat; }
set
{
int max = int.MinValue;
foreach (CNote note in _Notes)
{
if (note.EndBeat > max)
max = note.EndBeat;
}
if (value >= max)
if (value >= _MaxBeat)
_EndBeat = value;
}
}
@@ -302,13 +290,7 @@ namespace Vocaluxe.Lib.Song
{
get
{
int Result = int.MaxValue;
foreach (CNote note in _Notes)
{
if (note.StartBeat < Result)
Result = note.StartBeat;
}
return Result;
return _MinBeat;
}
}
@@ -316,13 +298,7 @@ namespace Vocaluxe.Lib.Song
{
get
{
int Result = int.MinValue;
foreach (CNote note in _Notes)
{
if (note.EndBeat > Result)
Result = note.EndBeat;
}
return Result;
return _MaxBeat;
}
}
@@ -429,6 +405,7 @@ namespace Vocaluxe.Lib.Song
public void AddNote(CNote Note)
{
_Notes.Add(Note);
updateMinMaxBeat(Note);
}
public bool InsertNote(CNote Note, int Index)
@@ -436,6 +413,7 @@ namespace Vocaluxe.Lib.Song
if (_Notes.Count >= Index)
{
_Notes.Insert(Index, Note);
updateMinMaxBeat(Note);
return true;
}
return false;
@@ -446,6 +424,7 @@ namespace Vocaluxe.Lib.Song
if (_Notes.Count > Index)
{
_Notes.RemoveAt(Index);
updateMinMaxBeat();
return true;
}
return false;
@@ -457,6 +436,7 @@ namespace Vocaluxe.Lib.Song
{
_Notes.RemoveAt(Index);
_Notes.Insert(Index, Note);
updateMinMaxBeat();
return true;
}
return false;
@@ -467,6 +447,7 @@ namespace Vocaluxe.Lib.Song
if (_Notes.Count > 0)
{
_Notes[_Notes.Count - 1].Duration++;
updateMinMaxBeat();
}
return false;
}
@@ -474,6 +455,31 @@ namespace Vocaluxe.Lib.Song
public void DeleteAllNotes()
{
_Notes.Clear();
_MinBeat = int.MaxValue;
_MaxBeat = int.MinValue;
}
private void updateMinMaxBeat(CNote Note)
{
if (Note.StartBeat < _MinBeat)
{
_MinBeat = Note.StartBeat;
}
if (Note.EndBeat > _MaxBeat)
{
_MaxBeat = Note.EndBeat;
}
}
private void updateMinMaxBeat()
{
_MinBeat = int.MaxValue;
_MaxBeat = int.MinValue;
foreach (CNote note in _Notes)
{
updateMinMaxBeat(note);
}
}
#endregion Methods
}