Mercurial > hg > syncopation-dataset
annotate synpy/TOB.py @ 76:90b68f259541 tip
updated parameter_setter to be able to find the
TimeSignature.pkl file without putting it in the pwd
author | christopherh <christopher.harte@eecs.qmul.ac.uk> |
---|---|
date | Wed, 13 May 2015 09:27:36 +0100 |
parents | ef891481231e |
children |
rev | line source |
---|---|
christopher@45 | 1 ''' |
christopher@45 | 2 Author: Chunyang Song |
christopher@45 | 3 Institution: Centre for Digital Music, Queen Mary University of London |
christopher@45 | 4 |
christopher@45 | 5 ''' |
christopher@45 | 6 |
christopher@45 | 7 from basic_functions import ceiling, find_divisor, is_prime, velocity_sequence_to_min_timespan |
christopher@45 | 8 |
christopher@45 | 9 def get_syncopation(bar, parameters = None): |
christopher@45 | 10 binarySequence = velocity_sequence_to_min_timespan(bar.get_binary_sequence()) |
christopher@45 | 11 sequenceLength = len(binarySequence) |
christopher@45 | 12 |
christopher@45 | 13 syncopation = 0 |
christopher@45 | 14 |
christopher@45 | 15 # if the length of b_sequence is 1 or a prime number, syncopation is 0; |
christopher@45 | 16 # otherwise the syncopation is calculated by adding up the number of off-beat notes |
christopher@45 | 17 if not ( (sequenceLength == 1) or (is_prime(sequenceLength)) ): |
christopher@45 | 18 # find all the divisors other than 1 and the length of this sequence |
christopher@45 | 19 divisors = find_divisor(sequenceLength) |
christopher@45 | 20 del divisors[0] |
christopher@45 | 21 del divisors[-1] |
christopher@45 | 22 |
christopher@45 | 23 # the on-beat/off-beat positions are the ones that can/cannot be subdivided by the sequenceLength; |
christopher@45 | 24 # the on-beat positions are set to be 0, off-beat positions are set to be 1 |
christopher@45 | 25 offbeatness = [1]*sequenceLength |
christopher@45 | 26 for index in range(sequenceLength): |
christopher@45 | 27 for d in divisors: |
christopher@45 | 28 if index % d == 0: |
christopher@45 | 29 offbeatness[index] = 0 |
christopher@45 | 30 break |
christopher@45 | 31 #print 'offbeatness', offbeatness |
christopher@45 | 32 # syncopation is the sum of the hadamard-product of the rhythm binary-sequence and the off-beatness |
christopher@45 | 33 syncopation += binarySequence[index]*offbeatness[index] |
christopher@45 | 34 |
christopher@45 | 35 return syncopation |