要发送消息触后(通道压力,多压力)AudioKit 使用基于十六进制转换的函数。不幸的是,官方文档中几乎没有关于这些功能的信息。
// POLYPRESSURE
// Use this code to get polypressure messages from your MIDI keyboard.
func receivedMIDIAfterTouch(_ pressure: MIDIByte, channel: MIDIChannel) {
// do something
}
// Use this code to send your polypressure messages to the MIDI output of your application.
func sendPolyPressureData(channel: MIDIChannel, noteNumber: MIDINoteNumber, value: MIDIByte) {
let noteCommand: MIDIByte = MIDIByte(0xA0) + channel
let message: [MIDIByte] = [noteCommand, noteNumber, value]
let event = AKMIDIEvent(data: message)
midi.sendEvent(event)
}
好吧,最后我将在这个答案中添加一些更多类似的 AudioKit MIDI 功能,文档中关于这些功能的说明太少了。
// CHANNEL PRESSURE
func receivedMIDIAftertouch(noteNumber: MIDINoteNumber,
pressure: MIDIByte,
channel: MIDIChannel) {
// do something
}
func sendChannelPressureData(channel: MIDIChannel, value: MIDIByte) {
let command: MIDIByte = MIDIByte(0xD0) + channel
let message: [MIDIByte] = [command, value, 0]
let event = AKMIDIEvent(data: message)
midi.sendEvent(event)
}
// CONTROLL CHANGE & MODULATION (СС_0)
func receivedMIDIController(_ controller: MIDIByte, value: MIDIByte, channel: MIDIChannel) {
// do something
}
func ccOut (channel: MIDIChannel, cc: MIDIByte, value: MIDIByte) {
let event = AKMIDIEvent(controllerChange: cc, value: value, channel: channel)
midi.sendEvent(event)
}
// PITCH BAND
func receivedMIDIPitchWheel(_ pitchWheelValue: MIDIWord, channel: MIDIChannel) {
// do something
}
/// Send a pitch bend message.
/// - Parameters:
/// - value: Value of pitch shifting between 0 and 16383. Send 8192 for no pitch bending.
/// - channel: Channel you want to send pitch bend message. Defaults 0.
func sendPitchBendData(channel: MIDIChannel, value: UInt16) {
let pitchCommand = MIDIByte(0xE0) + channel
let mask: UInt16 = 0x007F
let byte1 = MIDIByte(value & mask) // MSB, bit shift right 7
let byte2 = MIDIByte((value & (mask << 7)) >> 7) // LSB, mask of 127
let message: [MIDIByte] = [pitchCommand, byte1, byte2]
let event = AKMIDIEvent(data: message)
midi.sendEvent(event)
}