Mercurial > hg > syncopation-dataset
diff Syncopation models/TOB.py @ 20:b959c2acb927
Refactored all models except for KTH, all past testing except for SG.
author | csong <csong@eecs.qmul.ac.uk> |
---|---|
date | Tue, 07 Apr 2015 19:05:07 +0100 |
parents | 031e2ccb1fb6 |
children | df1e7c378ee0 |
line wrap: on
line diff
--- a/Syncopation models/TOB.py Fri Apr 03 22:57:27 2015 +0100 +++ b/Syncopation models/TOB.py Tue Apr 07 19:05:07 2015 +0100 @@ -4,21 +4,32 @@ ''' -from BasicFuncs import ceiling, find_divisor, get_min_timeSpan +from basic_functions import ceiling, find_divisor, is_prime, get_min_timeSpan -# This function calculates the syncopation value for TOB model. -def get_syncopation(seq): +def get_syncopation(bar, parameter = None): + binarySequence = bar.get_binary_sequence() + sequenceLength = len(binarySequence) + syncopation = 0 - bseq_ts = get_min_timeSpan(ceiling(seq)) # converting to binary and mininum time-span sequence - divisors = find_divisor(len(bseq_ts)) # find all the divisors other than 1 and the length of this sequence - del divisors[0] - del divisors[-1] - offbeatness = [1]*len(bseq_ts) - for index in range(len(bseq_ts)): - for d in divisors: - if index % d == 0: - offbeatness[index] = 0 - break - syncopation += bseq_ts[index]*offbeatness[index] + # 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