简体   繁体   中英

AudioKit 4.6 release: AKMIDICallbackInstrument not calling back

Really excited by all the additions in 4.6! After reviewing most of the changes, I did not see anything explicitly different in AKMIDICallbackInstrument , however, I cannot get the call back to work anymore. Here is my implementation:

var sequencer: AKSequencer = AKSequencer()
var callbackTrack: AKMusicTrack = AKMusicTrack()
var callbackInst: AKMIDICallbackInstrument = AKMIDICallbackInstrument() 

---

public func setupSequencerWithBeats(beats: Int, bpm: Double) {

    print("Num beats: \(beats) | BPM: \(bpm)")
    sequencer.setTempo(bpm)

    callbackTrack = sequencer.newTrack()!
    callbackTrack.setMIDIOutput(callbackInst.midiIn)

    for i in 0 ..< beats {
        callbackTrack.add(noteNumber: MIDINoteNumber(60), velocity: 100, position: AKDuration(beats: Double(i)), duration: AKDuration(beats: 1))
        }

    callbackInst.callback = {status, noteNumber, velocity in

        //Using the new AKMIDIStatus object to unwrap the status and check if it's .noteOn
        if let midiStatus = AKMIDIStatus(byte: status), midiStatus.type != .noteOn
            {
                return
            }

        // just some delegates to other classes                 
        self.sequencerdDelegate?.didRecieveCallbackFromSequencer(beatNumber: self.beatNumber)
        self.beatNumber += 1
    }

When I call sequencer.play() the callbackInst fails to fire the callback anymore. My assumption here is did something change with setMIDIOutput() method? If there is a better way to get a callback when a .noteOn event is fired in my sequencer, I would love to know. Thanks everyone!

Thanks to AudioKit contributor oettam for seeing a very small change in the 4.6.0 that affected all MIDI components! This issue is fixed with 4.6.1! His commit: https://github.com/AudioKit/AudioKit/commit/dcfbbb98058425e43af23b9df69fd9794ecc34d5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM