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