on 3/19/08 3:46 PM, Devon McDormand <[EMAIL PROTECTED]> wrote:

> The archives from June 2007 had a thread entitled "Device disconnected while
> playing".  The original problem: "We are trying to get a notification when the
> current MIDI device gets disconnected."   Roger said they look into it, and
> suggested where they should look, and what they might look for.
> 
> Notification on disconnect is of interest to me, so I took a quick look, and
> sure enough, code I insert into the MIM_CLOSE case in winmm_in_callback() from
> pmwinmm.c gets run shortly after I disconnect or power down a USB midi device.
> Before I decide how I'm going to make it so this notification is passed back
> to my client application, I want to make sure I can catch this same situation
> on OSX.  I've found reference to a constant
> "kAudioDevicePropertyDeviceIsAlive" but being completely unfamiliar with
> CoreMIDI, I don't yet know how to make use of this tiny nugget of information.
> Any suggestions?

I've used CoreMIDI in limited ways only, but knew vaguely where to look.

Before creating input/output ports it is necessary to call MIDIClientCreate
which specifies a device notification proc, which can receive the following
notifications (from the headers, but not the latest version):



/*
    @enum        MIDINotificationMessageID
    @abstract    Signifies the type of a MIDINotification.

    @constant    kMIDIMsgSetupChanged    Some aspect of the current
MIDISetup
                                        has changed.  No data.  Should
ignore this
                                        message if messages 2-6 are handled.
    @constant    kMIDIMsgObjectAdded        A device, entity or endpoint was
added.
                                        Structure is
MIDIObjectAddRemoveNotification.
                                        New for CoreMIDI 1.3.
    @constant    kMIDIMsgObjectRemoved    A device, entity or endpoint was
removed.
                                        Structure is
MIDIObjectAddRemoveNotification.
                                        New for CoreMIDI 1.3.
    @constant    kMIDIMsgPropertyChanged    An object's property was
changed.
                                        Structure is
MIDIObjectPropertyChangeNotification.
                                        New for CoreMIDI 1.3.
    @constant    kMIDIMsgThruConnectionsChanged    A persistent MIDI Thru
connection was created
                                        or destroyed.  No data.  New for
CoreMIDI 1.3.
    @constant    kMIDIMsgSerialPortOwnerChanged    A persistent MIDI Thru
connection was created
                                        or destroyed.  No data.  New for
CoreMIDI 1.3.
    @constant    kMIDIMsgIOError            A driver I/O error occurred.

*/
enum {    // MIDINotificationMessageID
    kMIDIMsgSetupChanged            = 1,
    kMIDIMsgObjectAdded                = 2,
    kMIDIMsgObjectRemoved            = 3,
    kMIDIMsgPropertyChanged            = 4,
    kMIDIMsgThruConnectionsChanged    = 5,
    kMIDIMsgSerialPortOwnerChanged    = 6,
    kMIDIMsgIOError                    = 7
};
typedef SInt32            MIDINotificationMessageID;



So I suspect you want to look for kMIDIMsgObjectRemoved, rather than polling
for kAudioDevicePropertyDeviceIsAlive (which I didn't look at).

The device notify proc is a MIDINotifyProc which takes a MIDINotification*
argument.  MIDINotification is a struct with a MIDINotificationMessageID
field.

See MIDIServices.h

HTH,
Kurt


_______________________________________________
media_api mailing list
[email protected]
http://lists.create.ucsb.edu/mailman/listinfo/media_api

Reply via email to