MIDI and Android

1,236 views
Skip to first unread message

Karsten Gebbert

unread,
Nov 15, 2012, 4:25:50 PM11/15/12
to android-musi...@googlegroups.com
Hi,

wonder what the commonly used way to access (USB-)MIDI devices is on Android 4+. I have re-compiled the kernel with the appropriate drivers, can see my device(s) doing cat /proc/asound/cards when connected to my nexux 7, but wonder how I can actually use the driver. Some digging reveals that alsa-lib can not be ported to bionic these days - *please* point out if I'm wrong about this :) - and there seems to be no generic way to do this as far my search tells me. Is anyone doing this out there (and how)? Any hints appreciated!

Best,
karsten

Peter Brinkmann

unread,
Nov 15, 2012, 7:45:52 PM11/15/12
to android-musi...@googlegroups.com
Hi Karsten,
I'm not sure how much mileage you'll get out of building kernels with
the appropriate drivers --- I'm mostly working on things that will
work with stock devices. It just happens that I've been tinkering with
USB MIDI lately, and I've got a tentative Java API that talks to my
Edirol PCR-30 keyboard. It isn't nearly done yet (it seems to choke
when messages come in at a high rate, and it loses the connection when
the device goes to sleep), but if you're interested in joining this
effort, I can upload the code to GitHub.
Cheers,
Peter

Karsten Gebbert

unread,
Nov 17, 2012, 4:44:19 PM11/17/12
to android-musi...@googlegroups.com, peter.b...@googlemail.com
Hi Peter!

that sounds really interesting. I'd love to know how you went about adding support for a piece of hardware like this without kernel driver support? I thought that some sort of driver level would be needed, unless, of course you implement that yourself in Java. If you don't mind explaining your strategy, I'd be most grateful, otherwise I'd love to take a peek at your lib (only if you feel comfortable making it available, of course).

Thanks, 

karsten 

Friedger Müffke

unread,
Nov 17, 2012, 4:57:14 PM11/17/12
to android-musi...@googlegroups.com, peter.b...@googlemail.com
There is an interesting post about writing your own driver in Java:
http://android.serverbox.ch/?p=549

Friedger

2012/11/17 Karsten Gebbert <karsten...@gmail.com>:

Peter Brinkmann

unread,
Nov 19, 2012, 10:06:08 PM11/19/12
to Peter Kirn, android-musi...@googlegroups.com
Alright, I pushed my my current take on USB MIDI for Android to the usb branch of the btmidi repository at GitHub: https://github.com/nettoyeurny/btmidi/tree/usb

A few points to keep in mind:

* No promises: The code is very preliminary. It's essentially untested, undocumented, un-anything-else-you-might-wish-for. I've only tried it with a Galaxy Nexus phone and Roland PCR-30 MIDI controller.
* It's all Java, using only official Android APIs, based on my reading of the USB MIDI specification.
* It seems to lose the connection whenever the phone goes to sleep.
* It also loses the connection when control-change messages come in at a high rate.
* The long-term goal is to provide a MIDI API for Android that'll work with either Bluetooth or USB.

So, it's not nearly done, but it seems like a reasonable proof of concept for now. Feedback and contributions are welcome!
Cheers,
     Peter




On Mon, Nov 19, 2012 at 6:55 AM, Peter Kirn <pe...@createdigitalmedia.net> wrote:
Wow, really some exciting stuff here. Peter, I'm interested in your effort. Does it seem to be something that's ... working?

Peter

Miron Roth

unread,
Nov 19, 2012, 10:14:49 PM11/19/12
to android-musi...@googlegroups.com
Peter, thanks for your efforts. How is the latency actually triggering sounds with the MIDI controller on your GNex? Thanks / m

Paul Nahay

unread,
Nov 19, 2012, 10:13:33 PM11/19/12
to android-musi...@googlegroups.com

I really hope this ball keeps rolling until MIDI is permanently available for all on Android!

 

Paul Nahay

Paul Nahay

unread,
Nov 15, 2012, 7:47:25 PM11/15/12
to android-musi...@googlegroups.com
I'm very interested in this, too, as I need a Java MIDI API myself.

