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