1

我对 Swift 很陌生并且正在苦苦挣扎,所以请放轻松。我正在 XCode 10.1 中使用 Swift 4 构建一个 macOS 项目

我使用从 AudioKit 提供的 MIDIUtility 示例项目中获得的以下代码从设备接收 sysex 消息:

func receivedMIDISystemCommand(_ data: [MIDIByte]) {
    if let command = AKMIDISystemCommand(rawValue: data[0]) {
        var newString = "MIDI System Command: \(command) \n"
        var hexArray = [UInt8]()
        for bit in data {
            hexArray.append(bit)    //this requires 'public typealias MIDIByte = UInt8'
            newString.append(String("\(bit) "))
        }
        updateText("\(newString) \n")
        updateData(hexArray)
    }
    updateText("received \(data.count) bytes of data \n\n")
}

我收到的 sysex 与使用 SysEx Librarian 或 MIDI Monitor 接收相同的 sysEx 时得到的非常不同。这两个应用程序都接收 6 个 32,110,110,110,110 和 110 字节的数据包。这是我期望从我的 MIDI 设备中得到的。我的代码得到 6 个 520、1300、20、1538、1294 和 1544 字节的数据包。看起来我想要的数据在这些数据包中,但它被一堆 0 吐出。

在 MIDI Monitor 或 SysEx Librarian 中收到的数据:我的代码收到的一些数据

为什么我的代码会收到这么多额外数据?有没有办法过滤掉不需要的数据,或者我需要弄清楚如何在我的项目中使用其他 AudioKit 的东西?

4

0 回答 0