Sorry, I'm not at all clear what you're trying to to do. Even less, why?
A midi file has a VERY specific structure, you can download the detailed spec from this site. As long as you follow the rules for the overall structure, then you CAN create a file manually as you're hinting at, even if the result is musical nonsense.
If you can work in DOS I have a couple of programms that might help you. DECODE and ENCODE. DECODE takes a midi file, and converts it into a .TXT file that you can edit and manipulate as txt, adding/removing parts as you like,
** As long as you honour the overall file/data structure **
Then, you use ENCODE to write the txt back into a midi file.
Just to hint at one bit of what you need, a midi 'event' should always have some timing data, followed by a byte which defines what sort of data this is (i.e. note on, note off, what channel, controller, etc), then a note number (frequency ?) or a controller number, then for a note say a 'velocity (i.e. loudness).
What data would your input be providing?
Geoff