changeset 10:a3ed7d2b57d8

updating main py files to point at new file names
author christopherh <christopher.harte@eecs.qmul.ac.uk>
date Fri, 03 Apr 2015 16:02:10 +0100
parents c2843ef4de2c
children 7d94ba423c04
files Syncopation models/basic_functions.py Syncopation models/music_objects.py Syncopation models/readmidi.py Syncopation models/rhythm_parser.py Syncopation models/syncopation.py
diffstat 5 files changed, 39 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/Syncopation models/basic_functions.py	Fri Apr 03 11:41:01 2015 +0100
+++ b/Syncopation models/basic_functions.py	Fri Apr 03 16:02:10 2015 +0100
@@ -150,6 +150,8 @@
 			break
 	return rhythm_category
 
+def string_to_sequence(inputString):
+	return map(int,inputString.split(','))
 
  # The split_by_bar function seperates the score representation of rhythm by bar lines, 
  # resulting in a list representingbar-by-bar rhythm sequence,
--- a/Syncopation models/music_objects.py	Fri Apr 03 11:41:01 2015 +0100
+++ b/Syncopation models/music_objects.py	Fri Apr 03 16:02:10 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):
--- a/Syncopation models/readmidi.py	Fri Apr 03 11:41:01 2015 +0100
+++ b/Syncopation models/readmidi.py	Fri Apr 03 16:02:10 2015 +0100
@@ -8,13 +8,13 @@
 from midiparser import MidiFile, MidiTrack, DeltaTime, MidiEvent
 #from RhythmParser import Bar
 
-from MusicObjects import *
+from music_objects import *
 
 
 
 
 
-def readMidiFile(filename):
+def read_midi_file(filename):
 	""" open and read a MIDI file, return a MidiFile object """
 
 	#create a midifile object, open and read a midi file
@@ -25,26 +25,28 @@
 
 	return midiFile
 
-def getBars(midiFile, trackindex=1):
+# def get_bars(midiFile, trackindex=1):
+# 	""" returns a list of bar objects from a MidiFile object """
 
-	track = midiFile.tracks[trackindex] # ignore dummy track 0
-	eventIdx = 0
-	numNotes = 0
+# 	# select a track to extract (default = 1, ignoring dummy track 0)
+# 	track = midiFile.tracks[trackindex] 
+# 	eventIndex = 0
+# 	numNotes = 0
 
-	noteonlist = []
-	noteOnFound==True
+# 	noteonlist = []
+# 	noteOnFound==True
 
-	while noteOnFound==True:
-		(noteOnIdx, noteOnDelta, noteOnFound) = self.findEvent(track, eventIdx, lambda e: e.type == 'NOTE_ON')
-		noteEvent = track.events[noteOnIdx]
-		eventIdx = noteOnIdx + 1
+# 	while noteOnFound==True:
+# 		(noteOnIndex, noteOnDelta, noteOnFound) = self.find_event(track, eventIndex, lambda e: e.type == 'NOTE_ON')
+# 		noteEvent = track.events[noteOnIndex]
+# 		eventIndex = noteOnIndex + 1
             	
 
 
 
 
 
-def findEvent(track, eventStartIdx, lambdaExpr):
+def find_event(track, eventStartIndex, lambdaExpr):
 	'''
 	From code by Csaba Sulyok:
 	Finds MIDI event based on lambda expression, starting from a given index.
@@ -54,14 +56,14 @@
 	3. flag whether or not any value was found, or we've reached the end of the event queue
 	'''
 
-	eventIdx = eventStartIdx
+	eventIndex = eventStartIndex
 	deltaTime = 0
-	while eventIdx < len(track.events) and not lambdaExpr(track.events[eventIdx]):
-	    if track.events[eventIdx].type == 'DeltaTime':
-	        deltaTime += track.events[eventIdx].time
-	    eventIdx += 1
+	while eventIndex < len(track.events) and not lambdaExpr(track.events[eventIndex]):
+	    if track.events[eventIndex].type == 'DeltaTime':
+	        deltaTime += track.events[eventIndex].time
+	    eventIndex += 1
 
-	success = eventIdx < len(track.events)
-	return (eventIdx, deltaTime, success)
+	success = eventIndex < len(track.events)
+	return (eventIndex, deltaTime, success)
 
 
--- a/Syncopation models/rhythm_parser.py	Fri Apr 03 11:41:01 2015 +0100
+++ b/Syncopation models/rhythm_parser.py	Fri Apr 03 16:02:10 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 11:41:01 2015 +0100
+++ b/Syncopation models/syncopation.py	Fri Apr 03 16:02:10 2015 +0100
@@ -16,7 +16,7 @@
 	
 	else:
 		while subdivision_seq == None:
-			from BasicFuncs import get_subdivision_seq
+			from basic_functions 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.
@@ -25,7 +25,7 @@
 		# 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
+			from basic_functions 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'