As you are not asking about playing music using MIDI and only want to create files, you don't even need to use any library. The full description of the MIDI file format is available. See, in particular
http://www.music.mcgill.ca/~ich/classes/mumt306/StandardMIDIfileformat.html[
^],
http://www.cs.cmu.edu/~music/cmsip/readings/Standard-MIDI-file-format-updated.pdf[
^].
Even though you would need to pay the fee to access the official standard document, actual description corresponding to the current MIDI standard 1.1 is available on the Web.
Well, you have the library implementing composing of MIDI files, use the library. You never mentioned what are your problems.
—SA