]> gitweb.factorcode.org Git - factor.git/blob - extra/midi/midi-tests.factor
3e19cf0da4fa890db783a745ea9153cb87a8a853
[factor.git] / extra / midi / midi-tests.factor
1 USING: io.encodings.binary io.streams.byte-array midi
2 midi.private sequences tools.test ;
3 IN: midi.tests
4
5 ! variable-width numbers
6 {
7     {
8         0x00
9         0x40
10         0x7f
11         0x80
12         0x2000
13         0x3fff
14         0x4000
15         0x100000
16         0x1fffff
17         0x200000
18         0x08000000
19         0x0fffffff
20     }
21 } [
22     {
23         B{ 0x00 }
24         B{ 0x40 }
25         B{ 0x7f }
26         B{ 0x81 0x00 }
27         B{ 0xC0 0x00 }
28         B{ 0xff 0x7f }
29         B{ 0x81 0x80 0x00 }
30         B{ 0xC0 0x80 0x00 }
31         B{ 0xff 0xff 0x7f }
32         B{ 0x81 0x80 0x80 0x00 }
33         B{ 0xC0 0x80 0x80 0x00 }
34         B{ 0xff 0xff 0xff 0x7f }
35     } [ binary [ read-number ] with-byte-reader ] map
36 ] unit-test
37
38 {
39     {
40         B{ 0x00 }
41         B{ 0x40 }
42         B{ 0x7f }
43         B{ 0x81 0x00 }
44         B{ 0xC0 0x00 }
45         B{ 0xff 0x7f }
46         B{ 0x81 0x80 0x00 }
47         B{ 0xC0 0x80 0x00 }
48         B{ 0xff 0xff 0x7f }
49         B{ 0x81 0x80 0x80 0x00 }
50         B{ 0xC0 0x80 0x80 0x00 }
51         B{ 0xff 0xff 0xff 0x7f }
52     }
53 } [
54     {
55         0x00
56         0x40
57         0x7f
58         0x80
59         0x2000
60         0x3fff
61         0x4000
62         0x100000
63         0x1fffff
64         0x200000
65         0x08000000
66         0x0fffffff
67     } [ binary [ write-number ] with-byte-writer ] map
68 ] unit-test
69
70 ! format: 0
71 {
72     T{ midi
73         { header
74             T{ midi-header
75                 { format 0 }
76                 { #chunks 1 }
77                 { division 96 }
78             }
79         }
80         { chunks
81             {
82                 T{ midi-track
83                     { events
84                         {
85                             T{ meta-event
86                                 { delta 0 }
87                                 { name "time-signature" }
88                                 { value
89                                     H{
90                                         { "clocks-per-tick" 24 }
91                                         { "denominator" 4 }
92                                         { "numerator" 4 }
93                                         {
94                                             "notated-32nd-notes-per-beat"
95                                             8
96                                         }
97                                     }
98                                 }
99                             }
100                             T{ meta-event
101                                 { delta 0 }
102                                 { name "set-tempo" }
103                                 { value 500000 }
104                             }
105                             T{ midi-event
106                                 { delta 0 }
107                                 { name "program-change" }
108                                 { value
109                                     H{
110                                         { "program" 5 }
111                                         { "channel" 0 }
112                                     }
113                                 }
114                             }
115                             T{ midi-event
116                                 { delta 0 }
117                                 { name "program-change" }
118                                 { value
119                                     H{
120                                         { "program" 46 }
121                                         { "channel" 1 }
122                                     }
123                                 }
124                             }
125                             T{ midi-event
126                                 { delta 0 }
127                                 { name "program-change" }
128                                 { value
129                                     H{
130                                         { "program" 70 }
131                                         { "channel" 2 }
132                                     }
133                                 }
134                             }
135                             T{ midi-event
136                                 { delta 0 }
137                                 { name "note-on" }
138                                 { value
139                                     H{
140                                         { "note" 48 }
141                                         { "velocity" 96 }
142                                         { "channel" 2 }
143                                     }
144                                 }
145                             }
146                             T{ midi-event
147                                 { delta 0 }
148                                 { name "note-on" }
149                                 { value
150                                     H{
151                                         { "note" 60 }
152                                         { "velocity" 96 }
153                                         { "channel" 2 }
154                                     }
155                                 }
156                             }
157                             T{ midi-event
158                                 { delta 96 }
159                                 { name "note-on" }
160                                 { value
161                                     H{
162                                         { "note" 67 }
163                                         { "velocity" 64 }
164                                         { "channel" 1 }
165                                     }
166                                 }
167                             }
168                             T{ midi-event
169                                 { delta 96 }
170                                 { name "note-on" }
171                                 { value
172                                     H{
173                                         { "note" 76 }
174                                         { "velocity" 32 }
175                                         { "channel" 0 }
176                                     }
177                                 }
178                             }
179                             T{ midi-event
180                                 { delta 192 }
181                                 { name "note-off" }
182                                 { value
183                                     H{
184                                         { "note" 48 }
185                                         { "velocity" 64 }
186                                         { "channel" 2 }
187                                     }
188                                 }
189                             }
190                             T{ midi-event
191                                 { delta 0 }
192                                 { name "note-off" }
193                                 { value
194                                     H{
195                                         { "note" 60 }
196                                         { "velocity" 64 }
197                                         { "channel" 2 }
198                                     }
199                                 }
200                             }
201                             T{ midi-event
202                                 { delta 0 }
203                                 { name "note-off" }
204                                 { value
205                                     H{
206                                         { "note" 67 }
207                                         { "velocity" 64 }
208                                         { "channel" 1 }
209                                     }
210                                 }
211                             }
212                             T{ midi-event
213                                 { delta 0 }
214                                 { name "note-off" }
215                                 { value
216                                     H{
217                                         { "note" 76 }
218                                         { "velocity" 64 }
219                                         { "channel" 0 }
220                                     }
221                                 }
222                             }
223                             T{ meta-event
224                                 { delta 0 }
225                                 { name "end-of-track" }
226                                 { value t }
227                             }
228                         }
229                     }
230                 }
231             }
232         }
233     }
234 } [
235     B{
236         0x4D 0x54 0x68 0x64
237             0x00 0x00 0x00 0x06
238             0x00 0x00
239             0x00 0x01
240             0x00 0x60
241
242         0x4D 0x54 0x72 0x6B
243             0x00 0x00 0x00 0x3B
244             0x00 0xFF 0x58 0x04 0x04 0x02 0x18 0x08
245             0x00 0xFF 0x51 0x03 0x07 0xA1 0x20
246             0x00 0xC0 0x05
247             0x00 0xC1 0x2E
248             0x00 0xC2 0x46
249             0x00 0x92 0x30 0x60
250             0x00 0x3C 0x60
251             0x60 0x91 0x43 0x40
252             0x60 0x90 0x4C 0x20
253             0x81 0x40 0x82 0x30 0x40
254             0x00 0x3C 0x40
255             0x00 0x81 0x43 0x40
256             0x00 0x80 0x4C 0x40
257             0x00 0xFF 0x2F 0x00
258     } >midi
259 ] unit-test
260
261 ! format: 1
262 {
263     T{ midi
264         { header
265             T{ midi-header
266                 { format 1 }
267                 { #chunks 4 }
268                 { division 96 }
269             }
270         }
271         { chunks
272             {
273                 T{ midi-track
274                     { events
275                         {
276                             T{ meta-event
277                                 { delta 0 }
278                                 { name "time-signature" }
279                                 { value
280                                     H{
281                                         { "clocks-per-tick" 24 }
282                                         { "denominator" 4 }
283                                         { "numerator" 4 }
284                                         {
285                                             "notated-32nd-notes-per-beat"
286                                             8
287                                         }
288                                     }
289                                 }
290                             }
291                             T{ meta-event
292                                 { delta 0 }
293                                 { name "set-tempo" }
294                                 { value 500000 }
295                             }
296                             T{ meta-event
297                                 { delta 384 }
298                                 { name "end-of-track" }
299                                 { value t }
300                             }
301                         }
302                     }
303                 }
304                 T{ midi-track
305                     { events
306                         {
307                             T{ midi-event
308                                 { delta 0 }
309                                 { name "program-change" }
310                                 { value
311                                     H{
312                                         { "program" 5 }
313                                         { "channel" 0 }
314                                     }
315                                 }
316                             }
317                             T{ midi-event
318                                 { delta 192 }
319                                 { name "note-on" }
320                                 { value
321                                     H{
322                                         { "note" 76 }
323                                         { "velocity" 32 }
324                                         { "channel" 0 }
325                                     }
326                                 }
327                             }
328                             T{ midi-event
329                                 { delta 192 }
330                                 { name "note-on" }
331                                 { value
332                                     H{
333                                         { "note" 76 }
334                                         { "velocity" 0 }
335                                         { "channel" 0 }
336                                     }
337                                 }
338                             }
339                             T{ meta-event
340                                 { delta 0 }
341                                 { name "end-of-track" }
342                                 { value t }
343                             }
344                         }
345                     }
346                 }
347                 T{ midi-track
348                     { events
349                         {
350                             T{ midi-event
351                                 { delta 0 }
352                                 { name "program-change" }
353                                 { value
354                                     H{
355                                         { "program" 46 }
356                                         { "channel" 1 }
357                                     }
358                                 }
359                             }
360                             T{ midi-event
361                                 { delta 96 }
362                                 { name "note-on" }
363                                 { value
364                                     H{
365                                         { "note" 67 }
366                                         { "velocity" 64 }
367                                         { "channel" 1 }
368                                     }
369                                 }
370                             }
371                             T{ midi-event
372                                 { delta 288 }
373                                 { name "note-on" }
374                                 { value
375                                     H{
376                                         { "note" 67 }
377                                         { "velocity" 0 }
378                                         { "channel" 1 }
379                                     }
380                                 }
381                             }
382                             T{ meta-event
383                                 { delta 0 }
384                                 { name "end-of-track" }
385                                 { value t }
386                             }
387                         }
388                     }
389                 }
390                 T{ midi-track
391                     { events
392                         {
393                             T{ midi-event
394                                 { delta 0 }
395                                 { name "program-change" }
396                                 { value
397                                     H{
398                                         { "program" 70 }
399                                         { "channel" 2 }
400                                     }
401                                 }
402                             }
403                             T{ midi-event
404                                 { delta 0 }
405                                 { name "note-on" }
406                                 { value
407                                     H{
408                                         { "note" 48 }
409                                         { "velocity" 96 }
410                                         { "channel" 2 }
411                                     }
412                                 }
413                             }
414                             T{ midi-event
415                                 { delta 0 }
416                                 { name "note-on" }
417                                 { value
418                                     H{
419                                         { "note" 60 }
420                                         { "velocity" 96 }
421                                         { "channel" 2 }
422                                     }
423                                 }
424                             }
425                             T{ midi-event
426                                 { delta 384 }
427                                 { name "note-on" }
428                                 { value
429                                     H{
430                                         { "note" 48 }
431                                         { "velocity" 0 }
432                                         { "channel" 2 }
433                                     }
434                                 }
435                             }
436                             T{ midi-event
437                                 { delta 0 }
438                                 { name "note-on" }
439                                 { value
440                                     H{
441                                         { "note" 60 }
442                                         { "velocity" 0 }
443                                         { "channel" 2 }
444                                     }
445                                 }
446                             }
447                             T{ meta-event
448                                 { delta 0 }
449                                 { name "end-of-track" }
450                                 { value t }
451                             }
452                         }
453                     }
454                 }
455             }
456         }
457     }
458 } [
459     B{
460         0x4D 0x54 0x68 0x64
461             0x00 0x00 0x00 0x06
462             0x00 0x01
463             0x00 0x04
464             0x00 0x60
465
466         0x4D 0x54 0x72 0x6B
467             0x00 0x00 0x00 0x14
468             0x00 0xFF 0x58 0x04 0x04 0x02 0x18 0x08
469             0x00 0xFF 0x51 0x03 0x07 0xA1 0x20
470             0x83 0x00 0xFF 0x2F 0x00
471
472         0x4D 0x54 0x72 0x6B
473             0x00 0x00 0x00 0x10
474             0x00 0xC0 0x05
475             0x81 0x40 0x90 0x4C 0x20
476             0x81 0x40 0x4C 0x00
477             0x00 0xFF 0x2F 0x00
478
479         0x4D 0x54 0x72 0x6B
480             0x00 0x00 0x00 0x0F
481             0x00 0xC1 0x2E
482             0x60 0x91 0x43 0x40
483             0x82 0x20 0x43 0x00
484             0x00 0xFF 0x2F 0x00
485
486         0x4D 0x54 0x72 0x6B
487             0x00 0x00 0x00 0x15
488             0x00 0xC2 0x46
489             0x00 0x92 0x30 0x60
490             0x00 0x3C 0x60
491             0x83 0x00 0x30 0x00
492             0x00 0x3C 0x00
493             0x00 0xFF 0x2F 0x00
494     } >midi
495 ] unit-test