Skip to content

Commit 500e5ff

Browse files
committed
Implement common bpm detection
1 parent 154dcce commit 500e5ff

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

qua/qua.go

+33-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,39 @@ func (q *Qua) CommonBPM() float32 {
7777
return 0
7878
}
7979

80-
return q.TimingPoints[0].BPM
80+
if len(q.TimingPoints) == 1 {
81+
return q.TimingPoints[0].BPM
82+
}
83+
84+
var durations = map[float32]float32{}
85+
lastTime := float32(q.MapLength())
86+
87+
for i := len(q.TimingPoints) - 1; i >= 0; i-- {
88+
point := q.TimingPoints[i]
89+
90+
if point.StartTime > lastTime {
91+
continue
92+
}
93+
94+
duration := lastTime - point.StartTime
95+
durations[point.BPM] += duration
96+
97+
lastTime = point.StartTime
98+
}
99+
100+
var maxBpm float32
101+
var maxDuration float32
102+
firstIter := true
103+
104+
for bpm, duration := range durations {
105+
if firstIter || duration > maxDuration {
106+
maxBpm = bpm
107+
maxDuration = duration
108+
firstIter = false
109+
}
110+
}
111+
112+
return maxBpm
81113
}
82114

83115
// CountHitObjectNormal Returns the count of normal hit objects in the map

0 commit comments

Comments
 (0)