char *mus_midi_describe(void) { int i, n; MIDIDeviceRef dev; CFStringRef cs1, cs2, cs3; char name[64], mfg[64], model[64], all[192]; char *buf; n = MIDIGetNumberOfDevices(); if (n <= 0) buf = (char *)CALLOC(192, sizeof(char)); else buf = (char *)CALLOC(n * 192, sizeof(char)); if (n <= 0) sprintf(buf, "no midi"); else { for (i = 0; i < n; i++) { dev = MIDIGetDevice(i); MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &cs1); MIDIObjectGetStringProperty(dev, kMIDIPropertyManufacturer, &cs2); MIDIObjectGetStringProperty(dev, kMIDIPropertyModel, &cs3); CFStringGetCString(cs1, name, sizeof(name), 0); CFStringGetCString(cs2, mfg, sizeof(mfg), 0); CFStringGetCString(cs3, model, sizeof(model), 0); CFRelease(cs1); CFRelease(cs2); CFRelease(cs3); sprintf(all, "%s (%s): %s\n", name, mfg, model); strcat(buf, all); } } return(buf); }
/* lifted from portmidi */ static char *get_ep_name(MIDIEndpointRef ep) { MIDIEntityRef entity; MIDIDeviceRef device; CFStringRef endpointName = NULL, deviceName = NULL, fullName = NULL; CFStringEncoding defaultEncoding; char* newName; /* get the default string encoding */ defaultEncoding = CFStringGetSystemEncoding(); /* get the entity and device info */ MIDIEndpointGetEntity(ep, &entity); MIDIEntityGetDevice(entity, &device); /* create the nicely formated name */ MIDIObjectGetStringProperty(ep, kMIDIPropertyName, &endpointName); MIDIObjectGetStringProperty(device, kMIDIPropertyName, &deviceName); if (deviceName != NULL) { fullName = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@: %@"), deviceName, endpointName); } else { fullName = endpointName; } /* copy the string into our buffer */ newName = (char*)mem_alloc(CFStringGetLength(fullName) + 1); CFStringGetCString(fullName, newName, CFStringGetLength(fullName) + 1, defaultEncoding); /* clean up */ if (fullName && !deviceName) CFRelease(fullName); return newName; }
static int findLaunchpadPro() { // find the input hardware port for (ItemCount i=0; i < MIDIGetNumberOfSources(); ++i) { MIDIEndpointRef endpoint = MIDIGetSource(i); if (endpoint) { // get the endpoint name (always available) CFStringRef endpointName = NULL; if (noErr != MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &endpointName)) { return -1; } if (CFStringCompare(endpointName, CFSTR("Standalone Port"), kCFCompareCaseInsensitive) == 0) { // found it! open the endpoint. if (noErr != MIDIInputPortCreate(g_client, CFSTR("In"), readProc, NULL, &g_inDevPort)) { return -1; } if (noErr != MIDIPortConnectSource(g_inDevPort, endpoint, NULL)) { return -1; } } } } // now find the output for (ItemCount i=0; i < MIDIGetNumberOfDestinations(); ++i) { MIDIEndpointRef endpoint = MIDIGetDestination(i); if (endpoint) { // get the endpoint name (always available) CFStringRef endpointName = NULL; if (noErr != MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &endpointName)) { return -1; } if (CFStringCompare(endpointName, CFSTR("Standalone Port"), kCFCompareCaseInsensitive) == 0) { // found it! open the endpoint. if (noErr != MIDIOutputPortCreate(g_client, CFSTR("Out"), &g_outDevPort)) { return -1; } g_outDevEndpoint = endpoint; } } } return !(g_inDevPort && g_outDevPort); }
// ____________________________________________________________________________ // Obtain the name of an endpoint without regard for whether it has connections. // The result should be released by the caller. static CFStringRef EndpointName(MIDIEndpointRef endpoint, bool isExternal) { CFMutableStringRef result = CFStringCreateMutable(NULL, 0); CFStringRef str; // begin with the endpoint's name str = NULL; MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &str); if (str != NULL) { CFStringAppend(result, str); CFRelease(str); } MIDIEntityRef entity = NULL; MIDIEndpointGetEntity(endpoint, &entity); if (entity == NULL) // probably virtual return result; if (CFStringGetLength(result) == 0) { // endpoint name has zero length -- try the entity str = NULL; MIDIObjectGetStringProperty(entity, kMIDIPropertyName, &str); if (str != NULL) { CFStringAppend(result, str); CFRelease(str); } } // now consider the device's name MIDIDeviceRef device = NULL; MIDIEntityGetDevice(entity, &device); if (device == NULL) return result; str = NULL; MIDIObjectGetStringProperty(device, kMIDIPropertyName, &str); if (str != NULL) { // if an external device has only one entity, throw away the endpoint name and just use the device name if (isExternal && MIDIDeviceGetNumberOfEntities(device) < 2) { CFRelease(result); return str; } else { // does the entity name already start with the device name? (some drivers do this though they shouldn't) // if so, do not prepend if (CFStringCompareWithOptions(str /* device name */, result /* endpoint name */, CFRangeMake(0, CFStringGetLength(str)), 0) != kCFCompareEqualTo) { // prepend the device name to the entity name if (CFStringGetLength(result) > 0) CFStringInsert(result, 0, CFSTR(" ")); CFStringInsert(result, 0, str); } CFRelease(str); } } return result; }
std::vector<QString> CoreMidiDriver::getOutputPortList() { INFOLOG( "retrieving output list" ); OSStatus err = noErr; std::vector<QString> cmPortList; cmSources = MIDIGetNumberOfSources(); INFOLOG ( "Getting number of MIDI sources . . .\n" ); unsigned i; for ( i = 0; i < cmSources; i++ ) { CFStringRef H2MidiNames; cmH2Src = MIDIGetSource( i ); if ( cmH2Src == NULL ) { ERRORLOG( "Could not open input device" ); } if ( cmH2Src ) { err = MIDIObjectGetStringProperty( cmH2Src, kMIDIPropertyName, &H2MidiNames ); INFOLOG ( "Getting MIDI object string property . . .\n" ); char cmName[ 64 ]; CFStringGetCString( H2MidiNames, cmName, 64, kCFStringEncodingASCII ); INFOLOG ( "Getting MIDI object name . . .\n" ); QString h2MidiPortName = cmName; cmPortList.push_back( h2MidiPortName ); } CFRelease( H2MidiNames ); } return cmPortList; }
QString MidiEnumeratorPrivate::extractName(MIDIEntityRef entity) { qDebug() << Q_FUNC_INFO; CFStringRef str = NULL; QString name; /* Get the name property */ OSStatus s = MIDIObjectGetStringProperty(entity, kMIDIPropertyModel, &str); if (s != 0) { qWarning() << "Unable to get manufacturer for MIDI entity:" << s; } else { /* Convert the name into a QString. */ CFIndex size = CFStringGetLength(str) + 1; char* buf = (char*) malloc(size); if (CFStringGetCString(str, buf, size, kCFStringEncodingISOLatin1)) name = QString(buf); free(buf); CFRelease(str); } return name; }
void setupMIDI(MyMIDIPlayer *player) { MIDIClientRef client; CheckError (MIDIClientCreate(CFSTR("Core MIDI to System Sounds Demo"), MyMIDINotifyProc, player, &client), "Couldn't create MIDI client"); MIDIPortRef inPort; CheckError (MIDIInputPortCreate(client, CFSTR("Input port"), MyMIDIReadProc, player, &inPort), "Couldn't create MIDI input port"); unsigned long sourceCount = MIDIGetNumberOfSources(); printf ("%ld sources\n", sourceCount); for (int i = 0; i < sourceCount; ++i) { MIDIEndpointRef src = MIDIGetSource(i); CFStringRef endpointName = NULL; CheckError(MIDIObjectGetStringProperty(src, kMIDIPropertyName, &endpointName), "Couldn't get endpoint name"); char endpointNameC[255]; CFStringGetCString(endpointName, endpointNameC, 255, kCFStringEncodingUTF8); printf(" source %d: %s\n", i, endpointNameC); CheckError (MIDIPortConnectSource(inPort, src, NULL), "Couldn't connect MIDI port"); } }
bool MIDIDevice::extractName() { CFStringRef str; OSStatus s; /* Get the name property */ s = MIDIObjectGetStringProperty(m_entity, kMIDIPropertyModel, &str); if (s != 0) { qWarning() << "Unable to get manufacturer for MIDI entity:" << s; m_name = tr("Unknown %1").arg(m_uid); } else { /* Convert the name into a QString. */ CFIndex size = CFStringGetLength(str) + 1; char* buf = (char*) malloc(size); if (CFStringGetCString(str, buf, size, kCFStringEncodingISOLatin1)) m_name = QString(buf); else m_name = tr("Unknown %1").arg(m_uid); free(buf); CFRelease(str); } return true; }
static std::string getPropertyAsString(MIDIObjectRef obj, CFStringRef property_id) { CFStringRef cf_str; MIDIObjectGetStringProperty(obj, property_id, &cf_str); std::string str(CFStringGetCStringPtr(cf_str, 0)); CFRelease(cf_str); return str; }
void CoreMidiDriver::open() { INFOLOG( "open" ); OSStatus err = noErr; QString sMidiPortName = Preferences::get_instance()->m_sMidiPortName; cmSources = MIDIGetNumberOfSources(); unsigned i; for ( i = 0; i < cmSources; i++ ) { CFStringRef H2MidiNames; cmH2Src = MIDIGetSource( i ); if ( cmH2Src ) { err = MIDIObjectGetStringProperty( cmH2Src, kMIDIPropertyName, &H2MidiNames ); char cmName[64]; err = CFStringGetCString( H2MidiNames, cmName, 64, kCFStringEncodingASCII ); QString h2MidiPortName = cmName; if ( h2MidiPortName == sMidiPortName ) { MIDIPortConnectSource ( h2InputRef, cmH2Src, NULL ); m_bRunning = true; } } CFRelease ( H2MidiNames ); } int n = MIDIGetNumberOfDestinations(); if (n > 0) { cmH2Dst = MIDIGetDestination(0); } if (cmH2Dst != NULL) { CFStringRef H2MidiNames; MIDIObjectGetStringProperty(cmH2Dst, kMIDIPropertyName, &H2MidiNames); //CFStringGetCString(pname, name, sizeof(name), 0); //MIDIPortConnectSource ( h2OutputRef, cmH2Dst, NULL ); MIDIPortConnectSource ( h2OutputRef, cmH2Dst, NULL ); if( H2MidiNames != NULL){ CFRelease( H2MidiNames ); } } }
const char * MidiIn::getDeviceInName(int index) { static char name[128+1]; MIDIEndpointRef sourceRef = MIDIGetSource(index); CFStringRef displayName; MIDIObjectGetStringProperty(sourceRef, kMIDIPropertyDisplayName, &displayName); CFStringGetCString(displayName, name, 129, kCFStringEncodingUTF8); name[128] = 0; return name; }
CFStringRef MidiDeviceUtil::GetOutDeviceName(int index) { MIDIEndpointRef endpoint = MIDIGetDestination(index); CFStringRef deviceName = NULL; MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &deviceName); return deviceName; }
CFStringRef MidiDeviceUtil::GetInDeviceManufacturer(int index) { MIDIEndpointRef endpoint = MIDIGetSource(index); CFStringRef manufacturer = NULL; MIDIObjectGetStringProperty(endpoint, kMIDIPropertyManufacturer, &manufacturer); return manufacturer; }
void CoreMIDI_GetObjectName(MIDIObjectRef obj, char *name, int size) { OSStatus err = noErr; CFStringRef cfname; err = MIDIObjectGetStringProperty(obj, kMIDIPropertyName, &cfname); if (err == noErr) { CFStringGetCString(cfname, name, size, kCFStringEncodingASCII); CFRelease(cfname); } }
CFStringRef MidiDeviceUtil::GetMidiDeviceName(int index) { MIDIDeviceRef device = GetMidiDevice(index); CFStringRef deviceName = NULL; OSStatus err = MIDIObjectGetStringProperty(device, kMIDIPropertyName, &deviceName); //TODO:Error return deviceName; }
char *getName( MIDIObjectRef &object ) { // Returns the name of a given MIDIObjectRef as char * CFStringRef name = nil; if (noErr != MIDIObjectGetStringProperty(object, kMIDIPropertyName, &name)) return nil; int len = CFStringGetLength(name)+1; char *value = (char *) malloc(len); CFStringGetCString(name, value, len, 0); CFRelease(name); return value; }
static String getMidiObjectName (MIDIObjectRef entity) { String result; CFStringRef str = nullptr; MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str); if (str != nullptr) { result = String::fromCFString (str); CFRelease (str); } 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); }
// ---------------------------------------------------------- vector<string> ofxAudioUnitMidi::getSourceNames() // ---------------------------------------------------------- { vector<string> sourceNames; ItemCount sourceCount = MIDIGetNumberOfSources(); for(int i = 0; i < sourceCount; i++) { MIDIEndpointRef source = MIDIGetSource(i); CFStringRef sourceName = NULL; MIDIObjectGetStringProperty(source, kMIDIPropertyName, &sourceName); char sourceNameCString[255]; CFStringGetCString(sourceName, sourceNameCString, 255, kCFStringEncodingUTF8); sourceNames.push_back(sourceNameCString); } return sourceNames; }
CFStringRef MidiDeviceUtil::GetMidiEndpointName(int deviceIndex, int entityIndex, int sourceIndex) { MIDIEndpointRef endpoint = GetMidiEndpoint(deviceIndex, entityIndex, sourceIndex); CFStringRef endpointName = NULL; OSStatus err = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &endpointName); if (err == 0) { //TODO:Error } return endpointName; }
// Get the name of an endpoint. extern "C" const char* MidiJackGetEndpointName(uint32_t id) { ResetPluginIfRequired(); MIDIObjectRef object; MIDIObjectType type; MIDIObjectFindByUniqueID(id, &object, &type); assert(type == kMIDIObjectType_Source); CFStringRef name; MIDIObjectGetStringProperty(object, kMIDIPropertyDisplayName, &name); static char buffer[256]; CFStringGetCString(name, buffer, sizeof(buffer), kCFStringEncodingUTF8); return buffer; }
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; } } } } } }
PoolStringArray MIDIDriverCoreMidi::get_connected_inputs() { PoolStringArray list; for (int i = 0; i < connected_sources.size(); i++) { MIDIEndpointRef source = connected_sources[i]; CFStringRef ref = NULL; char name[256]; MIDIObjectGetStringProperty(source, kMIDIPropertyDisplayName, &ref); CFStringGetCString(ref, name, sizeof(name), kCFStringEncodingUTF8); CFRelease(ref); list.push_back(name); } return list; }
//_________________________________________________________ // Find the device model associated to a MIDIEndpointRef Boolean GetModel (MIDIEndpointRef device, char* gmodel, int strlen) { int i,j,k, n,m,o,p; MIDIDeviceRef dev; MIDIEntityRef ref; CFStringRef pmodel; OSStatus err; n = MIDIGetNumberOfDevices(); for (i = 0; i < n; i++) { dev = MIDIGetDevice(i); err = MIDIObjectGetStringProperty(dev, kMIDIPropertyModel, &pmodel); if (err == noErr) { if (!CFStringGetCString(pmodel, gmodel, strlen, 0)) { fprintf(stderr, "GetModel error : string too long\n"); return false; } CFRelease(pmodel); m = MIDIDeviceGetNumberOfEntities(dev); for (j = 0; j < m; j++) { ref = MIDIDeviceGetEntity(dev,j); o = MIDIEntityGetNumberOfSources(ref); p = MIDIEntityGetNumberOfDestinations(ref); for (k = 0; k < o; k++) { if (MIDIEntityGetSource(ref,k) == device) return true; } for (k = 0; k < p; k++) { if (MIDIEntityGetDestination(ref,k) == device) return true; } } } } return false; }
// Return an array of all available sources, filled with the names of the sources static VALUE t_get_sources(VALUE self) { int number_of_sources = MIDIGetNumberOfSources(); VALUE source_ary = rb_ary_new2(number_of_sources); int idx; for(idx = 0; idx < number_of_sources; ++idx) { MIDIEndpointRef src = MIDIGetSource(idx); CFStringRef pname; char name[64]; MIDIObjectGetStringProperty(src, kMIDIPropertyName, &pname); CFStringGetCString(pname, name, sizeof(name), 0); CFRelease(pname); rb_ary_push(source_ary, rb_str_new2(name)); } return source_ary; }
// // @see com.sun.media.sound.AbstractMidiDeviceProvider.getDeviceInfo(). static int getEndpointProperty(int direction, INT32 deviceID, char *buffer, int bufferLength, CFStringRef propertyID) { if (deviceID < 0) { return MIDI_INVALID_DEVICEID; } MIDIEndpointRef endpoint; if (direction == MIDI_IN) { endpoint = MIDIGetSource(deviceID); } else if (direction == MIDI_OUT) { endpoint = MIDIGetDestination(deviceID); } else { return MIDI_INVALID_ARGUMENT; } if (!endpoint) { return MIDI_INVALID_DEVICEID; } int status = MIDI_SUCCESS; if (propertyID == kMIDIPropertyDriverVersion) { SInt32 driverVersion; status = MIDIObjectGetIntegerProperty(endpoint, kMIDIPropertyDriverVersion, &driverVersion); if (status != MIDI_SUCCESS) return status; snprintf(buffer, bufferLength, "%d", (int) driverVersion); } else { CFStringRef pname; status = MIDIObjectGetStringProperty(endpoint, propertyID, &pname); if (status != MIDI_SUCCESS) return status; CFStringExtractCString(pname, buffer, bufferLength, 0); } return MIDI_ERROR_NONE; }
int prListMIDIEndpoints(struct VMGlobals *g, int numArgsPushed) { OSStatus error; PyrSlot *a = g->sp; int numSrc = (int)MIDIGetNumberOfSources(); int numDst = (int)MIDIGetNumberOfDestinations(); PyrObject* idarray = newPyrArray(g->gc, 6 * sizeof(PyrObject), 0 , true); SetObject(a, idarray); PyrObject* idarraySo = newPyrArray(g->gc, numSrc * sizeof(SInt32), 0 , true); SetObject(idarray->slots+idarray->size++, idarraySo); g->gc->GCWrite(idarray, idarraySo); PyrObject* devarraySo = newPyrArray(g->gc, numSrc * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, devarraySo); g->gc->GCWrite(idarray, devarraySo); PyrObject* namearraySo = newPyrArray(g->gc, numSrc * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, namearraySo); g->gc->GCWrite(idarray, namearraySo); PyrObject* idarrayDe = newPyrArray(g->gc, numDst * sizeof(SInt32), 0 , true); SetObject(idarray->slots+idarray->size++, idarrayDe); g->gc->GCWrite(idarray, idarrayDe); PyrObject* namearrayDe = newPyrArray(g->gc, numDst * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, namearrayDe); g->gc->GCWrite(idarray, namearrayDe); PyrObject* devarrayDe = newPyrArray(g->gc, numDst * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, devarrayDe); g->gc->GCWrite(idarray, devarrayDe); for (int i=0; i<numSrc; ++i) { MIDIEndpointRef src = MIDIGetSource(i); SInt32 id; MIDIObjectGetIntegerProperty(src, kMIDIPropertyUniqueID, &id); MIDIEntityRef ent; error = MIDIEndpointGetEntity(src, &ent); CFStringRef devname, endname; char cendname[1024], cdevname[1024]; // Virtual sources don't have entities if(error) { MIDIObjectGetStringProperty(src, kMIDIPropertyName, &devname); MIDIObjectGetStringProperty(src, kMIDIPropertyName, &endname); CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8); CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8); } else { MIDIDeviceRef dev; MIDIEntityGetDevice(ent, &dev); MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &devname); MIDIObjectGetStringProperty(src, kMIDIPropertyName, &endname); CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8); CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8); } PyrString *string = newPyrString(g->gc, cendname, 0, true); SetObject(namearraySo->slots+i, string); namearraySo->size++; g->gc->GCWrite(namearraySo, (PyrObject*)string); PyrString *devstring = newPyrString(g->gc, cdevname, 0, true); SetObject(devarraySo->slots+i, devstring); devarraySo->size++; g->gc->GCWrite(devarraySo, (PyrObject*)devstring); SetInt(idarraySo->slots+i, id); idarraySo->size++; CFRelease(devname); CFRelease(endname); } // post("numDst %d\n", numDst); for (int i=0; i<numDst; ++i) { MIDIEndpointRef dst = MIDIGetDestination(i); SInt32 id; MIDIObjectGetIntegerProperty(dst, kMIDIPropertyUniqueID, &id); MIDIEntityRef ent; error = MIDIEndpointGetEntity(dst, &ent); CFStringRef devname, endname; char cendname[1024], cdevname[1024]; // Virtual destinations don't have entities either if(error) { MIDIObjectGetStringProperty(dst, kMIDIPropertyName, &devname); MIDIObjectGetStringProperty(dst, kMIDIPropertyName, &endname); CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8); CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8); } else { MIDIDeviceRef dev; MIDIEntityGetDevice(ent, &dev); MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &devname); MIDIObjectGetStringProperty(dst, kMIDIPropertyName, &endname); CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8); CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8); } PyrString *string = newPyrString(g->gc, cendname, 0, true); SetObject(namearrayDe->slots+namearrayDe->size++, string); g->gc->GCWrite(namearrayDe, (PyrObject*)string); PyrString *devstring = newPyrString(g->gc, cdevname, 0, true); SetObject(devarrayDe->slots+devarrayDe->size++, devstring); g->gc->GCWrite(devarrayDe, (PyrObject*)devstring); SetInt(idarrayDe->slots+idarrayDe->size++, id); CFRelease(devname); CFRelease(endname); } return errNone; }
CFStringRef MIDIClient::getName(MIDIObjectRef obj) { CFStringRef name; MIDIObjectGetStringProperty(obj, kMIDIPropertyName, &name); return name; }
//============================================================================== const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal) { String result; CFStringRef str = 0; MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str); if (str != 0) { result = PlatformUtilities::cfStringToJuceString (str); CFRelease (str); str = 0; } MIDIEntityRef entity = 0; MIDIEndpointGetEntity (endpoint, &entity); if (entity == 0) return result; // probably virtual if (result.isEmpty()) { // endpoint name has zero length - try the entity MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str); if (str != 0) { result += PlatformUtilities::cfStringToJuceString (str); CFRelease (str); str = 0; } } // now consider the device's name MIDIDeviceRef device = 0; MIDIEntityGetDevice (entity, &device); if (device == 0) return result; MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str); if (str != 0) { const String s (PlatformUtilities::cfStringToJuceString (str)); CFRelease (str); // if an external device has only one entity, throw away // the endpoint name and just use the device name if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2) { result = s; } else if (! result.startsWithIgnoreCase (s)) { // prepend the device name to the entity name result = (s + " " + result).trimEnd(); } } return result; }
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); }