Re: MidiNotification help
Re: MidiNotification help
- Subject: Re: MidiNotification help
- From: Philippe Wicker <email@hidden>
- Date: Mon, 20 Jan 2003 22:30:59 +0100
On Monday, January 20, 2003, at 12:01 PM, stephane - la poste wrote:
>
Ok, I think it's the way, but moreover this, there is a hole
>
somewhere...
>
- preliminary document don't talk about the "additional data"
>
structures...
>
- online doc (CoreMidi v1.3 ?) give a little help with infos about new
>
constants, but in my switch, none are catched !!!
The constants you need are defined in "CoreMIDI/MIDIServices.h" (line
512).
To set up a list of all MIDI endpoints available in your system you
need to proceed in 2 steps:
1. Get the endpoints that have been created **before** you created your
MIDIClient. This is the case for devices created by MIDI drivers, but
also for virtual endpoints created by some other application before. To
do this, you can use a code like the following C++ snippet:
// Get number of sources and destinations in the system
int src_endpoints_nmb = MIDIGetNumberOfSources() ;
int sdst_endpoints_nmb = MIDIGetNumberOfDestinations() ;
// Gather source endpoints reference
for (int each=0; each< src_endpoints_nmb; ++each) {
MidiEndpointRef ep_ref = MIDIGetSource(each) ;
// Here your code to save the reference
}
// Gather destination endpoints reference
for (int each=0; each< dst_endpoints_nmb; ++each) {
MidiEndpointRef ep_ref = MIDIGetDestination(each) ;
// Here your code to save the reference
}
application before. To do this, you can use a code like the following
snippet:
2. Optional (only if you want to dynamically record creation/deletion
of endpoints, I encourage you to do so because because then MIDI
applications can be launched in any order): install a MIDINotifyProc
callback and check for the message ID (just as you wrote in your
posting) . Here is a piece of code from my own application:
void
AT_MidiClient::MidiNotifyProc(const MIDINotification* message)
{
if (message->messageID == kMIDIMsgObjectAdded) {
MIDIObjectAddRemoveNotification*
msg = MIDIObjectAddRemoveNotification*)message ;
if (msg->childType == kMIDIObjectType_Source) {
// Here your code to save the new source ref
// and update your internal "clients" (eg
// update a popup menu, a list, ...)
}
if (msg->childType == kMIDIObjectType_Destination) {
// Here your code to save the new destination ref
// and update your internal "clients"
}
.....
}
else if (message->messageID == kMIDIMsgObjectRemoved) {
MIDIObjectAddRemoveNotification*
msg = (MIDIObjectAddRemoveNotification*)message ;
MIDIEndpointRef endpoint_ref = (MIDIEndpointRef)msg->child ;
if (msg->childType == kMIDIObjectType_Source) {
// Here your code to remove the source ref
// and update your internal "clients"
}
if (msg->childType == kMIDIObjectType_Destination) {
// Here your code to remove the destination ref
// and update your internal "clients"
}
.....
}
else if (message->messageID == kMIDIMsgPropertyChanged) {
// Currently ignored
}
else if (message->messageID == kMIDIMsgThruConnectionsChanged) {
// Currently ignored
}
else if (message->messageID == kMIDIMsgSerialPortOwnerChanged) {
// Currently ignored
}
}
In your case, I suspect that you did not caught any notification
because all the endpoints had all been created before you launched your
app.
To debug your code, I encourage you to use the valuable though free
tool developed by Kurt Revis (MIDI Monitor, downloadable on his web
site). You can also create virtual endpoints in your own app, they will
appear in notification messages to your MIDIClient.
Regards.
Philippe Wicker
email@hidden
_______________________________________________
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.