在Swift 2中使用Apples MusicSequence C API时遇到问题。我无法在调用MusicSequenceBarBeatTimeToBeats
时弄清楚如何摆脱EXEC_BAD_INSTRUCTION。
我在互联网上尝试了很多不同的解决方案,但似乎没有任何效果。
我的第一次尝试没有导致编译错误:
import Cocoa
import AudioToolbox
var musicSequence = MusicSequence()
NewMusicSequence(&musicSequence)
var barBeatTime = CABarBeatTime(bar: 1, beat: 1, subbeat: 0, subbeatDivisor: 960, reserved: 0)
var musicTimeStamp: MusicTimeStamp = 0
MusicSequenceBarBeatTimeToBeats(musicSequence, &barBeatTime, &musicTimeStamp)
然后我尝试了这个,但结果相同:
var barBeatTime = CABarBeatTime(bar: 1, beat: 1, subbeat: 0, subbeatDivisor: 960, reserved: 0)
var musicTimeStamp = UnsafeMutablePointer<MusicTimeStamp>.alloc(sizeof(MusicTimeStamp))
MusicSequenceBarBeatTimeToBeats(musicSequence, &barBeatTime, musicTimeStamp)
musicTimeStamp.dealloc(sizeof(MusicTimeStamp))
我尝试了withUnsafeutablePointer
函数,但运行时错误相同:
var barBeatTime = CABarBeatTime(bar: 1, beat: 1, subbeat: 0, subbeatDivisor: 960, reserved: 0)
var musicTimeStamp: MusicTimeStamp = 0
withUnsafeMutablePointer(&musicTimeStamp,
{
MusicSequenceBarBeatTimeToBeats(musicSequence, &barBeatTime, UnsafeMutablePointer($0))
})
如果我在第三个参数中传递nil它不会崩溃,但这是没用的,因为缺少输出。所以它似乎是问题的UnsafeMutablePointer<MusicTimeStamp>
输出参数。
MusicSequenceBarBeatTimeToBeats(musicSequence, &caBarBeatTime, nil)
有什么建议吗?