From ee70a8fa6bcd9d371b64392bf702ab1ffaa249ec Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sat, 17 Mar 2012 11:20:54 +0100 Subject: [PATCH] some performance changes in CNotes.cs (thx to rayo) --- Vocaluxe/Lib/Song/CNotes.cs | 66 ++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/Vocaluxe/Lib/Song/CNotes.cs b/Vocaluxe/Lib/Song/CNotes.cs index d5ac4dab..c732054e 100644 --- a/Vocaluxe/Lib/Song/CNotes.cs +++ b/Vocaluxe/Lib/Song/CNotes.cs @@ -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 _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 }