csong@1: ''' csong@1: Author: Chunyang Song csong@1: Institution: Centre for Digital Music, Queen Mary University of London csong@1: csong@1: ''' csong@1: csong@20: from basic_functions import ceiling, find_divisor, is_prime, get_min_timeSpan csong@1: csong@20: def get_syncopation(bar, parameter = None): csong@20: binarySequence = bar.get_binary_sequence() csong@20: sequenceLength = len(binarySequence) csong@20: csong@1: syncopation = 0 csong@1: csong@20: # if the length of b_sequence is 1 or a prime number, syncopation is 0; csong@20: # otherwise the syncopation is calculated by adding up the number of off-beat notes csong@20: if not ( (sequenceLength == 1) or (is_prime(sequenceLength)) ): csong@20: # find all the divisors other than 1 and the length of this sequence csong@20: divisors = find_divisor(sequenceLength) csong@20: del divisors[0] csong@20: del divisors[-1] csong@20: csong@20: # the on-beat/off-beat positions are the ones that can/cannot be subdivided by the sequenceLength; csong@20: # the on-beat positions are set to be 0, off-beat positions are set to be 1 csong@20: offbeatness = [1]*sequenceLength csong@20: for index in range(sequenceLength): csong@20: for d in divisors: csong@20: if index % d == 0: csong@20: offbeatness[index] = 0 csong@20: break csong@20: #print 'offbeatness', offbeatness csong@20: # syncopation is the sum of the hadamard-product of the rhythm binary-sequence and the off-beatness csong@20: syncopation += binarySequence[index]*offbeatness[index] csong@20: csong@1: return syncopation