Send MIDI messages over USB on Android

Jecimi picture Jecimi · Feb 1, 2012 · Viewed 17.1k times · Source

I would like to make an app on android which sends MIDI messages over USB to a computer to be able to control music softwares such as Cubase, FL, Reason, ect...

Hardware MIDI controllers (e.g Keyboards) are automatically recognized in music software on Windows. I guess it's because they use the universal MIDI protocol which is directly recognized by the music software. They don't need their own driver.

I'd like to be able to use my phone/tablet as a midi controller without having to install staff on the computer (like with hardware controllers).

There's a Demo Code on Android Developers to control a Missile Launcher toy through USB. If I send, using the same technique, messages that follow the MIDI protocol will it work just like that ?

Thank you in advance for your help

Answer

donturner picture donturner · Aug 19, 2015

With Android 6.0 (API 23) this is now possible - Android devices can act as class compliant (no drivers required) MIDI devices.

To switch into USB-MIDI mode users can swipe down from the top of the screen to access the USB mode selection screen (below).

Screenshot showing USB selection menu

An app can send MIDI messages using the new MIDI API. Here's some code to send a MIDI NoteOn message:

byte[] buffer = new buffer[3];
buffer[0] = (byte)0x90 + (byte)0x01; // Note On - Channel 1
buffer[1] = (byte)0x3C; // pitch (Note C3)
buffer[2] = (byte)127; // velocity
int offset = 0;
inputPort.send(buffer, offset, numBytes);

To send other message types consult the MIDI message specification. Note that bytes are signed in Java so this post might be helpful.