home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MAGAZINE / MISC / MNFEB91.ZIP / MIDIEXPL < prev    next >
Encoding:
Text File  |  1991-01-26  |  14.2 KB  |  385 lines

  1.                                  PURPOSE
  2.  
  3. It seems as though many people have an interest in the Musical Instrument 
  4. Digital Interface (MIDI), but for one reason or another have only obtained 
  5. word of mouth or fragmentary descriptions of the specification.  Basic 
  6. questions such as "what's the baud rate?", "is it EIA?" and the like seem to 
  7. keep surfacing.  This article is an attempt to provide the basic data to 
  8. MICRONEWS readers.
  9.  
  10. MICRONEWS
  11.  
  12.                           The MIDI Primer
  13.                             Bob McQueer
  14.  
  15. REFERENCE
  16.  
  17. The major written reference for this article is version 1.0 of the MIDI 
  18. specification, published by the International MIDI Association, copyright 
  19. 1983.  There exists an expanded document.  This document, which I have not 
  20. seen, is simply an expansion of the 1.0 spec. to contain more explanatory 
  21. material, and fill in some areas of hazy explanation.  There are no radical 
  22. departures from 1.0 in it.  I have also heard of a "2.0" spec., but the IMA 
  23. claims no such animal exists.  In any event, backwards compatibility with the 
  24. information I am presenting here should be maintained.
  25.  
  26.  
  27.  
  28.  
  29.  
  30. CONVENTIONS
  31.  
  32. I will give constants in C syntax, ie. 0x for hexadecimal.  If I refer to 
  33. bits by number, I number them starting with 0 for the low order (1's place) 
  34. bit.  The following notation:
  35.  
  36. >>
  37.  
  38. text
  39.  
  40. <<
  41.  
  42. will be used to delimit commentary which is not part of the "bare-bones" 
  43. specification.  A sentence or paragraph marked with a question mark in column 
  44. 1 is a point I would kind of like to hear something about myself.
  45.  
  46.                           OK, let's give it a shot.
  47.  
  48.  
  49.  
  50. PHYSICAL CONNECTOR SPECIFICATION
  51.  
  52. The standard connectors used for MIDI are 5 pin DIN.  Separate sockets are 
  53. used for input and output, clearly marked on a given device.  The spec. gives 
  54. 50 feet as the maximum cable length.  Cables are to be shielded twisted pair, 
  55. with the shield connecting pin 2 at both ends. The pair is pins 4 and 5, pins 
  56. 1 and 3 being unconnected:
  57.  
  58.                               2
  59.                           5       4
  60.                         3           1
  61.  
  62.  
  63. A device may also be equipped with a "MIDI-THRU" socket which is used to pass 
  64. the input of one device directly to output.
  65.  
  66. >>
  67. I think this arrangement shows some of the original conception of MIDI more 
  68. as a way of allowing keyboardists to control multiple boxes than an 
  69. instrument to computer interface.  The "daisy-chain" arrangement probably has 
  70. advantages for a performing musician who wants to play "stacked" synthesizers 
  71. for a desired sound, and has to be able to set things up on the road. <<
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. ELECTRICAL SPECIFICATION
  79.  
  80. Asynchronous serial interface.  The baud rate is 31.25 Kbaud (+/- 1%). There 
  81. are 8 data bits, with 1 start bit and 1 stop bit, for 320 microseconds per 
  82. serial byte.
  83.  
  84. MIDI is current loop, 5 mA.  Logic 0 is current ON.  The specification states 
  85. that input is to be optoisolated, and points out that Sharp PC-900 and HP 
  86. 6N138 optoisolators are satisfactory devices.  Rise and fall time for the 
  87. optoisolator should be less than 2 microseconds.
  88.  
  89. The specification shows a little circuit diagram for the connections to a 
  90. UART.  I am not going to reproduce it here.  There's not much to it - I think 
  91. the important thing it shows is +5 volt connection to pi 4 of the MIDI out 
  92. with pin 5 going to the UART, through 220 ohm load resisors. It also shows 
  93. that you're supposed to connect to the "in" side of the UART through an 
  94. optoisolator, and to the MIDI-THRU on the UART side of the isolator.
  95.  
  96.         
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. >>
  104.  
  105.  
  106. I'm not much of a hardware person, and don't really know what I'm talking 
  107. about in paragraphs like the three above.  I DO recognize that this is a 
  108. "non-standard" specification, which won't work over serial ports intended for 
  109. anything else.  People who do know about such things seem to either have 
  110. giggling or gagging fits when they see it, depending on their dispositions, 
  111. saying things like "I haven't seen current loop since the days of the old 
  112. teletypes".  I also know the fast 31.25 Kbaud pushes the edge for clocking 
  113. commonly available UART's. 
  114.  
  115. <<
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. DATA FORMAT
  128.  
  129. For standard MIDI messages, there is a clear concept that one device is a 
  130. "transmitter" or "master", and the other a "receiver" or "slave". Messages 
  131. take the form of opcode bytes, followed by data bytes. Opcode bytes are 
  132. commonly called "status" bytes, so we shall use this term.
  133.  
  134. >>
  135.  
  136. Very similar to handling a terminal via escape sequences.  There aren't ACK's 
  137. or other handshaking mechanisms in the protocol.
  138.  
  139. <<
  140.  
  141. Status bytes are marked by bit 7 being 1.  All data bytes must contain a 0 in 
  142. bit 7, and thus lie in the range 0 - 127.
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150. MIDI has a logical channel concept.  There are 16 logical channels, encoded 
  151. into bits 0 - 3 of the status bytes of messages for which a channel number is 
  152. significant.  Since bit 7 is taken over for marking the status byte, this 
  153. leaves 3 opcode bits for message types with a logical channel.  7 of the 
  154. possible 8 opcodes are used in this fashion,  reserving the status bytes 
  155. containing all 1's in the high nibble for "system" messages which don't have 
  156. a channel number.  The low order nibble in these remaining messages is really 
  157. further opcode.
  158.  
  159. >>
  160.  
  161. If you are interested in receiving MIDI input, look over the SYSTEM messages 
  162. even if you wish to ignore them.  Especially the "system exclusive" and "real 
  163. time" messages.  The real time messages may be legally inserted in the middle 
  164. of other data, and you should be aware of them, even though many devices 
  165. won't use them. 
  166.  
  167. <<
  168.  
  169.  
  170.  
  171.  
  172.  
  173. VOICE MESSAGES
  174.  
  175. I will cover the message with channel numbers first.  The opcode determines 
  176. the number of data bytes for a single message (see "running status byte", 
  177. below).  The specification divides these into "voice" and "mode" messages. 
  178. The "mode" messages are for control of the logical channels, and the control 
  179. opcodes are piggybacked onto the data bytes for the "parameter" message.  I 
  180. will go into this after describing the "voice messages".  These messages are:
  181.  
  182. status byte   meaning        data bytes
  183.  
  184. 0x80-0x8f     note off       2 - 1 byte pitch, followed by 1 byte velocity
  185. 0x90-0x9f     note on        2 - 1 byte pitch, followed by 1 byte velocity
  186. 0xa0-0xaf     key pressure   2 - 1 byte pitch, 1 byte pressure (after-touch)
  187. 0xb0-0xbf     parameter      2 - 1 byte parameter number, 1 byte setting
  188. 0xc0-0xcf     program        1 byte program selected
  189. 0xd0-0xdf     chan. pressure 1 byte channel pressure (after-touch)
  190. 0xe0-0xef     pitch wheel    2 bytes giving a 14 bit value, least
  191.                                    significant 7 bits first
  192.  
  193. Many explanations are necessary here:
  194.  
  195. For all of these messages, a convention called the "running status byte" may 
  196. be used.  If the transmitter wishes to send another message of the same type 
  197. on the same channel, thus the same status byte, the status byte need not be 
  198. resent.
  199.  
  200. Also, a "note on" message with a velocity of zero is to be synonymous with a 
  201. "note off".  Combined with the previous feature, this is intended to allow 
  202. long strings of notes to be sent without repeating status bytes.
  203.  
  204.  
  205. >>
  206.  
  207. From what I've seen, the "zero velocity note on" feature is very heavily 
  208. used.  My six-trak sends these, even though it sends status bytes on every 
  209. note anyway.  Roland stuff uses it.
  210.  
  211. <<
  212.  
  213. The pitch bytes of notes are simply number of half-steps, with middle C = 60.
  214.  
  215. >>      
  216.  
  217. On keyboard synthesizers, this usually simply means which physical key 
  218. corresponds, since the patch selection will change the actual pitch range of 
  219. the keyboard.  Most keyboards have one C key which is unmistakably in the 
  220. middle of the keyboard.  This is probably note 60.
  221.  
  222. <<
  223.  
  224. The velocity bytes for velocity sensing keyboards are supposed to represent a 
  225. logarithmic scale.  "advisable" in the words of the spec.  Non-velocity 
  226. sensing devices are supposed to send velocity 64.
  227.  
  228. The pitch wheel value is an absolute setting, 0 - 0x3FFF.  The 1.0 spec. says 
  229. that the increment is determined by the receiver. 0x2000 is to correspond to 
  230. a centered pitch wheel (unmodified notes)
  231.  
  232. >>
  233.  
  234. I believe standard scale steps are one of the things discussed in expansions.  
  235. The six-trak pitch wheel is up/down about a third. I believe several makers 
  236. have used this value, but I may be wrong.
  237.  
  238. The "pressure" messages are for keyboards which sense the amount of pressure 
  239. placed on an already depressed key, as opposed to velocity, which is how fast 
  240. it is depressed or released.
  241.  
  242. I'm not really certain of how "channel" pressure works.  Yamaha is one maker 
  243. that uses these messages, I know.
  244.  
  245. <<
  246.  
  247. Now, about those parameter messages.
  248.  
  249. Instruments are so fundamentally different in the various controls they have 
  250. that no attempt was made to define a standard set, like say 9 for "Filter 
  251. Resonance".  Instead, it was simply assumed that these messages allow you to 
  252. set "controller" dials, whose purposes are left to the given device, except 
  253. as noted below.  The first data bytes correspond to these "controllers" as 
  254. follows:
  255.  
  256. data byte
  257.  
  258. 0 - 31       continuous controllers 0 - 31, most significant byte
  259. 32 - 63      continuous controllers 0 - 31, least significant byte
  260. 64 - 95      on / off switches
  261.  
  262. 96 - 121     unspecified, reserved for future.
  263. 122 - 127    the "channel mode" messages I alluded to above.  See
  264.              below.
  265.  
  266.  
  267.  
  268.  
  269.  
  270. The second data byte contains the seven bit setting for the controller. The 
  271. switches have data byte 0 = OFF, 127 = ON with 1 - 126 undefined. If a 
  272. controller only needs seven bits of resolution, it is supposed to use the 
  273. most significant byte.  If both are needed, the order is specified as most 
  274. significant followed by least significant.  With a 14 bit controller, it is 
  275. to be legal to send only the least significant byte if the most significant 
  276. doesn't need to be changed.
  277.  
  278. >>
  279.  
  280. This may of, course, wind up stretched a bit by a given manufacturer. The 
  281. Six-Trak, for instance, uses only single byte values (LEFT justified within 
  282. the 7 bits at that), and recognizes >32 parameters
  283.  
  284. <<
  285.  
  286. Controller number 1 IS standardized to be the modulation wheel.  Are there 
  287. any other standardizations which are being followed by most manufacturers?
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295. MODE MESSAGES
  296.  
  297. These are messages with status bytes 0xb0 through 0xbf, and leading data 
  298. bytes 122 - 127.  In reality, these data bytes function as further opcode 
  299. data for a group of messages which control the combination of voices and 
  300. channels to be accepted by a receiver.
  301.  
  302. An important point is that there is an implicit "basic" channel over which a 
  303. given device is to receive these messages.  The receiver is to ignore mode 
  304. messages over any other channels, no matter what mode it might be in. The 
  305. basic channel for a given device may be fixed or set in some manner outside 
  306. the scope of the MIDI standard.
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318. The meaning of the values 122 through 127 is as follows:
  319.  
  320. data byte                   second data byte
  321. 122       local control     0 = local control off, 127 = on
  322. 123       all notes off     0
  323. 124       omni mode off     0
  324. 125       omni mode on      0
  325. 126       monophonic mode   number of monophonic channels, or 0
  326.                             for a number equal to receivers voices
  327. 127       polyphonic mode   0
  328.  
  329. 124 - 127 also turn all notes off.
  330.  
  331. Local control refers to whether or not notes played on an instruments 
  332. keyboard play on the instrument or not.  With local control off, the host is 
  333. still supposed to be able to read input data if desired, as well as sending 
  334. notes to the instrument.  Very much like "local echo" on a terminal, or "half 
  335. duplex" vs. "full duplex".
  336.  
  337. The mode setting messages control what channels / how many voices the 
  338. receiver recognizes.  The "basic channel" must be kept in mind. "Omni" refers 
  339. to the ability to receive voice messages on all channels.  "Mono" and "Poly" 
  340. refer to whether multiple voices are allowed.  The rub is that the omni 
  341. on/off state and the mono/poly state interact with each other.  We will go 
  342. over each of the four possible settings, called "modes" and given numbers in 
  343. the specification:
  344.  
  345. mode 1 - Omni on / Poly - voice messages received on all channels and
  346.          assigned polyphonically.  Basically, any notes it gets, it
  347.          plays, up to the number of voices it's capable of.
  348.  
  349. mode 2 - Omni on / Mono - monophonic instrument which will receive
  350.          notes to play in one voice on all channels.
  351.  
  352. mode 3 - Omni off / Poly - polyphonic instrument which will receive
  353.          voice messages on only the basic channel.
  354.  
  355. mode 4 - Omni off / Mono - A useful mode, but "mono" is a misnomer.
  356.          To operate in this mode a receiver is supposed to receive
  357.          one voice per channel.  The number channels recognized will be
  358.          given by the second data byte, or the maximum number of possible
  359.          voices if this byte is zero.  The set of channels thus defined
  360.          is a sequential set, starting with the basic channel.
  361. The spec. states that a receiver may ignore any mode that it cannot honor, or 
  362. switch to an alternate - "usually" mode 1.  Receivers are supposed to default 
  363. to mode 1 on power up.  It is also stated that power up conditions are 
  364. supposed to place a receiver in a state where it will only respond to note on 
  365. / note off messages, requiring a setting of some sort to enable the other 
  366. message types.
  367.  
  368. >>
  369.  
  370. I think this shows the desire to "daisy-chain" devices for performance from a 
  371. single master again.  We can set a series of instruments to different basic 
  372. channels, tie 'em together, and let them pass through the stuff they're not 
  373. supposed to play to someone down the line.
  374.  
  375. This suffers greatly from lack of acknowledgement concerning modes and usable 
  376. channels by a receiver.  You basically have to know your device, what it can 
  377. do, and what channels it can do it on.
  378.  
  379. I think most makers have used the "system exclusive" message (see below) to 
  380. handle channels in a more sophisticated manner, as well as changing "basic 
  381. channel" and enabling receipt of different message types under host control 
  382. rather than by adjustment on the device alone.
  383.  
  384. To continue, press ENTER                                    <MIDIEX2>
  385.