     }
 }
 
+extension MIDIEvent {
+    @inline(__always)
+    fileprivate init(packet p: inout MIDIPacket) {
+        self = withUnsafeBytes(of: &p.data) {
+            let data = Data(bytes: $0.baseAddress!, count : Int(p.length))
+            return MIDIEvent(timestamp: p.timeStamp, data: data)
+        }
+    }
+}
+
 extension MIDIPacketList: Sequence {
     public typealias Element = MIDIEvent
 

        var i = (0..<numPackets).makeIterator()

        return AnyIterator {
            guard let _ = i.next() else { return nil }
            defer {
                p = MIDIPacketNext(&p).pointee
            }

            return withUnsafeBytes(of: &p.data) {
                let data = Data(bytes: $0.baseAddress!, count : Int(p.length))
                return MIDIEvent(timestamp: p.timeStamp, data: data)
            }
        }
    }
}

}

extension UnsafeMutableRawBufferPointer {
    fileprivate mutating
    func copyBytes<S: Sequence>(from data: S) -> Int where S.Iterator.Element == UInt8 {
        var copied = 0
        for (i, byte) in data.enumerated() {
