Many applications will want to display a list of MIDI sources and/or destinations from which a user may choose. The following shows simple code for populating an NSPopUpButton with a list of MIDI sources.
- (void)buildPopUp
{
PYMIDIManager* manager = [PYMIDIManager sharedInstance];
[myPopUp removeAllItems];
NSArray* endpointArray = [manager realSources];
NSEnumerator* enumerator = [endpointArray objectEnumerator];
PYMIDIEndpoint* endpoint;
while (endpoint = [enumerator nextObject]) {
[myPopUp addItemWithTitle:[endpoint displayName]];
[[myPopUp lastItem] setRepresentedObject:endpoint];
}
}
To do the same for desinations, simply replace the
[manager realSources] call with
[manager realDestinations].
Note that [[myPopUp selectedItem] representedObject] can
be used to return the currently selected endpoint.
You should also register to receive PYMIDISetupChanged
notifications and call your buildPopUp method whenever
the setup changes to display the currently available endpoints.