Record and quantize Midi notes

My project Sonic Pi 3 Record/Player using TouchOSC worked along similar lines, without the quantisation. Also I used osc messages to send the note info rather than midi.
The way that I calculated the play times for the notes may be of interest.
I recorded note input in realtime, with an audible metronome to assist timing accuracy. I could then replay it a the same tempo or faster. I could also play a further part at the same time to give some harmony. I also recorded some envelope and volume information as well.

It would be interesting to play around with something similar using external midi input. It would be great to be able to get back time state info since it is already there, rather than having to calculate timings, but this would require some digging around in the SP code to make the info available and usable.