Standard MIDI file format

xiaoxiao2021-03-06  41

Standard MIDI file format Daistri Kudewell

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, heads 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:

The head block appears in the beginning of the file, there are three ways to describe the file. The head looks 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: 0-monorail 1- multi-regulation, synchronization   2-multi-regular, asynchronous

Monorand, it is obvious that there is only one track. 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 part after the head is the track block. Each track contains a head and can contain many MIDI commands you want. Track heads and file heads and similar:

4D 54 72 6B XX XX XX XX

In line with the head, the first 4 bytes are ASCII, this is MTRK, which is followed by 4 bytes of MTRK, gives the length of the track in bytes (excluding track heads).

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 (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 more confusion, 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 process is a text file that converts binary files (such as .mid) into a tagged boundary that corresponds to each byte in decimal.

    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.

                   

1.MIDI event command

Each command byte has two parts, left Nybble (4 digits) contains the current command, and right Nybble contains the channel number of the command to be executed. There are 16 MIDI channels 8 MIDI commands (command Nybble must be maximum. The bit is 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 close (release keyboard) nn = audio symbol VV = speed

9x 1001xxxx NN VV note open (press keyboard) nn = audio symbol vv = speed

AX 1010XXXX NN VV Touch the keyboard NN = 音 符 VV = speed

BX 1011xxxx CC VV Convert Control CC = Control No. VV = New Value CX 1100XXXX PP Change Program (Pieces) PP = New Server number

DX 1101xxxx CC contact after passage   CC = pipeline number

EX 1110XXXX BB TT changes mutual bite and gears (2000h indicates that default or no change) (what does not understand :) BB = value of 7-bit (Least Sig) TT = value of 7 (MOST SIG)

 The following table is a list of Meta-Events without channels, and their format is:

  inffx xx nn dd

 All meta-events is command (XX), length, or byte (NN) in data, current data (DD)

Hexadecimal binary data description 00 00000000 NN SSSS setting track No. NN = 02 (serial number of two bytes) SSSS = serial number

01 00000001 nn tt .. All text events you need  nn = text length tt = text characters in bytes

02 00000010 NN TT .. The same text, but used for copyright information NN TT = the same text event

03 00000011 nn tt .. sequence or track name NN TT = the same text event

04 00000100 nn Tt .. Track Musical Inn Nn TT = Text Event

05 00000101 nn tt .. lyrics NN TT = the same text event

06 00000110 NN TT .. Tag NN TT = Top Text Event

07 00000111 NN TT .. floating point note NN TT = the same text event

2F 00101111 00 This event must appear at the end of each track

51 01010001 03 TTTTTT Settings TTTTTT = Microsecond / Quarantin

58 01011000 04 NN DD CC BB Terminal NN = Team Number Molecular DD = Termary Item 3 = 8 Shot, etc .. CC = Bebrace Rhythm BB = Two-quarter note marked No. 32 Digital 59 01011001 02 SF Mi Tone Symbol SF = Challenge / Dressance (-7 = 7 Dressance, 0 = Benchmark C Tone, 7 = 7) Mi = High Stress / Small (0 = Motor, 1 = small adjustment)

7f 01111111 xx dd .. Detailed information of the sequencer XX = byte number DD = data

The following table lists the system messages that control the entire system. There is no number of MIDI channels here (these are generally applied to the MIDI keyboard.)

Hexadecimal binary data description

F8 11111000 Synchronization The timer FA 11111010 begins the current queue FB 11111011 Continued a queue Fc 11111100 from the stopped place to stop a queue

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 | 117 | 118 | 119 10 || 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | Reference: "MID I 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 Signing. ------------------ Dec.cpp --- ---------------------------------

/ * File Dec.cpp

By Dustin Caldwell (Dustin@gse.utah.edu)

* /

#include #include #include

Void helpdoc ();

Main () {file * fp;

Unsigned char ch, C;

IF ((fp = fopen (_Argv [1], "rb"))) == 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 Equivalent 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"); }

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ... ---------------

/ * File rec.cpp by Dustin Caldwell (Dustin@gse.utah.edu) * / # include #include #include #include

Void helpdoc ();

Main () {file * RFP, * WFP;

Unsigned char ch, C; char s [20];

IF ((RFP = FOPEN (_Argv [1], "R"))) == null) / * open the read file * / {printf ("canNot Open file% S / N", _ argv [1]); helpdoc ); Exit (-1);

IF ((WFP = FOPEN (_Argv [2], "WB"))) == null) / * open the write file * / {printf ("canNot Open file% s / n", _ argv [1]); helpdoc ); Exit (-1);

C = 0;

CH = FGETC (RFP);

While (! Feof (RFP)) / * loop for whole file * / {

IF (isalNum (CH)) / * only 'See' Valid ASCII Chars * / {C = 0; While (Isdigit (CH)) / * Only Use Decimal Digits (0-9) * / {S [C] = CH ; / * Build a string containing the number * / c ; ch = fgetc (RFP);} s [c] = null; / * must have null terminator * /

FPUTC (ATOI (S), WFP); / * Write the binary Equivalent to file * /

}

CH = FGETC (RFP); / * loop unsteil next Number Starts * /

}

Fclose (RFP); / * Close Up * / Fclose (WFP);

Void helpdoc () / * Print help message * / {printf ("/ n text file encoder / n / n");

Printf ("/ n Syntax: Rec text_file_name binary_file_name / n / n"); Printf ("by Dustin Caldwell (Dustin@gse.utah.edu) / N / N"); Printf ("this is a program what reads an ASCII Tab- / n "); Printf (" Delimited File and Builds a Binary File WHERE / N "); Printf (" Each Byte of the Binary File Is One of The Decimal / N "); Printf (" Digits in The Text File ./N "); Printf (" Eg: / n / n "); Printf (" C: /> REC SON3.TXT SON3.MID / N / N "); Printf (" (This Will Create A File Called Son3 .MID which is / n "); Printf (" a Valid Binary File / N / N "); Printf (" (Dec.exe May Also Be Useful, As IT Decodes Binary Files / N / N "); Printf ("Have Fun !! / N");

转载请注明原文地址:https://www.9cbs.com/read-71920.html

New Post(0)