-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
70 lines (53 loc) · 1.28 KB
/
event.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
package balafon
import (
"fmt"
"strings"
"github.com/mgnsk/balafon/internal/ast"
"gitlab.com/gomidi/midi/v2/smf"
)
// Channel is a MIDI channel.
type Channel uint8
func (c Channel) Uint8() uint8 {
return uint8(c)
}
func (c Channel) Human() uint8 {
return uint8(c) + 1
}
func NewChannelFromMIDI(ch uint8) Channel {
return Channel(ch)
}
func NewChannelFromHuman(ch uint8) Channel {
return Channel(ch - 1)
}
// Voice is a score voice.
type Voice uint8
func (v Voice) Uint8() uint8 {
return uint8(v)
}
// Event is a balafon event.
type Event struct {
Note *ast.Note // only for note on messages and rests
Message smf.Message
IsFlat bool // if the midi note was lowered due to key sig
Pos uint32 // in relative ticks from beginning of bar
Duration uint32 // in ticks
Voice Voice
Track uint8 // track is the MIDI channel in human value
}
func (e *Event) String() string {
var s strings.Builder
if e.Track > 0 {
s.WriteString(fmt.Sprintf("track: %d ", e.Track))
}
s.WriteString(fmt.Sprintf("pos: %d dur: %d", e.Pos, e.Duration))
if e.Voice > 0 {
s.WriteString(fmt.Sprintf(" voice: %d", e.Voice))
}
if e.Note != nil {
s.WriteString(" note: ")
e.Note.WriteTo(&s)
}
s.WriteString(" message: ")
s.WriteString(e.Message.String())
return s.String()
}