Add MIDI

Change-Id: I643a2dfc0febccc7f4440f654f495bca8ea7b62c
diff --git a/src/accessories/audio.jd b/src/accessories/audio.jd
index 9202438..0b61b3f 100644
--- a/src/accessories/audio.jd
+++ b/src/accessories/audio.jd
@@ -74,3 +74,9 @@
 <p class="note"><strong>Note:</strong> The ADK 2012 source code includes an open source Bluetooth stack that
 is built for the Texas Instruments CC2564 chip, but can work with any Bluetooth chip that
 implements a standard Host/Controller Interface (HCI).</p>
+
+<h2 id="midi-over-usb">MIDI over USB and Bluetooth LE</h2>
+<p>Both USB and Bluetooth Low Energy can be used as transports for the
+<a href="http://en.wikipedia.org/wiki/MIDI">MIDI</a> protocol.
+See <a href="{@docRoot}devices/audio/midi.html">MIDI</a> for more information.
+</p>
diff --git a/src/devices/audio/midi.jd b/src/devices/audio/midi.jd
new file mode 100644
index 0000000..b6fb99b
--- /dev/null
+++ b/src/devices/audio/midi.jd
@@ -0,0 +1,160 @@
+page.title=MIDI
+@jd:body
+
+<!--
+    Copyright 2015 The Android Open Source Project
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+
+<div id="qv-wrapper">
+  <div id="qv">
+    <h2>In this document</h2>
+    <ol id="auto-toc">
+    </ol>
+  </div>
+</div>
+
+<p>
+<a href="http://en.wikipedia.org/wiki/MIDI">MIDI</a> (Musical Instrument Digital Interface)
+is a standard protocol for inter-connecting computers with musical instruments, stage lighting,
+and other time-oriented media.
+</p>
+
+<p>
+The physical <a href="http://en.wikipedia.org/wiki/Transport_layer">transport layer</a>
+specified in original MIDI 1.0 is a current loop with
+<a href="http://en.wikipedia.org/wiki/DIN_connector">5-pin DIN</a> connector.
+</p>
+
+<p>
+Since MIDI 1.0, additional transports have been defined, including MIDI over USB
+and a proposed draft for MIDI over
+<a href="http://en.wikipedia.org/wiki/Bluetooth_low_energy">Bluetooth Low Energy</a> (BLE.)
+</p>
+
+<p>
+Strictly speaking, MIDI is unrelated to audio. But since MIDI is commonly used with
+music, this article is placed in the audio section.
+</p>
+
+<h2>MIDI for Android</h2>
+
+<p>
+Android 3.1 and later support
+<a href="http://en.wikipedia.org/wiki/USB_On-The-Go">USB On-The-Go</a>,
+which permits an Android device to act as USB host to drive USB
+peripherals. The USB host mode APIs introduced in Android 3.1 permit
+developers to implement MIDI over USB at the application level, but until
+recently there have been no built-in platform APIs for MIDI.
+</p>
+
+<p>
+Beginning with the Android M release, device makers can enable optional MIDI support in the platform.
+Supported transports include USB, draft BLE, and virtual (inter-app).
+</p>
+
+<p>
+For details on application programming with the new MIDI APIs, see the
+<a href="https://android-preview.googleplex.com/reference/android/media/midi/package-summary.html">android.media.midi</a>
+package.
+</p>
+
+<p>
+The remainder of this article discusses how an Android device maker can
+enable MIDI support in the platform.
+</p>
+
+<h2>Enabling transports</h2>
+
+<h3>USB host mode</h3>
+
+<p>
+To enable MIDI for USB host mode, first support USB host mode in general, and
+then enable <code>CONFIG_SND_RAWMIDI</code> in your kernel configuration.
+</p>
+
+<h3>USB peripheral mode</h3>
+
+<p>
+To enable MIDI for USB peripheral mode, you may need to apply patches
+to your Linux kernel to integrate the
+<code>drivers/usb/gadget/f_midi.c</code> into the USB gadget
+driver. As of this writing, these patches are available for Linux kernel version
+3.10. These patches have not yet been updated for
+<a href="http://en.wikipedia.org/wiki/Configfs">ConfigFs</a>
+(a new architecture
+for USB gadget drivers), nor are they merged at upstream
+<a href="http://kernel.org"</a>kernel.org</a>.
+</p>
+
+<p>
+The patches are shown in commit order for the <code>tegra</code> tree:
+</p>
+<ol>
+<li><a href="https://android.googlesource.com/kernel/tegra/+/261230ce54cfc119efe643fc1d128e431d1678d3"</a>261230ce54cfc119efe643fc1d128e431d1678d3</a></li>
+<li><a href="https://android.googlesource.com/kernel/tegra/+/3f048135f3028e503d9d6e32b602e362bd9f374f"</a>3f048135f3028e503d9d6e32b602e362bd9f374f</a></li>
+<li><a href="https://android.googlesource.com/kernel/tegra/+/ae2019d83ecf14454315240c16dc3136212f0da2"</a>ae2019d83ecf14454315240c16dc3136212f0da2</a></li>
+</ol>
+
+<p>
+In addition, the end user must also check the box for MIDI
+in the <em>Settings</em> dialog for <em>Select USB configuration</em>,
+or by pulling down from the top of screen while attached
+to the USB host, and choosing <strong>MIDI</strong> for "Use USB for ...".
+</p>
+
+<h3>BLE</h3>
+
+<p>
+MIDI over BLE is always enabled.
+As this transport is in draft status, it is subject to change.
+</p>
+
+<h3>Virtual (inter-app)</h3>
+
+<p>
+The virtual (inter-app) transport is always enabled.
+</p>
+
+<h2>Claiming the feature</h2>
+
+<p>
+Applications can screen for the presence of MIDI support using the
+<code>android.software.midi</code> feature.
+</p>
+
+<p>
+To claim MIDI support, add this line to your <code>device.mk</code>:
+</p>
+<pre>
+PRODUCT_COPY_FILES += \
+frameworks/native/data/etc/android.software.midi.xml:system/etc/permissions/android.software.midi.xml
+</pre>
+
+<p>
+See the
+<a href="{@docRoot}compatibility/android-cdd.pdf">Android Compatibility Definition Document (CDD)</a>
+for information
+on requirements to claim the feature.
+</p>
+
+<h2 id="hostDebugging">Debugging while in host mode</h2>
+
+<p>
+While in USB host mode, Android Debug Bridge (adb) debugging over USB is unavailable.
+See section <a href="http://developer.android.com/tools/help/adb.html#wireless">Wireless usage</a>
+of
+<a href="http://developer.android.com/tools/help/adb.html">Android Debug Bridge</a>
+for an alternative.
+</p>
diff --git a/src/devices/devices_toc.cs b/src/devices/devices_toc.cs
index ca4ef2d..c5afca2 100644
--- a/src/devices/devices_toc.cs
+++ b/src/devices/devices_toc.cs
@@ -51,6 +51,7 @@
           <li><a href="<?cs var:toroot ?>devices/audio/avoiding_pi.html">Priority Inversion</a></li>
           <li><a href="<?cs var:toroot ?>devices/audio/src.html">Sample Rate Conversion</a></li>
           <li><a href="<?cs var:toroot ?>devices/audio/debugging.html">Debugging</a></li>
+          <li><a href="<?cs var:toroot ?>devices/audio/midi.html">MIDI</a></li>
           <li><a href="<?cs var:toroot ?>devices/audio/usb.html">USB Digital Audio</a></li>
           <li><a href="<?cs var:toroot ?>devices/audio/tv.html">TV Audio</a></li>
         </ul>