Complete .mid write() and tests.

The .mid file format works very well with thorough test coverage. We
ensure that a file from the JSB collection may be read and serialized by
the lua.mid library and that the contents of the binary file will be
identical to the source file.