Reputation: 11
I'm using an existing app (Midi Link Sync) to send MIDI clock data to my separate AudioKit iOS application.
AudioKit does pick-up the message, however, the AKMIDIListener does not fire.
AKMIDIListener implemented as-is from playground demo: link
This is because in the _AKMIDI+Receiving.swift_ file, the handleMIDIMessage function is not called (line 155) due to the event status & command being nil
.
The misfiring occurs in line 69-70 of the AKMIDIEvent.swift (see source code on AudioKit master). On my end, the data packet with the MIDI clock sent via the MIDI link sync app contains one data entry: 0xF8 (clock). Line 69 enforces the data length to be > 1 rather than >= 1.
Is this a bug with the AudioKit framework or should MIDI messages be structured with more than one data entry by default?
Upvotes: 1
Views: 135
Reputation: 319
You should check out AKMIDITempoListener. It's a helper object to deal with clock events. This helper object observes clock messages to determine tempo and it provides some conveniences for observing clock message events and tempo events. It can be used to observe clock quantum events and beat events (24 clock ticks), quantum events (6 clock ticks), tempo events, start/continue, and stop events. It can also be used to synchronize a start with the next clock event.
You can check out an example of my testing usage by opening the MacOS development project located in AudioKit ▸ Developer ▸ macOS ▸ macOSDevelopment. Then open "MIDI Connection Manger.swift".
public let tempoListener = AKMIDITempoListener(smoothing: 0.98, bpmHistoryLimit: 1)
init() {
midi.addListener(tempoListener)
tempoListener.clockListener?.addObserver(self)
tempoListener.addObserver(self)
}
Then further down in the file there is the extension to receive the events:
extension MIDIConnectionManger: AKMIDIBeatObserver {
func preparePlay(continue: Bool) {
debugPrint("MMC Start Prepare Play")
}
func startFirstBeat(continue: Bool) {
debugPrint("MMC Start First Beat")
}
func stopSRT() {
debugPrint("MMC Stop")
}
func receivedBeatEvent(beat: UInt64) {
}
func receivedQuantum(quarterNote: UInt8, beat: UInt64, quantum: UInt64) {
}
func receivedQuarterNoteBeat(quarterNote: UInt8) {
//debugPrint("Quarter Note: ", quarterNote)
}
}
You probably want to just focus on the receivedQuantum function if you all you care about are clock events. The main midi listeners are quite focused on midi note events and such, less so than the single byte midi messages.
Upvotes: 1