view Syncopation models/TOB.py @ 23:df1e7c378ee0

fixed KTH, and WNBD
author csong <csong@eecs.qmul.ac.uk>
date Sun, 12 Apr 2015 13:06:17 +0100
parents b959c2acb927
children cc38b3047ed9
line wrap: on
line source
'''
Author: Chunyang Song
Institution: Centre for Digital Music, Queen Mary University of London

'''

from basic_functions import ceiling, find_divisor, is_prime

def get_syncopation(bar, parameter = None):
	binarySequence = bar.get_binary_sequence()
	sequenceLength = len(binarySequence)

	syncopation = 0

	# if the length of b_sequence is 1 or a prime number, syncopation is 0;
	# otherwise the syncopation is calculated by adding up the number of off-beat notes
	if not ( (sequenceLength == 1) or (is_prime(sequenceLength)) ):
		# find all the divisors other than 1 and the length of this sequence
		divisors = find_divisor(sequenceLength)		
		del divisors[0]
		del divisors[-1]

		# the on-beat/off-beat positions are the ones that can/cannot be subdivided by the sequenceLength;
		# the on-beat positions are set to be 0, off-beat positions are set to be 1
		offbeatness = [1]*sequenceLength			
		for index in range(sequenceLength):
			for d in divisors:
				if index % d == 0:
					offbeatness[index] = 0
					break
			#print 'offbeatness', offbeatness
			# syncopation is the sum of the hadamard-product of the rhythm binary-sequence and the off-beatness 
			syncopation += binarySequence[index]*offbeatness[index]
	
	return syncopation