static String getConnectedEndpointName (MIDIEndpointRef endpoint) { String result; // Does the endpoint have connections? CFDataRef connections = nullptr; int numConnections = 0; MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections); if (connections != nullptr) { numConnections = ((int) CFDataGetLength (connections)) / (int) sizeof (MIDIUniqueID); if (numConnections > 0) { const SInt32* pid = reinterpret_cast<const SInt32*> (CFDataGetBytePtr (connections)); for (int i = 0; i < numConnections; ++i, ++pid) { MIDIUniqueID uid = (MIDIUniqueID) ByteOrder::swapIfLittleEndian ((uint32) *pid); MIDIObjectRef connObject; MIDIObjectType connObjectType; OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType); if (err == noErr) { String s; if (connObjectType == kMIDIObjectType_ExternalSource || connObjectType == kMIDIObjectType_ExternalDestination) { // Connected to an external device's endpoint (10.3 and later). s = getEndpointName (static_cast<MIDIEndpointRef> (connObject), true); } else { // Connected to an external device (10.2) (or something else, catch-all) s = getMidiObjectName (connObject); } if (s.isNotEmpty()) { if (result.isNotEmpty()) result += ", "; result += s; } } } } CFRelease (connections); } if (result.isEmpty()) // Here, either the endpoint had no connections, or we failed to obtain names for them. result = getEndpointName (endpoint, false); return result; }
// Obtain the name of an endpoint, following connections. // The result should be released by the caller. static CFStringRef ConnectedEndpointName(MIDIEndpointRef endpoint) { CFMutableStringRef result = CFStringCreateMutable(NULL, 0); CFStringRef str; OSStatus err; // Does the endpoint have connections? CFDataRef connections = NULL; int nConnected = 0; bool anyStrings = false; err = MIDIObjectGetDataProperty(endpoint, kMIDIPropertyConnectionUniqueID, &connections); if (connections != NULL) { // It has connections, follow them // Concatenate the names of all connected devices nConnected = CFDataGetLength(connections) / sizeof(MIDIUniqueID); if (nConnected) { const SInt32 *pid = reinterpret_cast <const SInt32 *>(CFDataGetBytePtr(connections)); for (int i = 0; i < nConnected; ++i, ++pid) { MIDIUniqueID id = EndianS32_BtoN(*pid); MIDIObjectRef connObject; MIDIObjectType connObjectType; err = MIDIObjectFindByUniqueID(id, &connObject, &connObjectType); if (err == noErr) { if (connObjectType == kMIDIObjectType_ExternalSource || connObjectType == kMIDIObjectType_ExternalDestination) { // Connected to an external device's endpoint (10.3 and later). str = EndpointName(static_cast <MIDIEndpointRef>(connObject), true); } else { // Connected to an external device (10.2) (or something else, catch-all) str = NULL; MIDIObjectGetStringProperty(connObject, kMIDIPropertyName, &str); } if (str != NULL) { if (anyStrings) CFStringAppend(result, CFSTR(", ")); else anyStrings = true; CFStringAppend(result, str); CFRelease(str); } } } } CFRelease(connections); } if (anyStrings) return result; // Here, either the endpoint had no connections, or we failed to obtain names for any of them. return EndpointName(endpoint, false); }
void CAMIDIEndpoints::AddEndpoints(MIDIEndpointRef endpoint, EndpointList &eplist) { Endpoint *ep, *prev; OSStatus err; CFStringRef str; // Add the driver-owned endpoint ep = new Endpoint(endpoint, EndpointName(endpoint, false), NULL); eplist.push_back(ep); prev = ep; // Does the endpoint have connections? CFDataRef connections = NULL; int nConnected = 0; MIDIObjectGetDataProperty(endpoint, kMIDIPropertyConnectionUniqueID, &connections); if (connections != NULL) { // It has connections, follow them nConnected = CFDataGetLength(connections) / sizeof(MIDIUniqueID); if (nConnected) { const SInt32 *pid = reinterpret_cast <const SInt32 *>(CFDataGetBytePtr(connections)); for (int i = 0; i < nConnected; ++i, ++pid) { MIDIUniqueID id = 0;//EndianS32_BtoN(*pid); MIDIObjectRef connObject; MIDIObjectType connObjectType; err = MIDIObjectFindByUniqueID(id, &connObject, &connObjectType); if (err == noErr) { if (connObjectType == kMIDIObjectType_ExternalSource || connObjectType == kMIDIObjectType_ExternalDestination) { // Connected to an external device's endpoint (10.3 and later). str = EndpointName(static_cast <MIDIEndpointRef>(connObject), true); } else { // Connected to an external device (10.2) (or something else, catch-all) str = NULL; MIDIObjectGetStringProperty(connObject, kMIDIPropertyName, &str); } if (str != NULL) { ep = new Endpoint(endpoint, str, connObject); eplist.push_back(ep); prev->SetNext(ep); prev = ep; } } } } } }
const String getConnectedEndpointName (MIDIEndpointRef endpoint) { String result; // Does the endpoint have connections? CFDataRef connections = 0; int numConnections = 0; MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections); if (connections != 0) { numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID)); if (numConnections > 0) { const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections)); for (int i = 0; i < numConnections; ++i, ++pid) { MIDIUniqueID uid = EndianS32_BtoN (*pid); MIDIObjectRef connObject; MIDIObjectType connObjectType; OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType); if (err == noErr) { String s; if (connObjectType == kMIDIObjectType_ExternalSource || connObjectType == kMIDIObjectType_ExternalDestination) { // Connected to an external device's endpoint (10.3 and later). s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true); } else { // Connected to an external device (10.2) (or something else, catch-all) CFStringRef str = 0; MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str); if (str != 0) { s = PlatformUtilities::cfStringToJuceString (str); CFRelease (str); } } if (s.isNotEmpty()) { if (result.isNotEmpty()) result += ", "; result += s; } } } } CFRelease (connections); } if (result.isNotEmpty()) return result; // Here, either the endpoint had no connections, or we failed to obtain names for any of them. return getEndpointName (endpoint, false); }