Mercurial > hg > syncopation-dataset
comparison Syncopation models/basic_functions.py @ 28:5de1cb45c145
Parameters setting implemented.
author | csong <csong@eecs.qmul.ac.uk> |
---|---|
date | Sun, 12 Apr 2015 22:34:35 +0100 |
parents | d9d22e6f396d |
children | 7a1730bbf15a |
comparison
equal
deleted
inserted
replaced
27:ed29ed80635c | 28:5de1cb45c145 |
---|---|
79 isPrime = False | 79 isPrime = False |
80 return isPrime | 80 return isPrime |
81 | 81 |
82 # upsample a velocity sequence to certain length, e.g. [1,1] to [1,0,0,0,1,0,0,0] | 82 # upsample a velocity sequence to certain length, e.g. [1,1] to [1,0,0,0,1,0,0,0] |
83 def upsample_velocity_sequence(velocitySequence, length): | 83 def upsample_velocity_sequence(velocitySequence, length): |
84 upsampledVelocitySequence = [0]*length | 84 upsampledVelocitySequence = None |
85 if length%len(velocitySequence) != 0: | 85 if length%len(velocitySequence) != 0: |
86 print 'Error: the velocity sequence can only be upsampled to the interger times of its length.' | 86 print 'Error: the velocity sequence can only be upsampled to the interger times of its length.' |
87 else: | 87 else: |
88 upsampledVelocitySequence = [0]*length | |
88 scalingFactor = length/len(velocitySequence) | 89 scalingFactor = length/len(velocitySequence) |
89 for index in range(len(velocitySequence)): | 90 for index in range(len(velocitySequence)): |
90 upsampledVelocitySequence[index*scalingFactor] = velocitySequence[index] | 91 upsampledVelocitySequence[index*scalingFactor] = velocitySequence[index] |
91 return upsampledVelocitySequence | 92 return upsampledVelocitySequence |
92 | 93 |
212 # else: | 213 # else: |
213 # subdivision_seq = subdivision_seq[0:L_max+1] | 214 # subdivision_seq = subdivision_seq[0:L_max+1] |
214 | 215 |
215 # return subdivision_seq | 216 # return subdivision_seq |
216 | 217 |
217 | |
218 # The split_by_bar function seperates the score representation of rhythm by bar lines, | |
219 # resulting in a list representingbar-by-bar rhythm sequence, | |
220 # e.g. rhythm = ['|',[ts1,td1,v1], [ts2,td2,v2], '|',[ts3,td3,v3],'|'...] | |
221 # rhythm_bybar = [ [ [ts1,td1,v1], [ts2,td2,v2] ], [ [ts3,td3,v3] ], [...]] | |
222 # def split_by_bar(rhythm): | |
223 # rhythm_bybar = [] | |
224 # bar_index = [] | |
225 # for index in range(len(rhythm)): | |
226 # if rhythm[index] == '|': | |
227 | |
228 # return rhythm_bybar | |
229 | |
230 # def yseq_to_vseq(yseq): | |
231 # vseq = [] | |
232 | |
233 # return vseq | |
234 | |
235 | |
236 # # testing | |
237 # print find_prime_factors(10) | |
238 # print find_prime_factors(2) | |
239 # print find_prime_factors(12) | |
240 | |
241 | |
242 # print is_prime(1) # False | |
243 # print is_prime(2) # True | |
244 # print is_prime(3) # True | |
245 # print is_prime(29) # True | |
246 # print is_prime(345) # False | |
247 # print is_prime(999979) # True | |
248 # print is_prime(999981) # False |