'Sets the length of the melody to the specified number of steps.
If the melody is not long enough, ends any sustained notes and adds NO_EVENT
steps for padding. If it is too long, it will be truncated to the requested
length.
Args:
steps: How many steps long the melody should be.
from_left: Whether to add/remove from the left instead of right.'

def set_length(self, steps, from_left=False):

    old_len = len(self)
    super(Melody, self).set_length(steps, from_left=from_left)
    if ((steps > old_len) and (not from_left)):
        for i in reversed(range(old_len)):
            if (self._events[i] == MELODY_NOTE_OFF):
                break
            elif (self._events[i] != MELODY_NO_EVENT):
                self._events[old_len] = MELODY_NOTE_OFF
                break
