diff Syncopation models/LHL.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 5de1cb45c145
line wrap: on
line diff
--- a/Syncopation models/LHL.py	Fri Apr 03 22:57:27 2015 +0100
+++ b/Syncopation models/LHL.py	Tue Apr 07 19:05:07 2015 +0100
@@ -30,15 +30,13 @@
 		for a in range(len(subBinarySequences)):
 			recursive_tree(subBinarySequences[a], subdivisionSequence, weightSequence, subWeightSequences[a], level+1)
 
+#!!!! needs fixing
 def are_parameters_valid(parameters):
-	areValid = False
-	if 'Lmax' not in parameters :
+	areValid = True
+#	if 'Lmax' not in parameters :
 
 def get_syncopation(bar, parameters = None):
-	'''
-	The get_syncopation function calculates syncopation value . 
-	'''
-#def get_syncopation(seq, subdivision_seq, weight_seq, prebar_seq, rhythm_category):
+	del terminalNodes[:]
 	syncopation = None
 
 	binarySequence = bar.get_binary_sequence()
@@ -50,7 +48,7 @@
 		# If the parameters are not given, use the default settings
 		if parameters == None:
 			Lmax  = 5
-			weightSequence = range(0,-Lmax,-1)
+			weightSequence = range(0,-Lmax,-1) # i.e. [0,-1,-2,-3,-4]
 		else:
 			if are_parameters_valid(parameters):
 				Lmax = parameters['Lmax']
@@ -65,7 +63,7 @@
 			recursive_tree(ceiling(prebarBinarySequence), subdivisionSequence, weightSequence, weightSequence[0],0)
 			
 			# Only keep the last note-type node
-			while terminalNodes[-1].node_type != 'N':
+			while terminalNodes[-1].nodeType != 'N':
 				del terminalNodes[-1]
 			del terminalNodes[0:-1]
 
@@ -73,15 +71,15 @@
 		recursive_tree(ceiling(binarySequence), subdivisionSequence, weightSequence, weightSequence[0],0)
 		
 		# for t in terminalNodes:
-		# 	print '<', t.node_type, t.metrical_weight, '>'
+		# 	print '<', t.nodeType, t.metricalWeight, '>'
 
 		# Search for the NR pairs that contribute to syncopation, 
 		# then add the weight-difference to the NRpairSyncopation list
 		NRpairSyncopation = []
 		for i in range(len(terminalNodes)-1,0,-1):
-			if terminalNodes[i].node_type == 'R':
+			if terminalNodes[i].nodeType == 'R':
 				for j in range(i-1, -1, -1):
-					if (terminalNodes[j].node_type == 'N') & (terminalNodes[i].metricalWeight >= terminalNodes[j].metricalWeight):
+					if (terminalNodes[j].nodeType == 'N') & (terminalNodes[i].metricalWeight >= terminalNodes[j].metricalWeight):
 						NRpairSyncopation.append(terminalNodes[i].metricalWeight - terminalNodes[j].metricalWeight)
 						break
 		#print NRpairSyncopation