Xcode 8 beta 6中的MusicEventIteratorGetEventInfo

时间:2016-08-19 17:39:16

标签: swift xcode

直到Xcode 8 beta 5,我可以使用以下内容访问MusicEventIterator中的事件信息:

var type: MusicEventType = 0
var stamp: MusicTimeStamp = 0
var data: UnsafePointer<()>? = nil
var size: UInt32 = 0

while(hasCurrentEvent != false) {
        MusicEventIteratorGetEventInfo(iterator!, &stamp, &type,
        &data, &size) 
    // do stuff with stamp, type, data...
}

我设法在Apple开发网站上获得了一些处理“数据”的帮助,但是首先获取数据也被打破了。我收到关于在“data”声明中使用“UnsafeRawPointer”的警告,以及关于无法在MusicEventIteratorGetEventInfo()调用中将数据用作inout参数的错误... 虽然我知道他们正在使事情变得更具确定性和面向未来(即编译器),但每隔几个月C-interop的变化令人难以置信。我的MIDI文件解析器代码已经改变了3次......

作为参考,MusicEventIteratorGetEventInfo具有签名:

func MusicEventIteratorGetEventInfo(_ inIterator: MusicEventIterator,
 _ outTimeStamp: UnsafeMutablePointer<MusicTimeStamp>,
 _ outEventType: UnsafeMutablePointer<MusicEventType>,
 _ outEventData: UnsafeMutablePointer<UnsafePointer<Void>>,
 _ outEventDataSize: UnsafeMutablePointer<UInt32>) -> OSStatus

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

this显示了这一点:

  

声明

outEventData

第三个参数UnsafeMutablePointer<UnsafeRawPointer?>的类型为UnsafeMutablePointer<T>。 通常,当API声明T时,您声明一个类型为var type: MusicEventType = 0 var stamp: MusicTimeStamp = 0 var data: UnsafeRawPointer? = nil //<- Declare a variable of type `UnsafeRawPointer?`. var size: UInt32 = 0 while hasCurrentEvent != false { MusicEventIteratorGetEventInfo(iterator!, &stamp, &type, &data, &size) //<- Pass it as an inout argument. // do stuff with stamp, type, data... } 的变量,并将其作为inout参数传递。

所以,这应该有效:

     map <silent> <leader><cr> :noh<cr>

答案 1 :(得分:0)

如果其他人遇到同样的问题,这似乎有效:

// Somewhere to put the raw midi data
var type: MusicEventType = 0
var stamp: MusicTimeStamp = -1
let data: UnsafeMutablePointer<UnsafeRawPointer?> = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: MemoryLayout<MusicEventType>.size)

var size: UInt32 = 0
var tsChangeStamp: MusicTimeStamp = 0

while(hasCurrentEvent != false) {
        MusicEventIteratorGetEventInfo(iterator!, &stamp, &type, data, &size)
    // do stuff...
}