Midi to Sonic Pi script (Experimental proof of concept)

I now have a working script that will handle changes in tempo during the piece, with the constraints that
a) each part must change tempo at the same time, and
b) the tempo change must occur at the beginning of a note or rest, and not during either.
(Midi can change the tempo during a note or rest, but this is not possible with Sonic Pi)

I have tested it with Bach Brandenburg Concerto no 3 which has 10 separate voices and several tempo changes and a duration of over 10 minutes! It does the conversion from midi file to Sonic Pi file in a fraction of a second.