Issues with MidiOutput::getDevices


#1

I have a JUCE app that is a standalone wrapping a plugin, via the StandaloneFilterWindow. 

In the app I'm using MidiOutput::getDevices to get a device list. I'm doing this is multiple places in the code. I'm using JUCE 3.1.1 and I'm on Mac OSX 10.9 with xcode 6.1.1. 

When I start my app, the function returns the correct list of devices. When I then quit and start it again, I have a good chance of getting the correct number of devices in the list but for the names, it just says <error> ..... if I have 4 devices then the stringarray has 4x <error> in it. 

When I look at the console I'm seeing this 

10/02/15 20:58:37,224 MIDIServer[55392]: 20:58:37.223 NOTE:      [0x7fff725e5310] MIDIServer.cpp:353: FullInit: MIDIServer [55392] starting; arch=x86_64

And I'm guessing that this happens roughly around the time the getDevices function returns the list with the <error> strings in it. 

Does anyone know what's going on here? 


#2

Haven't seen anything like this myself, but it sounds very much like your drivers that are at fault.

You can see where the "<error>" string comes from - line 180 of juce_mac_CoreMidi.cpp. That means that the OS is returning a null midi endpoint (or the endpoint has no name).. Perhaps because the midi drivers you're using can only support a single client, and it takes a few seconds to disconnect when you kill your app before it can allow another app to reconnect?

You should try debugging through the code down to the OS call level to see if you can spot any clues, but I suspect that this won't be something that is a mistake in juce, or even something that we could add a workaround for.


#3

OK, I investigated some more today and I got a core midi error on line 322 of your code, in MidiOutput::openDevice. In particular, on this line of code:

if (CHECK_ERROR (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))

the actual error reported is 0xffffffce, and from what I can see this is an OSStatus code. I searched around but could not find out what this code actually means... your function uses MIDIGetDestination, and the MIDI Services Reference at 

https://developer.apple.com/library/ios/documentation/CoreMidi/Reference/MIDIServices_Reference/#//apple_ref/c/func/MIDIGetDestination

Says that the return value of that function is "A reference to a destination, or NULL if an error occurred". I'm guessing you are trying to get the name of the device through MIDIObjectGetStringProperty, but perhaps the endPoint parameter is null because that is what MIDIGetDestination returned? It would be very helpful if your code actually printed the error, instead of the 0xffffffce so I would know why exactly the index that I'm passing to openDevice is no longer valid, even though I got it before calling openDevice, using MidiOutput::getDevices() ... 

I kept getting the same error, and I was able to consistently reproduce it, all while only using Apple's IAC ports in osx 10.9. I would start the app, quit and restart and I would have the same problem again. 

So eventually I went into the audio / midi setup dialog on osx. The IAC ports were online (checkbox checked). I then unchecked the device is online checkbox which put the device offline, and then checked it again to bring the device back online. And that solved the problem!

So yes, strictly speaking not your problem, BUT .... if your code would have given me more hints about the actual error codes reported by core midi, and what they mean, then I would have saved myself a day of work :-) 

So it would be great if you could add some functions to the MidiOutput/MidiInput class that would print the actual core midi error as a string instead of just printing an error code. 

I still don't know what exactly put the IAC ports into this state in the first place and why marking them offline and then back online solved the issue.