diff Syncopation models/music_objects.py @ 40:6371e8f21f7d

updating the syncopation functions to fix a few problems
author christopherh <christopher.harte@eecs.qmul.ac.uk>
date Thu, 23 Apr 2015 15:46:58 +0100
parents cc38b3047ed9
children
line wrap: on
line diff
--- a/Syncopation models/music_objects.py	Mon Apr 13 23:06:49 2015 +0100
+++ b/Syncopation models/music_objects.py	Thu Apr 23 15:46:58 2015 +0100
@@ -11,7 +11,7 @@
 
 		if firstarg != None:
 			if isinstance(firstarg,basestring):
-				intlist = string_to_sequence(firstarg)
+				intlist = string_to_sequence(firstarg,int)
 				self.startTime = intlist[0]
 				self.duration = intlist[1]
 				self.velocity = intlist[2]
@@ -48,6 +48,13 @@
 			noteSequenceString += note.to_string() + ","
 		return noteSequenceString[:-1]
 
+
+class NormalisedVelocityValueOutOfRange(Exception):
+	def __init__(self, value):
+		self.value = value
+	def __str__(self):
+		return repr(self.value)
+
 # VelocitySequence is a list of float numbers
 class VelocitySequence(list):
 	def __init__(self, velocitySequence = None):
@@ -58,7 +65,16 @@
 				self+=velocitySequence
 
 	def string_to_velocity_sequence(self,inputString):
-		self.extend(string_to_sequence(inputString))
+		
+		def convert_velocity_value(argstring):
+			value = float(argstring)
+			if value>=0 and value<=1:
+				return value
+			else:
+				raise NormalisedVelocityValueOutOfRange("Value: "+argstring+" in " + inputString)
+
+		self.extend(string_to_sequence(inputString,convert_velocity_value))
+
 
 	def to_string(self):
 		return str(velocity_sequence_to_min_timespan(self))[1:-1].replace(" ","")
@@ -96,7 +112,7 @@
 
 
 def note_sequence_to_velocity_sequence(noteSequence, timespanTicks = None):
-	
+
 	velocitySequence = VelocitySequence()
 	
 	previousNoteStartTime = -1