public int TicksToMillis(int ticks)
{
var time = 0;
var bpm = 120.0;
var lastChange = 0;
// find start and bpm of last tempo change before time
for (int i = 0; i < _tempoChanges.Count; i++)
{
var c = _tempoChanges[i];
if (ticks < c.Ticks)
{
break;
}
time = c.Time;
bpm = c.Bpm;
lastChange = c.Ticks;
}
// add the missing millis
ticks -= lastChange;
time += (int)(ticks * (60000.0 / (bpm * _division)));
return time;
}