Using binary search for note timing
This commit is contained in:
1 parent
f50ebd09e1
commit
dfe73d6dea
1 file changed
+20
-24
@@ -738,25 +738,23 @@ namespace Vocaluxe.Screens
|
||||
CWebcam.Close();
|
||||
}
|
||||
|
||||
private int FindCurrentLine(CLine[] line, CSong song)
|
||||
private int FindCurrentLine(CLines lines, CLine[] line, CSong song)
|
||||
{
|
||||
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!
|
||||
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);
|
||||
//Earlist possible line break is 10s before first note
|
||||
if (FirstNoteTime <= CurrentTime + 10f)
|
||||
{
|
||||
float FirstNoteTime = CGame.GetTimeFromBeats(line[j].FirstNoteBeat, song.BPM);
|
||||
//Earlist possible line break is 10s before first note
|
||||
if (FirstNoteTime <= CurrentTime + 10f)
|
||||
{
|
||||
//First line has no predecessor or line has to be shown
|
||||
if(j == 0 || FirstNoteTime - CConfig.MinLineBreakTime <= CurrentTime) return j;
|
||||
float LastNoteTime = CGame.GetTimeFromBeats(line[j-1].LastNoteBeat, song.BPM);
|
||||
//No line break if last line is not fully evaluated (with 50% tolerance -> tested so notes are drawn)
|
||||
if(LastNoteTime + CConfig.MicDelay/1000f * 1.5f >= CurrentTime) return j-1;
|
||||
return j;
|
||||
}
|
||||
//First line has no predecessor or line has to be shown
|
||||
if(j == 0 || FirstNoteTime - CConfig.MinLineBreakTime <= CurrentTime) return j;
|
||||
float LastNoteTime = CGame.GetTimeFromBeats(line[j-1].LastNoteBeat, song.BPM);
|
||||
//No line break if last line is not fully evaluated (with 50% tolerance -> tested so notes are drawn)
|
||||
if(LastNoteTime + CConfig.MicDelay/1000f * 1.5f >= CurrentTime) return j-1;
|
||||
return j;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
@@ -772,19 +770,18 @@ namespace Vocaluxe.Screens
|
||||
if (song == null)
|
||||
return;
|
||||
|
||||
CLines[] lines = new CLines[song.Notes.Lines.Length];
|
||||
|
||||
_CurrentBeat = CGame.CurrentBeat;
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
for (int i = 0; i < song.Notes.LinesCount; i++)
|
||||
{
|
||||
if (i > 1)
|
||||
break; // for later
|
||||
|
||||
lines[i] = song.Notes.GetLines(i);
|
||||
CLine[] line = lines[i].Line;
|
||||
CLines lines = song.Notes.GetLines(i);
|
||||
CLine[] line = lines.Line;
|
||||
|
||||
// find current line
|
||||
int nr = FindCurrentLine(line, song);
|
||||
int nr = FindCurrentLine(lines, line, song);
|
||||
|
||||
if (nr != -1)
|
||||
{
|
||||
@@ -1054,16 +1051,15 @@ namespace Vocaluxe.Screens
|
||||
return null;
|
||||
|
||||
float[] Alpha = new float[Song.Notes.Lines.Length * 2];
|
||||
CLines[] lines = new CLines[Song.Notes.Lines.Length];
|
||||
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);
|
||||
CLine[] line = lines[i].Line;
|
||||
CLines lines = Song.Notes.GetLines(i);
|
||||
CLine[] line = lines.Line;
|
||||
|
||||
// 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
|
||||
int CurrentLine = 0;
|
||||
|
||||
Reference in new issue
Block a user