-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnormal.go
More file actions
41 lines (35 loc) · 1.03 KB
/
normal.go
File metadata and controls
41 lines (35 loc) · 1.03 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
package loop
// Normal is a normal loop
//
// |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
type Normal struct {
Settings
}
// Enabled returns true if the loop is enabled
func (l *Normal) Enabled() bool {
return true
}
// Length returns the length of the loop
func (l *Normal) Length() int {
return calcLoopLen(l.Begin, l.End)
}
// CalcPos calculates the position based on the loop details
func (l *Normal) CalcPos(pos int, length int) (int, bool) {
if pos < 0 {
return 0, false
}
if pos < l.End {
return pos, false
}
loopLen := l.Length()
if loopLen < 0 {
return max(pos, length), false
} else if loopLen == 0 {
return l.Begin, true
}
dist := pos - l.End
loopedPos := dist % loopLen
return l.Begin + loopedPos, true
}