'Returns the label for the given position in the melody.
Returns an int in the range [0, self.num_classes). Assuming
self._min_note = 48, self._note_range = 36, and two lookback distances,
then self.num_classes = 40.
Values [0, 39]:
[0, 35]: Note-on event for midi pitch [48, 84).
36: No event.
37: Note-off event.
38: Repeat first lookback (takes precedence over above values).
39: Repeat second lookback (takes precedence over above values).
Args:
events: A magenta.music.Melody object.
position: An integer event position in the melody.
Returns:
A label, an integer.'

def events_to_label(self, events, position):

    if ((position < self._lookback_distances[(-1)]) and (events[position] == MELODY_NO_EVENT)):
        return ((self._note_range + len(self._lookback_distances)) + 1)
    for (i, lookback_distance) in reversed(list(enumerate(self._lookback_distances))):
        lookback_position = (position - lookback_distance)
        if ((lookback_position >= 0) and (events[position] == events[lookback_position])):
            return ((self._note_range + 2) + i)
    if (events[position] == MELODY_NOTE_OFF):
        return (self._note_range + 1)
    if (events[position] == MELODY_NO_EVENT):
        return self._note_range
    return (events[position] - self._min_note)
