changeset 13:bc3b9022ebc4

Merged.
author csong <csong@eecs.qmul.ac.uk>
date Fri, 03 Apr 2015 17:05:31 +0100
parents 4acddc008048
children 4fb9c00e4ef0
files Syncopation models/basic_functions.py Syncopation models/music_objects.py Syncopation models/rhythm_parser.py Syncopation models/syncopation.py
diffstat 4 files changed, 41 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/Syncopation models/basic_functions.py	Fri Apr 03 16:38:32 2015 +0100
+++ b/Syncopation models/basic_functions.py	Fri Apr 03 17:05:31 2015 +0100
@@ -142,13 +142,22 @@
 	return subdivision_seq
 
 
-def get_rhythm_category(sequence, subdivision_seq):
-	rhythm_category = 'mono'
-	for f in find_prime_factors(len(get_min_timeSpan(sequence))):
-		if not (f in subdivision_seq): 
-			rhythm_category = 'poly'
+def get_rhythm_category(velocitySequence, subdivisionSequence):
+	'''
+	The get_rhythm_category function is used to detect rhythm category: monorhythm or polyrhythm.
+	For monorhythms, all prime factors of the length of minimum time-span representation of this sequence are
+	elements of its subdivision_seq, otherwise it is polyrhythm; 
+	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))):
+		if not (f in subdivisionSequence): 
+			rhythmCategory = 'poly'
 			break
-	return rhythm_category
+	return rhythmCategory
+
+def string_to_sequence(inputString):
+	return map(int, inputString.split(','))
 
 
  # The split_by_bar function seperates the score representation of rhythm by bar lines, 
--- a/Syncopation models/music_objects.py	Fri Apr 03 16:38:32 2015 +0100
+++ b/Syncopation models/music_objects.py	Fri Apr 03 17:05:31 2015 +0100
@@ -1,12 +1,12 @@
 
-from BasicFuncs import ceiling
+from basic_functions import ceiling, string_to_sequence
 
-import ParameterSetter 
-import RhythmParser 
+import parameter_setter 
+import rhythm_parser 
 
 class Note():
 	def __init__(self, argstring):
-		intlist = map(int,argstring.split(','))
+		intlist = string_to_sequence(argstring)
 		self.startTime = intlist[0]
 		self.duration = intlist[1]
 		self.velocity = intlist[2]
@@ -20,7 +20,7 @@
 			self.string_to_note_sequence(noteSequenceString)
 
 	def string_to_note_sequence(self, noteSequenceString):
-		noteSequenceString = RhythmParser.discardSpaces(noteSequenceString)
+		noteSequenceString = rhythm_parser.discardSpaces(noteSequenceString)
 		# try:
 			# Turning "(1,2,3),(4,5,6),(7,8,9)" into ["1,2,3","4,5,6,","7,8,9"]
 		listStrings = noteSequenceString[1:-1].split("),(")
@@ -30,13 +30,14 @@
 	# toString()
 
 
-print NoteSequence("(1,2,3),(4,5,6),(7,8,9)")
-# class VelocitySequence(list):
-# 	def __init__(self, noteSequenceString=None):
-# 		if noteSequenceString!=None:
-# 			self.string_to_note_sequence(noteSequenceString)
+#print NoteSequence("(1,2,3),(4,5,6),(7,8,9)")
+class VelocitySequence(list):
+	def __init__(self, noteSequenceString=None):
+		if noteSequenceString!=None:
+			self.string_to_note_sequence(noteSequenceString)
 
-# 	def string_to_note_sequence(string):
+	def string_to_note_sequence(self,inputString):
+		self.extend(string_to_sequence(inputString))
 
 
 class BarList(list):
@@ -48,6 +49,8 @@
 
 
 
+
+
 class Bar:
 
 	def __init__(self, rhythmSequence, timeSignature, ticksPerQuarter=None, qpmTempo=None, nextBar=None, prevBar=None):
@@ -66,12 +69,12 @@
 
 	def get_note_sequence(self):
 		#if self.noteSequence==None:
-		#	self.noteSequence = velocitySequenceToNotes(self.velocitySequence)
+		#	self.noteSequence = velocity_sequence_to_notes(self.velocitySequence)
 		return self.noteSequence
 
 	def get_velocity_sequence(self):
 		if self.velocitySequence==None:
-			self.velocitySequence = noteSequenceToVelocities(self.velocitySequence)
+			self.velocitySequence = note_sequence_to_velocities(self.velocitySequence)
 		return self.velocitySequence
 
 	def get_binary_sequence(self):
--- a/Syncopation models/rhythm_parser.py	Fri Apr 03 16:38:32 2015 +0100
+++ b/Syncopation models/rhythm_parser.py	Fri Apr 03 17:05:31 2015 +0100
@@ -6,7 +6,7 @@
 # Parse the rhythm file and return a list of Bar objects
 Piece = []
 
-from ParameterSetter import timesigBase
+from parameter_setter import timesigBase
 
 
 comment_sign = '#'
--- a/Syncopation models/syncopation.py	Fri Apr 03 16:38:32 2015 +0100
+++ b/Syncopation models/syncopation.py	Fri Apr 03 17:05:31 2015 +0100
@@ -19,20 +19,16 @@
 			from BasicFuncs import get_subdivision_seq
 			subdivision_seq = get_subdivision_seq(timesig, L_max)
 
-		# The get_rhythm_category function is used to detect rhythm category: monorhythm or polyrhythm.
-		# For monorhythms, all prime factors of the length of minimum time-span representation of this sequence are
-		# elements of its subdivision_seq, otherwise it is polyrhythm; 
-		# e.g. prime_factors of polyrhythm 100100101010 in 4/4 is [2,3] but subdivision_seq = [1,2,2] for 4/4 
-		def get_rhythm_category():
-			rhythm_category = 'mono'
-			from BasicFuncs import get_min_timeSpan, find_prime_factors
-			for f in find_prime_factors(len(get_min_timeSpan(seq))):
-				if not (f in subdivision_seq): 
-					rhythm_category = 'poly'
-					break
-			return rhythm_category
+		# def get_rhythm_category():
+		# 	rhythm_category = 'mono'
+		# 	from BasicFuncs import get_min_timeSpan, find_prime_factors
+		# 	for f in find_prime_factors(len(get_min_timeSpan(seq))):
+		# 		if not (f in subdivision_seq): 
+		# 			rhythm_category = 'poly'
+		# 			break
+		# 	return rhythm_category
 		
-		rhythm_category = get_rhythm_category()
+		# rhythm_category = get_rhythm_category()
 
 		if model == 'LHL':	
 			import LHL