import string
import os
-finale_clefs= ['treble', 'alto', 'tenor', 'bass', 'percussion', 'treble8vb', 'bass8vb', 'baritone']
+finale_clefs= ['treble', 'alto', 'tenor', 'bass', 'percussion', 'treble_8', 'bass_8', 'baritone']
def lily_clef (fin):
- return finale_clefs[fin]
+ try:
+ return finale_clefs[fin]
+ except IndexError:
+ sys.stderr.write ( '\nHuh? Found clef number %d\n' % fin)
+
+ return 'treble'
+
+
def gulp_file(f):
return open (f).read ()
a = articulation_dict[self.type]
except KeyError:
sys.stderr.write ("\nUnknown articulation no. %d on note no. %d" % (self.type, self.notenumber))
+ sys.stderr.write ("\nPlease add an entry to articulation_dict in the Python source")
a = '"art"'
c.note_suffix = '-' + a + c.note_suffix
def valid (self):
return self.valid
def calculate (self):
+ fs = []
+
if len (self.finale) < 2:
- sys.stderr.write ("Measure %d in staff %d has incomplete information.\n" % (self.number, self.staff.number))
- self.valid = 0
- return
+ fs = self.finale[0]
+ fs = map (string.atoi, list (fs))
+ self.clef = fs[1]
+ self.frames = [fs[0]]
+ else:
+ fs = self.finale[0] + self.finale[1]
- f0 = self.finale[0]
- f1 = self.finale[1]
-
- self.clef = string.atoi (f0[0])
- self.flags = string.atoi (f0[1])
- fs = map (string.atoi, list (f0[2:]) + [f1[0]])
+ fs = map (string.atoi, list (fs))
+ self.clef = fs[0]
+ self.flags = fs[1]
+ self.frames = fs[2:]
- self.frames = fs
class Frame:
def __init__ (self, finale):
g = m.global_measure
e = ''
- if last_key <> g.keysignature:
+ if g and last_key <> g.keysignature:
e = e + "\\key %s \\major; " % lily_notename (g.keysignature)
last_key = g.keysignature
- if last_time <> g.timesig :
+ if g and last_time <> g.timesig :
e = e + "\\time %d/%d; " % g.timesig
last_time = g.timesig
+
+
if last_clef <> m.clef :
- e = e + '\\clef %s;' % lily_clef (m.clef)
+ e = e + '\\clef "%s";' % lily_clef (m.clef)
last_clef = m.clef
if e:
if gap <> (0,1):
k = k +' ' + rat_to_lily_duration (gap) + '\n'
gap = (0,1)
k = k + e
-
- gap = rat_add (gap, g.length ())
+
+ if g:
+ gap = rat_add (gap, g.length ())
k = '%sglobal = \\notes { %s }\n\n ' % (self.staffid (), k)
gap = (0,1)
for m in self.measures[1:]:
if not m or not m.valid:
+ sys.stderr.write ("Skipping non-existant measure")
continue
-
-
- fr = m.frames[x]
+
+ fr = None
+ try:
+ fr = m.frames[x]
+ except IndexError:
+
+ sys.stderr.write ("Skipping nonexistent frame")
+ laystr = laystr + "% FOOBAR ! \n"
+ print laystr
if fr:
first_frame = fr
if gap <> (0,1):
gap = (0,1)
laystr = laystr + fr.dump ()
else:
- gap = rat_add (gap, m.global_measure.length ())
-
+ if m.global_measure :
+ gap = rat_add (gap, m.global_measure.length ())
+ else:
+ sys.stderr.write ( \
+ "No global measure for staff %d measure %d\n"
+ % (self.number, m.number))
if first_frame:
l = self.layerid (x)
laystr = '%s = \\notes { { %s } }\n\n' % (l, laystr)
= 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)
+ if len (self.entries) <= no:
+ # missing entries seem to be quite common.
+ # we fill'em up with None.
+ self.entries = self.entries + [None] * (no - len (self.entries) + 1)
current_entry = ((no, prev, next, dur, pos, entryflag, extended, follow), [])
- self.entries.append (current_entry)
+ self.entries[no] = current_entry
return m
def try_Sx(self,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) ))
+ if len (self.frames) <= frameno:
+ self.frames = self.frames + [None] * (frameno - len(self.frames) + 1)
- self.frames.append (Frame ((frameno, startnote, endnote)))
+ self.frames[frameno] = Frame ((frameno, startnote, endnote))
return m
+
def try_MS (self, l):
m = MSre.match (l)
if m:
try:
m.global_measure = self.measures[mno]
except IndexError:
- sys.stderr.write ("non-existent global measure %d" % mno)
+ sys.stderr.write ("Non-existent global measure %d" % mno)
continue
frame_obj_list = [None]
mno = mno + 1
for c in self.chords[1:]:
- c.calculate()
+ if c:
+ c.calculate()
for f in self.frames[1:]:
- f.calculate ()
+ if f:
+ f.calculate ()
for t in self.tuplets[1:]:
t.calculate (self.chords)
def unthread_entries (self):
self.chords = [None]
for e in self.entries[1:]:
- self.chords.append (Chord (e))
-
+ ch = None
+ if e:
+ ch = Chord (e)
+ self.chords.append (ch)
+
for e in self.chords[1:]:
+ if not e:
+ continue
e.prev = self.chords[e.finale[0][1]]
e.next = self.chords[e.finale[0][2]]
identify()
+e = None
for f in files:
if f == '-':
f = ''