Very neat problem. I've been working a lot lately with base64-encoded images and have regularly been using http://www.greywyvern.com/code/php/binary2base64 for image encoding. I just tried converting a MIDI file and putting the base64 text stream into an HTML and it played just fine in Firefox (which astonished me). Here's the code (with the Base64 stream removed for brevity):
<embed
autostart="true"
loop="false"
volume="100"
hidden="false"
src="data:audio/x-midi;base64,abc...."
></embed>
I'm not sure it's possible to go from a binary image to base64 in JS, but I suspect that going from MIDI might be. It's a start.