Skip to content

Commit

Permalink
Update enableMIDI (#2912)
Browse files Browse the repository at this point in the history
MIDISampler has a different enableMIDI method from the one in MIDICallbackInstrument. This makes them more similar, and fixes the issue with MIDISampler not playing from AppleSequencer in Xcode 15.3.
  • Loading branch information
NickCulbertson committed Apr 24, 2024
1 parent df84034 commit 1b11534
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Sources/AudioKit/MIDI/MIDISampler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ open class MIDISampler: AppleSampler, NamedNode {
fatalError("Expected AU to respond to MIDI.")
}
CheckError(MIDIDestinationCreateWithBlock(midiClient, cfName, &midiIn) { packetList, _ in
for e in packetList.pointee {
for event in e {
event.data.withUnsafeBufferPointer { ptr in
guard let ptr = ptr.baseAddress else { return }
midiBlock(AUEventSampleTimeImmediate, 0, event.data.count, ptr)
withUnsafePointer(to: packetList.pointee.packet) { packetPtr in
var p = packetPtr
for _ in 1...packetList.pointee.numPackets {
for event in p.pointee {
event.data.withUnsafeBufferPointer { ptr in
guard let ptr = ptr.baseAddress else { return }
midiBlock(AUEventSampleTimeImmediate, 0, event.data.count, ptr)
}
}
p = UnsafePointer<MIDIPacket>(MIDIPacketNext(p))
}
}
})
Expand Down

0 comments on commit 1b11534

Please sign in to comment.