Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何使用Audiokit发送midi poly压力信息?_Swift_Xcode8_Midi_Audiokit - Fatal编程技术网

Swift 如何使用Audiokit发送midi poly压力信息?

Swift 如何使用Audiokit发送midi poly压力信息?,swift,xcode8,midi,audiokit,Swift,Xcode8,Midi,Audiokit,目前,我正在构建一个应用程序,它基本上是我的病毒TI合成器的合成器控制器。该病毒允许使用MIDI CC消息设置其大部分参数。 使用Audiokit,这非常简单: midiOutput.sendEvent(AKMIDIEvent(controllerChange: 17, value: SomeValue, channel: 1)) 但是,某些参数需要使用“Poly Pressure”消息进行设置。 每个注释都映射到某个参数,压力值将用于设置te参数。这看起来像一个黑客,但它是它的方式 我现在的

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

midiOutput.sendEvent(AKMIDIEvent(controllerChange: 17, value: SomeValue, channel: 1))
但是,某些参数需要使用“Poly Pressure”消息进行设置。 每个注释都映射到某个参数,压力值将用于设置te参数。这看起来像一个黑客,但它是它的方式

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


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

要在触摸(通道压力、多压力)后发送消息,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)
    }
//通道压力
func ReceiveDmidIfterTouch(音符编号:MIDI音符编号,
压力:MIDIByte,
频道:MIDI频道){
//做点什么
}
func sendChannelPressureData(通道:MIDIChannel,值:MIDIByte){
let命令:MIDIByte=MIDIByte(0xD0)+通道
let消息:[MIDIByte]=[命令,值,0]
let event=AKMIDIEvent(数据:消息)
midi.sendEvent(事件)
}
//控制变化和调制(СС0)
func receivedMIDIController(u控制器:MIDIByte,值:MIDIByte,通道:MIDIChannel){
//做点什么
}
func cOut(通道:MIDIChannel,cc:MIDIByte,值:MIDIByte){
let event=AKMIDIEvent(controllerChange:cc,value:value,channel:channel)
midi.sendEvent(事件)
}
//音高带
func ReceivedDiPitchWheel(uPitchWheel值:MIDIWord,通道:MIDIChannel){
//做点什么
}
///发送俯仰弯曲信息。
///-参数:
///-值:在0和16383之间的变桨值。发送8192无俯仰弯曲。
///-通道:要发送俯仰弯曲信息的通道。默认值为0。
func sendPitchBendData(通道:MIDI通道,值:UInt16){
让pitchCommand=MIDIByte(0xE0)+通道
let掩码:UInt16=0x007F
让字节1=MIDIByte(值和掩码)//MSB,位右移7
让字节2=MIDIByte((值和(掩码>7)//LSB,掩码为127
let消息:[MIDIByte]=[pitchCommand,字节1,字节2]
let event=AKMIDIEvent(数据:消息)
midi.sendEvent(事件)
}