Mercurial > hg > syncopation-dataset
diff Syncopation models/rhythm_parser.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/rhythm_parser.py Mon Apr 13 23:06:49 2015 +0100 +++ b/Syncopation models/rhythm_parser.py Thu Apr 23 15:46:58 2015 +0100 @@ -20,6 +20,11 @@ line = line.replace(" ", '').replace("\t", '') return line +def discard_linereturns(line): + line = line.replace("\n","").replace("\r","") + return line + + # def extractInfo(line): # try: # if '{' not in line and '}' not in line: @@ -54,7 +59,7 @@ # if there is a valid field, it should be a time signature if field!=None: [fieldname,value] = field - if fieldname=="t": + if fieldname.lower()=="t": timeSignature = TimeSignature(value) else: print 'Error, first field in the file should set the time signature.' @@ -76,8 +81,8 @@ def parse_line(line, timeSignature=None, tempo=None, ticksPerQuarter=None): - #strip the line of spaces and comments - line = discard_spaces(discard_comments(line)).replace("\n","") + #strip the line of line returns, spaces and comments + line = discard_linereturns(discard_spaces(discard_comments(line))) bars = BarList() @@ -116,6 +121,11 @@ return bars, tempo, timeSignature, ticksPerQuarter +class RhythmSyntaxError(Exception): + def __init__(self, value): + self.value = value + def __str__(self): + return repr(self.value) def get_next_field(line): index = line.find("}") @@ -126,7 +136,7 @@ field = fieldtext.split("{") else: print 'Error, incorrect syntax: "'+line+'"' - #raise RhythmSyntaxError(line) + raise RhythmSyntaxError(line) return field,line