Fix `GetMostCommonBeatLength` returning zero in case of not timing points

This commit is contained in:
Dean Herbert 2023-05-08 16:55:48 +09:00
parent 1b7dd32eb1
commit d6ce56e6b1
1 changed files with 4 additions and 1 deletions

View File

@ -107,9 +107,12 @@ public double GetMostCommonBeatLength()
// Aggregate durations into a set of (beatLength, duration) tuples for each beat length
.GroupBy(t => Math.Round(t.beatLength * 1000) / 1000)
.Select(g => (beatLength: g.Key, duration: g.Sum(t => t.duration)))
// Get the most common one, or 0 as a suitable default
// Get the most common one, or 0 as a suitable default (see handling below)
.OrderByDescending(i => i.duration).FirstOrDefault();
if (mostCommon.beatLength == 0)
return TimingControlPoint.DEFAULT_BEAT_LENGTH;
return mostCommon.beatLength;
}