我在使用MusicTrack(XCode8.1,iOS10.1)的midi事件解析MIDIRawData
(SysEx Data)时遇到大麻烦
我设法使用以下代码(Swift3)解析MidiNoteMessages
和MidiChannelMessages
:
(使用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)?
谢谢你, 塞巴斯蒂安