         var packet: UnsafeMutablePointer<MIDIPacket> = MIDIPacketListInit(packetListPointer)
         packet = MIDIPacketListAdd(packetListPointer, 1_024, packet, time, data.count, data)
 
-        for endpoint in endpoints.values {
+        var endpointsRef: [MIDIEndpointRef] = []
+
+        if let endpointsUIDS = endpointsUIDs {
+            for endpointUID in endpointsUIDS {
+                if let endpoint = endpoints[endpointUID] {endpointsRef.append(endpoint)}
+            }
+        } else {
+            endpointsRef = Array(endpoints.values)
+        }
+
+        for endpoint in endpointsRef {
             let result = MIDISend(outputPort, endpoint, packetListPointer)
             if result != noErr {
                 Log("error sending midi: \(result)", log: OSLog.midi, type: .error)
             }
         }
 
-        if virtualOutputs[0] != 0 {
-            MIDIReceived(virtualOutputs[0], packetListPointer)
+        if virtualOutputs != [0] {
+            virtualOutputs.forEach {MIDIReceived($0, packetListPointer)}
         }
     }
 

    public func sendNoteOnMessageWithTime(noteNumber: MIDINoteNumber,
                                          velocity: MIDIVelocity,
                                          channel: MIDIChannel = 0,
                                          time: MIDITimeStamp = 0) {
        let noteCommand: MIDIByte = MIDIByte(0x90) + channel
        let message: [MIDIByte] = [noteCommand, noteNumber, velocity]
        self.sendMessageWithTime(message, time: time)
    }

    /// Send a Note Off Message with timestamp

    ///   - channel: MIDI Channel (default: 0)
    public func sendNoteOnMessage(noteNumber: MIDINoteNumber,
                                  velocity: MIDIVelocity,
                                  channel: MIDIChannel = 0,
                                  endpointsUIDs: [MIDIUniqueID]? = nil) {
        let noteCommand: MIDIByte = noteOnByte + channel
        let message: [MIDIByte] = [noteCommand, noteNumber, velocity]
        self.sendMessage(message, endpointsUIDs: endpointsUIDs)
    }

    /// Send a Note Off Message
