annotate Syncopation models/TOB.py @ 38:cc38b3047ed9

updated syncopation.y to allow output of sync for a bar list also fixed some problems in models and other modules
author christopherh <christopher.harte@eecs.qmul.ac.uk>
date Mon, 13 Apr 2015 23:06:49 +0100
parents df1e7c378ee0
children
rev   line source
csong@1 1 '''
csong@1 2 Author: Chunyang Song
csong@1 3 Institution: Centre for Digital Music, Queen Mary University of London
csong@1 4
csong@1 5 '''
csong@1 6
christopher@38 7 from basic_functions import ceiling, find_divisor, is_prime, velocity_sequence_to_min_timespan
csong@1 8
christopher@38 9 def get_syncopation(bar, parameters = None):
christopher@38 10 binarySequence = velocity_sequence_to_min_timespan(bar.get_binary_sequence())
csong@20 11 sequenceLength = len(binarySequence)
csong@20 12
csong@1 13 syncopation = 0
csong@1 14
csong@20 15 # if the length of b_sequence is 1 or a prime number, syncopation is 0;
csong@20 16 # otherwise the syncopation is calculated by adding up the number of off-beat notes
csong@20 17 if not ( (sequenceLength == 1) or (is_prime(sequenceLength)) ):
csong@20 18 # find all the divisors other than 1 and the length of this sequence
csong@20 19 divisors = find_divisor(sequenceLength)
csong@20 20 del divisors[0]
csong@20 21 del divisors[-1]
csong@20 22
csong@20 23 # the on-beat/off-beat positions are the ones that can/cannot be subdivided by the sequenceLength;
csong@20 24 # the on-beat positions are set to be 0, off-beat positions are set to be 1
csong@20 25 offbeatness = [1]*sequenceLength
csong@20 26 for index in range(sequenceLength):
csong@20 27 for d in divisors:
csong@20 28 if index % d == 0:
csong@20 29 offbeatness[index] = 0
csong@20 30 break
csong@20 31 #print 'offbeatness', offbeatness
csong@20 32 # syncopation is the sum of the hadamard-product of the rhythm binary-sequence and the off-beatness
csong@20 33 syncopation += binarySequence[index]*offbeatness[index]
csong@20 34
csong@1 35 return syncopation