Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 1 | page.title=MIDI |
| 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 | <a href="http://en.wikipedia.org/wiki/MIDI">MIDI</a> (Musical Instrument Digital Interface) |
| 30 | is a standard protocol for inter-connecting computers with musical instruments, stage lighting, |
| 31 | and other time-oriented media. |
| 32 | </p> |
| 33 | |
| 34 | <p> |
| 35 | The physical <a href="http://en.wikipedia.org/wiki/Transport_layer">transport layer</a> |
| 36 | specified in original MIDI 1.0 is a current loop with |
| 37 | <a href="http://en.wikipedia.org/wiki/DIN_connector">5-pin DIN</a> connector. |
| 38 | </p> |
| 39 | |
| 40 | <p> |
| 41 | Since MIDI 1.0, additional transports have been defined, including MIDI over USB |
| 42 | and a proposed draft for MIDI over |
| 43 | <a href="http://en.wikipedia.org/wiki/Bluetooth_low_energy">Bluetooth Low Energy</a> (BLE.) |
| 44 | </p> |
| 45 | |
| 46 | <p> |
| 47 | Strictly speaking, MIDI is unrelated to audio. But since MIDI is commonly used with |
| 48 | music, this article is placed in the audio section. |
| 49 | </p> |
| 50 | |
Clay Murphy | fb126fb | 2015-06-02 15:44:05 -0700 | [diff] [blame] | 51 | <h2 id="for-android">MIDI for Android</h2> |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 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> |
Glenn Kasten | a7790a9 | 2015-09-24 14:03:17 -0700 | [diff] [blame] | 63 | Beginning with the Android 6.0 (Marshmallow) release, device makers can enable optional MIDI support in the platform. |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 64 | Supported transports include USB, draft BLE, and virtual (inter-app). |
| 65 | </p> |
| 66 | |
| 67 | <p> |
Glenn Kasten | a7790a9 | 2015-09-24 14:03:17 -0700 | [diff] [blame] | 68 | For details on application programming with the new MIDI APIs, see the |
| 69 | <a href="https://developer.android.com/reference/android/media/midi/package-summary.html"><code>android.media.midi</code></a> |
| 70 | package. |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 71 | </p> |
| 72 | |
| 73 | <p> |
| 74 | The remainder of this article discusses how an Android device maker can |
| 75 | enable MIDI support in the platform. |
| 76 | </p> |
| 77 | |
Clay Murphy | fb126fb | 2015-06-02 15:44:05 -0700 | [diff] [blame] | 78 | <h2 id="transport">Enabling transports</h2> |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 79 | |
Glenn Kasten | 0cd546a | 2015-08-12 10:47:33 -0700 | [diff] [blame] | 80 | <p> |
| 81 | The implementation depends on ALSA for USB host mode and USB peripheral mode transports. |
| 82 | ALSA is not used for the BLE and virtual transports. |
| 83 | </p> |
| 84 | |
Clay Murphy | fb126fb | 2015-06-02 15:44:05 -0700 | [diff] [blame] | 85 | <h3 id="usb-host">USB host mode</h3> |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 86 | |
| 87 | <p> |
| 88 | To enable MIDI for USB host mode, first support USB host mode in general, and |
Glenn Kasten | 0cd546a | 2015-08-12 10:47:33 -0700 | [diff] [blame] | 89 | then enable <code>CONFIG_SND_RAWMIDI</code> and <code>CONFIG_SND_USB_MIDI</code> in your kernel configuration. |
| 90 | See <a href="{@docRoot}devices/tech/config/kernel.html">Android Kernel Configuration.</a> |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 91 | </p> |
| 92 | |
Glenn Kasten | a7790a9 | 2015-09-24 14:03:17 -0700 | [diff] [blame] | 93 | <p> |
| 94 | The MIDI over USB transport is formally defined by the |
| 95 | <a href="http://www.usb.org/developers/docs/devclass_docs/midi10.pdf"> |
| 96 | Universal Serial Bus Device Class Definition for MIDI Devices Release 1.0 Nov 1, 1999</a> |
| 97 | standard published by the |
| 98 | <a href="http://www.usb.org/">USB Implementers Forum, Inc</a>. |
| 99 | </p> |
| 100 | |
Clay Murphy | fb126fb | 2015-06-02 15:44:05 -0700 | [diff] [blame] | 101 | <h3 id="usb-peripheral">USB peripheral mode</h3> |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 102 | |
| 103 | <p> |
| 104 | To enable MIDI for USB peripheral mode, you may need to apply patches |
| 105 | to your Linux kernel to integrate the |
| 106 | <code>drivers/usb/gadget/f_midi.c</code> into the USB gadget |
| 107 | driver. As of this writing, these patches are available for Linux kernel version |
| 108 | 3.10. These patches have not yet been updated for |
| 109 | <a href="http://en.wikipedia.org/wiki/Configfs">ConfigFs</a> |
| 110 | (a new architecture |
| 111 | for USB gadget drivers), nor are they merged at upstream |
Glenn Kasten | 0cd546a | 2015-08-12 10:47:33 -0700 | [diff] [blame] | 112 | <a href="http://kernel.org">kernel.org</a>. |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 113 | </p> |
| 114 | |
| 115 | <p> |
Glenn Kasten | 0cd546a | 2015-08-12 10:47:33 -0700 | [diff] [blame] | 116 | The patches are shown in commit order for the kernel tree at project <code>kernel/common</code> |
| 117 | branch <code>android-3.10</code>: |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 118 | </p> |
| 119 | <ol> |
Glenn Kasten | 0cd546a | 2015-08-12 10:47:33 -0700 | [diff] [blame] | 120 | <li><a href="https://android-review.googlesource.com/#/c/127450/">https://android-review.googlesource.com/#/c/127450/</a></li> |
| 121 | <li><a href="https://android-review.googlesource.com/#/c/127452/">https://android-review.googlesource.com/#/c/127452/</a></li> |
| 122 | <li><a href="https://android-review.googlesource.com/#/c/143714/">https://android-review.googlesource.com/#/c/143714/</a></li> |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 123 | </ol> |
| 124 | |
| 125 | <p> |
| 126 | In addition, the end user must also check the box for MIDI |
Glenn Kasten | a7790a9 | 2015-09-24 14:03:17 -0700 | [diff] [blame] | 127 | in the <em>Settings / Developer options / Networking / Select USB Configuration</em> dialog, |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 128 | or by pulling down from the top of screen while attached |
Glenn Kasten | a7790a9 | 2015-09-24 14:03:17 -0700 | [diff] [blame] | 129 | to the USB host, selecting entry "USB for ...", and then choosing <strong>MIDI</strong>. |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 130 | </p> |
| 131 | |
Clay Murphy | fb126fb | 2015-06-02 15:44:05 -0700 | [diff] [blame] | 132 | <h3 id="ble">BLE</h3> |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 133 | |
| 134 | <p> |
Glenn Kasten | 0cd546a | 2015-08-12 10:47:33 -0700 | [diff] [blame] | 135 | MIDI over BLE is always enabled, provided the device supports BLE. |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 136 | As this transport is in draft status, it is subject to change. |
| 137 | </p> |
| 138 | |
Glenn Kasten | e388f25 | 2015-11-02 14:08:10 -0800 | [diff] [blame^] | 139 | <p> |
| 140 | The following changes should be applied to platform branch <code>android-6.0.0_r1</code> |
| 141 | to improve stability of MIDI over BLE: |
| 142 | </p> |
| 143 | <ul> |
| 144 | <li><a href="https://android-review.googlesource.com/#/c/179844/">179844</a></li> |
| 145 | <li><a href="https://android-review.googlesource.com/#/c/179845/">179845</a></li> |
| 146 | <li><a href="https://android-review.googlesource.com/#/c/179846/">179846</a></li> |
| 147 | <li><a href="https://android-review.googlesource.com/#/c/179847/">179847</a></li> |
| 148 | <li><a href="https://android-review.googlesource.com/#/c/179848/">179848</a></li> |
| 149 | </ul> |
| 150 | |
Clay Murphy | fb126fb | 2015-06-02 15:44:05 -0700 | [diff] [blame] | 151 | <h3 id="virtual">Virtual (inter-app)</h3> |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 152 | |
| 153 | <p> |
| 154 | The virtual (inter-app) transport is always enabled. |
| 155 | </p> |
| 156 | |
Clay Murphy | fb126fb | 2015-06-02 15:44:05 -0700 | [diff] [blame] | 157 | <h2 id="claim-feature">Claiming the feature</h2> |
Glenn Kasten | 806a68c | 2015-05-21 13:03:49 -0700 | [diff] [blame] | 158 | |
| 159 | <p> |
| 160 | Applications can screen for the presence of MIDI support using the |
| 161 | <code>android.software.midi</code> feature. |
| 162 | </p> |
| 163 | |
| 164 | <p> |
| 165 | To claim MIDI support, add this line to your <code>device.mk</code>: |
| 166 | </p> |
| 167 | <pre> |
| 168 | PRODUCT_COPY_FILES += \ |
| 169 | frameworks/native/data/etc/android.software.midi.xml:system/etc/permissions/android.software.midi.xml |
| 170 | </pre> |
| 171 | |
| 172 | <p> |
| 173 | See the |
| 174 | <a href="{@docRoot}compatibility/android-cdd.pdf">Android Compatibility Definition Document (CDD)</a> |
| 175 | for information |
| 176 | on requirements to claim the feature. |
| 177 | </p> |
| 178 | |
| 179 | <h2 id="hostDebugging">Debugging while in host mode</h2> |
| 180 | |
| 181 | <p> |
| 182 | While in USB host mode, Android Debug Bridge (adb) debugging over USB is unavailable. |
| 183 | See section <a href="http://developer.android.com/tools/help/adb.html#wireless">Wireless usage</a> |
| 184 | of |
| 185 | <a href="http://developer.android.com/tools/help/adb.html">Android Debug Bridge</a> |
| 186 | for an alternative. |
| 187 | </p> |