-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuntil.go
51 lines (42 loc) · 1.28 KB
/
until.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
package kallos
// Stoppable can be stopped
type Stoppable interface {
NumNoteEvents() int
LastEventIsNote() bool
Duration() float64
}
// StopCondition stops stream creation
type StopCondition interface {
ShouldStop(s Stoppable) bool
}
// LengthStopCondition stops stream creation after the stream reaches a certain length
type LengthStopCondition struct {
Length uint32
}
// NewLengthStopCondition returns a new length stop condition
func NewLengthStopCondition(length uint32) *LengthStopCondition {
return &LengthStopCondition{
Length: length,
}
}
// ShouldStop return true if stream creation should stop
func (sc *LengthStopCondition) ShouldStop(s Stoppable) bool {
return uint32(s.NumNoteEvents()) >= sc.Length
}
// DurationStopCondition stops stream creation after the stream reaches a certain duration in seconds
type DurationStopCondition struct {
Duration float64
}
// NewDurationStopCondition returns a new duration stop condition
func NewDurationStopCondition(duration float64) *DurationStopCondition {
return &DurationStopCondition{
Duration: duration,
}
}
// ShouldStop return true if stream creation should stop
func (sc *DurationStopCondition) ShouldStop(s Stoppable) bool {
if s.LastEventIsNote() {
return sc.Duration < (s.Duration() * SecondsPerBeat)
}
return false
}