Paul Nahay

-----Original Message-----
From: android-musi...@googlegroups.com
[mailto:android-musi...@googlegroups.com] On Behalf Of Peter
Brinkmann
Sent: Thursday, November 15, 2012 7:46 PM
To: android-musi...@googlegroups.com
Subject: Re: MIDI and Android

Hi Karsten,
I'm not sure how much mileage you'll get out of building kernels with the
appropriate drivers --- I'm mostly working on things that will work with
stock devices. It just happens that I've been tinkering with USB MIDI
lately, and I've got a tentative Java API that talks to my Edirol PCR-30
keyboard. It isn't nearly done yet (it seems to choke when messages come in
at a high rate, and it loses the connection when the device goes to sleep),
but if you're interested in joining this effort, I can upload the code to
GitHub.
Cheers,
Peter


On Thu, Nov 15, 2012 at 4:25 PM, Karsten Gebbert <karsten...@gmail.com>
wrote:
> Hi,
>
> wonder what the commonly used way to access (USB-)MIDI devices is on
> Android
> 4+. I have re-compiled the kernel with the appropriate drivers, can
> 4+see my

Peter Brinkmann

unread,
Nov 20, 2012, 9:40:55 PM11/20/12
to android-musi...@googlegroups.com
@Miron About latency, I haven't yet had the time to really evaluate this. From my point of view, stability is a much bigger concern. As long as the USB connection is lost every few minutes, there's little point in worrying about performance.

@Paul About keeping the ball rolling, I'm afraid I won't be able to spend much time on this for the foreseeable future. For now, I'm mostly focusing on updating my OpenSL library for Android 4.2. I'd be very happy if other people were willing to help.

Generally speaking, if this USB MIDI library takes off at all, it'll have to be a communal effort. That's the main reason why I decided to post this code in its current preliminary form. That'll take some coding and a lot of testing --- one of the challenges will be to get this to work with the unbelievable diversity of quirky USB devices that are out there.

Paul Nahay

unread,
Nov 20, 2012, 9:42:19 PM11/20/12
to android-musi...@googlegroups.com

What assistance do you need?

 

Paul Nahay

Peter Brinkmann

unread,
Nov 20, 2012, 10:08:44 PM11/20/12
to android-musi...@googlegroups.com
On Tue, Nov 20, 2012 at 9:42 PM, Paul Nahay <pna...@sprynet.com> wrote:

What assistance do you need?


Lots of assistance! Here are a few things to look at:

