2

Here is my code to create a Midi Event Packet. It creates a note on/off event with velocity and note number on channel 1.

How can I set a channel number?

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
TylerP
  • 9,600
  • 4
  • 39
  • 43
Sébastien REMY
  • 2,399
  • 21
  • 39

1 Answers1

3

I just found the solution. You need to add a channel to the Note On / Note Off hex value:

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
TylerP
  • 9,600
  • 4
  • 39
  • 43
Sébastien REMY
  • 2,399
  • 21
  • 39