'Collapses a melody event value into a zero-based index range.
Args:
event: A Melody event value. -2 = no event, -1 = note-off event,
[0, 127] = note-on event for that midi pitch.
Returns:
An int in the range [0, self.num_classes). 0 = no event,
1 = note-off event, [2, self.num_classes) = note-on event for
that pitch relative to the [self._min_note, self._max_note) range.
Raises:
ValueError: If `event` is a MIDI note not between self._min_note and
self._max_note, or an invalid special event value.'

def encode_event(self, event):

    if (event < (- NUM_SPECIAL_MELODY_EVENTS)):
        raise ValueError(('invalid    melody    event    value:    %d' % event))
    if ((event >= 0) and (event < self._min_note)):
        raise ValueError(('melody    event    less    than    min    note:    %d    <    %d' % (event, self._min_note)))
    if (event >= self._max_note):
        raise ValueError(('melody    event    greater    than    max    note:    %d    >=    %d' % (event, self._max_note)))
    if (event < 0):
        return (event + NUM_SPECIAL_MELODY_EVENTS)
    return ((event - self._min_note) + NUM_SPECIAL_MELODY_EVENTS)