* Testing: Does the included sample project work with your setup? Is it stable? If not, under what conditions does it lose the USB connection? What does it take to get the connection back (restarting the app, force stopping and restarting the app, power-cycling the MIDI device, etc.)?
* A better test app; the current one only tests MIDI input.
* Robustness: Fix intermittent USB connection failures. That's the most important part, really.
* Better USB device detection: Most USB MIDI devices do a lousy job of identifying themselves as MIDI devices. So, instead of looking for USB class and subclass values like the USB MIDI specs suggest, the current version looks at most attached USB endpoints and identifies those that sort of behave like MIDI endpoints. I hope that's not the final word.
* Better USB device configuration: The current version assumes that a USB device has at most one input channel and one output channel (that's USB channels, not MIDI channels). That's not true in general (it's not even true for my own PCR-30), but it seemed good enough for a proof of concept. The finished version needs to be smarter than that.

That's about it for now, I think.
Cheers,
     Peter

 

Peter Brinkmann

unread,
Jan 11, 2013, 12:45:42 AM1/11/13
to android-musi...@googlegroups.com
Progress!

My Java driver for USB MIDI is largely done, I think. You can find the latest version at GitHub: https://github.com/nettoyeurny/btmidi

I've been able to solve most of the problems that I outlined in my previous post to this thread. In particular:

* Robustness: Turns out that the connection failures I was experiencing were due to failing hardware and a minor lifecycle issue. With new MIDI hardware and a tiny adjustment to the code, the connection now seems rock solid.
* Testing/test app: I added a simple app that tests both input and output, and both directions seem to work nicely.
* Device configuration: The revised API faithfully reflects the layout of interfaces, inputs, and outputs of a given device, i.e., it is now general enough to describe any device.

As a bonus, the new implementation shares much code with my old support for MIDI over Bluetooth, and so it'll be easy to support both USB and Bluetooth MIDI in one app. Once the connection is set up, the entire communication goes through one interface.

Left to do:

* Device detection is still a bit rough. Since a lot of MIDI devices don't properly identify themselves as such, the current implementation still treats any device as a MIDI device, as long as it has endpoints that look like they might be MIDI endpoints. There's a chance of false positives, but that's better than false negatives, I think.
* The string representation of devices and interfaces only shows unhelpful numerical IDs. It would be nice to use those IDs to look up human-readable device info in a list like this one: http://www.linux-usb.org/usb.ids
* More testing! I only have a small number of Android and MIDI devices to experiment with. More testing is needed.

I think the code is ready to be used by other people. It's too early to promise that the API will remain unchanged, but I don't anticipate any major changes. Any feedback would be appreciated!
Cheers,
     Peter

Martin Roth

unread,
Jan 11, 2013, 3:23:54 AM1/11/13
to android-musi...@googlegroups.com
Awesome stuff. Good work Peter! :)

Paul Nahay

unread,
Jan 11, 2013, 8:37:19 AM1/11/13
to android-musi...@googlegroups.com

FANTASTIC!

 

I intend to be using this later this year!

 

THANK YOU for doing this!

Peter Brinkmann

unread,
Jan 12, 2013, 1:46:04 PM1/12/13
to android-musi...@googlegroups.com

Thanks for your messages, Martin and Paul!

In the meantime, I checked off one more item of the to-do list: The latest version now includes support for retrieving human-readable device info from the web. The API changed a little bit in the process. Please make sure to pull the latest version from GitHub if you want to experiment with it.

Paul Nahay

unread,
Jan 12, 2013, 1:51:15 PM1/12/13
to android-musi...@googlegroups.com

Thanks. It’s going to be a while before I will be experimenting with this, but please keep me 100% in the loop, as the apps I will write for Android will all need MIDI in/out capability!

Miles Egan

unread,
Feb 21, 2013, 11:41:02 PM2/21/13
to android-musi...@googlegroups.com, peter.b...@googlemail.com
Thanks so much for your work on this. I've been considering porting my iOS midi control app to Android for a while and this was the missing piece.

Peter Brinkmann

unread,
Feb 21, 2013, 11:55:46 PM2/21/13
to Miles Egan, android-musi...@googlegroups.com

Glad to hear that! Please let me know how this is working for you. Also, make sure to pull the latest version from GitHub. I recently made a few changes that make it a little more robust as well as easier to use.

Miles Egan

unread,
Feb 21, 2013, 11:56:45 PM2/21/13
to Peter Brinkmann, android-musi...@googlegroups.com
Will do. Thanks. I have to finish some bill-playing client work before
I can get back to fun apps again but this is at the top of my list.
--
miles
http://www.plastaq.com

Paul Nahay

unread,
Feb 23, 2013, 11:07:00 AM2/23/13
to android-musi...@googlegroups.com

I too intend to be using this extensively later this year!

 

Paul Nahay

 

From: android-musi...@googlegroups.com [mailto:android-musi...@googlegroups.com] On Behalf Of Peter Brinkmann
Sent: Thursday, February 21, 2013 11:56 PM
To: Miles Egan
Cc: android-musi...@googlegroups.com
Subject: Re: MIDI and Android

 

 

Glad to hear that! Please let me know how this is working for you. Also, make sure to pull the latest version from GitHub. I recently made a few changes that make it a little more robust as well as easier to use.

 

On Thu, Feb 21, 2013 at 11:41 PM, Miles Egan <mile...@gmail.com> wrote:

Thanks so much for your work on this. I've been considering porting my iOS midi control app to Android for a while and this was the missing piece.

 

--
You received this message because you are subscribed to the Google Groups "Android Music Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-music-deve...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages