AudioKit 4.6 release: AKMIDICallbackInstrument not calling back

时光总嘲笑我的痴心妄想 提交于 2019-12-08 06:17:23

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/54682484/audiokit-4-6-release-akmidicallbackinstrument-not-calling-back

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!