Skip to content

Commit

Permalink
Merge pull request #81 from orchetect/dev
Browse files Browse the repository at this point in the history
Fixed `MIDIEventPacket` timestamp
  • Loading branch information
orchetect authored Apr 10, 2022
2 parents 1aa3b7e + 8d8e40a commit bf6ce74
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ extension MIDIEventPacket {
@available(macOS 11, iOS 14, macCatalyst 14, tvOS 14, watchOS 7, *)
@inline(__always)
internal init(
words: [MIDI.UMPWord]
words: [MIDI.UMPWord],
timeStamp: UInt64 = mach_absolute_time()
) throws {

guard words.count > 0 else {
Expand All @@ -30,7 +31,7 @@ extension MIDIEventPacket {
var packet = MIDIEventPacket()

// time stamp
packet.timeStamp = .zero // zero means "now" when sending MIDI
packet.timeStamp = timeStamp

// word count
packet.wordCount = UInt32(words.count)
Expand All @@ -57,7 +58,8 @@ extension MIDIEventPacket {
@available(macOS 11, iOS 14, macCatalyst 14, tvOS 14, watchOS 7, *)
@inline(__always)
internal init(
wordsUsingBuilder words: [MIDI.UMPWord]
wordsUsingBuilder words: [MIDI.UMPWord],
timeStamp: UInt64 = mach_absolute_time()
) throws {

guard words.count > 0 else {
Expand All @@ -73,7 +75,9 @@ extension MIDIEventPacket {
}

let packetBuilder = MIDIEventPacket
.Builder(maximumNumberMIDIWords: 64) // must be 64 or we get crashes!
.Builder(maximumNumberMIDIWords: 64) // must be 64 or we get heap overflows/crashes!

packetBuilder.timeStamp = Int(timeStamp)

words.forEach { packetBuilder.append($0) }

Expand All @@ -97,10 +101,12 @@ extension MIDIEventList {
@inline(__always)
internal init(
protocol midiProtocol: MIDIProtocolID,
packetWords: [MIDI.UMPWord]
packetWords: [MIDI.UMPWord],
timeStamp: UInt64 = mach_absolute_time()
) throws {

let packet = try MIDIEventPacket(words: packetWords)
let packet = try MIDIEventPacket(words: packetWords,
timeStamp: timeStamp)

self = MIDIEventList(protocol: midiProtocol,
numPackets: 1,
Expand Down

0 comments on commit bf6ce74

Please sign in to comment.