I’m working on a couple of AU’s and I’m doing KVO on allParameterValues to 
update my UI. I’ve noticed that 

observeValue(forKeyPath keyPath: String?, of object: Any?, change: 
[NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)

is called twice when setting a preset via either fullState or currentPreset. In 
both calls, it looks like both the old value and the new value are false.

Since I’m only updating the UI, this actually works out OK and doesn’t cause 
any real issues. But, for the sake of efficiency, I’d like to know if this is 
the expected behavior or if I’m doing something wrong. If this is what is 
expected, is there a way to differentiate between the two calls?

As a note, the reason I’m observing on allParameterValues to begin with is that 
the closure on the parameterTree set using token(byAddingParameterObserver:) 
isn’t called in my AUViewController when fullState is used to set a new preset. 
It is called when setting from currentPreset. In a somewhat stranger situation, 
the closure is called when I set up the same observer closure on the 
parameterTree in the main ViewController of my host application when fullState 
is used to set the new preset. Is that expected behavior as well?

In both locations, the parameter tree observer is added essentially like this:

        let paramTree = hostModel.secondAUNode?.auAudioUnit.parameterTree
        let parameterObserverToken = paramTree?.token( 
byAddingParameterObserver: { [weak self] address, value in
                guard let strongSelf = self else { return }
                DispatchQueue.main.async {
                    print("Got an update ... \(address): \(value)")

Thanks, Rob
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (Coreaudio-api@lists.apple.com)
Help/Unsubscribe/Update your Subscription:

This email sent to arch...@mail-archive.com

Reply via email to