Home | History | Annotate | Download | only in audio
      1 <html devsite>
      2   <head>
      3     <title>MIDI</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 <a href="http://en.wikipedia.org/wiki/MIDI">MIDI</a> (Musical Instrument Digital Interface)
     28 is a standard protocol for inter-connecting computers with musical instruments, stage lighting,
     29 and other time-oriented media.
     30 </p>
     31 
     32 <p>
     33 Strictly speaking, MIDI is unrelated to audio. But since MIDI is commonly used with
     34 music, this article is placed in the audio section.
     35 </p>
     36 
     37 <h2 id="transports">Transports</h2>
     38 
     39 <p>
     40 The physical <a href="http://en.wikipedia.org/wiki/Transport_layer">transport layer</a>
     41 specified in original MIDI 1.0 is a current loop with
     42 <a href="http://en.wikipedia.org/wiki/DIN_connector">5-pin DIN</a> connector.
     43 </p>
     44 
     45 <p>
     46 Since MIDI 1.0, additional transports have been defined, including MIDI over USB
     47 and a proposed draft for MIDI over
     48 <a href="http://en.wikipedia.org/wiki/Bluetooth_low_energy">Bluetooth Low Energy</a> (BLE).
     49 </p>
     50 
     51 <h2 id="for-android">MIDI for Android</h2>
     52 
     53 <p>
     54 Android 3.1 and later support
     55 <a href="http://en.wikipedia.org/wiki/USB_On-The-Go">USB On-The-Go</a>,
     56 which permits an Android device to act as USB host to drive USB
     57 peripherals. The USB host mode APIs introduced in Android 3.1 permit
     58 developers to implement MIDI over USB at the application level, but until
     59 recently there have been no built-in platform APIs for MIDI.
     60 </p>
     61 
     62 <p>
     63 Beginning with the Android 6.0 (Marshmallow) release, device makers can enable optional MIDI support in the platform.
     64 Android directly supports USB, draft BLE, and virtual (inter-app) transports.
     65 Android indirectly supports MIDI 1.0 via an external adapter.
     66 </p>
     67 
     68 <p>
     69 For details on application programming with the new MIDI APIs, see the
     70 <a href="https://developer.android.com/reference/android/media/midi/package-summary.html"><code>android.media.midi</code></a>
     71 package.
     72 </p>
     73 
     74 <p>
     75 The remainder of this article discusses how an Android device maker can
     76 enable MIDI support in the platform.
     77 </p>
     78 
     79 <h2 id="transport">Enabling transports</h2>
     80 
     81 <p>
     82 The implementation depends on ALSA for USB host mode and USB peripheral mode transports.
     83 ALSA is not used for the BLE and virtual transports.
     84 </p>
     85 
     86 <h3 id="usb-host">USB host mode</h3>
     87 
     88 <p>
     89 To enable MIDI for USB host mode, first support USB host mode in general, and
     90 then enable <code>CONFIG_SND_RAWMIDI</code> and <code>CONFIG_SND_USB_MIDI</code> in your kernel configuration.
     91 See <a href="/devices/tech/config/kernel.html">Android Kernel Configuration.</a>
     92 </p>
     93 
     94 <p>
     95 The MIDI over USB transport is formally defined by the
     96 <a href="http://www.usb.org/developers/docs/devclass_docs/midi10.pdf">
     97 Universal Serial Bus Device Class Definition for MIDI Devices Release 1.0 Nov 1, 1999</a>
     98 standard published by the
     99 <a href="http://www.usb.org/">USB Implementers Forum, Inc</a>.
    100 </p>
    101 
    102 <h3 id="usb-peripheral">USB peripheral mode</h3>
    103 
    104 <p>
    105 To enable MIDI for USB peripheral mode, you may need to apply patches
    106 to your Linux kernel to integrate the
    107 <code>drivers/usb/gadget/f_midi.c</code> into the USB gadget
    108 driver. As of this writing, these patches are available for Linux kernel version
    109 3.10. These patches have not yet been updated for
    110 <a href="http://en.wikipedia.org/wiki/Configfs">ConfigFs</a>
    111 (a new architecture
    112 for USB gadget drivers), nor are they merged at upstream
    113 <a href="http://kernel.org">kernel.org</a>.
    114 </p>
    115 
    116 <p>
    117 The patches are shown in commit order for the kernel tree at project <code>kernel/common</code>
    118 branch <code>android-3.10</code>:
    119 </p>
    120 <ol>
    121 <li><a href="https://android-review.googlesource.com/#/c/127450/">https://android-review.googlesource.com/#/c/127450/</a></li>
    122 <li><a href="https://android-review.googlesource.com/#/c/127452/">https://android-review.googlesource.com/#/c/127452/</a></li>
    123 <li><a href="https://android-review.googlesource.com/#/c/143714/">https://android-review.googlesource.com/#/c/143714/</a></li>
    124 </ol>
    125 
    126 <p>
    127 In addition, the end user must also check the box for MIDI
    128 in the <em>Settings / Developer options / Networking / Select USB Configuration</em> dialog,
    129 or by pulling down from the top of screen while attached
    130 to the USB host, selecting entry "USB for ...", and then choosing <strong>MIDI</strong>.
    131 </p>
    132 
    133 <h3 id="ble">BLE</h3>
    134 
    135 <p>
    136 MIDI over BLE is always enabled, provided the device supports BLE.
    137 As this transport is in draft status, it is subject to change.
    138 </p>
    139 
    140 <h3 id="virtual">Virtual (inter-app)</h3>
    141 
    142 <p>
    143 The virtual (inter-app) transport is always enabled.
    144 </p>
    145 
    146 <h2 id="claim-feature">Claiming the feature</h2>
    147 
    148 <p>
    149 Applications can screen for the presence of MIDI support using the
    150 <code>android.software.midi</code> feature.
    151 </p>
    152 
    153 <p>
    154 To claim MIDI support, add this line to your <code>device.mk</code>:
    155 </p>
    156 <pre class="devsite-click-to-copy">
    157 PRODUCT_COPY_FILES += \
    158 frameworks/native/data/etc/android.software.midi.xml:system/etc/permissions/android.software.midi.xml
    159 </pre>
    160 
    161 <p>
    162 See the
    163 <a href="/compatibility/android-cdd.pdf">Android Compatibility Definition Document (CDD)</a>
    164 for information
    165 on requirements to claim the feature.
    166 </p>
    167 
    168 <h2 id="hostDebugging">Debugging while in host mode</h2>
    169 
    170 <p>
    171 While in USB host mode, Android Debug Bridge (adb) debugging over USB is unavailable.
    172 See section <a href="http://developer.android.com/tools/help/adb.html#wireless">Wireless usage</a>
    173 of
    174 <a href="http://developer.android.com/tools/help/adb.html">Android Debug Bridge</a>
    175 for an alternative.
    176 </p>
    177 
    178   </body>
    179 </html>
    180