Read Me

Algorithmic composers strive to make music with their computers, but computers make naught but numbers. Seeking a way to convert their binary masterworks into audible reality, algorhitmic composers often turn to the MIDI file format for help. Its straightforward numeric representation of pitch combined with its flexibility is appealing, but the file format is abstruse. After spending hours reading about variable length delta-times, header chunks and big-endian byte order, many perfectly good composers decide that dealing with such Delphic nonsense only detracts from the music itself. Their algorithmic music, they say, would only be misunderstood if heard by the crass public anyhow, so why bother?

MKMIDIFile is an Objective-C class that attempts to simplify this vexing problem. It reduces all of the counterintuitive data formats of the MIDI file specification to musician-friendly formats. An algorithmic composer using MKMIDIFile.h need only instatntiate a midi file, add some tracks, turn some notes on and off (with durations expressed as a fractions of a quarter note), and save the file. Inserting tempo changes, key changes, text, and other events is just as simple. For flexibility, MKMIDIFile also has a method that allows the insertion of otherwise unsupported MIDI messages as byte arrays.

MKMIDIFile is also capable of reading and parsing .mid files saved on disk. the +midiFileFromFile method parses a .mid file into individual MKMIDIEvents. It is then easy to iterate over the events and extract useful information.

Because MKMIDIFile is written in Objctive-C, it can easily be integrated into programs written for OSX and iPhone OS, but because it does not rely on Cocoa.h (or any other system-dependent library), it can be used in just about any Objective-C project. Furthermore, because Objective-C is a superset of ANSI C, MKMIDIFile can easily be integrated to existing ANSI C projects by merely changing the name of your code from MyGreatCode.c to MyGreatCode.m.

Incase you can't always remember that MIDI channel 2 is represented by the number 1, middle C is 0x3C (hexidecimal), or that 0x0A selects the most significant bit of the pan mode-change thingy, then you can cheat by using MKMIDIStatusBytes.h. This file reduces large sections of the MIDI format to human-readable constants, like CHANNEL_2, MIDI_PITCH_MIDDLE_C, PAN_MSB (as if you will ever need this), and so forth.

These files, as well as the other files needed to make them operate (MKMIDIEventList, MKMIDIEvent and MKArray), along with a simple demonstrative main.m program, are available free of charge and free of copyright or other annoying lisence in the 'downloads' section of the 'MIDI' menu above. Although this code works beautifully on my 32 bit, little-endian UNIX based macbook when compiled with gcc, is not guarenteed to work no your machine. Infact, it will probably crash your computer irreparably. The Header files can be accesed for reference via the above menu. Functionality of the class may change at any time, so if something does not work, make sure you have the most current version of the code. To compile the example main program with gcc, download all of the files: along with one of the sample main() programs in the menu above.

Put them all in a directory together with nothing else in it, and execute the following:

I am always willing to help anyone, beginner or veteran, with music and programming related problems, and welcome questions, comments, advice, feedback, rants, wish-lists, and twenty dollar bills. Feel free to email me any of these using the link above.





:/ root#