Mercurial > hg > syncopation-dataset
changeset 7:1adcd2267e7e
update musicobjects and rhtyhmparser
author | csong <csong@eecs.qmul.ac.uk> |
---|---|
date | Wed, 01 Apr 2015 22:17:32 +0100 |
parents | ac882f5e6a11 |
children | 2c5df6a4a22f |
files | Syncopation models/MusicObjects.py Syncopation models/RhythmParser.py Syncopation models/rhythmbase/testrhythm.txt |
diffstat | 3 files changed, 22 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/Syncopation models/MusicObjects.py Tue Mar 31 16:59:45 2015 +0100 +++ b/Syncopation models/MusicObjects.py Wed Apr 01 22:17:32 2015 +0100 @@ -1,19 +1,36 @@ -from collections import namedtuple from ParameterSetter import get_subdivision_seq, get_beat_level -Note = namedtuple('Note', 'startTime duration velocity') +from RhythmParser import discardSpaces +class Note(): + def __init__(self, argstring): + intlist = map(int,argstring.split(',')) + self.startTime = intlist[0] + self.duration = intlist[1] + self.velocity = intlist[2] + + # toString() + +# NoteSequence is a list of Note class NoteSequence(list): def __init__(self, noteSequenceString=None): if noteSequenceString!=None: self.stringToNoteSequence(noteSequenceString) - def stringToNoteSequence(noteSequenceString): + def stringToNoteSequence(self, noteSequenceString): + noteSequenceString = 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("),(") + for localString in listStrings: + self.append(Note(localString)) + # toString() +print NoteSequence("(1,2,3),(4,5,6),(7,8,9)") # class VelocitySequence(list): # def __init__(self, noteSequenceString=None): # if noteSequenceString!=None: @@ -28,7 +45,7 @@ if isinstance(rhythm_seq, NoteSequence): self.noteSequence = rhythm_seq self.velocitySequence = None - else if isinstance(rhythm_seq, VelocitySequence): + elif isinstance(rhythm_seq, VelocitySequence): self.velocitySequence = rhythm_seq self.noteSequence = None
--- a/Syncopation models/RhythmParser.py Tue Mar 31 16:59:45 2015 +0100 +++ b/Syncopation models/RhythmParser.py Wed Apr 01 22:17:32 2015 +0100 @@ -24,11 +24,8 @@ line = line[0:line.find(comment_sign)] return line -spaces = [' ', '\t'] def discardSpaces(line): - for charactor in spaces: - while (charactor in line): - line = line.replace(charactor, '') + line = line.replace(" ", '').replace("\t", '') return line def extractInfo(line):
--- a/Syncopation models/rhythmbase/testrhythm.txt Tue Mar 31 16:59:45 2015 +0100 +++ b/Syncopation models/rhythmbase/testrhythm.txt Wed Apr 01 22:17:32 2015 +0100 @@ -1,5 +1,3 @@ t{4/4} v{1,0,0,1,0,0,1,0,0,0,1,0,0.8,0,0,0} # This is a comment v{1,0,0,1,0,0,1,0,0,0,1,0,1,0,0,0} t{3/4} v{1,1,1} - -y{(), } \ No newline at end of file