comparison 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
comparison
equal deleted inserted replaced
19:9030967a05f8 20:b959c2acb927
2 Author: Chunyang Song 2 Author: Chunyang Song
3 Institution: Centre for Digital Music, Queen Mary University of London 3 Institution: Centre for Digital Music, Queen Mary University of London
4 4
5 ''' 5 '''
6 6
7 from BasicFuncs import ceiling, find_divisor, get_min_timeSpan 7 from basic_functions import ceiling, find_divisor, is_prime, get_min_timeSpan
8 8
9 # This function calculates the syncopation value for TOB model. 9 def get_syncopation(bar, parameter = None):
10 def get_syncopation(seq): 10 binarySequence = bar.get_binary_sequence()
11 sequenceLength = len(binarySequence)
12
11 syncopation = 0 13 syncopation = 0
12 bseq_ts = get_min_timeSpan(ceiling(seq)) # converting to binary and mininum time-span sequence
13 divisors = find_divisor(len(bseq_ts)) # find all the divisors other than 1 and the length of this sequence
14 del divisors[0]
15 del divisors[-1]
16 14
17 offbeatness = [1]*len(bseq_ts) 15 # if the length of b_sequence is 1 or a prime number, syncopation is 0;
18 for index in range(len(bseq_ts)): 16 # otherwise the syncopation is calculated by adding up the number of off-beat notes
19 for d in divisors: 17 if not ( (sequenceLength == 1) or (is_prime(sequenceLength)) ):
20 if index % d == 0: 18 # find all the divisors other than 1 and the length of this sequence
21 offbeatness[index] = 0 19 divisors = find_divisor(sequenceLength)
22 break 20 del divisors[0]
23 syncopation += bseq_ts[index]*offbeatness[index] 21 del divisors[-1]
22
23 # the on-beat/off-beat positions are the ones that can/cannot be subdivided by the sequenceLength;
24 # the on-beat positions are set to be 0, off-beat positions are set to be 1
25 offbeatness = [1]*sequenceLength
26 for index in range(sequenceLength):
27 for d in divisors:
28 if index % d == 0:
29 offbeatness[index] = 0
30 break
31 #print 'offbeatness', offbeatness
32 # syncopation is the sum of the hadamard-product of the rhythm binary-sequence and the off-beatness
33 syncopation += binarySequence[index]*offbeatness[index]
34
24 return syncopation 35 return syncopation