swift 如何使用CoreMidi创建一个带通道的MidiEventPacket?

x33g5p2x  于 2022-10-31  发布在  Swift
关注(0)|答案(1)|浏览(129)

这是我创建MIDI事件包的代码。它创建了一个音符开/关事件,在通道1上有力度和音符编号。
如何设置频道编号?

var midiEventPacket = MIDIEventPacket ()
midiEventPacket.timeStamp = 0
midiEventPacket.wordCount = 1
midiEventPacket.words.0 = isNoteOff ? 0x20900000 : 0x20800000
midiEventPacket.words.0 = midiEventPacket.words.0 | ((note) << 8) // Note  = 60
midiEventPacket.words.0 = midiEventPacket.words.0 | UInt32(velocity) // Velocity = 127
fdbelqdn

fdbelqdn1#

我刚刚找到了解决方案。你需要添加一个通道到音符开/音符关十六进制值:

var midiEventPacket = MIDIEventPacket ()
midiEventPacket.timeStamp = 0
midiEventPacket.wordCount = 1
midiEventPacket.words.0 = (isNoteOff ? 0x20900000 : 0x20800000) + (UInt32(channel - 1) << 16) // -1 because midi channel range is 1..16
midiEventPacket.words.0 = midiEventPacket.words.0 | ((note) << 8) // Note  = 60
midiEventPacket.words.0 = midiEventPacket.words.0 | UInt32(velocity) // Velocity = 127

相关问题