-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathloopmode.go
More file actions
executable file
·56 lines (49 loc) · 2.14 KB
/
loopmode.go
File metadata and controls
executable file
·56 lines (49 loc) · 2.14 KB
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
package loop
// Mode is the mode of operation for the looping ranges of "things" (samples, envelope points, etc)
type Mode uint8
const (
// ModeDisabled is for disabled looping
// |start>----------------------------------------end| <= on playthrough 1, whole sample plays
ModeDisabled = Mode(iota)
// ModeLegacy is for legacy looping: (old MOD players)
// |start>----------------------------------------end| <= on playthrough 1, whole sample plays
// |-------------|loopBegin>-----loopEnd|------------| <= only if looped and on playthrough 2+, only the part that loops plays
// |-------------|loopBegin>----------------------end| <= on playthrough 2+, the loop ends and playback continues to end, if !keyOn
ModeLegacy
// ModeNormal is for normal looping: (S3M/XM/IT)
// |start>-----------------------loopEnd|------------| <= on playthrough 1, whole sample plays
// |-------------|loopBegin>-----loopEnd|------------| <= only if looped and on playthrough 2+, only the part that loops plays
// |-------------|loopBegin>----------------------end| <= on playthrough 2+, the loop ends and playback continues to end, if !keyOn
ModeNormal
// ModePingPong is for ping-pong looping:
// |start>-----------------------loopEnd|------------| <= on playthrough 1, whole sample plays
// |-------------|loopBegin>----<loopEnd|------------| <= only if looped and on playthrough 2+, part that loops plays and ping-pongs
// |-------------|loopBegin>----------------------end| <= on playthrough 2+, the loop ends and playback continues to end, if !keyOn
ModePingPong
)
// simple helper to consolidate loop length calculations
// (yeah, it could just be the math in place, but whatever)
func calcLoopLen(loopBegin int, loopEnd int) int {
return loopEnd - loopBegin
}
// NewLoop creates a loop based on the specified mode and settings
func NewLoop(mode Mode, settings Settings) Loop {
switch mode {
case ModeDisabled:
return &Disabled{}
case ModeLegacy:
return &Legacy{
Settings: settings,
}
case ModeNormal:
return &Normal{
Settings: settings,
}
case ModePingPong:
return &PingPong{
Settings: settings,
}
default:
panic("unhandled loop mode")
}
}