Post not yet marked as solved
Post marked as unsolved with 2 replies, 1,250 views
I'm trying to get tempo related messages from the AVAudioSequencer.tempoTrack.
class TempoHandler {
private var midiEndpoint = MIDIEndpointRef()
private var midiClient = MIDIClientRef()
private let sequencer: AVAudioSequencer
public init(sequencer: AVAudioSequencer) {
self.sequencer = sequencer
}
func setup() {
var status = MIDIClientCreateWithBlock("TempoHandler.Client" as CFString, &midiClient, nil)
try checkStatus(status: status, error: SequencerMIDIContextError.createMidiClient)
status = MIDIDestinationCreateWithBlock(midiClient, "TempoHandler.In" as CFString, &midiEndpoint, midiIO)
try checkStatus(status: status, error: SequencerMIDIContextError.createMidiDestination)
sequencer.tempoTrack.destinationMIDIEndpoint = midiEndpoint
}
private func midiIO(_ packetList: UnsafePointer<MIDIPacketList>, _ src: UnsafeMutableRawPointer?) {
let packets = packetList.pointee
var packet = packets.packet
for _ in 0 ..< packets.numPackets {
print("TempoHandler received " + String(format:"%02X", packet.data.0))
packet = MIDIPacketNext(&packet).pointee
}
}
}
My sequencer is fully loaded with a MIDI file before I call setup() then sequencer.prepareToPlay() if that matters.
The MIDI file contains multiple SetTempo meta messages that are audibly well handled by the sequencer.
When instead setting my midiEndpoint as a destination to another track (sequencer.tracks[0]), my handler does output note messages.
But with the tempo track, no MIDI message is received. Is there something I'm missing ?