2

我在 Swift 2 中使用 Apples MusicSequence C API 时遇到问题。我不知道如何在调用MusicSequenceBarBeatTimeToBeats.

我尝试了很多在互联网上找到的不同解决方案,但似乎没有任何效果。

我的第一次没有导致编译错误的尝试是:

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)

结果是: MusicSequenceBarBeatTimeToBeats 代码行中的 EXEC_BAD_INSTRUCTION (code=1, address=0xe)

然后我尝试了这个,但结果相同:

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)

有什么建议么?

4

0 回答 0