Re: User presentation of device names in Jaguar
Re: User presentation of device names in Jaguar
- Subject: Re: User presentation of device names in Jaguar
- From: Pete Yandell <email@hidden>
- Date: Thu, 1 May 2003 11:48:55 +1000
From the official Apple documentation at
file:///Developer/Documentation/CoreAudio/MIDI/Topics/appnotes.html :
Display of endpoint names
Here is the recommended algorithm for display of a MIDIEndpointRef 's
name.
Get the endpoint's kMIDIPropertyConnectionUniqueID property.
If the endpoint has exactly one connected external device, display the
external device's name.
If the endpoint has multiple connected external devices, there are
several possibilities depending on the context:
- Attempt to choose exactly one device to display (e.g. if the context
involves events on only one MIDI channel, and only one of the devices
receives on that channel, it's clearly reasonable to display only that
device)
- Concatenate the names of all of the devices, separated by commas
(some special characters such as slashes and dashes are common in
device names)
- Display the physical MIDI port's name (as below)
If an endpoint has no connected external devices, display the
endpoint's name, which will normally be inherited from its entity's
name:
- If the name obtained in this manner is an empty string, use
MIDIEntityGetDevice to obtain the device and use the device's name.
(This works around a bug in some versions of the AppleMIDIUSB driver.)
- If the name obtained in this manner is not unique among the other
sources or destinations in the system, or, if your application has
sufficient screen space to display long names, prepend the device's
name and a space to the endpoint's name.
And here's the code from my PYMIDI framework (available at
http://pete.yandell.com/software/) to do it. I go with sticking
together all the external device names, and I also always prepend the
device name to the endpoint name.
CFStringRef deviceName = nil;
MIDIEntityRef entityRef;
result = MIDIEndpointGetEntity (midiEndpointRef, &entityRef);
if (result == noErr) {
MIDIDeviceRef deviceRef;
result = MIDIEntityGetDevice (entityRef, &deviceRef);
if (result == noErr) {
result = MIDIObjectGetStringProperty (deviceRef,
kMIDIPropertyName, &deviceName);
}
}
CFStringRef endpointName;
result = MIDIObjectGetStringProperty (midiEndpointRef,
kMIDIPropertyName, &endpointName);
if (deviceName != nil &&
CFStringCompare (deviceName, endpointName,
kCFCompareCaseInsensitive) != kCFCompareEqualTo)
{
name = [[NSString alloc] initWithFormat:@"%@ %@", deviceName,
endpointName];
}
else {
name = [[NSString alloc]
initWithString:(NSString*)endpointName];
}
if (deviceName != nil) CFRelease (deviceName);
CFRelease (endpointName);
NSString* displayName;
CFDataRef externalIDs;
OSStatus result;
NSMutableArray* names = [NSMutableArray arrayWithCapacity:0];
// Pull in a list of external devices connected to our endpoint
result = MIDIObjectGetDataProperty (
midiEndpointRef, kMIDIPropertyConnectionUniqueID, &externalIDs
);
// If we do have external devices, grab all their names and glue
them together
if (result == noErr) {
int i;
for (i = 0; i < CFDataGetLength (externalIDs); i += 4) {
SInt32 externalID;
CFDataGetBytes (externalIDs, CFRangeMake (i, 4),
(UInt8*)&externalID);
if (externalID != 0) {
MIDIObjectRef externalDevice;
MIDIObjectType deviceType;
result = MIDIObjectFindByUniqueID (externalID,
&externalDevice, &deviceType);
CFStringRef externalName;
result = MIDIObjectGetStringProperty (externalDevice,
kMIDIPropertyName, &externalName);
[names addObject:[NSString
stringWithString:(NSString*)externalName]];
CFRelease (externalName);
}
}
CFRelease (externalIDs);
}
if ([names count] > 0)
displayName = [names componentsJoinedByString:@", "];
else
displayName = name;
return displayName;
Yes, there are places in here where I really should do a little more
error checking.
And can I just say what an incredible amount of pain is required to do
something that just about every MIDI app needs to do. Why isn't there a
CoreMIDI function that does all this hard work for us?
Pete Yandell
http://pete.yandell.com/
On Thursday, May 1, 2003, at 12:52 AM, Cianflone, Chris wrote:
>
So did we ever get confirmation on what we are supposed to do? I see
>
a lot
>
of apps behaving differently than ours. It looks like it is not good
>
enough
>
to iterate through destinations, for example, via
>
MIDIGetNumberOfDestinations()/MIDIGetDestination() and get a name via
>
kMIDIPropertyName.
>
>
> ----------
>
> From: Pete Yandell
>
> Sent: Tuesday, September 17, 2002 11:09 PM
>
> To: email@hidden
>
> Subject: User presentation of device names in Jaguar
>
>
>
> Some questions for discussion:
>
>
>
> Now that Jaguar has this lovely Audio MIDI Setup app and users can
>
> create and name external devices, how should MIDI port selection in
>
> apps be handled? Just using the endpoint name gives the name of the
>
> MIDI interface and port, but not the name of any external device
>
> connected to it? Is there an easy way to retrieve and display this
>
> information?
>
>
>
> Secondly, what's considered correct behaviour when the user moves an
>
> external device from one MIDI port to another. Should apps configured
>
> to talk to the original port notice the device has moved and start
>
> piping data to the new port?
>
>
>
> Pete Yandell
>
> http://pete.yandell.com/
>
> _______________________________________________
>
> coreaudio-api mailing list | email@hidden
>
> Help/Unsubscribe/Archives:
>
> http://www.lists.apple.com/mailman/listinfo/coreaudio-api
>
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.