Home | History | Annotate | Download | only in audio
      1 page.title=MIDI Architecture
      2 @jd:body
      3 
      4 <!--
      5     Copyright 2015 The Android Open Source Project
      6 
      7     Licensed under the Apache License, Version 2.0 (the "License");
      8     you may not use this file except in compliance with the License.
      9     You may obtain a copy of the License at
     10 
     11         http://www.apache.org/licenses/LICENSE-2.0
     12 
     13     Unless required by applicable law or agreed to in writing, software
     14     distributed under the License is distributed on an "AS IS" BASIS,
     15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16     See the License for the specific language governing permissions and
     17     limitations under the License.
     18 -->
     19 
     20 <div id="qv-wrapper">
     21   <div id="qv">
     22     <h2>In this document</h2>
     23     <ol id="auto-toc">
     24     </ol>
     25   </div>
     26 </div>
     27 
     28 <p>
     29 This article describes the generic MIDI architecture, independent of
     30 any platform implementation, API, or platform-specific features.
     31 </p>
     32 
     33 <h2 id="keyConcepts">Key concepts</h2>
     34 
     35 <h3 id="events">Events</h3>
     36 
     37 <p>
     38 The MIDI protocol is designed for event-based communication.
     39 An <a href="https://en.wikipedia.org/wiki/Event_(computing)">event</a>
     40 is an indication that something happened or will happen at a specified
     41 time. MIDI events are represented by <em>messages</em>, atomic
     42 bundles of information.
     43 </p>
     44 
     45 <h3 id="transport">Transport</h3>
     46 
     47 <p>
     48 MIDI messages are encoded and delivered via a
     49 <a href="https://en.wikipedia.org/wiki/Transport_layer">transport layer</a>,
     50 abbreviated <em>transport</em>, which sends the raw MIDI data
     51 to the recipient who then decodes the data into messages.
     52 </p>
     53 
     54 <p>
     55 Hardware-based MIDI transports include:
     56 </p>
     57 <ul>
     58 <li>MIDI 1.0 current loop with
     59 <a href="https://en.wikipedia.org/wiki/DIN_connector">5-pin DIN</a> connector</li>
     60 <li>USB</li>
     61 <li>Bluetooth Low Energy (BLE)</li>
     62 </ul>
     63 
     64 <h3 id="messageRepresentation">Message representation</h3>
     65 
     66 <p>
     67 A MIDI transport specification describes how to convey messages.
     68 Although the packaging of messages is transport-specific at the
     69 lowest level, at a higher level applications can consider a
     70 time-ordered sequence of messages to be a demarcated
     71 <a href="https://en.wikipedia.org/wiki/Bytestream">byte stream</a>.
     72 This is possible because each message contains
     73 enough information to determine the total length of the message,
     74 provided the start of the message boundary is known.
     75 </p>
     76 
     77 <p>
     78 Most MIDI messages are short (one to three bytes), yet there is the
     79 capability for longer messages via <em>SysEx</em>.
     80 </p>
     81 
     82 <h3 id="timestamps">Timestamps</h3>
     83 
     84 <p>
     85 A <a href="https://en.wikipedia.org/wiki/Timestamp">timestamp</a>
     86 is an optional label attached to a message at origination or upon receipt,
     87 depending on the transport.  The timestamp is expressed in time units
     88 such as seconds or
     89 <a href="https://en.wikipedia.org/wiki/Jiffy_(time)">ticks</a>.
     90 </p>
     91 
     92 <p>
     93 In the absence of an explicit timestamp, the system must substitute
     94 the timestamp of the immediately preceding message or the current
     95 time.  The accuracy of these timestamps, whether explicit or implicit,
     96 is an important aspect of the reliability of a MIDI-based system.
     97 </p>
     98 
     99 <p>
    100 Timestamps are not part of the MIDI 1.0 protocol. They are often added
    101 as part of a platform-specific API.  The BLE transport has timestamps
    102 to indicate the timing of the multiple individual messages sent within
    103 one BLE packet.
    104 </p>
    105 
    106 <h3 id="devices">Devices</h3>
    107 
    108 <p>
    109 A <a href="https://en.wikipedia.org/wiki/Peripheral">peripheral</a>
    110 provides input/output (I/O) capability for a computer.  The terms
    111 <em>MIDI peripheral</em> and <em>MIDI device</em> commonly
    112 refer to any hardware or software module that supports the MIDI protocol.
    113 Within this document, <em>MIDI peripheral</em> refers to the
    114 physical entity and <em>MIDI device</em> describes the module that
    115 actually implements MIDI.
    116 </p>
    117 
    118 <h3 id="ports">Ports</h3>
    119 
    120 <p>
    121 A <a href="https://en.wikipedia.org/wiki/Computer_port_(hardware)">port</a>
    122 is an interface point between computers and peripherals.
    123 </p>
    124 
    125 <p>
    126 MIDI 1.0 uses a female 5-pin DIN socket as the port.
    127 Each port is either <em>OUT</em> (source of MIDI data), <em>IN</em> (sink for MIDI data),
    128 or <em>THRU</em> (meaning an <em>IN</em> which is directly routed to an <em>OUT</em>).
    129 </p>
    130 
    131 <p>
    132 Other transports such as USB and BLE extend the
    133 <a href="https://en.wikipedia.org/wiki/Computer_port_(software)">port concept</a>.
    134 </p>
    135 
    136 <p>
    137 A MIDI device has at least one <em>OUT</em> port, <em>IN</em> port, or both.
    138 </p>
    139 
    140 <p>
    141 The MIDI device supplies stream(s) of messages originating at each <em>OUT</em> port,
    142 and receives stream(s) of messages arriving at each <em>IN</em> port.
    143 The terms <em>IN</em> and <em>OUT</em> are of course relative to one port;
    144 from the perspective of the other port the reverse term applies.
    145 </p>
    146 
    147 <h3 id="connection">Connection</h3>
    148 
    149 <p>
    150 In the MIDI 1.0 transport, an <em>OUT</em> port connects to at most
    151 one <em>IN</em> or <em>THRU</em> port due to the nature of the current loop.
    152 In USB and BLE transports, the same is true at the lowest layer, though
    153 an implementation may re-condition the message stream so that it can
    154 be broadcast to multiple <em>IN</em> ports.
    155 </p>
    156 
    157 <h3 id="cable">Cables</h3>
    158 
    159 <p>
    160 A MIDI 1.0 <a href="https://en.wikipedia.org/wiki/Cable">cable</a> is the
    161 physical bundle of wires that connects an <em>OUT</em> port to an <em>IN</em> or <em>THRU</em> port.
    162 The cable carries data only.
    163 </p>
    164 
    165 <p class="note">
    166 <strong>Note:</strong>
    167 There are non-standard modifications to MIDI that supply power over the
    168 two unused pins.  This is called <em>phantom power</em>.
    169 </p>
    170 
    171 <p>
    172 A <a href="https://en.wikipedia.org/wiki/USB#Cabling">USB cable</a>
    173 is similar, except there is a wide variety of connector types,
    174 and the <em>IN</em>/<em>OUT</em>/<em>THRU</em> concept is replaced by the host/peripheral role.
    175 </p>
    176 
    177 <p>
    178 When operating in USB host mode, the host device supplies power to the
    179 MIDI peripheral.  Most small MIDI peripherals take one USB unit load (100
    180 mA) or less.  However some larger peripherals, or peripherals with audio
    181 output or lights, require more power than the host device can supply.
    182 If you experience problems, try another MIDI peripheral or a powered
    183 USB hub.
    184 </p>
    185 
    186 <h3 id="channel">Channel</h3>
    187 
    188 <p>
    189 Each MIDI message stream in multiplexed among 16 <em>channels</em>.
    190 Most messages are directed at a specific channel,
    191 but there are message types that aren't channel-specific.
    192 Conventionally the channels are numbered one to 16, though
    193 represented by channel values of zero to 15.
    194 </p>
    195 
    196 <p>
    197 If the application needs more than 16 channels or a higher throughput
    198 than one message stream can support, then multiple ports
    199 must be used.
    200 </p>
    201 
    202 <p>
    203 In MIDI 1.0, this is accomplished by multiple cables connecting pairs of ports.
    204 </p>
    205 
    206 <p>
    207 In the MIDI over USB transport, a single USB endpoint can support multiple
    208 ports, each identified by a <em>cable number</em> [sic].
    209 According to the USB MIDI specification,
    210 the <em>cable number</em> identifies the virtual port within the endpoint.
    211 </p>
    212 
    213 <p class="note">
    214 <strong>Note:</strong>
    215 <em>port number</em> would have been a more accurate term,
    216 given that it identifies a port.
    217 </p>
    218 
    219 <p>
    220 Thus a single USB physical cable can carry more than one set of 16 channels.
    221 </p>
    222 
    223 <h2 id="platformImplementation">Platform implementation</h2>
    224 
    225 <p>
    226 As noted in the introduction, these generic MIDI concepts apply to all
    227 implementations.  For the interpretation of the concepts on the Android
    228 platform, see the
    229 <a href="http://developer.android.com/reference/android/media/midi/package-summary.html">
    230 Android MIDI User Guide for <code>android.media.midi</code></a>.
    231 </p>
    232