-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidi.go
71 lines (60 loc) · 1.28 KB
/
midi.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
65
66
67
68
69
70
71
package main
import "time"
const (
midiNoteOff int = 0x80
midiNoteOn int = 0x90
midiVmax int = 127
labelPortDefault string = "<default>"
labelPortSelected string = "<selected>"
)
type midiNote struct {
Channel int
Note int
}
type noteMap map[string]midiNote
type event struct {
Notes row
Velocities row
Channels row
Figures []midiFigure
}
type midiEvent struct {
channel int
note int
velocity int
}
type figure struct {
key string
velocity int
pattern string
}
type midiFigure []midiEvent
func playChord(e event, q chan midiEvent) {
debugf("playChord(): %v", e)
for i, note := range e.Notes {
q <- midiEvent{e.Channels[i], note, e.Velocities[i]}
}
}
// play a list of micro pattern midi events. The events are stretched
// out equally over the duration of one major event.
func playFigure(fig midiFigure, timing time.Duration, q chan midiEvent) {
if len(fig) < 1 {
return
}
debugf("playFigure(): %v", fig)
sleepval := timing / time.Duration(len(fig))
for i := 0; i < len(fig); i++ {
if fig[i].note != 0 {
q <- fig[i]
}
time.Sleep(sleepval)
}
}
func processMidiQ(q chan midiEvent) {
debugf("processMidiQ(): started")
var ev midiEvent
for {
ev = <-q
sendMidiNote(ev.channel, ev.note, ev.velocity)
}
}