Developing MIDI applications on Android

djdroid-landscap_20190809-180405_1

About Android MIDI

In 2015 Android introduced MIDI support. Android has billions of users which means there's a whole lot of people with MIDI compatible devices in their pocket!

In this article I'll explore the most popular types of MIDI applications on Android and how to choose the right MIDI API when developing your own app.

Common types of MIDI app

 The two most popular types of MIDI app are:

1) Apps controlled by MIDI. These are apps which primarily receive MIDI data, such as synthesizers, drum machines and DJing apps.

2) MIDI controller apps. These apps are used to control other apps, external hardware or external software (such as a desktop audio workstation).

Apps controlled by MIDI

These apps receive MIDI data from hardware connected over Bluetooth or USB, or from a virtual MIDI service running on the phone itself.

The virtual analog synthesizer app, DRC can be played using an external MIDI keyboard  

 MIDI controller apps

These types of apps are designed to control other apps by sending MIDI to them. Examples include:

  • Using the phone's touch screen as an X-Y pad which sends MIDI Control Change messages
  • Using the phone's accelerometer to send MIDI pitch bend information
  • Step sequencing and piano roll apps

Super MIDI Box is a MIDI drum machine and step sequencer 

These types of apps are especially useful on Android because of how easy it is to use Android as a USB-MIDI device.

Android as a USB-MIDI device

A little-known feature of Android is that when connected to a USB host (like a computer) it can become a class compliant USB-MIDI device. This is done in the USB settings.  

Android's MIDI setting is shown when it's connected to a USB host

Once the USB mode is changed to MIDI, it will appear on the host as a MIDI device with one input channel and one output channel. A MIDI controller app can then be used to control software, such as a Digital Audio Workstation (DAW), on the host.

A Pixel XL in USB-MIDI mode connected to MacOS shows as a 1-in/1-out MIDI device

Inside the app the MIDI device will show up as "Android USB Peripheral" with a single input port and a single output port.

DRC app connected to the Android USB Peripheral MIDI device

Android's MIDI APIs 

 In order to develop a MIDI application on Android you'll need to use one or both of the available MIDI APIs. Here's a summary of the available APIs and their features:

JVM Midi

 In Android Marshmallow (API 23) the JVM Midi API was released. It can be accessed using Kotlin or the Java Programming Language. It enables you to enumerate, connect and communicate with MIDI devices over USB, Bluetooth LE and other apps advertising as virtual MIDI services.

Pros

  • Available on over 60% of all Android devices (correct as of July 10th 2019)

Cons

  • Sending MIDI messages to C/C++ code requires use of JNI which can introduce complexity due to multi-threading
  • MIDI data only available through callback mechanism

You must use this API for enumerating and connecting to MIDI devices, however, for reading and writing you can choose between this API and the Native Midi API described below.

Native Midi

In Android Q the Native MIDI API was released. It's specifically designed for communicating with MIDI devices inside an audio callback which makes it easy to control audio rendering objects, for example a software synthesizer.

This API only handles sending and receiving MIDI data, not MIDI device enumeration or connection. That still needs to be done using the JVM API.

Pros

  • Easy to integrate with existing C and C++ code
  • Best possible latency
  • MIDI data can be received and sent inside an audio callback without blocking

Cons

  • Still need to enumerate and connect to MIDI devices in Kotlin or the Java Programming Language using the JVM MIDI API
  • Only available on Android Q and above 

Getting Started 

You can start developing a MIDI app using Android Studio. You'll want to check out the following resources:

You should also take a look at the existing MIDI apps on the Google Play Store.

If you are using audio in your app you might want to check out the Oboe library for developing high performance audio apps.

If you have questions about developing MIDI apps on Android feel free to ask them on the android-midi group. Good luck and have fun!

SoulPedal® Beta Testing Begins - A Wearable Expres...
Tirare - MIDI String Instrument

Related Posts