diff Syncopation models/PRS.py @ 20:b959c2acb927

Refactored all models except for KTH, all past testing except for SG.
author csong <csong@eecs.qmul.ac.uk>
date Tue, 07 Apr 2015 19:05:07 +0100
parents 9030967a05f8
children df1e7c378ee0
line wrap: on
line diff
--- a/Syncopation models/PRS.py	Fri Apr 03 22:57:27 2015 +0100
+++ b/Syncopation models/PRS.py	Tue Apr 07 19:05:07 2015 +0100
@@ -14,9 +14,9 @@
 		cost = 1
 	elif sequence[0] == 1 and sequence[-1] == 0:			# run1 prototype
 		cost = 2
-	elif sequence[0] == 1 and (nextSequence == None or nenextSequencext_seq[0] == 0):	# run2 prototype
+	elif sequence[0] == 1 and (nextSequence == None or nextSequence[0] == 0):	# run2 prototype
 		cost = 2
-	elif sequence[0] == 1 and sequence[-1] == 1 and nextSequence != None and nextSequence[0] == 1:		# upbeat prototype
+	elif sequence[-1] == 1 and nextSequence != None and nextSequence[0] == 1:		# upbeat prototype
 		cost = 3
 	elif sequence[0] == 0:							# syncopated prototype
 		cost = 5
@@ -25,44 +25,47 @@
 
 # This function calculates the syncopation value (cost) for the sequence with the postbar_seq for a certain level. 
 def syncopation_perlevel(subSequences):
+	print 'subSequences', subSequences
 	total = 0
 	for l in range(len(subSequences)-1):
+		print 'cost', get_cost(subSequences[l], subSequences[l+1])
 		total = total + get_cost(subSequences[l], subSequences[l+1])
+	print 'total this level', total
 	normalised = float(total)/(len(subSequences)-1)
 	
 	return normalised
 
-#def get_syncopation(seq,subdivision_seq, postbar_seq, rhythm_category):
 def get_syncopation(bar, parameters = None):
-	'''
-	The get_syncopation function calculates the overall syncopation value for a bar of sequence.
-	'''
 	syncopation = None
 
 	binarySequence = bar.get_binary_sequence()
 	subdivisionSequence = bar.get_subdivision_sequence()
 
+	# PRS does not handle polyrhythms
 	if get_rhythm_category(binarySequence, subdivisionSequence) == 'poly':
 		print 'Warning: PRS model detects polyrhythms so returning None.'
 	else:
 		syncopation = 0
 
+		# retrieve the binary sequence in the next bar
 		if bar.get_next_bar() != None:
 			nextbarBinarySequence = bar.get_next_bar().get_binary_sequence()
 		else:
 			nextbarBinarySequence = None
 
-		# the initial number of sub-sequences at a certain metrical level
+		# numberOfSubSeqs is the number of sub-sequences at a certain metrical level, initialised to be 1 (at the bar level)
 		numberOfSubSeqs = 1	
 		for subdivisor in subdivisionSequence:
-			# the number of sub-sequence at the current level is product of all the subdivisors up to the current level
+			# numberOfSubSeqs is product of all the subdivisors up to the current level
 			numberOfSubSeqs = numberOfSubSeqs * subdivisor
+			
 			# recursion stops when the length of sub-sequence is less than 2
 			if len(binarySequence)/numberOfSubSeqs >= 2:		
 				# generate sub-sequences and append the next bar sequence
 				subSequences = subdivide(ceiling(binarySequence), numberOfSubSeqs)	
 				subSequences.append(nextbarBinarySequence)
 				# adding syncopation at each metrical level to the total syncopation
+				#print 'per level', syncopation_perlevel(subSequences)
 				syncopation += syncopation_perlevel(subSequences)	
 			else:
 				break