-
Notifications
You must be signed in to change notification settings - Fork 0
/
conductor.go
59 lines (48 loc) · 1.25 KB
/
conductor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package gophengine
import "log/slog"
type Conductor struct {
Bpm int
Crochet float64
StepCrochet float64
SongPosition float64
LastSongPos float64
Offset float64
SafeFrames int
SafeZoneOffset float64
BPMChangeMap []BPMChangeEvent
}
func NewConductor(bpm int) *Conductor {
c := new(Conductor)
c.Bpm = bpm
c.Crochet = (60 / float64(bpm)) * 1000
c.StepCrochet = c.Crochet / 4
c.Offset = 0
c.SafeFrames = 10
c.SafeZoneOffset = (float64(c.SafeFrames) / 60) * 1000
return c
}
func (c *Conductor) MapBPMChanges(song *Song) {
c.BPMChangeMap = []BPMChangeEvent{}
var curBPM int = song.Bpm
var totalSteps int = 0
var totalPos float64 = 0
for _, note := range song.Notes {
if note.ChangeBPM && note.Bpm != curBPM {
curBPM = note.Bpm
c.BPMChangeMap = append(c.BPMChangeMap, BPMChangeEvent{
StepTime: totalSteps,
SongTime: totalPos,
Bpm: curBPM,
})
}
var deltaSteps int = note.LengthInSteps
totalSteps += deltaSteps
totalPos += ((60 / float64(curBPM)) * 1000 / 4) * float64(deltaSteps)
}
slog.Info("new BPM map", "BPMChangeMap", c.BPMChangeMap)
}
func (c *Conductor) ChangeBPM(newBpm int) {
c.Bpm = newBpm
c.Crochet = (60 / float64(c.Bpm)) * 1000
c.StepCrochet = c.Crochet / 4
}