blob: 41e8cc0c0a77f84a93f86141a34017ecf0887623 [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>
35The physical <a href="http://en.wikipedia.org/wiki/Transport_layer">transport layer</a>
36specified 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>
41Since MIDI 1.0, additional transports have been defined, including MIDI over USB
42and 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>
47Strictly speaking, MIDI is unrelated to audio. But since MIDI is commonly used with
48music, this article is placed in the audio section.
49</p>
50
Clay Murphyfb126fb2015-06-02 15:44:05 -070051<h2 id="for-android">MIDI for Android</h2>
Glenn Kasten806a68c2015-05-21 13:03:49 -070052
53<p>
54Android 3.1 and later support
55<a href="http://en.wikipedia.org/wiki/USB_On-The-Go">USB On-The-Go</a>,
56which permits an Android device to act as USB host to drive USB
57peripherals. The USB host mode APIs introduced in Android 3.1 permit
58developers to implement MIDI over USB at the application level, but until
59recently there have been no built-in platform APIs for MIDI.
60</p>
61
62<p>
63Beginning with the Android M release, device makers can enable optional MIDI support in the platform.
64Supported transports include USB, draft BLE, and virtual (inter-app).
65</p>
66
67<p>
Glenn Kasten60fd1eb2015-06-02 08:16:16 -070068For details on application programming with the new MIDI APIs,
69first download the
70<a href="https://developer.android.com/preview/download.html#docs">preview reference</a>
71and then see the <code>android.media.midi</code> package.
Glenn Kasten806a68c2015-05-21 13:03:49 -070072</p>
73
74<p>
75The remainder of this article discusses how an Android device maker can
76enable MIDI support in the platform.
77</p>
78
Clay Murphyfb126fb2015-06-02 15:44:05 -070079<h2 id="transport">Enabling transports</h2>
Glenn Kasten806a68c2015-05-21 13:03:49 -070080
Glenn Kasten0cd546a2015-08-12 10:47:33 -070081<p>
82The implementation depends on ALSA for USB host mode and USB peripheral mode transports.
83ALSA is not used for the BLE and virtual transports.
84</p>
85
Clay Murphyfb126fb2015-06-02 15:44:05 -070086<h3 id="usb-host">USB host mode</h3>
Glenn Kasten806a68c2015-05-21 13:03:49 -070087
88<p>
89To enable MIDI for USB host mode, first support USB host mode in general, and
Glenn Kasten0cd546a2015-08-12 10:47:33 -070090then enable <code>CONFIG_SND_RAWMIDI</code> and <code>CONFIG_SND_USB_MIDI</code> in your kernel configuration.
91See <a href="{@docRoot}devices/tech/config/kernel.html">Android Kernel Configuration.</a>
Glenn Kasten806a68c2015-05-21 13:03:49 -070092</p>
93
Clay Murphyfb126fb2015-06-02 15:44:05 -070094<h3 id="usb-peripheral">USB peripheral mode</h3>
Glenn Kasten806a68c2015-05-21 13:03:49 -070095
96<p>
97To enable MIDI for USB peripheral mode, you may need to apply patches
98to your Linux kernel to integrate the
99<code>drivers/usb/gadget/f_midi.c</code> into the USB gadget
100driver. As of this writing, these patches are available for Linux kernel version
1013.10. These patches have not yet been updated for
102<a href="http://en.wikipedia.org/wiki/Configfs">ConfigFs</a>
103(a new architecture
104for USB gadget drivers), nor are they merged at upstream
Glenn Kasten0cd546a2015-08-12 10:47:33 -0700105<a href="http://kernel.org">kernel.org</a>.
Glenn Kasten806a68c2015-05-21 13:03:49 -0700106</p>
107
108<p>
Glenn Kasten0cd546a2015-08-12 10:47:33 -0700109The patches are shown in commit order for the kernel tree at project <code>kernel/common</code>
110branch <code>android-3.10</code>:
Glenn Kasten806a68c2015-05-21 13:03:49 -0700111</p>
112<ol>
Glenn Kasten0cd546a2015-08-12 10:47:33 -0700113<li><a href="https://android-review.googlesource.com/#/c/127450/">https://android-review.googlesource.com/#/c/127450/</a></li>
114<li><a href="https://android-review.googlesource.com/#/c/127452/">https://android-review.googlesource.com/#/c/127452/</a></li>
115<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 -0700116</ol>
117
118<p>
119In addition, the end user must also check the box for MIDI
120in the <em>Settings</em> dialog for <em>Select USB configuration</em>,
121or by pulling down from the top of screen while attached
122to the USB host, and choosing <strong>MIDI</strong> for "Use USB for ...".
123</p>
124
Clay Murphyfb126fb2015-06-02 15:44:05 -0700125<h3 id="ble">BLE</h3>
Glenn Kasten806a68c2015-05-21 13:03:49 -0700126
127<p>
Glenn Kasten0cd546a2015-08-12 10:47:33 -0700128MIDI over BLE is always enabled, provided the device supports BLE.
Glenn Kasten806a68c2015-05-21 13:03:49 -0700129As this transport is in draft status, it is subject to change.
130</p>
131
Clay Murphyfb126fb2015-06-02 15:44:05 -0700132<h3 id="virtual">Virtual (inter-app)</h3>
Glenn Kasten806a68c2015-05-21 13:03:49 -0700133
134<p>
135The virtual (inter-app) transport is always enabled.
136</p>
137
Clay Murphyfb126fb2015-06-02 15:44:05 -0700138<h2 id="claim-feature">Claiming the feature</h2>
Glenn Kasten806a68c2015-05-21 13:03:49 -0700139
140<p>
141Applications can screen for the presence of MIDI support using the
142<code>android.software.midi</code> feature.
143</p>
144
145<p>
146To claim MIDI support, add this line to your <code>device.mk</code>:
147</p>
148<pre>
149PRODUCT_COPY_FILES += \
150frameworks/native/data/etc/android.software.midi.xml:system/etc/permissions/android.software.midi.xml
151</pre>
152
153<p>
154See the
155<a href="{@docRoot}compatibility/android-cdd.pdf">Android Compatibility Definition Document (CDD)</a>
156for information
157on requirements to claim the feature.
158</p>
159
160<h2 id="hostDebugging">Debugging while in host mode</h2>
161
162<p>
163While in USB host mode, Android Debug Bridge (adb) debugging over USB is unavailable.
164See section <a href="http://developer.android.com/tools/help/adb.html#wireless">Wireless usage</a>
165of
166<a href="http://developer.android.com/tools/help/adb.html">Android Debug Bridge</a>
167for an alternative.
168</p>