AU Support for begin and end gesture


#1

Hi Jules, I’ve added support for begin and end gesture in AudioUnitPluginFormat. Here are the changes in case you’d like to integrate them. Notably, the Apple documentation states that the run loop and run loop mode can be passed in as null (as you were doing with AUListenerCreate), however providing either or both as null returned a parameter error so I explicitly passed in the defaults instead.

CHANGES:

Replace member “AUParameterListenerRef parameterListenerRef;” with “AUEventListenerRef eventListenerRef;”

In setPluginCallbacks(), replace the old “AUListenerCreate” and it’s supporting code with “AUEventListenerCreate” and it’s supporting code

            AUEventListenerCreate(eventListenerCallback, this, (CFRunLoopRef)GetCFRunLoopFromEventLoop(GetCurrentEventLoop()), kCFRunLoopDefaultMode, 0, 0, &eventListenerRef);
            
            for (int i = 0; i < parameters.size(); ++i)
            {
                const ParamInfo& p = *parameters.getUnchecked(i);
                
                AudioUnitParameter paramToAdd;
                paramToAdd.mAudioUnit = audioUnit;
                paramToAdd.mParameterID = p.paramID;
                paramToAdd.mScope = kAudioUnitScope_Global;
                paramToAdd.mElement = 0;
                
                AudioUnitEvent event;
                event.mArgument.mParameter = paramToAdd;

                event.mEventType = kAudioUnitEvent_ParameterValueChange;
                AUEventListenerAddEventType(eventListenerRef, nullptr, &event);
                
                event.mEventType = kAudioUnitEvent_BeginParameterChangeGesture;
                AUEventListenerAddEventType(eventListenerRef, nullptr, &event);
                
                event.mEventType = kAudioUnitEvent_EndParameterChangeGesture;
                AUEventListenerAddEventType(eventListenerRef, nullptr, &event);
                
            }

Replace “parameterListenerCallback” with “eventListenerCallback”

    static void eventListenerCallback (void * inUserData, void * inObject, const AudioUnitEvent * inEvent, UInt64 inEventHostTime,AudioUnitParameterValue inParameterValue) {
        ((AudioUnitPluginInstance*) inUserData)->eventOccured(inEvent, inParameterValue);
    }

Replace “parameterChanged” with “eventOccured”

    void eventOccured (const AudioUnitEvent* event, float newValue)
    {
        
        switch (event->mEventType) {
                
            case kAudioUnitEvent_ParameterValueChange:
                for (int i = 0; i < parameters.size(); ++i)
                {
                    const ParamInfo& p = *parameters.getUnchecked(i);
                    
                    if (p.paramID == event->mArgument.mParameter.mParameterID)
                    {
                        sendParamChangeMessageToListeners (i, (newValue - p.minValue) / (p.maxValue - p.minValue));
                        break;
                    }
                }
                
                break;
            case kAudioUnitEvent_BeginParameterChangeGesture:
                beginParameterChangeGesture(event->mArgument.mParameter.mParameterID);
                break;
            case kAudioUnitEvent_EndParameterChangeGesture:
                endParameterChangeGesture(event->mArgument.mParameter.mParameterID);
                break;
                
        }
        
    }

#2

Cool stuff, thanks! Will have a look at that later today!