'Returns a copy of the current captured sequence.
If called before the thread terminates, `end_time` is required and any open
notes will have their end time set to it, any notes starting after it will
be removed, and any notes ending after it will be truncated. `total_time`
will also be set to `end_time`.
Args:
end_time: The float time in seconds to close any open notes and after
which to close or truncate notes, if the thread is still alive.
Otherwise, must be None.
Returns:
A copy of the current captured NoteSequence proto with open notes closed
at and later notes removed or truncated to `end_time`.
Raises:
MidiHubException: When the thread is alive and `end_time` is None or the
thread is terminated and `end_time` is not None.'

def captured_sequence(self, end_time=None):

    current_captured_sequence = music_pb2.NoteSequence()
    with self._lock:
        current_captured_sequence.CopyFrom(self._captured_sequence)
    if self.is_alive():
        if (end_time is None):
            raise MidiHubException('`end_time`    must    be    provided    when    capture    thread    is    still    running.')
        for (i, note) in enumerate(current_captured_sequence.notes):
            if (note.start_time >= end_time):
                del current_captured_sequence.notes[i:]
                break
            if ((not note.end_time) or (note.end_time > end_time)):
                note.end_time = end_time
        current_captured_sequence.total_time = end_time
    elif (end_time is not None):
        raise MidiHubException('`end_time`    must    not    be    provided    when    capture    is    complete.')
    return current_captured_sequence
