|
There are three different types of events that can fall into the
The This new API also provides a universal notification of signaling begin or end parameter change gestures. An example of a gesture would be a user clicking and dragging a slider on an UI. The begin gesture in this case would be the users first click, whereas the end gesture would be when the user releases the mouse button. This is much like Carbon mouse click events, but now a developer can expand the definition of gestures to events other than just mouse clicks (such as pressing a key on the keyboard). AudioUnitEvents and AUEventListenersAudio Unit Events are comprised of an AudioUnitEventType and possibly an argument, which can refer to either an AudioUnitParameter or an AudioUnitProperty. Listing 1: The AudioUnitEvent struct as defined in AudioUnitUtilities.h typedef struct AudioUnitEvent { AudioUnitEventType mEventType; union { AudioUnitParameter mParameter; AudioUnitProperty mProperty; } mArgument; } AudioUnitEvent; An Listing 2: AudioUnitEventType as defined in AudioUnitUtilities.h typedef UInt32 AudioUnitEventType; enum { kAudioUnitEvent_ParameterValueChange = 0, kAudioUnitEvent_BeginParameterChangeGesture = 1, kAudioUnitEvent_EndParameterChangeGesture = 2, kAudioUnitEvent_PropertyChange = 3 }; Listeners can be created to monitor changes in the parameters or properties of an Audio Unit. The After the event listener is created, you may add events it will listen for by using Listing 3: The AUEventListenerProc callback as defined in AudioUnitUtilities.h typedef void (*AUEventListenerProc) (void * inCallbackRefCon, void * inObject, const AudioUnitEvent * inEvent, UInt64 inEventHostTime, Float32 inParameterValue); Listing 4: AUListenerCreate declaration as defined in AudioUnitUtilities.h extern OSStatus AUListenerCreate(AUParameterListenerProc inProc, void *inRefCon, CFRunLoopRef inRunLoop, CFStringRef inRunLoopMode, Float32 inNotificationInterval, AUParameterListenerRef *outListener); Listing 5: Creating an Audio Unit Event Listener OSStatus createListener(){ OSStatus result = noErr; AudioUnitProperty myProperty; AudioUnitEvent myPropertyEvent; AUEventListenerRef MyListener; //this may be a run loop of your choosing CFRunLoopRef runLoop = (CFRunLoopRef)GetCFRunLoopFromEventLoop(GetCurrentEventLoop()); CFStringRef loopMode = kCFRunLoopDefaultMode; myPropertyEvent.mEventType = kAudioUnitEvent_PropertyChange; myPropertyEvent.mArgument.mProperty = myProperty; AUEventListenerCreate(MyPropertyListener, NULL, runLoop, loopMode, 100, 100, &MyListener); AUEventListenerAddEventType(MyListener, NULL, &myPropertyEvent ); return result; } Handling Parameter ChangesAudio Unit parameters are used to modify the behavior of the rendering process of an Audio Unit. Parameters can be used to modify volume, gain, delay and many other behaviors that would have an effect on an Audio Unit. These changes are often applied in real time and notifications of these changes can be sent and received through an Parameter change notifications can be sent by an Audio Unit or host using The Listing 6: Short example of creating an AudioUnitEvent (Parameter Change) and notifying AUEventListener AudioUnitEvent myEvent; myEvent.mEventType = kAudioUnitEvent_ParameterValueChange; myEvent.mArgument.mParameter.mAudioUnit = myAudioUnit; myEvent.mArgument.mParameter.mParameterID = parameterID; myEvent.mArgument.mParameter.mScope = kAudioUnitScope_Global; myEvent.mArgument.mParameter.mElement = 0; AUEventListenerNotify(NULL, NULL, &myEvent); Handling Property ChangesProperties represent a general and extensible mechanism for passing information to and from Audio Units. The type of information passed by properties can be managed by listening for AudioUnitEvents. Actions both internal and external to an Audio Unit can change a property's value. For instance, an output audio unit that tracks the device that a user chooses in the Sound Preferences pane is the Default Output Unit. The device can be changed at any time through user interaction. If a program has an instance of the Property change notifications can be implemented by using an Listing 7: Short example of creating an AudioUnitEvent (Property Change) and notifying AUEventListener AudioUnitEvent myEvent; myEvent.mEventType = kAudioUnitEvent_PropertyChange; myEvent.mArgument.mProperty.mAudioUnit = myAudioUnit; myEvent.mArgument.mProperty.mPropertyID = PropertyID; myEvent.mArgument.mProperty.mScope = kAudioUnitScope_Global; myEvent.mArgument.mProperty.mElement = 0; AUEventListenerNotify(NULL, NULL, &myEvent); Notifications of begin/end gesturesAudio Units have a general method of sending begin and end gesture notifications. Begin and end gesture notifications send a signal to say that a parameter is about to be changed or has finished changing. This enables both Carbon and Cocoa UIs to send and receive these types of event notifications from user interactions, then decide what to do with that information. This new mechanism generalizes the definition of gestures so that any interaction with the GUI can be interpreted as a gesture, therefore removing the limitation of mouse clicks (mouse up, mouse down) as the only valid gesture that can be interpreted. This will eventually deprecate the Carbon view events For example, a user may want to click and drag a parameter button on an Audio Unit's GUI to change its value. The UI can be made to react to the user's selection by changing the button color to provide feedback to the user that a parameter value is about to be changed. After the parameter button is released, an end parameter change gesture notification can be sent out to revert the button color. Begin and end gesture notifications have no data associated with them. Using Listing 8: Short example of managing parameter value changes using begin & end gestures void CreateAudioUnitEventForParameterID(AudioUnitEvent *myEvent, AudioUnitParameterID parameterID){ myEvent->mArgument.mParameter.mAudioUnit = myAudioUnit; myEvent->mArgument.mParameter.mParameterID = parameterID; myEvent->mArgument.mParameter.mScope = kAudioUnitScope_Global; myEvent->mArgument.mParameter.mElement = 0; } void HandleMouseDown(AudioUnitEvent *myEvent){ myEvent->mEventType = kAudioUnitEvent_BeginParameterChangeGesture; AUEventListenerNotify(NULL, NULL, myEvent); } void HandleParameterChange(AudioUnitEvent *myEvent){ myEvent->mEventType =kAudioUnitEvent_ParameterValueChange; AUEventListenerNotify(NULL, NULL, myEvent); } void HandleMouseUp(AudioUnitEvent *myEvent){ myEvent->mEventType = kAudioUnitEvent_EndParameterChangeGesture; AUEventListenerNotify(NULL, NULL, myEvent); } SummaryThe ReferencesAudio and MIDI on Mac OS X (May 2001) Document Revision History
Posted: 2005-04-29 |
|