'Handles a single incoming MIDI message during capture.
If the message is a note_on event, ends the previous note (if applicable)
and opens a new note in the capture sequence. Ignores repeated note_on
events.
If the message is a note_off event matching the current open note in the
capture sequence
Args:
msg: The mido.Message MIDI message to handle.'

@concurrency.serialized
def _capture_message(self, msg):

    if ((msg.type == 'note_off') or ((msg.type == 'note_on') and (msg.velocity == 0))):
        if ((self._open_note is None) or (msg.note != self._open_note.pitch)):
            return
        self._open_note.end_time = msg.time
        self._open_note = None
    elif (msg.type == 'note_on'):
        if self._open_note:
            if (self._open_note.pitch == msg.note):
                return
            self._open_note.end_time = msg.time
        self._open_note = self._add_note(msg)
