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:
- ``ON time pitch volume:'' play a note at the given pitch and volume after
time units of time have passed since the last event.
- ``OFF time pitch:'' turn off a note of the given pitch after
time units of time have passed since the last event.
- ``DAMPER time DOWN|UP:'' create a pedal-down or pedal-up event
for the dampler pedal after time units of time have passed since the last event.
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:
- Two-Repeat-MEF.txt,
Two-Repeat.mid, two notes, played one after another.
- C-Major-Scale-MEF.txt,
C-Major-Scale.mid:
A C major scale, where each note is played for 1/2 a second,
and each successive note is played right after the previous note has stopped.
- C-Major-Scale-Damper-MEF.txt,
C-Major-Scale-Damper.mid:
The same C major scale as above, only now the damper pedal is held down thoughout.
- C-Major-Scale-Overlap-MEF.txt,
C-Major-Scale-Overlap.mid:
A C major scale,
and each successive note is played a half a second after the previous note, but each
note is held for a second. Thus, the scale sounds a little blurry.
- Repeating-Louder-MEF.txt,
Repeating-Louder.mid:
Middle C, repeating every 1/10th of a second, getting louder at each repetition.
And below are some more complex piano pieces:
- Chopin-Black-Key-MEF.txt,
Chopin-Black-Key.mid: Chopin's "Black Key" Etude, Opus 10, #5.
- Chopin-Military-Polonaise-Beginning-MEF.txt,
Chopin-Military-Polonaise-Beginning.mid: The
beginning of Chopin's "Military" Polonaise, Opus 40, #1.
- Gershwin-RIB-MEF.txt,
Gershwin-RIB.mid: Gershwin's Rhapsody in Blue, played by the Composer on
a Duo-Art Piano Roll, and then converted to MIDI.
- Rachmaninoff-Elegy-MEF.txt,
Rachmaninoff-Elegy.mid: Rachmaninoff's Elegy, Opus 3, #1.
- Scriabin-Etude-Beginning-MEF.txt,
Scriabin-Etude-Beginning.mid: Beginning of Scriabin's Etude, Opus 8, #10.
- bach_565-MEF.txt,
bach_565.mid: Bach's D minor Toccata (maybe and Fugue -- I haven't listened that far),
BWV 565.
- Coltrane_Mr_PC-MEF.txt,
Coltrane.mid: Melody from Mr. PC, by John Coltrane (from the
album Giant Steps). Thanks to Forrest Sable for sending me that one (CS302, 2014).
Converting CS302-Midi-Event-Files into MIDI and vice versa
I have two programs that turn Midi Event Files into MIDI:
- mef2jmid outputfile takes a CS302-Midi-Event-File on standard input, and turns
it into an intermediate format called JMID. This is a text format that is
much closer to MIDI than our event files.
- jmid2mid outputfile takes a JMID file on standard input and turns
it into a MIDI file on outputfile. You should be able to play the MIDI
file on your web browser, or using Quicktime.
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.