This function was submitted by Douglas Casey Tucker and apparently derived largely from PortMidi.
| 1177 | // This function was submitted by Douglas Casey Tucker and apparently |
| 1178 | // derived largely from PortMidi. |
| 1179 | CFStringRef EndpointName( MIDIEndpointRef endpoint, bool isExternal ) |
| 1180 | { |
| 1181 | CFMutableStringRef result = CFStringCreateMutable( NULL, 0 ); |
| 1182 | CFStringRef str; |
| 1183 | |
| 1184 | // Begin with the endpoint's name. |
| 1185 | str = NULL; |
| 1186 | MIDIObjectGetStringProperty( endpoint, kMIDIPropertyName, &str ); |
| 1187 | if ( str != NULL ) { |
| 1188 | CFStringAppend( result, str ); |
| 1189 | CFRelease( str ); |
| 1190 | } |
| 1191 | |
| 1192 | // some MIDI devices have a leading space in endpoint name. trim |
| 1193 | CFStringRef space = CFStringCreateWithCString(NULL, " ", kCFStringEncodingUTF8); |
| 1194 | CFStringTrim(result, space); |
| 1195 | CFRelease(space); |
| 1196 | |
| 1197 | MIDIEntityRef entity = 0; |
| 1198 | MIDIEndpointGetEntity( endpoint, &entity ); |
| 1199 | if ( entity == 0 ) |
| 1200 | // probably virtual |
| 1201 | return result; |
| 1202 | |
| 1203 | if ( CFStringGetLength( result ) == 0 ) { |
| 1204 | // endpoint name has zero length -- try the entity |
| 1205 | str = NULL; |
| 1206 | MIDIObjectGetStringProperty( entity, kMIDIPropertyName, &str ); |
| 1207 | if ( str != NULL ) { |
| 1208 | CFStringAppend( result, str ); |
| 1209 | CFRelease( str ); |
| 1210 | } |
| 1211 | } |
| 1212 | // now consider the device's name |
| 1213 | MIDIDeviceRef device = 0; |
| 1214 | MIDIEntityGetDevice( entity, &device ); |
| 1215 | if ( device == 0 ) |
| 1216 | return result; |
| 1217 | |
| 1218 | str = NULL; |
| 1219 | MIDIObjectGetStringProperty( device, kMIDIPropertyName, &str ); |
| 1220 | if ( CFStringGetLength( result ) == 0 ) { |
| 1221 | CFRelease( result ); |
| 1222 | return str; |
| 1223 | } |
| 1224 | if ( str != NULL ) { |
| 1225 | // if an external device has only one entity, throw away |
| 1226 | // the endpoint name and just use the device name |
| 1227 | if ( isExternal && MIDIDeviceGetNumberOfEntities( device ) < 2 ) { |
| 1228 | CFRelease( result ); |
| 1229 | return str; |
| 1230 | } else { |
| 1231 | if ( CFStringGetLength( str ) == 0 ) { |
| 1232 | CFRelease( str ); |
| 1233 | return result; |
| 1234 | } |
| 1235 | // does the entity name already start with the device name? |
| 1236 | // (some drivers do this though they shouldn't) |
no outgoing calls
no test coverage detected