Now I need to write the notes to a file, and determine when sessions start and end. This is pretty easy - I just see if any notes have been played in two minutes. If none, it's the end of a session and I can flush to disk. PyGame.midi input events are arrays with two values: another data array, and a timestamp. I normalise the timestamps by subtracting the first timestamp from each subsequent one. The data array is: status, data1, data2, data3. For a note on, this is 144, pitch, velocity, channel. For a note off, my piano is sending 144, pitch, 0, channel. MIDIUtil looked promising for saving this, but it handles the low level note-on/note-off business - data I already have, so I'd have to do complicated stuff to reverse that, pass it to the library which would then undo it. Something simpler is needed: mxm's midi writer .