File Specification: CS302 Midi Event File

The CS302 Midi Event File starts with the word "CS302-Midi-Event-File". After that, the file should contain events, specified by keywords and values. Keywords and values are words separated by whitespace. There is no concept of a line of text -- the input is composed of simple words (this makes it easier to read input in C++).

The following are the events that may be specified:

Time units are integers, and represent 1/480 of a second. Zero is a fine time unit. Negative time units are not allowed.

Pitches are specified by integers between 0 and 127. Middle C is 60.

Volumes are integers between 1 (soft) and 127 (loud).

When the damper pedal is down, then, if a note is playing and turned off, it does not get turned off, but remains playing until the damper pedal is up (I'll give an example).


Some Examples

The first example is a simple file that plays a C-major chord for one second -- C-Major-MEF.txt. Here's the MIDI file: C-Major.mid.

CS302-Midi-Event-File

ON 0 60 64
ON 0 64 64
ON 0 67 64

OFF 480 60
OFF   0 64
OFF   0 67

The next example shows how the damper pedal keeps notes playing longer. The file is C-Major-Damper-MEF.txt and the MIDI file is C-Major-Damper.mid. The damper pedal is set to DOWN as the notes start playing, and is set to UP two seconds later. Thus, even though the notes are turned off one second after they are turned on, they keep playing until the damper pedal is set to UP.

CS302-Midi-Event-File

ON 0 60 64
ON 0 64 64
ON 0 67 64

DAMPER 0 DOWN

OFF 480 60
OFF   0 64
OFF   0 67

DAMPER 480 UP

Other simple examples:

And below are some more complex piano pieces:


Converting CS302-Midi-Event-Files into MIDI and vice versa

I have two programs that turn Midi Event Files into MIDI:

Converting MIDI into a CS302-Midi-Event-File is more of a black art. The first step is to use mid2jmid outputfile, which takes a MIDI file on standard input and turns it into a JMID file on outputfile. At that point, you should look at the first few lines. Here are two examples:

UNIX> head tmp.txt
JMID FILE
Format: 1  ntracks: 1  Division: 480
TRACK 0
    962 NOTE-ON  90  39  88
      0 NOTE-ON  90  27  83
    346 CONTROL  B0  64 127
     38 NOTE-ON  90  46  60
    308 NOTE-ON  90  54  66
    288 NOTE-ON  90  63  54
    336 NOTE-ON  90  70  55
UNIX> mid2jmid < bach_565.mid tmp.txt
UNIX> head tmp.txt
JMID FILE
Format: 1  ntracks: 10  Division: 240
TRACK 0
      0 META       FF 7F 3 00 00 41
      0 META       FF 58 4 04 02 18 08
      0 META       FF 51 3 07 A1 20
      0 META       FF 2F 0
TRACK 1
      0 META       FF 01 6 43 68 75 72 63 68
      0 PROGRM   C0  19
UNIX> 
In the first case, the MIDI file is simple -- one track. In the second, it's not, with 10 tracks. Basically, what you should do is go into vi and delete all the tracks but the one that you want. Then, run jmid2mef outputfile on it. That strips out all the events but the NOTE and DAMPER events, and converts the result into a Midi Event File:
UNIX> sed -e '1930,$d' -e 3,7d tmp.txt > bach_565-JMID.txt
UNIX> jmid2mef < bach_565-JMID.txt bach_565-MEF.txt
UNIX> mef2jmid < bach_565-MEF.txt tmp-jmid.txt
UNIX> jmid2mid < tmp-jmid.txt bach-stripped.mid
The result, in bach-stripped.mid has the Bach piece, but with everything but the ON/OFF/DAMPER events stripped out.

You may have to do a little more editing at times, because sometimes MIDI files are weird.