blob: 5662b544f606318ceb646e651acb1e0408680bd2 [file] [log] [blame]
Glenn Kasten806a68c2015-05-21 13:03:49 -07001page.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)
30is a standard protocol for inter-connecting computers with musical instruments, stage lighting,
31and other time-oriented media.
32</p>
33
34<p>
Glenn Kasten5fe481b2015-11-09 14:18:42 -080035Strictly speaking, MIDI is unrelated to audio. But since MIDI is commonly used with
36music, this article is placed in the audio section.
37</p>
38
39<h2 id="transports">Transports</h2>
40
41<p>
Glenn Kasten806a68c2015-05-21 13:03:49 -070042The physical <a href="http://en.wikipedia.org/wiki/Transport_layer">transport layer</a>
43specified in original MIDI 1.0 is a current loop with
44<a href="http://en.wikipedia.org/wiki/DIN_connector">5-pin DIN</a> connector.
45</p>
46
47<p>
48Since MIDI 1.0, additional transports have been defined, including MIDI over USB
49and a proposed draft for MIDI over
Bert McMeen9ecd0312015-11-11 13:31:09 -080050<a href="http://en.wikipedia.org/wiki/Bluetooth_low_energy">Bluetooth Low Energy</a> (BLE).
Glenn Kasten806a68c2015-05-21 13:03:49 -070051</p>
52
Clay Murphyfb126fb2015-06-02 15:44:05 -070053<h2 id="for-android">MIDI for Android</h2>
Glenn Kasten806a68c2015-05-21 13:03:49 -070054
55<p>
56Android 3.1 and later support
57<a href="http://en.wikipedia.org/wiki/USB_On-The-Go">USB On-The-Go</a>,
58which permits an Android device to act as USB host to drive USB
59peripherals. The USB host mode APIs introduced in Android 3.1 permit
60developers to implement MIDI over USB at the application level, but until
61recently there have been no built-in platform APIs for MIDI.
62</p>
63
64<p>
Glenn Kastena7790a92015-09-24 14:03:17 -070065Beginning with the Android 6.0 (Marshmallow) release, device makers can enable optional MIDI support in the platform.
Glenn Kasten5fe481b2015-11-09 14:18:42 -080066Android directly supports USB, draft BLE, and virtual (inter-app) transports.
67Android indirectly supports MIDI 1.0 via an external adapter.
Glenn Kasten806a68c2015-05-21 13:03:49 -070068</p>
69
70<p>
Glenn Kastena7790a92015-09-24 14:03:17 -070071For details on application programming with the new MIDI APIs, see the
72<a href="https://developer.android.com/reference/android/media/midi/package-summary.html"><code>android.media.midi</code></a>
73package.
Glenn Kasten806a68c2015-05-21 13:03:49 -070074</p>
75
76<p>
77The remainder of this article discusses how an Android device maker can
78enable MIDI support in the platform.
79</p>
80
Clay Murphyfb126fb2015-06-02 15:44:05 -070081<h2 id="transport">Enabling transports</h2>
Glenn Kasten806a68c2015-05-21 13:03:49 -070082
Glenn Kasten0cd546a2015-08-12 10:47:33 -070083<p>
84The implementation depends on ALSA for USB host mode and USB peripheral mode transports.
85ALSA is not used for the BLE and virtual transports.
86</p>
87
Clay Murphyfb126fb2015-06-02 15:44:05 -070088<h3 id="usb-host">USB host mode</h3>
Glenn Kasten806a68c2015-05-21 13:03:49 -070089
90<p>
91To enable MIDI for USB host mode, first support USB host mode in general, and
Glenn Kasten0cd546a2015-08-12 10:47:33 -070092then enable <code>CONFIG_SND_RAWMIDI</code> and <code>CONFIG_SND_USB_MIDI</code> in your kernel configuration.
93See <a href="{@docRoot}devices/tech/config/kernel.html">Android Kernel Configuration.</a>
Glenn Kasten806a68c2015-05-21 13:03:49 -070094</p>
95
Glenn Kastena7790a92015-09-24 14:03:17 -070096<p>
97The MIDI over USB transport is formally defined by the
98<a href="http://www.usb.org/developers/docs/devclass_docs/midi10.pdf">
99Universal Serial Bus Device Class Definition for MIDI Devices Release 1.0 Nov 1, 1999</a>
100standard published by the
101<a href="http://www.usb.org/">USB Implementers Forum, Inc</a>.
102</p>
103
Clay Murphyfb126fb2015-06-02 15:44:05 -0700104<h3 id="usb-peripheral">USB peripheral mode</h3>
Glenn Kasten806a68c2015-05-21 13:03:49 -0700105
106<p>
107To enable MIDI for USB peripheral mode, you may need to apply patches
108to your Linux kernel to integrate the
109<code>drivers/usb/gadget/f_midi.c</code> into the USB gadget
110driver. As of this writing, these patches are available for Linux kernel version
1113.10. These patches have not yet been updated for
112<a href="http://en.wikipedia.org/wiki/Configfs">ConfigFs</a>
113(a new architecture
114for USB gadget drivers), nor are they merged at upstream
Glenn Kasten0cd546a2015-08-12 10:47:33 -0700115<a href="http://kernel.org">kernel.org</a>.
Glenn Kasten806a68c2015-05-21 13:03:49 -0700116</p>
117
118<p>
Glenn Kasten0cd546a2015-08-12 10:47:33 -0700119The patches are shown in commit order for the kernel tree at project <code>kernel/common</code>
120branch <code>android-3.10</code>:
Glenn Kasten806a68c2015-05-21 13:03:49 -0700121</p>
122<ol>
Glenn Kasten0cd546a2015-08-12 10:47:33 -0700123<li><a href="https://android-review.googlesource.com/#/c/127450/">https://android-review.googlesource.com/#/c/127450/</a></li>
124<li><a href="https://android-review.googlesource.com/#/c/127452/">https://android-review.googlesource.com/#/c/127452/</a></li>
125<li><a href="https://android-review.googlesource.com/#/c/143714/">https://android-review.googlesource.com/#/c/143714/</a></li>
Glenn Kasten806a68c2015-05-21 13:03:49 -0700126</ol>
127
128<p>
129In addition, the end user must also check the box for MIDI
Glenn Kastena7790a92015-09-24 14:03:17 -0700130in the <em>Settings / Developer options / Networking / Select USB Configuration</em> dialog,
Glenn Kasten806a68c2015-05-21 13:03:49 -0700131or by pulling down from the top of screen while attached
Glenn Kastena7790a92015-09-24 14:03:17 -0700132to the USB host, selecting entry "USB for ...", and then choosing <strong>MIDI</strong>.
Glenn Kasten806a68c2015-05-21 13:03:49 -0700133</p>
134
Clay Murphyfb126fb2015-06-02 15:44:05 -0700135<h3 id="ble">BLE</h3>
Glenn Kasten806a68c2015-05-21 13:03:49 -0700136
137<p>
Glenn Kasten0cd546a2015-08-12 10:47:33 -0700138MIDI over BLE is always enabled, provided the device supports BLE.
Glenn Kasten806a68c2015-05-21 13:03:49 -0700139As this transport is in draft status, it is subject to change.
140</p>
141
Glenn Kastene388f252015-11-02 14:08:10 -0800142<p>
143The following changes should be applied to platform branch <code>android-6.0.0_r1</code>
144to improve stability of MIDI over BLE:
145</p>
146<ul>
147<li><a href="https://android-review.googlesource.com/#/c/179844/">179844</a></li>
148<li><a href="https://android-review.googlesource.com/#/c/179845/">179845</a></li>
149<li><a href="https://android-review.googlesource.com/#/c/179846/">179846</a></li>
150<li><a href="https://android-review.googlesource.com/#/c/179847/">179847</a></li>
151<li><a href="https://android-review.googlesource.com/#/c/179848/">179848</a></li>
152</ul>
153
Clay Murphyfb126fb2015-06-02 15:44:05 -0700154<h3 id="virtual">Virtual (inter-app)</h3>
Glenn Kasten806a68c2015-05-21 13:03:49 -0700155
156<p>
157The virtual (inter-app) transport is always enabled.
158</p>
159
Clay Murphyfb126fb2015-06-02 15:44:05 -0700160<h2 id="claim-feature">Claiming the feature</h2>
Glenn Kasten806a68c2015-05-21 13:03:49 -0700161
162<p>
163Applications can screen for the presence of MIDI support using the
164<code>android.software.midi</code> feature.
165</p>
166
167<p>
168To claim MIDI support, add this line to your <code>device.mk</code>:
169</p>
170<pre>
171PRODUCT_COPY_FILES += \
172frameworks/native/data/etc/android.software.midi.xml:system/etc/permissions/android.software.midi.xml
173</pre>
174
175<p>
176See the
177<a href="{@docRoot}compatibility/android-cdd.pdf">Android Compatibility Definition Document (CDD)</a>
178for information
179on requirements to claim the feature.
180</p>
181
182<h2 id="hostDebugging">Debugging while in host mode</h2>
183
184<p>
185While in USB host mode, Android Debug Bridge (adb) debugging over USB is unavailable.
186See section <a href="http://developer.android.com/tools/help/adb.html#wireless">Wireless usage</a>
187of
188<a href="http://developer.android.com/tools/help/adb.html">Android Debug Bridge</a>
189for an alternative.
190</p>