Truthfully MIDI file format isnt all that complicated.
IT IS if you decode it the way everyone tells you too
because they go the hardway around everything. If you keep everything in the form of text it makes it mucho easir to work with and alot more friendly.
MIDI is based on a header chunk and track chunks
the heaer is 4 byte string MThd the next 4 bytes is the length of the header "which will always be 6" 00 00 00 06
notice that some data will be reversed "Big Endien" format BUT WHO CARES it will always be 00 00 00 06 or its not an midi! So no fancey reading functions here. So we read the next 6 bytes:
the next 2 bytes is th MIDI type 00 00 whch will be either 0 1 or 2 "which you can check in text form" 0 is a single track midi 2 is a yncronized multi track midi and 3 is a asyncronised track "meaning they dont nessessarily start and play at the same time". the next 2 bytes is the number of tracks 00 00 This isnt needed cause you can just ceck for an end of file and count the tracks as ou encounter them throughout the file. The last two bytes of the header is the number of DELTA TIME TICKS 00 00 , Ahem Delta time ticks suck! but this number matters...
after the header is your first track and each track at this point adon begin with its very own HEADER 4 bytes big that says MTrk and after that is a 4 bytes that tells you the LENGTH of the track (I havnt found it usefull for anything since each track ends with an exact special cmmand for ending the track. Okay after the trac header is the ACTUAL midi DATA YAY! .......... MWAHAHAHAHA
right away its important to note the first piece of data is a DELTA TIME! yay more of these things.. ALOT OF THEM!
after each MIDI event so foth is a delta time even if its 00 it will still be there. This s the time etween each action "which is important between notes to keep them timed right" this value is also MOST SIGNIFICANT BYTE FIRST!
meaning all but the last piece of this numberwill have a binary value of 1??? ???? the last byte of the delta time will have a binary value of 0??? ???? VOILA!
how do you read this? well since DB DOSE NOT suck! Lee gave us a nic BIN$ function =P clip a nice MSB$=RIGHT$(BIN$(DELTA),8) and check the left
IF LEFT$(MSB$,1)=0 then is last byte of the delta time. else go read the next byte.
simple! after each delta time is a MIDI EVENT there is kinds of midi events from what I seen a MIDI META EVENT
which changes things like tracks and stores text. RUNNING event which plays notes and adjusts things and SYSTEM EVENTS that control a lugged in keybord or the sequencer itself.
I would tell you every command but you only need to get my snippet off the snippet forum to see how they work TOODOLOO
There was a man on the stairs that wasn't there.
He wasn't there agian today I think he's from the CIA.