-
Notifications
You must be signed in to change notification settings - Fork 13
/
play_notes_every.go
64 lines (60 loc) · 2.1 KB
/
play_notes_every.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
60
61
62
63
64
package definitions
import (
. "github.com/bspaans/bleep/sequencer/automations"
. "github.com/bspaans/bleep/sequencer/sequences"
"github.com/bspaans/bleep/util"
)
type PlayNotesEveryDef struct {
Notes []int `json:"notes,omitempty" yaml:"notes"`
NotesAutomation *IntArrayAutomationDef `json:"auto_notes,omitempty" yaml:"auto_notes"`
Channel int `json:"channel" yaml:"channel"`
Velocity int `json:"velocity,omitempty" yaml:"velocity"`
VelocityAutomation *AutomationDef `json:"auto_velocity,omitempty" yaml:"auto_velocity"`
Duration interface{} `json:"duration" yaml:"duration"`
Every interface{} `json:"every" yaml:"every"`
Offset interface{} `json:"offset" yaml:"offset"`
}
func (e *PlayNotesEveryDef) GetSequence(ctx *context) (Sequence, error) {
every := uint(0)
if e.Every != nil {
every_, err := parseDuration(e.Every, ctx.Granularity)
if err != nil {
return nil, util.WrapError("play_notes", err)
}
every = every_
}
duration, err := parseDuration(e.Duration, ctx.Granularity)
if err != nil {
return nil, util.WrapError("play_notes", err)
}
notesF := IntArrayIdAutomation(e.Notes)
if e.NotesAutomation != nil {
notesF_, err := e.NotesAutomation.GetAutomation()
if err != nil {
return nil, util.WrapError("play_notes > auto_notes", err)
}
notesF = notesF_
}
velocityF := IntIdAutomation(e.Velocity)
if e.VelocityAutomation != nil {
velocityF_, err := e.VelocityAutomation.GetAutomation()
if err != nil {
return nil, util.WrapError("play_note > auto_velocity", err)
}
velocityF = velocityF_
}
var result Sequence
if every == 0 {
result = PlayNotesAutomation(duration, e.Channel, notesF, velocityF)
} else {
result = PlayNotesEveryAutomation(every, duration, e.Channel, notesF, velocityF)
}
if e.Offset != nil {
offset, err := parseDuration(e.Offset, ctx.Granularity)
if err != nil {
return nil, util.WrapError("play_note > offset", err)
}
return Offset(offset, result), nil
}
return result, nil
}