How to connect AKSequencer to a AKCallbackInstrument?

前端 未结 2 958
情话喂你
情话喂你 2021-01-02 17:38

I want to read a midi file and display things when note events are triggered. I found this stackoverflow question, where the second answer suggests to use AudioKit : How Do

相关标签:
2条回答
  • 2021-01-02 17:54

    True, the class AKCallbackInstrument does not have a property midiIn, although the documentation does show it being used that way. Instead of using AKCallbackInstrument, use AKMIDICallbackInstrument. That class has midiIn, and seems to work fine.

    0 讨论(0)
  • 2021-01-02 17:59

    typewriter found the solution to my problem. Here is the code which works now, printing the midi number of the note each time it is played (but I didn't add sound yet) :

    // dont write the .mid extension in filename :
    let sequencer = AKSequencer(filename:"coucou") 
    let callbackInstr = AKMIDICallbackInstrument()
    callbackInstr.callback = myCallBack
    sequencer.setGlobalMIDIOutput(callbackInstr.midiIn)
    sequencer.play()
    
    func myCallBack(a:UInt8, b:MIDINoteNumber, c:MIDIVelocity) -> () {
        if (a == 144) {  // if noteOn
            print(b)
        }
    }
    
    0 讨论(0)
提交回复
热议问题