I would like to embed a custom view created by an Audio Unit into a window that uses Auto Layout. After trying dozens of combinations, I still haven't found a way to do this which works with a large selection of Audio Units.
The goal would be to create a container NSView
object with the Audio Unit View as a subview, and to set constraints in such a way that the size of the container matches that of the AU view, including when the latter resizes itself. The container should have translatesAutoresizingMaskIntoConstraints
set to NO
, so it plays nice with the rest of the window.
My first attempt was to create two constraints simply forcing the size of both (container and AU) views to be equal. This fails as the AU view then collapses to a very small size.
Another attempt was to create fixed size constraints for the container view that are initialised to match the AU view, to listen for NSViewFrameDidChangeNotification
for the AU view, and to adjust the fixed sizes as required. This crashes as soon as the AU view wants to resize itself. The reason is that when I increase the size of the container to match the AU view, the autoresizing mask constraints instruct the AU view to increase its size again, causing an infinite loop.
What works best so far is to turn translatesAutoresizingMaskIntoConstraints
off for the AU view and to set the size of the container by listening to frame change notifications. This appears to work for all AUv2 Audio Units, but for AUv3 Audio Units (in particular Apple's demo AUv3), I always get a view size of (1,1) which is obviously useless. I would be very grateful for any insight into how to make this work...