diff Syncopation models/basic_functions.py @ 23:df1e7c378ee0

fixed KTH, and WNBD
author csong <csong@eecs.qmul.ac.uk>
date Sun, 12 Apr 2015 13:06:17 +0100
parents 2dbc09ca8013
children d9d22e6f396d
line wrap: on
line diff
--- a/Syncopation models/basic_functions.py	Thu Apr 09 23:49:16 2015 +0100
+++ b/Syncopation models/basic_functions.py	Sun Apr 12 13:06:17 2015 +0100
@@ -80,12 +80,12 @@
 	return isPrime
 
 # convert a velocity sequence to its minimum time-span representation
-def velocity_sequence_to_min_timetpan(velocitySequence):
+def velocity_sequence_to_min_timespan(velocitySequence):
 	minTimeSpanVelocitySeq = [1]
 	for divisors in find_divisor(len(velocitySequence)):
 		segments = subdivide(velocitySequence,divisors)
 		if len(segments)!=0:
-			del minTimeSpanSequence[:]
+			del minTimeSpanVelocitySeq[:]
 			for s in segments:
 				minTimeSpanVelocitySeq.append(s[0])
 			if sum(minTimeSpanVelocitySeq) == sum(velocitySequence):
@@ -93,21 +93,27 @@
 	return minTimeSpanVelocitySeq
 
 # convert a note sequence to its minimum time-span representation
-def note_sequence_to_min_timespan(noteSequence, barTicks):
-	barBinaryArray = [0]*barTicks
+def note_sequence_to_min_timespan(noteSequence):
+	from music_objects import note_sequence_to_velocity_sequence
+	timeSpanTicks = len(note_sequence_to_velocity_sequence(noteSequence))
+#	print timeSpanTicks
+
+	barBinaryArray = [0]*(timeSpanTicks+1)
 	for note in noteSequence:
 		# mark note_on event (i.e. startTime) and note_off event (i.e. endTime = startTime + duration) as 1 in the barBinaryArray
-		barBinaryArray[note[0]] = 1
-		barBinaryArray[note[0]+note[1]] = 1
+		barBinaryArray[note.startTime] = 1
+		barBinaryArray[note.startTime + note.duration] = 1
 
 	# convert the barBinaryArray to its minimum time-span representation
-	minBarBinaryArray = velocitySequence_to_min_timeSpan(barBinaryArray)
+	minBarBinaryArray = velocity_sequence_to_min_timetpan(barBinaryArray[:-1])
+	print barBinaryArray
+	print minBarBinaryArray
 	delta_t = len(barBinaryArray)/len(minBarBinaryArray)
 
 	# scale the startTime and duration of each note by delta_t
 	for note in noteSequence:
-		note[0] = note[0]/delta_t
-		note[1] = note[1]/delta_t
+		note.startTime = note.startTime/delta_t
+		note.duration = note.duration/delta_t
 
 	return noteSequence