Using binary search for note timing

This commit is contained in:
Flamefire committed 2013-02-23 17:46:06 +01:00
1 parent f50ebd09e1
commit dfe73d6dea
1 file changed
+11 -15
+11 -15
View File
@@ -738,13 +738,12 @@ namespace Vocaluxe.Screens
CWebcam.Close(); CWebcam.Close();
} }
private int FindCurrentLine(CLine[] line, CSong song) private int FindCurrentLine(CLines lines, CLine[] line, CSong song)
{ {
float CurrentTime = _CurrentTime - song.Gap; float CurrentTime = _CurrentTime - song.Gap;
//We are only interested in the last matching line, so either do not check further after line[j].StartBeat > _CurrentBeat or go backwards! //We are only interested in the last matching line, so either do not check further after line[j].StartBeat > _CurrentBeat or go backwards!
for (int j = line.Length - 1; j >= 0; j--) int j = lines.FindPreviousLine(_CurrentBeat);
{ for (; j >= 0; j--)
if (line[j].StartBeat <= _CurrentBeat)
{ {
float FirstNoteTime = CGame.GetTimeFromBeats(line[j].FirstNoteBeat, song.BPM); float FirstNoteTime = CGame.GetTimeFromBeats(line[j].FirstNoteBeat, song.BPM);
//Earlist possible line break is 10s before first note //Earlist possible line break is 10s before first note
@@ -758,7 +757,6 @@ namespace Vocaluxe.Screens
return j; return j;
} }
} }
}
return -1; return -1;
} }
@@ -772,19 +770,18 @@ namespace Vocaluxe.Screens
if (song == null) if (song == null)
return; return;
CLines[] lines = new CLines[song.Notes.Lines.Length];
_CurrentBeat = CGame.CurrentBeat; _CurrentBeat = CGame.CurrentBeat;
for (int i = 0; i < lines.Length; i++) for (int i = 0; i < song.Notes.LinesCount; i++)
{ {
if (i > 1) if (i > 1)
break; // for later break; // for later
lines[i] = song.Notes.GetLines(i); CLines lines = song.Notes.GetLines(i);
CLine[] line = lines[i].Line; CLine[] line = lines.Line;
// find current line // find current line
int nr = FindCurrentLine(line, song); int nr = FindCurrentLine(lines, line, song);
if (nr != -1) if (nr != -1)
{ {
@@ -1054,16 +1051,15 @@ namespace Vocaluxe.Screens
return null; return null;
float[] Alpha = new float[Song.Notes.Lines.Length * 2]; float[] Alpha = new float[Song.Notes.Lines.Length * 2];
CLines[] lines = new CLines[Song.Notes.Lines.Length];
float CurrentTime = _CurrentTime - Song.Gap; float CurrentTime = _CurrentTime - Song.Gap;
for (int i = 0; i < lines.Length; i++) for (int i = 0; i < Song.Notes.LinesCount; i++)
{ {
lines[i] = Song.Notes.GetLines(i); CLines lines = Song.Notes.GetLines(i);
CLine[] line = lines[i].Line; CLine[] line = lines.Line;
// find current line for lyric sub fading // find current line for lyric sub fading
int CurrentLineSub = FindCurrentLine(line, Song); int CurrentLineSub = FindCurrentLine(lines, line, Song);
// find current line for lyric main fading // find current line for lyric main fading
int CurrentLine = 0; int CurrentLine = 0;