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:
parent
03dde6a2a8
commit
3bc38d1e3b
1 changed files with 28 additions and 19 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue