gpt4 book ai didi

swift - 我如何使用 Audiokit 发送 midi poly pressure 消息?

转载 作者:搜寻专家 更新时间:2023-10-31 23:09:37 25 4
gpt4 key购买 nike

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

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

但是,某些参数需要使用“多压力”消息进行设置。每个音符都映射到一些参数,压力值将用于设置参数。这看起来像是 hack,但事实就是如此。

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

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

最佳答案

发送消息 Aftertouch( channel 压力、多压力)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)
}

关于swift - 我如何使用 Audiokit 发送 midi poly pressure 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44908391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com