Thanks to peres for working out how it works in the original engine. Also, fix the length of MIDI events so it works properly.