【发布时间】:2020-11-29 08:43:39
【问题描述】:
我可能在这里做了一些非常愚蠢的事情,但这让我陷入了困境。 我正在尝试显示音频单元的视图(如果有的话)。我的理解是 AU 工厂类应该返回一个 NSView(我不担心某些 v3 单元返回 ViewController 的选项)。我有这个方法:
func getAUcocoaView(_ audioUnit: AudioUnit ) -> NSView {
var dataSize = UInt32(MemoryLayout<AudioUnitCocoaViewInfo>.size)
var cocoaViewInfoRawPtr = UnsafeMutableRawPointer.allocate(byteCount: MemoryLayout<AudioUnitCocoaViewInfo>.size, alignment: MemoryLayout<AudioUnitCocoaViewInfo>.alignment)
defer {
cocoaViewInfoRawPtr.deallocate()
}
let result = AudioUnitGetProperty(audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global, 0, cocoaViewInfoRawPtr, &dataSize)
if result != 0 {
print("Couldn't get AudioUnit property: kAudioUnitProperty_CocoaUI")
}
let cocoaViewInfo = cocoaViewInfoRawPtr.bindMemory(to: AudioUnitCocoaViewInfo.self, capacity: 1).pointee
let factoryClassNameCF = cocoaViewInfo.mCocoaAUViewClass
let factoryClassName = factoryClassNameCF.takeUnretainedValue() as String
let cocoaViewBundlePathCF = cocoaViewInfo.mCocoaAUViewBundleLocation
let cocoaViewBundlePath = cocoaViewBundlePathCF.takeUnretainedValue()
let bundle = Bundle(url: cocoaViewBundlePath as URL)
let factoryClass = bundle!.classNamed(factoryClassName) as! NSObject.Type
let auView = factoryClass.init()
return auView as! NSView
}
在最终尝试强制转换为 NSView 之前,一切似乎都按预期工作。我的理解是 AU 工厂类返回一个 NSView ,但是这种强制转换的尝试导致: “无法将 'JUCE_AUCocoaViewClass_ab7d1f643f11dc89' (0x600000e5a730) 类型的值转换为 'NSView' (0x7fff8ceab778)。” 我可能错过了一些非常愚蠢的东西,但要么: a)如何从中获得 NSView ?或者; b) 如果不是这样,如何调用 AU 视图?
非常感谢任何帮助。
【问题讨论】:
标签: audiounit