Recording formats for the MidiOutput class


The MidiOutput class can record MIDI data being sent through it into three different types of files.

ascii file description

Each time the output MIDI buffer is flushed, that output data will be written as one line of text. The first number on the line is the time in milliseconds delay from the last lines sending time. Then the MIDI data from the MIDI output buffer is printed separated by spaces.

If the MIDI value is greater than 127 (0xf7) then the value will be printed as a hexadecimal number (preceeded with "0x") since it is a MIDI command, which is easier to read in hexadecimal notation. If you edit an ascii output file, then you can write any numbers either in decimal or hexadecimal form.

Comments can be included in the file by using a semi-colon (;) which will cause all text after the semi-colon to the end of the line to be ignored. Blank lines are also ignored.

Example that plays a middle C for one second and does some other things:

   ; delta time/MIDI output at delta time
   0       0x90  60 127                       ; note on: middle C loud
   0       0xb0   7  64                       ; volume controller
   0       0xef  45  12                       ; pitch wheel
   0       0xf0  12 0xf7                      ; system exclusive
   0       0xf0  10  20  30  40  50 0xf7      ; system exclusive
   1000    0x90  60   0                       ; note off: middle C

binary file description

Delta times are written as four-byte (unsigned) numbers. MIDI data for a particular Delta time are then written as one-byte values. At the end of the delta time line, the byte 0xf8 is written which signals that the next four bytes in the file are the next delta time. All numbers are written most significant byte first.

Example that is equiavlent to the previous ascii format example, bytes written out in hex, and there are no returns or comments in the output file:

   00 00 00 00 90 3c ff f8                    ; note on: middle C loud
   00 00 00 00 b0 07 40 f8                    ; volume controller
   00 00 00 00 ef 2d 12 f8                    ; pitch wheel
   00 00 00 00 f0 12 f7 f8                    ; system exclusive
   00 00 00 00 f0 10 14 1e 28 32 f7 f8        ; system exclusive
   00 00 03 e8 90 3c 00 f8                    ; note off: middle C
The resulting file contains 52 bytes, while the ascii example above contains about 100 bytes without comments

MIDI file description

Delta times written in Variable-Length Values. Will be described more later. Not implemented for now.





Send comments/errors on this page to craig@ccrma.stanford.edu