我正在尝试使用receivedMIDINoteOn函数在音序器播放音符时闪烁UILabel.我尝试过使用AKMIDIListener协议但没有成功.我还制作了一个AKMIDISampler子类,并从音序器发送midi.它播放midi但未调用receivedMIDINoteOn.
这就是我在指挥的init()中所拥有的:
init() {
[ahSampler, beeSampler, gooSampler,flasher] >>> samplerMixer
AudioKit.output = samplerMixer
AudioKit.start()
let midi = AKMIDI()
midi.createVirtualPorts()
midi.openInput("Session 1")
midi.addListener(self)
}
Run Code Online (Sandbox Code Playgroud)
导体遵循AKMIDIListener协议
这是功能:永远不会被调用
func receivedMIDINoteOn(noteNumber: MIDINoteNumber, velocity: MIDIVelocity, channel: MIDIChannel)
{
print("got it")
}
Run Code Online (Sandbox Code Playgroud)
这是AKMIDISampler的子类,它获得midi并播放正弦合成器,但是从不调用receivedMIDINoteOn.
class Flasher: AKMIDISampler
{
override func receivedMIDINoteOn(noteNumber: MIDINoteNumber, velocity: MIDIVelocity, channel: MIDIChannel)
{
print("Flasher got it!")
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:我应该使用AKCallbackInstrument类,并覆盖它的start()函数.