Send MIDI messages over USB on Android

人盡茶涼 提交于 2019-12-03 03:25:15

No, it doesn't work remotely like that.

USB MIDI devices do use a driver... it's just that they are generally "class compliant", and can all use the same stock driver that comes with the OS.

To do what you are proposing, you will need to emulate a device over USB... complete with the appropriate PnP IDs and what not. This is next to impossible. The code you found was for using USB in host mode, not the other way around.

You will find that it is far easier to send MIDI via network, and use one of the many network MIDI drivers available.

donturner

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).

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.

I wrote the USB MIDI Driver for Android.
Useful to build your own MIDI controller / receiver.

https://github.com/kshoji/USB-MIDI-Driver

The another midi driver is 'nmj' library.
This library also supports USB MIDI. Moreover, it supports some network-MIDI protocols, MIDI over bluetooth and MIDI over ADB(debug connection).

http://www.humatic.de/htools/nmj/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!