diff --git a/Sources/MIDIKitSMF/MIDIFile/Chunk/Track.swift b/Sources/MIDIKitSMF/MIDIFile/Chunk/Track.swift index fbebf277e4..e07a96d138 100644 --- a/Sources/MIDIKitSMF/MIDIFile/Chunk/Track.swift +++ b/Sources/MIDIKitSMF/MIDIFile/Chunk/Track.swift @@ -309,17 +309,15 @@ extension MIDIFile.Chunk.Track { /// Returns ``events`` mapped to their beat position in the sequence. /// This is computed so avoid frequent calls to this method. /// Ensure the `ppq` supplied is the same as used in the MIDI file. - public func eventsAtBeatPositions(ppq: UInt16) -> [(beat: Double, event: MIDIFileEventPayload)] { + public func eventsAtBeatPositions(ppq: UInt16) -> [(beat: Double, event: MIDIFileEvent)] { var position: Double = 0.0 - return events.lazy - .map { $0.smfUnwrappedEvent } - .map { (delta, payload) in - let deltaTicks = delta.ticksValue(using: .musical(ticksPerQuarterNote: ppq)) - if deltaTicks != 0 { - position += Double(deltaTicks) / Double(ppq) - } - return (beat: position, event: payload) + return events.map { + let deltaTicks = $0.delta.ticksValue(using: .musical(ticksPerQuarterNote: ppq)) + if deltaTicks != 0 { + position += Double(deltaTicks) / Double(ppq) } + return (beat: position, event: $0) + } } } diff --git a/Sources/MIDIKitSMF/MIDIFile/Types/TimeBase.swift b/Sources/MIDIKitSMF/MIDIFile/Types/TimeBase.swift index c62204d4a6..79dcc04917 100644 --- a/Sources/MIDIKitSMF/MIDIFile/Types/TimeBase.swift +++ b/Sources/MIDIKitSMF/MIDIFile/Types/TimeBase.swift @@ -12,7 +12,7 @@ import MIDIKitCore extension MIDIFile { /// MIDI file timebase as described in the MIDI file header. public enum TimeBase: Equatable, Hashable { - /// Musical: Delta-time ticks per quarter note (PPQN / PPQ / PPQBase). + /// Musical: Delta-time ticks per quarter note (PPQN / PPQ / PPQBase / TPQN). /// /// Common values: 96, 120, 480, 960. Cubase exports at 480 by default. /// Can also be a larger value if needed. @@ -41,8 +41,8 @@ extension MIDIFile.TimeBase { extension MIDIFile.TimeBase { var rawData: Data { switch self { - case let .musical(TicksPerQuarterNote): - return (TicksPerQuarterNote & 0b01111111_11111111) + case let .musical(ticksPerQuarterNote): + return (ticksPerQuarterNote & 0b01111111_11111111) .toData(.bigEndian) case let .timecode(smpteFormat, ticksPerFrame):