I want to make sure I understand the behavior of what happens when a physical MIDI device is unplugged between a call to MIDIGetNumberOfDestinations() and MIDIGetDestination().
My assumption has been that that MIDIGetDestination is range checked and that a NULL value will be returned for an index that is now out of range.
ItemCount ndest = MIDIGetNumberOfDestinations();
MIDIEndpointRef endpoint = NULL;
CFStringRef stringProp = NULL;
for( ItemCount i = 0; ItemCount < ndest; ++i ) {
// before we got here for one of out valid i's
// the MIDI device was unplugged
endpoint = MIDIGetDestination( i );
// Get NULL for index out of range
if( endpoint != NULL ) {
stringProp == NULL
MIDIObjectGetStringProperty( endpoint, kMIDIPropertyDisplayName, &stringProp );
// disconnect occurred between getting destination and property
if( stringProp != NULL ) {
CFShow( stringProp );
CFRelease( stringProp );
}
}
}
That being said... what if the removal is processed between MIDIGetDestination and MIDIObjectGetStringProperty? Since as far as I can tell, MIDIEndpointRef instances are not reference counted.. how can I be sure this call will work? or what CoreMIDI facility gaurantees that a physical enpoint being removed will