-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests.lua
135 lines (124 loc) · 4.06 KB
/
run-tests.lua
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
128
129
130
131
132
133
134
135
function runTests(args)
print("running tests")
clearGrid(args.grid1)
args.grid1.children[1].values.x = 1
sendGrid(args.grid1)
-- Expect only the first button to be pressed
-- 0b1111110 = 126
-- 0b11 = 3
-- 0b11111 = 31
assertSent(126,3,31)
clearGrid(args.grid1)
sendGrid(args.grid1)
-- Expect no buttons to be pressed
-- 0b1111111 = 127
-- 0b11 = 3
-- 0b11111 = 31
assertSent(127,3,31)
clearGrid(args.grid1)
args.grid1.children[14].values.x = 1
sendGrid(args.grid1)
-- Expect only the last synth button to be pressed
-- 0b1111111 = 127
-- 0b11 = 3
-- 0b01111 = 15
assertSent(127,3,15)
advanceClock(96)
assert(position == 0, "position == "..position)
advanceClock(0)
assert(position == 0, "position == "..position)
advanceClock(97)
assert(position == 1, "position == "..position)
advanceClock(96)
assert(position == 1, "position == "..position)
advanceClock()
assert(position == 2, "position == "..position)
resetClock()
assert(position == 0, "position == "..position)
-- it sends the grid after one bar
clearGrid(args.grid1)
args.grid1.children[1].values.x = 1
queueGrid({ grid = args.grid1, when = 96 })
advanceClock(96)
assertSent(126,3,31)
-- it sends the grid repeatedly for every clock pulse until we tell it to stop
clearGrid(args.grid1)
args.grid1.children[1].values.x = 1
startPushGrid({ grid = args.grid1 })
advanceClock()
assertSent(126,3,31)
sendMuteNRPN(127,3,31)
assertSent(127,3,31)
advanceClock()
assertSent(126,3,31)
endPushGrid()
sendMuteNRPN(127,3,31)
assertSent(127,3,31)
advanceClock()
assertSent(127,3,31)
resetClock()
-- detects control change channel 1
assert(isControlChange({ MIDIMessageType.CONTROLCHANGE, 1, 102 }) == true, "MIDIMessageType.CONTROLCHANGE on channel 1 not detected as control change")
assert(isControlChange({ MIDIMessageType.CONTROLCHANGE+1, 1, 106 }) == true, "MIDIMessageType.CONTROLCHANGE on channel 2 not detected as control change")
assert(not isControlChange({ MIDIMessageType.CONTROLCHANGE+100, 1, 106 }) == true, "MIDIMessageType.CONTROLCHANGE on invalid channel detected as control change")
assert(not isControlChange({ MIDIMessageType.NOTE_ON, 12, 88 }), "MIDIMessageType.NOTE_ON detected as MIDIMessageType.CONTROLCHANGE")
-- can save/replay last value of control changes
stashControlChange({ MIDIMessageType.CONTROLCHANGE, 1, 102 })
assert(peekControlChangeStash({ MIDIMessageType.CONTROLCHANGE, 1 }) == 102)
stashControlChange({ MIDIMessageType.CONTROLCHANGE, 1, 127 })
assert(peekControlChangeStash({ MIDIMessageType.CONTROLCHANGE, 1 }) == 127)
stashControlChange({ MIDIMessageType.CONTROLCHANGE+2, 1, 1 })
assert(peekControlChangeStash({ MIDIMessageType.CONTROLCHANGE+2, 1 }) == 1)
clearControlChangeStash()
assert(peekControlChangeStash({ MIDIMessageType.CONTROLCHANGE+2, 1 }) == nil)
clearControlChangeStash()
assert(equals(peekControlChangeStash(), {}))
clearControlChangeStash()
stashControlChange({ MIDIMessageType.CONTROLCHANGE, 1, 102 })
assert(equals(peekControlChangeStash(), {
[MIDIMessageType.CONTROLCHANGE] = {
[1] = 102
}
}), "oopsy")
assert(equals(
sequenceFromControlChangeStash({
[MIDIMessageType.CONTROLCHANGE] = {
[1] = 102
}
}),
{
{ MIDIMessageType.CONTROLCHANGE, 1, 102 }
}
))
assert(equals(
sequenceFromControlChangeStash({
[MIDIMessageType.CONTROLCHANGE] = {
[1] = 102
},
[MIDIMessageType.CONTROLCHANGE+1] = {
[1] = 102
}
}),
{
{ MIDIMessageType.CONTROLCHANGE, 1, 102 },
{ MIDIMessageType.CONTROLCHANGE+1, 1, 102 }
}
))
assert(equals(
sequenceFromControlChangeStash({
[MIDIMessageType.CONTROLCHANGE] = {
[1] = 102,
[2] = 100
},
[MIDIMessageType.CONTROLCHANGE+1] = {
[1] = 102
}
}),
{
{ MIDIMessageType.CONTROLCHANGE, 1, 102 },
{ MIDIMessageType.CONTROLCHANGE, 2, 100 },
{ MIDIMessageType.CONTROLCHANGE+1, 1, 102 }
}
))
print("All tests passed!")
end