# MIDI over USB

**URL:** <https://forum.juce.com/t/midi-over-usb/24460>\
**Category:** Android\
**Created:** [October 1, 2017, 10:02pm UTC](https://forum.juce.com/t/midi-over-usb/24460 "2017-10-01T22:02:24Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [October 1, 2017, 10:02pm UTC](https://forum.juce.com/t/midi-over-usb/24460/1 "2017-10-01T22:02:24Z")

</div>

Hi, are there any permissions that needed to be granted in order to use MIDI over USB? There doesn’t appear to be anything in the Projucer options.

thx

---

<div class="post-metadata">

**Author:** ![jonathonracz](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jonathonracz](https://forum.juce.com/u/jonathonracz)\
**Post date:** [October 2, 2017, 2:20am UTC](https://forum.juce.com/t/midi-over-usb/24460/2 "2017-10-02T02:20:08Z")

</div>

I assume you’re on desktop? Because I’ve never had any permission issues manipulating MIDI hardware under macOS and Windows. Could be different under mobile platforms though.

---

<div class="post-metadata">

**Author:** ![yfede](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yfede/32/506_2.png) [@yfede](https://forum.juce.com/u/yfede)\
**Post date:** [October 2, 2017, 8:59am UTC](https://forum.juce.com/t/midi-over-usb/24460/3 "2017-10-02T08:59:34Z")

</div>

I think he refers to Android given the topic’s category

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [October 2, 2017, 9:20am UTC](https://forum.juce.com/t/midi-over-usb/24460/4 "2017-10-02T09:20:02Z")

</div>

Yes, this is for Android. The functions for returning MIDI inputs and outputs are not returning any results. Other Android apps I run are seeing the attached devices.

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [October 2, 2017, 9:28am UTC](https://forum.juce.com/t/midi-over-usb/24460/5 "2017-10-02T09:28:53Z")

</div>

You need to build for at least SDK 23.

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [October 2, 2017, 9:30am UTC](https://forum.juce.com/t/midi-over-usb/24460/6 "2017-10-02T09:30:15Z")

</div>

ah, really? wow… there’s no MIDI support in Juce at all before that? thx

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 2, 2017, 10:11am UTC](https://forum.juce.com/t/midi-over-usb/24460/7 "2017-10-02T10:11:11Z")

</div>

> [@leehu](#):
>
> there’s no MIDI support in Juce at all before that?

I think that’s because there’s no MIDI support in _Android_ before that!

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [October 2, 2017, 12:24pm UTC](https://forum.juce.com/t/midi-over-usb/24460/8 "2017-10-02T12:24:24Z")

</div>

I was wondering that, but then I have other apps running on 19 that access MIDI. From what I’ve read it was overhauled in 23 though and given much better APIs so I just assumed you chose to support from then onwards. It seems that MIDI have been available from 3.1

---

<div class="post-metadata">

**Author:** ![jonathonracz](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jonathonracz](https://forum.juce.com/u/jonathonracz)\
**Post date:** [October 2, 2017, 2:06pm UTC](https://forum.juce.com/t/midi-over-usb/24460/9 "2017-10-02T14:06:09Z")

</div>

Doh, missed that this was in the Android section (usually just read from the aggregate main page)… sorry @leehu!

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [October 2, 2017, 3:21pm UTC](https://forum.juce.com/t/midi-over-usb/24460/10 "2017-10-02T15:21:58Z")

</div>

ha, no probs - i normally put things in the title aswell, but didn’t on this occasion

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [October 2, 2017, 8:13pm UTC](https://forum.juce.com/t/midi-over-usb/24460/11 "2017-10-02T20:13:02Z")

</div>

Hi Fabian. Rebuilt for 23 and upgraded tablet and still no MIDI in/out showing. Are there any demo/tests apps to run for MIDI connectivity? thx

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [October 3, 2017, 7:44am UTC](https://forum.juce.com/t/midi-over-usb/24460/12 "2017-10-03T07:44:49Z")

</div>

Hmm that’s strange. Should definitely work. When re-saving for any API version \>= 23 the Projucer will add extra code to your app’s main java file, so make sure you are really using the Projucer to re-save after changing the API version.

> [@leehu](#):
>
> It seems that MIDI have been available from 3.1

Can you point me to any website that Android has support for midi prior to SDK version 23. This [page](https://developer.android.com/reference/android/media/midi/package-summary.html) states that SDK version 23 is required.

You can use [this sample code](https://github.com/googlesamples/android-MidiSynth) from google to test midi connectivity. Or re-target the JuceDemo to API version 23, enable bluetooth permissions and then go to the audio settings page in the JuceDemo to select your midi input. You can then use the synthesiser example to play some notes.

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [October 3, 2017, 8:15am UTC](https://forum.juce.com/t/midi-over-usb/24460/13 "2017-10-03T08:15:56Z")

</div>

thx. i’ll try that. i don’t have bluetooth permission enabled for my app, so I’ll try that too.

This is page I was looking at:  
[https://source.android.com/devices/audio/midi](https://source.android.com/devices/audio/midi)

Maybe I’ve misunderstood something, but this page seems to suggest MIDI is available from 3.1 but new APIs were added from 23 to presumably make things easier for developers. Whilst still on 19 I was running this app:

[https://play.google.com/store/apps/details?id=com.extreamsd.usbmidimonitor&hl=en\_GB](https://play.google.com/store/apps/details?id=com.extreamsd.usbmidimonitor&hl=en_GB)

and it was showing the incoming MIDI from a synth that I had connected via an OTG cable

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [October 3, 2017, 11:25am UTC](https://forum.juce.com/t/midi-over-usb/24460/15 "2017-10-03T11:25:25Z")

</div>

Hi, so found a bug in my MIDI in/out filtering code for Android so now the inputs/outputs are appearing. Opening output is fine, but the call to MidiInput::openDevice() is failing. After looking at the demo code it appears as though this is not called directly but via the DeviceManager so perhaps I should be doing this instead. Seems to work fine for other OSes. Anyway, will try this on Android. thx

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [October 3, 2017, 11:27am UTC](https://forum.juce.com/t/midi-over-usb/24460/16 "2017-10-03T11:27:59Z")

</div>

You may need bluetooth runtime permissions if this is a bluetooth midi device.

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [October 3, 2017, 11:29am UTC](https://forum.juce.com/t/midi-over-usb/24460/17 "2017-10-03T11:29:23Z")

</div>

Not using any bluetooth - this is all direct USB over an OTG cable.

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [October 3, 2017, 11:30am UTC](https://forum.juce.com/t/midi-over-usb/24460/18 "2017-10-03T11:30:43Z")

</div>

Hmmm if it works with the JUCE demo then have a look at how the AudioDeviceManager opens the midi device. There isn’t a whole lot of fancy code there.

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [October 3, 2017, 11:32am UTC](https://forum.juce.com/t/midi-over-usb/24460/19 "2017-10-03T11:32:07Z")

</div>

yeah, just looking at that now - doesn’t seem to be anything special as you say…

---

<div class="post-metadata">

**Author:** ![leehu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leehu/32/3280_2.png) [@leehu](https://forum.juce.com/u/leehu)\
**Post date:** [October 3, 2017, 1:08pm UTC](https://forum.juce.com/t/midi-over-usb/24460/20 "2017-10-03T13:08:08Z")

</div>

Ok, so I think I have a handle on this and why my stuff is not working and the demo does.  
When building a standalone, this code gets executed at startup for OSX and Android:

#if JUCE\_IOS || JUCE\_ANDROID  
void timerCallback() override  
{  
auto newMidiDevices = MidiInput::getDevices();

…  
for (auto& newDevice : newMidiDevices)  
if (! lastMidiDevices.contains (newDevice))  
deviceManager.setMidiInputEnabled (newDevice, true);  
}  
#endif

It opens all the MIDI devices it can find. Any calls to MidiInput::OpenDevice() on Android will then fail - seems to be ok on iOS - maybe this is because iOS MIDI is mulit-ported like OSX and Android isn’t like Windows? Anyway, I commented out this code and my code now works as expected. So it seems on Android that we have to go through the DeviceManager created at startup. As the JuceDemo is not running the standalone code, it does not see this issue.

I’m not sure how to get hold of the DeviceManager class that lives inside the standalone filter window from my plugin inside my code to use it - can you tell me how?

I guess ideally, if we want to manage MIDI devices ourselves, without using the DeviceManager class, it would be nice to be able to tell the Android build not to go and open all the MIDI input devices at startup so that the rest the same behaviour is seen across all platforms. Or maybe there’s a call on DeviceManager to tell it to close everything - haven’t checked yet

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [October 3, 2017, 2:03pm UTC](https://forum.juce.com/t/midi-over-usb/24460/21 "2017-10-03T14:03:40Z")

</div>

> [@leehu](#):
>
> maybe this is because iOS MIDI is mulit-ported like OSX and Android isn’t like Windows

Yes that’s spot on. I forgot about that. We had a similar issue with ROLI’s NOISE app on Android: you can only open midi devices once.

So the standalone target is a simple standalone app to get you going quickly. It will simply connect all midi devices to your `AudioProcessor` - so without even opening any MidiDevices in your own code, you should be getting the midi into your `AudioProcessor` via the `processBlock` callback. You don’t need to use any AudioDeviceManager or anything. Check-out the JuceDemoPlugin or the AUv3Synth samples.

If you need something more custom [1] then you may need to roll your own custom app for your plugin. See option number 2 in this post for more information:

> [@Styling the Standalone plugin window?](https://forum.juce.com/t/styling-the-standalone-plugin-window/21872/15):
>
> There are two approaches here that you could do: you use the standalone app that JUCE already provides for you. Then you don’t need any macros etc. This is the approach that JUCE’s audio plugin demo uses. If you want different behaviour in your standalone app (compared to your plug-in), you can use: PluginHostType::getPluginLoadedAs() == AudioProcessor::wrapperType\_Standalone For example, you could use this in a parentHierarchyChanged callback in your plug-ins editor to change the window st…

[1] Let us know why the midi handling of the default standalone target app does not work for you. Maybe we can add it to JUCE.

[Next page](https://forum.juce.com/t/midi-over-usb/24460.md?page=2)
