Reputation: 86
Currently i'm building an app which is basically a synthesizer controller for my Virus TI synthesizer. The Virus allows most of it's parameters to be set using MIDI CC messages. Using Audiokit this very simple:
midiOutput.sendEvent(AKMIDIEvent(controllerChange: 17, value: SomeValue, channel: 1))
However, some parameters need to be set using "Poly Pressure" messages. Each note is mapped to some parameter, and the pressure value will be used to set te parameter. This looks like a hack, but it is the way it is.
My problem is now that i cannot find a way to send midi poly pressure messages since they do not seem to be available in audiokit. (in other words: there is no poly pressure event type)
Question: is there any way to send poly pressure messages using audiokit? For example, is it possible to construct a new message type yourself?
Upvotes: 3
Views: 566
Reputation: 21
To send messages Aftertouch (channel pressure, polypressure) AudioKit use the functions that are based on the hexadecimal transformations. Unfortunately in the official documentation about these functions almost no information.
// 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)
}
Well, in the end I will add to this answer a few more similar AudioKit MIDI functions, about which too little is said in the documentation.
// 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)
}
Upvotes: 1