如何从Swift 3中的midiEvent解析MIDIRawData(SysEx)? (在iOS下)

时间:2016-12-10 17:14:12

标签: ios coremidi

我在使用MusicTrack(XCode8.1,iOS10.1)的midi事件解析MIDIRawData(SysEx Data)时遇到大麻烦 我设法使用以下代码(Swift3)解析MidiNoteMessagesMidiChannelMessages

(使用MusicEventIteratorGetEventInfo提取eventType和eventData ...)

switch eventType {

case kMusicEventType_MIDINoteMessage:

     let temp = eventData?.bindMemory(to: MIDINoteMessage.self, capacity: 5)
     let channel = temp!.pointee.channel
     let note = temp!.pointee.note 
     let vel = temp!.pointee.velocity
     let relVel = temp!.pointee.releaseVelocity
     let duration = temp!.pointee.duration

case kMusicEventType_MIDIChannelMessage:
     let temp = eventData?.bindMemory(to: MIDIChannelMessage.self, capacity: 4)
     let status = temp!.pointee.status & 0b11110000
     let channel = temp!.pointee.status & 0b0000111
     let data1 = temp!.pointee.data1
     let data2 = temp!.pointee.data2
     let reserved = temp!.pointee.reserved

在下面的例子中,我获得了正确的数据长度,但数据本身只包含SysEx消息的第一个条目

case kMusicEventType_MIDIRawData:
                debug.printDebugText(text: "kMusicEventType_MIDIRawData", ToConsole: debugViewGlobal)
     let raw = eventData?.bindMemory(to: MIDIRawData.self, capacity: 2)
     let length = raw!.pointee.length
     let data = raw!.pointee.data // (should be of Type (UInt8)… but is just one UInt8 Value

我如何获得剩余的SysEs消息? 我该如何处理(UInt8)?

谢谢你, 塞巴斯蒂安

0 个答案:

没有答案