     
     public let type: Type
     
-    public let time: TimeInterval
-    
-    public init(_ type: Type, time: TimeInterval = 0.0) {
+    public let delay: TimeInterval
+    
+    public init(_ type: Type, delay: TimeInterval = 0.0) {
         self.type = type
-        self.time = time
+        self.delay = delay
     }
 
 }

    internal init(_ message: MIDIMessage) {
        switch message.type {
        case .noteOff(let channel, let key, let velocity):
            self.init(time: message.time, status: 8, channel: channel, data1: key, data2: velocity)
        case .noteOn(let channel, let key, let velocity):
            self.init(time: message.time, status: 9, channel: channel, data1: key, data2: velocity)
        case .polyphonicKeyPressure(let channel, let key, let pressure):
            self.init(time: message.time, status: 10, channel: channel, data1: key, data2: pressure)
        case .controlChange(let channel, let controller, let value):
            self.init(time: message.time, status: 11, channel: channel, data1: controller, data2: value)
        case .channelMode(let channel, let type):
            switch type {
            case .allSoundOff:
                self.init(time: message.time, status: 11, channel: channel, data1: 120, data2: 0)
            case .resetAllControllers:
                self.init(time: message.time, status: 11, channel: channel, data1: 121, data2: 0)
            case .localControlOff:
                self.init(time: message.time, status: 11, channel: channel, data1: 122, data2: 0)
            case .localControlOn:
                self.init(time: message.time, status: 11, channel: channel, data1: 122, data2: 127)
            case .allNotesOff:
                self.init(time: message.time, status: 11, channel: channel, data1: 123, data2: 0)
            case .omniModeOff:
                self.init(time: message.time, status: 11, channel: channel, data1: 124, data2: 0)
            case .omniModeOn:
                self.init(time: message.time, status: 11, channel: channel, data1: 125, data2: 0)
            case .monoModeOn(let channels):
                self.init(time: message.time, status: 11, channel: channel, data1: 126, data2: channels)
            case .polyModeOn:
                self.init(time: message.time, status: 11, channel: channel, data1: 127, data2: 0)
            }
        case .programChange(let channel, let number):
            self.init(time: message.time, status: 12, channel: channel, data1: number)
        case .channelPressure(let channel, let pressure):
            self.init(time: message.time, status: 13, channel: channel, data1: pressure)
        case .pitchBendChange(let channel, let leastSignificantBits, let mostSignificantBits):
            self.init(time: message.time, status: 14, channel: channel, data1: leastSignificantBits, data2: mostSignificantBits)
        case .systemCommon(let type):
            switch type {
            case .systemExclusive:
                self.init(time: message.time, status: 15, channel: 0)
            case .midiTimeCodeQuarterFrame(let type, let values):
                self.init(time: message.time, status: 15, channel: 1, data1: (type << 4) | (values & 0b00001111))
            case .songPositionPointer(let leastSignificantBits, let mostSignificantBits):
                self.init(time: message.time, status: 15, channel: 2, data1: leastSignificantBits, data2: mostSignificantBits)
            case .songSelect(let song):
                self.init(time: message.time, status: 15, channel: 3, data1: song)
            case .tuneRequest:
                self.init(time: message.time, status: 15, channel: 5)
            }
        case .systemRealTime(let type):
            switch type {
            case .timingClock:
                self.init(time: message.time, status: 15, channel: 8)
            case .start:
                self.init(time: message.time, status: 15, channel: 10)
            case .continue:
                self.init(time: message.time, status: 15, channel: 11)
            case .stop:
                self.init(time: message.time, status: 15, channel: 12)
            case .activeSensing:
                self.init(time: message.time, status: 15, channel: 14)
            case .reset:
                self.init(time: message.time, status: 15, channel: 15)
            }
        default:
            self.init(time: message.time, status: 0, channel: 0)
        }
    }
    


extension MIDIPacket {
    
    fileprivate init(delay: TimeInterval, status: UInt8, channel: UInt8) {
        self.init()
        self.timeStamp = mach_absolute_time() + MIDITimeStamp(delay * 1_000_000_000)
        self.length = 1
        self.data.0 = (status << 4) | (channel & 0b00001111)
    }
    
    fileprivate init(delay: TimeInterval, status: UInt8, channel: UInt8, data1: UInt8) {
        self.init()
        self.timeStamp = mach_absolute_time() + MIDITimeStamp(delay * 1_000_000_000)
        self.length = 2
        self.data.0 = (status << 4) | (channel & 0b00001111)
        self.data.1 = data1 & 0b01111111
    }
    
    fileprivate init(delay: TimeInterval, status: UInt8, channel: UInt8, data1: UInt8, data2: UInt8) {
        self.init()
        self.timeStamp = mach_absolute_time() + MIDITimeStamp(delay * 1_000_000_000)
        self.length = 3
        self.data.0 = (status << 4) | (channel & 0b00001111)
        self.data.1 = data1 & 0b01111111
        self.data.2 = data2 & 0b01111111
    }
    
    fileprivate var delay: TimeInterval {
        return TimeInterval(timeStamp) / 1_000_000_000
    }
    
