'Transpose and octave shift the notes in this Melody.
The key center of this melody is computed with a heuristic, and the notes
are transposed to be in the given key. The melody is also octave shifted
to be centered in the given range. Additionally, all notes are octave
shifted to lie within a given range.
Args:
min_note: Minimum pitch (inclusive) that the resulting notes will take on.
max_note: Maximum pitch (exclusive) that the resulting notes will take on.
transpose_to_key: The melody is transposed to be in this key or None if
should not be transposed. 0 = C Major.
Returns:
How much notes are transposed by.'

def squash(self, min_note, max_note, transpose_to_key=None):

    if (transpose_to_key is None):
        transpose_amount = 0
    else:
        melody_key = self.get_major_key()
        key_diff = (transpose_to_key - melody_key)
        midi_notes = [note for note in self._events if (MIN_MIDI_PITCH <= note <= MAX_MIDI_PITCH)]
        if (not midi_notes):
            return 0
        melody_min_note = min(midi_notes)
        melody_max_note = max(midi_notes)
        melody_center = ((melody_min_note + melody_max_note) / 2)
        target_center = (((min_note + max_note) - 1) / 2)
        center_diff = (target_center - (melody_center + key_diff))
        transpose_amount = (key_diff + (NOTES_PER_OCTAVE * int(round((center_diff / float(NOTES_PER_OCTAVE))))))
    self.transpose(transpose_amount, min_note, max_note)
    return transpose_amount
