1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-28 02:30:05 +00:00

AudioUnit hosting: added code to handle plugin latency changes

This commit is contained in:
jules 2016-01-07 09:41:36 +00:00
parent 03dde6a2a8
commit 3bc38d1e3b

View file

@ -445,12 +445,7 @@ public:
(int) (numOutputBusChannels * numOutputBusses),
(double) newSampleRate, estimatedSamplesPerBlock);
Float64 latencySecs = 0.0;
UInt32 latencySize = sizeof (latencySecs);
AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
0, &latencySecs, &latencySize);
setLatencySamples (roundToInt (latencySecs * newSampleRate));
updateLatency();
{
AudioStreamBasicDescription stream;
@ -889,6 +884,16 @@ public:
}
}
void updateLatency()
{
Float64 latencySecs = 0.0;
UInt32 latencySize = sizeof (latencySecs);
AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
0, &latencySecs, &latencySize);
setLatencySamples (roundToInt (latencySecs * getSampleRate()));
}
void handleIncomingMidiMessage (void*, const MidiMessage& message)
{
const ScopedLock sl (midiInLock);
@ -993,22 +998,24 @@ private:
AUEventListenerAddEventType (eventListenerRef, nullptr, &event);
}
// Add a listener for program changes
AudioUnitEvent event;
event.mArgument.mProperty.mAudioUnit = audioUnit;
event.mArgument.mProperty.mPropertyID = kAudioUnitProperty_PresentPreset;
event.mArgument.mProperty.mScope = kAudioUnitScope_Global;
event.mArgument.mProperty.mElement = 0;
event.mEventType = kAudioUnitEvent_PropertyChange;
AUEventListenerAddEventType (eventListenerRef, nullptr, &event);
// Add a listener for parameter list changes
event.mArgument.mProperty.mPropertyID = kAudioUnitProperty_ParameterList;
AUEventListenerAddEventType (eventListenerRef, nullptr, &event);
addPropertyChangeListener (kAudioUnitProperty_PresentPreset);
addPropertyChangeListener (kAudioUnitProperty_ParameterList);
addPropertyChangeListener (kAudioUnitProperty_Latency);
}
}
void addPropertyChangeListener (AudioUnitPropertyID type) const
{
AudioUnitEvent event;
event.mEventType = kAudioUnitEvent_PropertyChange;
event.mArgument.mProperty.mPropertyID = type;
event.mArgument.mProperty.mAudioUnit = audioUnit;
event.mArgument.mProperty.mPropertyID = kAudioUnitProperty_PresentPreset;
event.mArgument.mProperty.mScope = kAudioUnitScope_Global;
event.mArgument.mProperty.mElement = 0;
AUEventListenerAddEventType (eventListenerRef, nullptr, &event);
}
void eventCallback (const AudioUnitEvent& event, AudioUnitParameterValue newValue)
{
switch (event.mEventType)
@ -1040,6 +1047,8 @@ private:
updateHostDisplay();
else if (event.mArgument.mProperty.mPropertyID == kAudioUnitProperty_PresentPreset)
sendAllParametersChangedEvents();
else if (event.mArgument.mProperty.mPropertyID == kAudioUnitProperty_Latency)
updateLatency();
break;
}