'Detects whether the note played is repeating previous notes excessively.
Args:
action_note: An integer representing the note just played.
Returns:
True if the note just played is excessively repeated, False otherwise.'

def detect_repeating_notes(self, action_note):

    num_repeated = 0
    contains_held_notes = False
    contains_breaks = False
    for i in range((len(self.composition) - 1), (-1), (-1)):
        if (self.composition[i] == action_note):
            num_repeated += 1
        elif (self.composition[i] == NOTE_OFF):
            contains_breaks = True
        elif (self.composition[i] == NO_EVENT):
            contains_held_notes = True
        else:
            break
    if ((action_note == NOTE_OFF) and (num_repeated > 1)):
        return True
    elif ((not contains_held_notes) and (not contains_breaks)):
        if (num_repeated > 4):
            return True
    elif (contains_held_notes or contains_breaks):
        if (num_repeated > 6):
            return True
    elif (num_repeated > 8):
        return True
    return False
