-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbar_test.go
127 lines (108 loc) · 2.32 KB
/
bar_test.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package balafon_test
import (
"fmt"
"testing"
"time"
"github.com/mgnsk/balafon"
"github.com/mgnsk/balafon/internal/constants"
. "github.com/onsi/gomega"
)
func TestBarCapTimeSignatures(t *testing.T) {
for _, tc := range []struct {
timesig [2]uint8
capacity uint32
}{
{
timesig: [2]uint8{1, 4},
capacity: uint32(constants.TicksPerQuarter),
},
{
timesig: [2]uint8{4, 4},
capacity: uint32(constants.TicksPerWhole),
},
} {
g := NewWithT(t)
bar := balafon.Bar{}
bar.SetTimeSig(tc.timesig[0], tc.timesig[1])
g.Expect(bar.Cap()).To(Equal(tc.capacity))
}
}
func TestZeroDurationBar(t *testing.T) {
for _, tc := range []struct {
input string
dur time.Duration
}{
{
input: ":time 1 1; :tempo 60; :bar 1 :program 1; :end; :play 1",
dur: 0,
},
{
input: ":time 1 1; :tempo 60; :assign c 60; :bar 1 c :end; :play 1",
dur: 4 * time.Second,
},
} {
t.Run(tc.input, func(t *testing.T) {
g := NewWithT(t)
it := balafon.New()
g.Expect(it.EvalString(tc.input)).To(Succeed())
bars := it.Flush()
g.Expect(bars).To(HaveLen(1))
g.Expect(bars[0].Duration(60)).To(Equal(tc.dur))
})
}
}
func TestBarDurationMultiTrack(t *testing.T) {
g := NewWithT(t)
bar := balafon.Bar{
Events: []balafon.Event{
{
Duration: uint32(constants.TicksPerQuarter),
},
{
Duration: uint32(constants.TicksPerQuarter),
},
},
}
bar.SetTimeSig(1, 4)
g.Expect(bar.Duration(60)).To(Equal(time.Second))
}
func TestBarDurationTimeSignatures(t *testing.T) {
for _, tc := range []struct {
timesig string
input string
}{
{
timesig: "1 4",
input: "c",
},
{
timesig: "2 8",
input: "c",
},
} {
t.Run(fmt.Sprintf(":time %s", tc.timesig), func(t *testing.T) {
g := NewWithT(t)
it := balafon.New()
g.Expect(it.EvalString(fmt.Sprintf(":time %s", tc.timesig))).To(Succeed())
g.Expect(it.EvalString(":assign c 60")).To(Succeed())
g.Expect(it.EvalString(tc.input)).To(Succeed())
bars := it.Flush()
g.Expect(bars).To(HaveLen(1))
g.Expect(bars[0].Duration(60)).To(Equal(time.Second))
})
}
}
func TestEmptyBarIsInvalid(t *testing.T) {
g := NewWithT(t)
// Commands that don't emit MIDI events.
input := `
:bar mybar
:assign a 1
:velocity 1
:channel 1
:voice 1
:end
`
it := balafon.New()
g.Expect(it.EvalString(input)).NotTo(Succeed())
}