The standard MIDI file format is like a strange beast. Overall, it is so that you can't resist. Of course, how do you see it irrelevant, but use a sufficiently descriptor to describe a piece of music and make it reproduced, not very little work. However, although it is complicated, the structure of the MIDI file format is still very straightforward. Here I have to give up some things, because after all, I am not MIDI is not MIDI file expert! Recently, I prepared a Gravis ultrasonic sound card for my PC. After listening to several MIDI files (.mid), I thought: "Oh, if I can make my own MIDI (.mid) file, how is it? ! "Well, after a few hours of annoying, I found that those don't have no value. However, I will not let a lengthy file format can stop (in addition, I told my wife, the computer is not very difficult, and I hate as a false gentle). So, if you find anything in this article, please let me know, I will modify it. At the same time, the scope of this document does not provide all types of MIDI commands and any possible file configuration! This basic guide will enable readers to make MIDI types (in moderate time investment). 1. Overview: A MIDI file is basically consisting of two parts, headers and track blocks. The second section describes the head block, and the third quarter tells the track block. A MIDI file has a header to describe the format of the file, and many track blocks. A track can imagine that you can assign a track for some kind of sound, a score, a musical instrument or anything you need. 2. Head: Head block appears in the beginning of the file, there are three ways to describe files. The head is always like this: 4D 54 68 64 00 00 00 06 FF FF NN NN DD DD The first 4 bytes are equivalent to the ASCII code MTHD, then 4 bytes after MTHD are the size of the head . It will always be 00 00 00 00 06 because the current header information will always be 6 bytes. FF FF is the format of the document, there are 3 formats: Synchronous multi-track means that all tracks are vertical synchronization, or other wording begins at the same time, and can express a different part of a song. The asynchronous multi-track is not necessary to start at the same time, and can be completely disagreeable. nn is the number of orbits in the MIDI file. DD DD is the number of rhythm of each 4-cenon DELTA-TIME (this will be described in detail later). 3. Orbital block: The remaining file parts after the header is the track block. Each track contains a head and can contain many MIDI commands you want. The track head and the file head and its similarity: 4D 54 72 6B xx xx xx xx The length of the orbit of bytes (excluding the track head). Under Head is the MIDI event, these events are the same as data that can be accepted and transmitted with accumulated MIDI synthesizer ports. A MIDI event is preceded in a delta-time. A delta-time is the number of rhythm after the MIDI event is executed, and the number of rhythm of each quarter note has previously defined in the header of the file. This delta-time is a variable length encoded value.
Although this format is confusing, it allows you to use a large number of numerals as needed, which will not waste some bytes due to the numerical case of small demand! The value is converted to a 7-bit byte, and in addition to the last byte, the most meaningful one of each byte is 1, in addition to the maximum active bit. This allows a value to be read by one byte, if you find the highest valid bit is 0, this is the last bit of this value (smaller than the meaning). According to MIDI, all Delta-Time has up to 4 bytes. Delta-Time is the MIDI event, each MIDI event (except for the running event) with a command byte of the highest valid bit, always 1 (value will be> 128). The list of most commands is in Appendix A. Each command has different parameters and lengths, but the next data will be the highest valid bit zero (value will <128). There is an exception here that Meta-Event, the highest effective bit can be 1. However, Meta-Events requires a long parameter to distinguish. minor mistakes can cause confusion that is running mode, which is where the current MIDI command is ignored, and the final version of the MIDI command is assumed. This means that if the command is included, the MIDI event is converted by Delta-Time and the parameter. 4. Summary: If this note is just making problems more confusing, then the examples provided below may help clarify the problem! At the same time, two utilities and a diagram file are included in this document: Dec.exe - This public program converts binary files (such as .mid) into a tag boundary that corresponds to each byte of decimal. Text file. ec.exe - This public program converts each byte of the decimal text file with the tag boundary to binary files. Midinote.ps - this is a note page for the keyboard and the five-tarant spectrum. The channel number of the command, here there are 16 MIDI channels 8 MIDI commands (command NYBBLE must have the highest valid bit of 1). In the following table, x represents the MIDI channel number. All notes are data bytes <128 (the highest valid bit is 0).
Hexadecimal binary data description 8X 1000XXXX NN VV note closed (release keyboard) nn = audio symbol vv = speed 9X 1001xxxx NN VV note open (keyboard) NN = 音 符 VV = speed AX 1010XXXX NN VV Touch the keyboard after NN = Audio symbol vv = speed BX 1011xxxx CC vv switch control CC = control number vv = new value CX 1100XXXX PP change program (pieces) PP = new program number DX 1101XXXX CC contact after passage CCC = Pipe number EX 1110XXXX BB TT changes mutual bite and gears (2000h indicates the default or no change) (what does not understand :) BB = value low 7-bit (Least Sig) TT = value of 7 digits (MOST SIG) The following table is a list of Meta-events without channels. Their format is: f Number (NN), current data (DD) hex binary data description 00 00000000 NN SSSS setting track number NN = 02 (serial number of two bytes) SSSS = serial number 01 00000001 NN tt .. All text events you need nn = text length in bytes TT = text character 02 00000010 nn tt .. The same text, but used for copyright information NN TT = same text event 03 00000011 NN Tt .. sequence or track name NN TT = the same text event 04 00000100 nn tt .. Track Musical Name NN TT = That Event 05 00000101 NN TT .. lyrics NN TT = That Event 06 00000110 NN Tt .. tag NN TT = The same text event 07 00000111 nn tt .. floating point note NN TT =
Tong Text Event 2F 00101111 00 This event must be at the end of each track 51 01010001 03 TTTTT set beat TTTTTT = microsecond / quadrite note 58 01011000 04 NN DD CC BB beam marker NN = Termary mark molecule DD = Termary marker 2 = quarter 3 = 8 shots, etc .. CC = Stroeat BB = No. 32 of a quarter note Number 59 01011001 02 SF Mi Tone symbol SF = upgrade / lowered ( -7 = 7 decline, 0 = reference C adjustment, 7 = 7 promotion) MI = high-key / minor (0 = high-key, 1 = small adjustment) 7F 0111111 XX DD .. Sequencer XX = Sending bytes DD = Data The following table lists the system messages that control the entire system. There is no number of MIDI channels (these generally applied only to MIDI keyboards.) Hexadecimal binary data Description F8 11111000 Synchronous Timer FA 11111010 Starting the current queue FB 11111011 Continued from the stopped place FC 1111100 Stop one The following table lists the command tags corresponding to the note.
Octagon || 音 符 # || || C | C # | D | D # | e | f | f # | g | g # | a | a # | b --------------- -------------------------------------------------- ------------ 0 || 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 1 || 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 || 48 | 49 | 50 | 51 | 52 | 56 | 57 | 58 | 59 5 || 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 6 || 72 | 73 | 74 | 75 | 76 | 80 | 81 | 82 | 83 7 || 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | || 96 | 97 | 98 | 99 || | 101 | 102 | 106 | 107 9 || 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 10 || 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | References: "MIDI Systems and Control" Francis Rumsey 1990 Focal Press "MIDI and Sound Book for the Atari ST" Bernd Enders and Wolfgang Klem 1989 M & T Publishing, Inc.MIDI file specs and general MIDI specs were Also Obtained by sending e-mail to listserv@auvm.american.edu with the phrase get midispec package in the message. ------------------------- ----- Dec.cpp ---------------------------------- / * file dec.cppby Dustin Caldwell (Dustin@gse.utah.edu) * / # include
NULL) / * Open file to read * / {printf ("cannot open file% s / n", _ argv [1]); helpdoc (); exit (-1);} c = 0; ch = fgetc (fp) WHILE (! Feof (fp)) / * loop for whole file * / {printf ("% u / t", ch); / * Print Every byte's decimal equiv. * / C ; if (c> 8) / * Print 8 Numbers to a line * / {c = 0; Printf ("/ n");} CH = fgetc (fp);} fclose (fp); / * close up * /} void helpdoc () / * Print Help Message * / {Printf ("/ n binary file decoder / n / n"); Printf ("/ n syntax: dec binary_file_name / n / n"); Printf ("by Dustin Caldwell (Dustin@gse.utah.edu) / N / N "); Printf (" This Is A Filter Program That Reads A Binary File / N "); Printf (" and Prints The Decimal Equiv) Alent of Each Byte / N "); Printf (" Tab-Separated. this is mostly useful when piped / n "); Printf (" INTO ANOTHER File to Be Edited Manually. Eg: / N / N "); Printf (" " C: /> DEC SONATA3.MID> SON3.TXT / N / N "); Printf (" This Will Create A File Called Son3.txt Which CAN / N "); Printf (" Be Edited with any Ascii Editor). / N / N "); Printf (" (Rec.exe May Also Be useful, as it reencodes the / n "); Printf (" ASCII TEXT FILE) ./ n / n "); Printf (" Have Fun !! / N ");
} -------------------------- - Rec.cpp ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------- / * file rec.cpp by Dustin Caldwell (Dustin@gse.utah.edu) * / # include