Thanks to you all for your help.
I've stripped down Kyle's patch (because I understood it - also I had a little trouble with Frank's patch - Pd couldn't create certain objects).
It does exactly what I need. I'm assuming the size of the file will be limited to available memory, is that right? I shall give it a thorough test tomorrow to see if it holds up.
And thank you, Martin, for pointing me towards the midifile object. I shall take a look at this when I'm in less of a hurry.
Best,
Rwb.