使用AudioKit从MIDI文件读取音符
我正在尝试构build一个从MIDI文件中提取音符的音序器。
目前我正在使用AudioKit进行音乐数据处理。 想知道如何从AudioKit的MIDI文件中获取音符数据/事件。
我试图使用AKSequencer和输出到AKMIDINode来聆听MIDI事件,但似乎无法从中得到任何东西。
class CustomMIDINode: AKMIDINode { override init(node: AKPolyphonicNode) { print("Node create") // OK super.init(node: node) } func receivedMIDINoteOff(noteNumber: MIDINoteNumber, velocity: MIDIVelocity, channel: MIDIChannel) { print("midi note off") // Not printed } func receivedMIDISetupChange() { print("midi setup changed") // Not printed } override func receivedMIDINoteOn(_ noteNumber: MIDINoteNumber, velocity: MIDIVelocity, channel: MIDIChannel) { print("receivedMIDINoteOn") // Not printed } } func setupSynth() { oscBank.attackDuration = 0.05 oscBank.decayDuration = 0.1 oscBank.sustainLevel = 0.1 oscBank.releaseDuration = 0.1 } let seq = AKSequencer(filename: "music") let oscBank = AKOscillatorBank() var midi = AKMIDI() let midiNode = CustomMIDINode(node: oscBank) setupSynth() midi.openInput() midi.addListener(midiNode) seq.tracks.forEach { (track) in track.setMIDIOutput(midiNode.midiIn) } AudioKit.output = midiNode AudioKit.start() seq.play()