- def try_BC (self, l):
- m = BCre.match (l)
- if m:
- bn = string.atoi (m.group (1))
- where = string.atoi (m.group (2)) / 1024.0
- return m
- def try_TP(self, l):
- m = TPre.match (l)
- if m:
- (nil, num) = map (string.atoi, (m.groups ()[0:2]))
- entries = map (string.atoi, (m.groups ()[2:]))
-
- if self.tuplets[-1] == None or num <> self.tuplets[-1].start_note:
- self.tuplets.append (Tuplet (num))
-
- self.tuplets[-1].append_finale (entries)
-
- def try_IM (self, l):
- m = IMre.match (l)
- if m:
- a = string.atoi (m.group (1))
- b = string.atoi (m.group (2))
-
- fin = map (string.atoi, m.groups ()[2:])
-
- self.articulations.append (Articulation (a,b,fin))
- return m
- def try_verse (self,l):
- m = versere .match (l)
- if m:
- a = string.atoi (m.group (1))
- body =m.group (2)
-
- body = re.sub (r"""\^[a-z]+\([^)]+\)""", "", body)
- body = re.sub ("\^[a-z]+", "", body)
- self.verses.append (Verse (a, body))
-
- return m
- def try_ve (self,l):
- m = vere .match (l)
- if m:
- a = string.atoi (m.group (1))
- b = string.atoi (m.group (2))
-
- fin = map (string.atoi, m.groups ()[2:])
-
- self.syllables.append (Syllable (a,b,fin))
- return m
- def try_eE (self, l):
- m = eEre.match (l)
- if m:
- tup = m.groups()
- (no, prev, next, dur, pos, entryflag, extended, follow) = tup
- (no, prev, next, dur, pos,extended, follow) \
- = tuple (map (string.atoi, [no,prev,next,dur,pos,extended,follow]))
-
- entryflag = string.atol (entryflag,16)
- if no > len (self.entries):
- sys.stderr.write ("\nHuh? Entry number to large,\nexpected %d got %d. Filling with void entries.\n" % (len(self.entries), no ))
- while len (self.entries) <> no:
- c = ((len (self.entries), 0, 0, 0, 0, 0L, 0, 0), [])
- self.entries.append (c)
-
- current_entry = ((no, prev, next, dur, pos, entryflag, extended, follow), [])
- self.entries.append (current_entry)
- return m
-
- def try_Sx(self,l):
- m = Sxre.match (l)
- if m:
- slurno = string.atoi (m.group (1))
-
- if len (self.slurs) == slurno:
- self.slurs.append (Slur (slurno))
-
- params = list (m.groups ()[1:])
- params = map (string.atoi, params)
- self.slurs[-1].append_entry (params)
-
- return m
- def try_GF(self, l):
- m = GFre.match (l)
- if m:
- (staffno,measno) = m.groups ()[0:2]
- s = string.atoi (staffno)
- me = string.atoi (measno)
-
- entry = m.groups () [2:]
- st = self.get_staff (s)
- meas = st.get_measure (me)
- meas.add_finale_entry (entry)
-
- # frame ?
- def try_FR(self, l):
- m = FRre.match (l)
- if m:
- (frameno, startnote, endnote, foo, bar) = m.groups ()
- (frameno, startnote, endnote) = tuple (map (string.atoi, [frameno, startnote, endnote]))
- if frameno > len (self.frames):
- sys.stderr.write ("Frame no %d missing, filling up to %d\n" % (len(self.frames), frameno))
- while frameno <> len (self.frames):
- self.frames.append (Frame ((len (self.frames), 0,0) ))
-
- self.frames.append (Frame ((frameno, startnote, endnote)))
-
- return m
- def try_MS (self, l):
- m = MSre.match (l)
- if m:
- measno = string.atoi (m.group (1))
- keynum = string.atoi (m.group (3))
- meas =self. get_global_measure (measno)
- meas.set_keysig (keynum)
-
- beats = string.atoi (m.group (4))
- beatlen = string.atoi (m.group (5))
- meas.set_timesig ((beats, beatlen))
-
- return m
-
- def try_note (self, l):
- m = note_re.match (l)
- if m:
- (pitch, flag) = m.groups ()
- pitch = string.atoi (pitch)
- flag = string.atol (flag,16)
- self.entries[-1][1].append ((pitch,flag))
-
- def parse (self, name):
- sys.stderr.write ('parsing ...')
- sys.stderr.flush ()
+ def try_BC (self, indices, contents):
+ bn = indices[0]
+ where = contents[0] / 1024.0
+ def try_TP(self, indices, contents):
+ (nil, num) = indices
+
+ if self.tuplets[-1] == None or num <> self.tuplets[-1].start_note:
+ self.tuplets.append (Tuplet (num))
+
+ self.tuplets[-1].append_finale (contents)
+
+ def try_IM (self, indices, contents):
+ (a,b) = indices
+ fin = contents
+ self.articulations.append (Articulation (a,b,fin))
+ def try_verse (self, indices, contents):
+ a = indices[0]
+ body = contents[0]
+
+ body = re.sub (r"""\^[a-z]+\([^)]+\)""", "", body)
+ body = re.sub ("\^[a-z]+", "", body)
+ self.verses.append (Verse (a, body))
+ def try_ve (self,indices, contents):
+ (a,b) = indices
+ self.syllables.append (Syllable (a,b,contents))
+
+ def try_eE (self,indices, contents):
+ no = indices[0]
+ (prev, next, dur, pos, entryflag, extended, follow) = contents[:7]
+
+ fill_list_to (self.chords, no)
+ self.chords[no] =Chord (no, contents)
+
+ def try_Sx(self,indices, contents):
+ slurno = indices[0]
+ fill_list_to (self.slurs, slurno)
+ self.slurs[slurno] = Slur(slurno, contents)
+
+ def try_IX (self, indices, contents):
+ n = indices[0]
+ a = contents[0]
+ b = contents[1]
+
+ ix= None
+ try:
+ ix = self.articulation_defs[n]
+ except IndexError:
+ ix = Articulation_def (n,a,b)
+ self.articulation_defs.append (Articulation_def (n, a, b))