3

目前我正在构建一个应用程序,它基本上是我的 Virus TI 合成器的合成器控制器。该病毒允许使用 MIDI CC 消息设置其大部分参数。使用 Audiokit 这很简单:

midiOutput.sendEvent(AKMIDIEvent(controllerChange: 17, value: SomeValue, channel: 1))

但是,需要使用“Poly Pressure”消息设置一些参数。每个音符都映射到某个参数,压力值将用于设置参数。这看起来像一个黑客,但它就是这样。

我现在的问题是我找不到发送 midi poly 压力消息的方法,因为它们似乎在 audiokit 中不可用。(换句话说:没有多边形压力事件类型)

问题:有什么方法可以使用 audiokit 发送 poly pressure 消息?例如,是否可以自己构造一个新的消息类型?

4

1 回答 1

0

要发送消息触后(通道压力,多压力)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)
    }
于 2018-07-29T17:14:53.053 回答