+class Chord:
+ def __init__ (self):
+ self.pitches = []
+ self.grace = 0
+ self.cue = 0
+ self.slurstart = []
+ self.slurstop = []
+ self.scripts = []
+ self.syllables = []
+ self.dots = 0
+ self.basic_duration = 4
+ self.tied = 0
+
+ self.note_suffix = self.note_prefix = ''
+ self.chord_suffix = self.chord_prefix = ''
+
+ def add_script (self,s):
+ self.scripts.append (s)
+ def set_duration (self, d):
+ self.basic_duration = d
+ def add_syllable (self, s):
+ self.syllables.append (s)
+ def add_pitch (self,t):
+ self.pitches.append (t)
+
+ def dump (self):
+ str = ''
+
+ sd = ''
+ if self.basic_duration == 0.5:
+ sd = '\\breve'
+ else:
+ sd = '%d' % self.basic_duration
+
+ sd = sd + '.' * self.dots
+
+ for p in self.pitches:
+ if str:
+ str = str + ' '
+ str = str + pitch_to_lily_string (p)
+
+ if len (self.pitches) > 1:
+ str = '<<%s>>' % str
+ elif len (self.pitches) == 0:
+ str = 'r'
+
+ str = str + sd + '-(' * len (self.slurstart) + '-)' * len (self.slurstart)
+ for s in self.scripts:
+ str = str + '-' + s
+
+ str = self.note_prefix +str + self.note_suffix
+ str = self.chord_prefix + str + self.chord_suffix
+ return str
+
+class Measure_start:
+ def dump (self):
+ return ' |\n'
+
+class Parser:
+ def append_entry (self, e):
+ self.entries.append (e)
+ def append_chord (self,c ):
+ self.chords.append (c)
+ self.entries.append (c)
+ def last_chord (self):
+ return self.chords[-1]
+ def __init__ (self, fn):
+ self.divs_per_q = 1
+ self.header_dict = {
+ 'tagline' :'automatically converted from Musedata',
+ 'copyright' : 'all rights reserved -- free for noncommercial use'
+ # musedata license (argh)
+ }
+ self.entries = []
+ self.chords = []
+
+
+ lines = open (fn).readlines ()
+ lines = map (lambda x: re.sub ("\r$", '', x), lines)
+ lines = self.parse_header (lines)
+ lines = self.append_lines (lines)
+ str = string.join (lines, '\n')
+ lines = re.split ('[\n\r]+', str)
+ self.parse_body (lines)
+
+ def parse_header (self, lines):
+ enter = string.split (lines[3], ' ')
+ self.header_dict['enteredby'] = string.join (enter[1:])
+ self.header_dict['enteredon'] = enter[0]
+ self.header_dict['opus'] = lines[4]
+ self.header_dict['source'] = lines[5]
+ self.header_dict['title'] = lines[6]
+ self.header_dict['subtitle'] = lines[7]
+ self.header_dict['instrument']= lines[8]
+ self.header_dict['musedatamisc'] =lines[9]
+ self.header_dict['musedatagroups'] =lines[10]
+ self.header_dict['musedatagroupnumber']=lines[11]
+ lines = lines[12:]
+ comment = 0
+ while lines:
+ if lines[0][0] == '$':
+ break
+ lines = lines[1:]
+ return lines
+
+ def parse_musical_attributes (self,l):
+ atts = re.split('([A-Z][0-9]?):', l)
+ atts = atts[1:]
+ found = {}
+ while len (atts):
+ id = atts[0]
+ val = atts[1]
+ atts = atts[2:]
+ found[id] = val
+
+ try:
+ self.divs_per_q = string.atoi (found['Q'])
+ except KeyError:
+ pass
+
+ self.append_entry (Attribute_set (found))
+ def append_entry (self, e):
+ self.entries.append (e)