Mercurial > hg > syncopation-dataset
comparison Syncopation models/synpy/TOB.py @ 45:6e9154fc58df
moving the code files to the synpy package directory
author | christopherh <christopher.harte@eecs.qmul.ac.uk> |
---|---|
date | Thu, 23 Apr 2015 23:52:04 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
44:144460f34b5e | 45:6e9154fc58df |
---|---|
1 ''' | |
2 Author: Chunyang Song | |
3 Institution: Centre for Digital Music, Queen Mary University of London | |
4 | |
5 ''' | |
6 | |
7 from basic_functions import ceiling, find_divisor, is_prime, velocity_sequence_to_min_timespan | |
8 | |
9 def get_syncopation(bar, parameters = None): | |
10 binarySequence = velocity_sequence_to_min_timespan(bar.get_binary_sequence()) | |
11 sequenceLength = len(binarySequence) | |
12 | |
13 syncopation = 0 | |
14 | |
15 # if the length of b_sequence is 1 or a prime number, syncopation is 0; | |
16 # otherwise the syncopation is calculated by adding up the number of off-beat notes | |
17 if not ( (sequenceLength == 1) or (is_prime(sequenceLength)) ): | |
18 # find all the divisors other than 1 and the length of this sequence | |
19 divisors = find_divisor(sequenceLength) | |
20 del divisors[0] | |
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 | |
35 return syncopation |