当前位置: 首页 > 工具软件 > AudioKit > 使用案例 >

c语言读取midi文件举例子,使用AudioKit从MIDI文件中读取音符

空慈
2023-12-01

Tony Fung Choi Fung

8

ios

swift

audiokit

我正在尝试构建一个从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()

 类似资料: