Android Example Midi USB device manager

The attached project shows the use of the USB library to communicate with Midi Devices over USB. I realize that this may open a can of worms, as it seems nothing about Midi communication is straightforward.

So if there are issues and questions, perhaps we can learn together on this one.

There are two main classes, MidiUSBManager and MidiInClass, the MidiUSBManager deals with the USB connectivity side and holds the USB objects and methods required for the communication. The MidiInClass is basically just a thread that captures incoming mididata and parses it according to the message received (Sysex is ignored).

Midi thru is implemented in the MidiInClass by sending the received messages directly to the USB OutEndpoint, basically a repeater. There are also three buttons which pass Kick Drum, Snare and Hi-Hat, midi data directly to the attached device.

As my main sound device is a Yamaha MU10, I had to implement an XG mode switch to get Drum sounds to play on channel 10.

I have tried it on a couple of interfaces, both of which seem to work OK.

You will need to be aware that midi for USB has it's own standard for communications, which is basically 4 byte packets. Details of which can be found here: http://www.usb.org/developers/devclass_docs/midi10.pdf . If you need information on Midi data structures good places to look are here: http://www.sonicspot.com/guide/midifiles.html

or here: http://www.somascape.org/midi/tech/mfile.html which is a bit more complete.

If you start the application with a usb Midi device already plugged in you will need to press the Connect button. If you plug the device in while the app is running it will automatically connect. It would be straightforward to do a scan when the app starts to see if a device is available if you want to.

If this brings up any questions, which I'm sure it will, please ask them here and I will try to find the answers.

Minimum API is 12 and the device needs to have an OTG USB port. And you obviously need a USB midi cable or device.

The demo requires: Broadcast Receiver Library V2 from Thomas (xverhelstx), which although not strictly necessary, it is nice to know when a device has been disconnected.

Also required: JavaObject, RandomAccessFile, Thread and USB libraries.

It was developed on V3.5 of B4a, but I don't think it uses anything that would preclude it running on older versions.

Please post here and let me know how it works for you.
 

Attachments

  • USBMidiTest3.zip
    13.7 KB · Views: 839
  • USBMidiTest3-B4a3.2.zip
    13.5 KB · Views: 737
Last edited:

stevel05

Expert
Licensed User
Longtime User
It was written with v3.5. What are you trying to run it on?
 
Top