'Detects whether the last motif played repeats an earlier motif played.
Args:
action: One-hot encoding of the chosen action.
bar_length: The number of beats in one bar. This determines how many beats
the model has in which to play the motif.
Returns:
True if the note just played belongs to a motif that is repeated. False
otherwise.'

def detect_repeated_motif(self, action, bar_length=8):

    composition = (self.composition + [np.argmax(action)])
    if (len(composition) < bar_length):
        return (False, None)
    (motif, _) = self.detect_last_motif(composition=composition, bar_length=bar_length)
    if (motif is None):
        return (False, None)
    prev_composition = self.composition[:(- (bar_length - 1))]
    for i in range(((len(prev_composition) - len(motif)) + 1)):
        for j in range(len(motif)):
            if (prev_composition[(i + j)] != motif[j]):
                break
        else:
            return (True, motif)
    return (False, None)
