diff Syncopation models/basic_functions.py @ 26:d9d22e6f396d

fixed SG!
author csong <csong@eecs.qmul.ac.uk>
date Sun, 12 Apr 2015 15:53:58 +0100
parents df1e7c378ee0
children 5de1cb45c145
line wrap: on
line diff
--- a/Syncopation models/basic_functions.py	Sun Apr 12 13:06:17 2015 +0100
+++ b/Syncopation models/basic_functions.py	Sun Apr 12 15:53:58 2015 +0100
@@ -79,6 +79,18 @@
 				isPrime = False
 	return isPrime
 
+# upsample a velocity sequence to certain length, e.g. [1,1] to [1,0,0,0,1,0,0,0]
+def upsample_velocity_sequence(velocitySequence, length):
+	upsampledVelocitySequence = [0]*length
+	if length%len(velocitySequence) != 0:
+		print 'Error: the velocity sequence can only be upsampled to the interger times of its length.'
+	else:
+		scalingFactor = length/len(velocitySequence)
+		for index in range(len(velocitySequence)):
+			upsampledVelocitySequence[index*scalingFactor] = velocitySequence[index]
+	return upsampledVelocitySequence
+
+
 # convert a velocity sequence to its minimum time-span representation
 def velocity_sequence_to_min_timespan(velocitySequence):
 	minTimeSpanVelocitySeq = [1]
@@ -118,7 +130,6 @@
 	return noteSequence
 
 
-
 # get_note_indices returns all the indices of all the notes in this velocity_sequence
 def get_note_indices(velocitySequence):
 	noteIndices = []
@@ -159,7 +170,7 @@
 	e.g. prime_factors of polyrhythm 100100101010 in 4/4 is [2,3] but subdivision_seq = [1,2,2] for 4/4 
 	'''
 	rhythmCategory = 'mono'
-	for f in find_prime_factors(len(get_min_timeSpan(velocitySequence))):
+	for f in find_prime_factors(len(velocity_sequence_to_min_timespan(velocitySequence))):
 		if not (f in subdivisionSequence): 
 			rhythmCategory = 'poly'
 			break