In this document
MIDI (Musical Instrument Digital Interface) is a standard protocol for inter-connecting computers with musical instruments, stage lighting, and other time-oriented media.
The physical transport layer specified in original MIDI 1.0 is a current loop with 5-pin DIN connector.
Since MIDI 1.0, additional transports have been defined, including MIDI over USB and a proposed draft for MIDI over Bluetooth Low Energy (BLE.)
Strictly speaking, MIDI is unrelated to audio. But since MIDI is commonly used with music, this article is placed in the audio section.
MIDI for Android
Android 3.1 and later support USB On-The-Go, 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.
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).
For details on application programming with the new MIDI APIs,
first download the
preview reference
and then see the android.media.midi
package.
The remainder of this article discusses how an Android device maker can enable MIDI support in the platform.
Enabling transports
The implementation depends on ALSA for USB host mode and USB peripheral mode transports. ALSA is not used for the BLE and virtual transports.
USB host mode
To enable MIDI for USB host mode, first support USB host mode in general, and
then enable CONFIG_SND_RAWMIDI
and CONFIG_SND_USB_MIDI
in your kernel configuration.
See Android Kernel Configuration.
USB peripheral mode
To enable MIDI for USB peripheral mode, you may need to apply patches
to your Linux kernel to integrate the
drivers/usb/gadget/f_midi.c
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
ConfigFs
(a new architecture
for USB gadget drivers), nor are they merged at upstream
kernel.org.
The patches are shown in commit order for the kernel tree at project kernel/common
branch android-3.10
:
- https://android-review.googlesource.com/#/c/127450/
- https://android-review.googlesource.com/#/c/127452/
- https://android-review.googlesource.com/#/c/143714/
In addition, the end user must also check the box for MIDI in the Settings dialog for Select USB configuration, or by pulling down from the top of screen while attached to the USB host, and choosing MIDI for "Use USB for ...".
BLE
MIDI over BLE is always enabled, provided the device supports BLE. As this transport is in draft status, it is subject to change.
Virtual (inter-app)
The virtual (inter-app) transport is always enabled.
Claiming the feature
Applications can screen for the presence of MIDI support using the
android.software.midi
feature.
To claim MIDI support, add this line to your device.mk
:
PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.software.midi.xml:system/etc/permissions/android.software.midi.xml
See the Android Compatibility Definition Document (CDD) for information on requirements to claim the feature.
Debugging while in host mode
While in USB host mode, Android Debug Bridge (adb) debugging over USB is unavailable. See section Wireless usage of Android Debug Bridge for an alternative.