Reading notes from a MIDI file using AudioKit

I am trying to create a sequencer that takes notes from a midi file.

I am currently using AudioKit to process music data. I would like to know how I can get data / event notes from a midi file using AudioKit.

I tried using an AKSequencer and output to AKMIDINode to listen for a MIDI event, but it seems that nothing can get from it.

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() 
+8
ios swift audiokit
source share
2 answers

Have you looked at any of the Audio Kit projects available for download? They are very useful for troubleshooting AK. I really find examples better than documentation (since the implementation is not well explained).

As for your question, you can add a midi listener to the event, there is an example of this code in the Analog Synth X Project available here .

 let midi = AKMIDI() midi.createVirtualPorts() midi.openInput("Session 1") midi.addListener(self) 

For more processed code, you can reference this , although the code is most likely out of date in parts.

+3
source share

Tony, is it that you are not getting any MIDI events or just print statements?

I agree with Axemastas answer about adding AKMidiListener to the class, as well as checking the MIDI code examples that come with AudioKit. This example ROM Player shows how to play external MIDI files using AKMidiSsmpler node:

https://github.com/AudioKit/ROMPlayer

To display the print, try wrapping it in DispatchQueue.main.async so that it is in the main thread. Here's the implementation question for AudioKit MIDI with sample code that I posted here:

AudioKit iOS function - receivedMIDINoteOn

Hope this helps.

+1
source share

All Articles