OLD | NEW |
1 #!@TARGET_PYTHON@ | 1 #!@TARGET_PYTHON@ |
2 | 2 |
3 # This file is part of LilyPond, the GNU music typesetter. | 3 # This file is part of LilyPond, the GNU music typesetter. |
4 # | 4 # |
5 # LilyPond is free software: you can redistribute it and/or modify | 5 # LilyPond is free software: you can redistribute it and/or modify |
6 # it under the terms of the GNU General Public License as published by | 6 # it under the terms of the GNU General Public License as published by |
7 # the Free Software Foundation, either version 3 of the License, or | 7 # the Free Software Foundation, either version 3 of the License, or |
8 # (at your option) any later version. | 8 # (at your option) any later version. |
9 # | 9 # |
10 # LilyPond is distributed in the hope that it will be useful, | 10 # LilyPond is distributed in the hope that it will be useful, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 if version == '@' + 'TOPLEVEL_VERSION' + '@': | 56 if version == '@' + 'TOPLEVEL_VERSION' + '@': |
57 version = '(unknown version)' # uGUHGUHGHGUGH | 57 version = '(unknown version)' # uGUHGUHGHGUGH |
58 | 58 |
59 """ | 59 """ |
60 @relocate-preamble@ | 60 @relocate-preamble@ |
61 """ | 61 """ |
62 | 62 |
63 ################################################################ | 63 ################################################################ |
64 | 64 |
65 import lilylib as ly | 65 import lilylib as ly |
66 | 66 |
67 finale_clefs= ['treble', 'alto', 'tenor', 'bass', 'percussion', 'treble_8', 'bas
s_8', 'baritone'] | 67 finale_clefs= ['treble', 'alto', 'tenor', 'bass', 'percussion', 'treble_8', 'bas
s_8', 'baritone'] |
68 | 68 |
69 def lily_clef (fin): | 69 def lily_clef (fin): |
70 try: | 70 try: |
71 return finale_clefs[fin] | 71 return finale_clefs[fin] |
72 except IndexError: | 72 except IndexError: |
73 sys.stderr.write ( '\nHuh? Found clef number %d\n' % fin) | 73 sys.stderr.write ( '\nHuh? Found clef number %d\n' % fin) |
74 | 74 |
75 return 'treble' | 75 return 'treble' |
76 | 76 |
77 | 77 |
78 | 78 |
79 def gulp_file(f): | 79 def gulp_file(f): |
80 return open (f).read () | 80 return open (f).read () |
81 | 81 |
82 # notename 0 == central C | 82 # notename 0 == central C |
83 distances = [0, 2, 4, 5, 7, 9, 11, 12] | 83 distances = [0, 2, 4, 5, 7, 9, 11, 12] |
84 def semitones (name, acc): | 84 def semitones (name, acc): |
85 return (name / 7 ) * 12 + distances[name % 7] + acc | 85 return (name / 7 ) * 12 + distances[name % 7] + acc |
86 | 86 |
87 # represent pitches as (notename, alteration), relative to C-major scale | 87 # represent pitches as (notename, alteration), relative to C-major scale |
88 def transpose(orig, delta): | 88 def transpose(orig, delta): |
89 (oname, oacc) = orig | 89 (oname, oacc) = orig |
90 (dname, dacc) = delta | 90 (dname, dacc) = delta |
91 | 91 |
92 old_pitch =semitones (oname, oacc) | 92 old_pitch =semitones (oname, oacc) |
93 delta_pitch = semitones (dname, dacc) | 93 delta_pitch = semitones (dname, dacc) |
94 nname = (oname + dname) | 94 nname = (oname + dname) |
95 nacc = oacc | 95 nacc = oacc |
96 new_pitch = semitones (nname, nacc) | 96 new_pitch = semitones (nname, nacc) |
97 | 97 |
98 nacc = nacc - (new_pitch - old_pitch - delta_pitch) | 98 nacc = nacc - (new_pitch - old_pitch - delta_pitch) |
99 | 99 |
100 return (nname, nacc) | 100 return (nname, nacc) |
101 | 101 |
102 | 102 |
103 | 103 |
104 def interpret_finale_key_sig (finale_id): | 104 def interpret_finale_key_sig (finale_id): |
105 """ | 105 """ |
106 find the transposition of C-major scale that belongs here. | 106 find the transposition of C-major scale that belongs here. |
107 | 107 |
108 we are not going to insert the correct major/minor, we only want to | 108 we are not going to insert the correct major/minor, we only want to |
109 have the correct number of accidentals | 109 have the correct number of accidentals |
110 """ | 110 """ |
111 | 111 |
112 p = (0,0) | 112 p = (0,0) |
113 | 113 |
114 | 114 |
115 bank_number = finale_id >> 8 | 115 bank_number = finale_id >> 8 |
116 accidental_bits = finale_id & 0xff | 116 accidental_bits = finale_id & 0xff |
117 | 117 |
118 if 0 <= accidental_bits < 7: | 118 if 0 <= accidental_bits < 7: |
119 while accidental_bits > 0: | 119 while accidental_bits > 0: |
120 p = transpose (p, (4,0)) # a fifth up | 120 p = transpose (p, (4,0)) # a fifth up |
121 accidental_bits = accidental_bits - 1 | 121 accidental_bits = accidental_bits - 1 |
122 elif 248 < accidental_bits <= 255: | 122 elif 248 < accidental_bits <= 255: |
123 while accidental_bits < 256: | 123 while accidental_bits < 256: |
124 p = transpose (p, (3,0)) | 124 p = transpose (p, (3,0)) |
(...skipping 28 matching lines...) Expand all Loading... |
153 while d > edu: | 153 while d > edu: |
154 d = d >> 1 | 154 d = d >> 1 |
155 log = log << 1 | 155 log = log << 1 |
156 | 156 |
157 edu = edu - d | 157 edu = edu - d |
158 dots = 0 | 158 dots = 0 |
159 if edu == d /2: | 159 if edu == d /2: |
160 dots = 1 | 160 dots = 1 |
161 elif edu == d*3/4: | 161 elif edu == d*3/4: |
162 dots = 2 | 162 dots = 2 |
163 return (log, dots) | 163 return (log, dots) |
164 | 164 |
165 def rational_to_lily_skip (rat): | 165 def rational_to_lily_skip (rat): |
166 (n,d) = rat | 166 (n,d) = rat |
167 | 167 |
168 basedur = 1 | 168 basedur = 1 |
169 while d and d % 2 == 0: | 169 while d and d % 2 == 0: |
170 basedur = basedur << 1 | 170 basedur = basedur << 1 |
171 d = d >> 1 | 171 d = d >> 1 |
172 | 172 |
173 str = 's%d' % basedur | 173 str = 's%d' % basedur |
174 if n != 1: | 174 if n != 1: |
175 str = str + '*%d' % n | 175 str = str + '*%d' % n |
176 if d != 1: | 176 if d != 1: |
177 str = str + '/%d' % d | 177 str = str + '/%d' % d |
178 | 178 |
179 return str | 179 return str |
180 | 180 |
181 def gcd (a,b): | 181 def gcd (a,b): |
182 if b == 0: | 182 if b == 0: |
183 return a | 183 return a |
184 c = a | 184 c = a |
185 while c: | 185 while c: |
186 c = a % b | 186 c = a % b |
187 a = b | 187 a = b |
188 b = c | 188 b = c |
189 return a | 189 return a |
190 | 190 |
191 | 191 |
192 def rat_simplify (r): | 192 def rat_simplify (r): |
193 (n,d) = r | 193 (n,d) = r |
194 if d < 0: | 194 if d < 0: |
195 d = -d | 195 d = -d |
196 n = -n | 196 n = -n |
197 if n == 0: | 197 if n == 0: |
198 return (0,1) | 198 return (0,1) |
199 else: | 199 else: |
200 g = gcd (n, d) | 200 g = gcd (n, d) |
201 return (n/g, d/g) | 201 return (n/g, d/g) |
202 | 202 |
203 def rat_multiply (a,b): | 203 def rat_multiply (a,b): |
204 (x,y) = a | 204 (x,y) = a |
205 (p,q) = b | 205 (p,q) = b |
206 | 206 |
207 return rat_simplify ((x*p, y*q)) | 207 return rat_simplify ((x*p, y*q)) |
208 | 208 |
209 def rat_add (a,b): | 209 def rat_add (a,b): |
210 (x,y) = a | 210 (x,y) = a |
211 (p,q) = b | 211 (p,q) = b |
212 | 212 |
(...skipping 20 matching lines...) Expand all Loading... |
233 self.start_note = number | 233 self.start_note = number |
234 self.finale = [] | 234 self.finale = [] |
235 | 235 |
236 def append_finale (self, fin): | 236 def append_finale (self, fin): |
237 self.finale.append (fin) | 237 self.finale.append (fin) |
238 | 238 |
239 def factor (self): | 239 def factor (self): |
240 n = self.finale[0][2]*self.finale[0][3] | 240 n = self.finale[0][2]*self.finale[0][3] |
241 d = self.finale[0][0]*self.finale[0][1] | 241 d = self.finale[0][0]*self.finale[0][1] |
242 return rat_simplify( (n, d)) | 242 return rat_simplify( (n, d)) |
243 | 243 |
244 def dump_start (self): | 244 def dump_start (self): |
245 return '\\times %d/%d { ' % self.factor () | 245 return '\\times %d/%d { ' % self.factor () |
246 | 246 |
247 def dump_end (self): | 247 def dump_end (self): |
248 return ' }' | 248 return ' }' |
249 | 249 |
250 def calculate (self, chords): | 250 def calculate (self, chords): |
251 edu_left = self.finale[0][0] * self.finale[0][1] | 251 edu_left = self.finale[0][0] * self.finale[0][1] |
252 | 252 |
253 startch = chords[self.start_note] | 253 startch = chords[self.start_note] |
254 c = startch | 254 c = startch |
255 while c and edu_left: | 255 while c and edu_left: |
256 c.tuplet = self | 256 c.tuplet = self |
257 if c == startch: | 257 if c == startch: |
258 c.chord_prefix = self.dump_start () + c.chord_prefix | 258 c.chord_prefix = self.dump_start () + c.chord_prefix |
259 | 259 |
260 if not c.grace: | 260 if not c.grace: |
261 edu_left = edu_left - c.EDU_duration () | 261 edu_left = edu_left - c.EDU_duration () |
262 if edu_left == 0: | 262 if edu_left == 0: |
263 c.chord_suffix = c.chord_suffix+ self.dump_end () | 263 c.chord_suffix = c.chord_suffix+ self.dump_end () |
264 c = c.__next__ | 264 c = c.__next__ |
265 | 265 |
266 if edu_left: | 266 if edu_left: |
267 sys.stderr.write ("\nHuh? Tuplet starting at entry %d was too short.
" % self.start_note) | 267 sys.stderr.write ("\nHuh? Tuplet starting at entry %d was too short.
" % self.start_note) |
268 | 268 |
269 class Slur: | 269 class Slur: |
270 def __init__ (self, number, params): | 270 def __init__ (self, number, params): |
271 self.number = number | 271 self.number = number |
272 self.finale = params | 272 self.finale = params |
273 | 273 |
274 def append_entry (self, finale_e): | 274 def append_entry (self, finale_e): |
275 self.finale.append (finale_e) | 275 self.finale.append (finale_e) |
276 | 276 |
277 def calculate (self, chords): | 277 def calculate (self, chords): |
278 startnote = self.finale[5] | 278 startnote = self.finale[5] |
279 endnote = self.finale[3*6 + 2] | 279 endnote = self.finale[3*6 + 2] |
280 try: | 280 try: |
281 cs = chords[startnote] | 281 cs = chords[startnote] |
282 ce = chords[endnote] | 282 ce = chords[endnote] |
283 | 283 |
284 if not cs or not ce: | 284 if not cs or not ce: |
285 raise IndexError | 285 raise IndexError |
286 | 286 |
287 cs.note_suffix = '-(' + cs.note_suffix | 287 cs.note_suffix = '-(' + cs.note_suffix |
288 ce.note_suffix = ce.note_suffix + '-)' | 288 ce.note_suffix = ce.note_suffix + '-)' |
289 | 289 |
290 except IndexError: | 290 except IndexError: |
291 sys.stderr.write ("""\nHuh? Slur no %d between (%d,%d), with %d note
s""" % (self.number, startnote, endnote, len (chords))) | 291 sys.stderr.write ("""\nHuh? Slur no %d between (%d,%d), with %d note
s""" % (self.number, startnote, endnote, len (chords))) |
292 | 292 |
293 | 293 |
294 class Global_measure: | 294 class Global_measure: |
295 def __init__ (self, number): | 295 def __init__ (self, number): |
296 self.timesig = '' | 296 self.timesig = '' |
297 self.number = number | 297 self.number = number |
298 self.key_signature = None | 298 self.key_signature = None |
299 self.scale = None | 299 self.scale = None |
300 self.force_break = 0 | 300 self.force_break = 0 |
301 | 301 |
302 self.repeats = [] | 302 self.repeats = [] |
303 self.finale = [] | 303 self.finale = [] |
304 | 304 |
305 def __str__ (self): | 305 def __str__ (self): |
306 return repr(self.finale) | 306 return repr(self.finale) |
307 | 307 |
308 def set_timesig (self, finale): | 308 def set_timesig (self, finale): |
309 (beats, fdur) = finale | 309 (beats, fdur) = finale |
310 (log, dots) = EDU_to_duration (fdur) | 310 (log, dots) = EDU_to_duration (fdur) |
311 | 311 |
312 if dots == 1: | 312 if dots == 1: |
313 beats = beats * 3 | 313 beats = beats * 3 |
314 log = log * 2 | 314 log = log * 2 |
315 dots = 0 | 315 dots = 0 |
316 | 316 |
317 if dots != 0: | 317 if dots != 0: |
318 sys.stderr.write ("\nHuh? Beat duration has dots? (EDU Duration = %
d)" % fdur) | 318 sys.stderr.write ("\nHuh? Beat duration has dots? (EDU Duration = %
d)" % fdur) |
319 self.timesig = (beats, log) | 319 self.timesig = (beats, log) |
320 | 320 |
321 def length (self): | 321 def length (self): |
322 return self.timesig | 322 return self.timesig |
323 | 323 |
324 def set_key_sig (self, finale): | 324 def set_key_sig (self, finale): |
325 k = interpret_finale_key_sig (finale) | 325 k = interpret_finale_key_sig (finale) |
326 self.key_signature = k | 326 self.key_signature = k |
327 self.scale = find_scale (k) | 327 self.scale = find_scale (k) |
328 | 328 |
329 def set_flags (self,flag1, flag2): | 329 def set_flags (self,flag1, flag2): |
330 | 330 |
331 # flag1 isn't all that interesting. | 331 # flag1 isn't all that interesting. |
332 if flag2 & 0x8000: | 332 if flag2 & 0x8000: |
333 self.force_break = 1 | 333 self.force_break = 1 |
334 | 334 |
335 if flag2 & 0x0008: | 335 if flag2 & 0x0008: |
336 self.repeats.append ('start') | 336 self.repeats.append ('start') |
337 if flag2 & 0x0004: | 337 if flag2 & 0x0004: |
338 self.repeats.append ('stop') | 338 self.repeats.append ('stop') |
339 | 339 |
340 if flag2 & 0x0002: | 340 if flag2 & 0x0002: |
341 if flag2 & 0x0004: | 341 if flag2 & 0x0004: |
342 self.repeats.append ('bracket') | 342 self.repeats.append ('bracket') |
343 | 343 |
344 articulation_dict ={ | 344 articulation_dict ={ |
345 94: '^', | 345 94: '^', |
346 109: '\\prall', | 346 109: '\\prall', |
347 84: '\\turn', | 347 84: '\\turn', |
348 62: '\\mordent', | 348 62: '\\mordent', |
349 85: '\\fermata', | 349 85: '\\fermata', |
350 46: '.', | 350 46: '.', |
351 # 3: '>', | 351 # 3: '>', |
352 # 18: '\arpeggio' , | 352 # 18: '\arpeggio' , |
353 } | 353 } |
354 | 354 |
355 class Articulation_def: | 355 class Articulation_def: |
356 def __init__ (self, n, a, b): | 356 def __init__ (self, n, a, b): |
357 self.finale_glyph = a & 0xff | 357 self.finale_glyph = a & 0xff |
358 self.number = n | 358 self.number = n |
359 | 359 |
360 def dump (self): | 360 def dump (self): |
361 try: | 361 try: |
362 return articulation_dict[self.finale_glyph] | 362 return articulation_dict[self.finale_glyph] |
363 except KeyError: | 363 except KeyError: |
364 sys.stderr.write ("\nUnknown articulation no. %d" % self.finale_glyp
h) | 364 sys.stderr.write ("\nUnknown articulation no. %d" % self.finale_glyp
h) |
365 sys.stderr.write ("\nPlease add an entry to articulation_dict in the
Python source") | 365 sys.stderr.write ("\nPlease add an entry to articulation_dict in the
Python source") |
366 return None | 366 return None |
367 | 367 |
368 class Articulation: | 368 class Articulation: |
369 def __init__ (self, a,b, finale): | 369 def __init__ (self, a,b, finale): |
370 self.definition = finale[0] | 370 self.definition = finale[0] |
371 self.notenumber = b | 371 self.notenumber = b |
372 | 372 |
373 def calculate (self, chords, defs): | 373 def calculate (self, chords, defs): |
374 c = chords[self.notenumber] | 374 c = chords[self.notenumber] |
375 | 375 |
376 adef = defs[self.definition] | 376 adef = defs[self.definition] |
377 lystr =adef.dump() | 377 lystr =adef.dump() |
378 if lystr == None: | 378 if lystr == None: |
379 lystr = '"art"' | 379 lystr = '"art"' |
380 sys.stderr.write ("\nThis happened on note %d" % self.notenumber) | 380 sys.stderr.write ("\nThis happened on note %d" % self.notenumber) |
381 | 381 |
382 c.note_suffix = '-' + lystr | 382 c.note_suffix = '-' + lystr |
(...skipping 12 matching lines...) Expand all Loading... |
395 self.number = number | 395 self.number = number |
396 self.split_syllables () | 396 self.split_syllables () |
397 def split_syllables (self): | 397 def split_syllables (self): |
398 ss = re.split ('(-| +)', self.body) | 398 ss = re.split ('(-| +)', self.body) |
399 | 399 |
400 sep = 0 | 400 sep = 0 |
401 syls = [None] | 401 syls = [None] |
402 for s in ss: | 402 for s in ss: |
403 if sep: | 403 if sep: |
404 septor = re.sub (" +", "", s) | 404 septor = re.sub (" +", "", s) |
405 septor = re.sub ("-", " -- ", septor) | 405 septor = re.sub ("-", " -- ", septor) |
406 syls[-1] = syls[-1] + septor | 406 syls[-1] = syls[-1] + septor |
407 else: | 407 else: |
408 syls.append (s) | 408 syls.append (s) |
409 | 409 |
410 sep = not sep | 410 sep = not sep |
411 | 411 |
412 self.syllables = syls | 412 self.syllables = syls |
413 | 413 |
414 def dump (self): | 414 def dump (self): |
415 str = '' | 415 str = '' |
416 line = '' | 416 line = '' |
417 for s in self.syllables[1:]: | 417 for s in self.syllables[1:]: |
418 line = line + ' ' + s | 418 line = line + ' ' + s |
419 if len (line) > 72: | 419 if len (line) > 72: |
420 str = str + ' ' * 4 + line + '\n' | 420 str = str + ' ' * 4 + line + '\n' |
421 line = '' | 421 line = '' |
422 | 422 |
423 str = """\nverse%s = \\lyricmode {\n %s }\n""" % (encodeint (self.numbe
r - 1) ,str) | 423 str = """\nverse%s = \\lyricmode {\n %s }\n""" % (encodeint (self.numbe
r - 1) ,str) |
424 return str | 424 return str |
425 | 425 |
426 class KeySignature: | 426 class KeySignature: |
427 def __init__(self, pitch, sig_type = 0): | 427 def __init__(self, pitch, sig_type = 0): |
428 self.pitch = pitch | 428 self.pitch = pitch |
429 self.sig_type = sig_type | 429 self.sig_type = sig_type |
430 | 430 |
431 def signature_type (self): | 431 def signature_type (self): |
432 if self.sig_type == 1: | 432 if self.sig_type == 1: |
433 return "\\minor" | 433 return "\\minor" |
434 else: | 434 else: |
435 # really only for 0, but we only know about 0 and 1 | 435 # really only for 0, but we only know about 0 and 1 |
436 return "\\major" | 436 return "\\major" |
437 | 437 |
438 def equal (self, other): | 438 def equal (self, other): |
439 if other and other.pitch == self.pitch and other.sig_type == self.sig_ty
pe: | 439 if other and other.pitch == self.pitch and other.sig_type == self.sig_ty
pe: |
440 return 1 | 440 return 1 |
441 else: | 441 else: |
442 return 0 | 442 return 0 |
443 | 443 |
444 | 444 |
445 class Measure: | 445 class Measure: |
446 def __init__(self, no): | 446 def __init__(self, no): |
447 self.number = no | 447 self.number = no |
448 self.frames = [0] * 4 | 448 self.frames = [0] * 4 |
449 self.flags = 0 | 449 self.flags = 0 |
450 self.clef = 0 | 450 self.clef = 0 |
451 self.finale = [] | 451 self.finale = [] |
452 self.global_measure = None | 452 self.global_measure = None |
453 self.staff = None | 453 self.staff = None |
454 self.valid = 1 | 454 self.valid = 1 |
455 | 455 |
456 | 456 |
457 def valid (self): | 457 def valid (self): |
458 return self.valid | 458 return self.valid |
459 def calculate (self): | 459 def calculate (self): |
460 fs = [] | 460 fs = [] |
461 | 461 |
462 if len (self.finale) < 2: | 462 if len (self.finale) < 2: |
463 fs = self.finale[0] | 463 fs = self.finale[0] |
464 | 464 |
465 self.clef = fs[1] | 465 self.clef = fs[1] |
(...skipping 23 matching lines...) Expand all Loading... |
489 # do grace notes. | 489 # do grace notes. |
490 lastch = None | 490 lastch = None |
491 in_grace = 0 | 491 in_grace = 0 |
492 for c in self.chords: | 492 for c in self.chords: |
493 if c.grace and (lastch == None or (not lastch.grace)): | 493 if c.grace and (lastch == None or (not lastch.grace)): |
494 c.chord_prefix = r'\grace {' + c.chord_prefix | 494 c.chord_prefix = r'\grace {' + c.chord_prefix |
495 in_grace = 1 | 495 in_grace = 1 |
496 elif not c.grace and lastch and lastch.grace: | 496 elif not c.grace and lastch and lastch.grace: |
497 lastch.chord_suffix = lastch.chord_suffix + ' } ' | 497 lastch.chord_suffix = lastch.chord_suffix + ' } ' |
498 in_grace = 0 | 498 in_grace = 0 |
499 | 499 |
500 lastch = c | 500 lastch = c |
501 | 501 |
502 if lastch and in_grace: | 502 if lastch and in_grace: |
503 lastch.chord_suffix += '}' | 503 lastch.chord_suffix += '}' |
504 | 504 |
505 | 505 |
506 def dump (self): | 506 def dump (self): |
507 str = '%% FR(%d)\n' % self.number | 507 str = '%% FR(%d)\n' % self.number |
508 left = self.measure.global_measure.length () | 508 left = self.measure.global_measure.length () |
509 | 509 |
510 | 510 |
511 ln = '' | 511 ln = '' |
512 for c in self.chords: | 512 for c in self.chords: |
513 add = c.ly_string () + ' ' | 513 add = c.ly_string () + ' ' |
514 if len (ln) + len(add) > 72: | 514 if len (ln) + len(add) > 72: |
515 str = str + ln + '\n' | 515 str = str + ln + '\n' |
516 ln = '' | 516 ln = '' |
517 ln = ln + add | 517 ln = ln + add |
518 left = rat_subtract (left, c.length ()) | 518 left = rat_subtract (left, c.length ()) |
519 | 519 |
520 str = str + ln | 520 str = str + ln |
521 | 521 |
522 if left[0] < 0: | 522 if left[0] < 0: |
523 sys.stderr.write ("""\nHuh? Going backwards in frame no %d, start/en
d (%d,%d)""" % (self.number, self.start, self.end)) | 523 sys.stderr.write ("""\nHuh? Going backwards in frame no %d, start/en
d (%d,%d)""" % (self.number, self.start, self.end)) |
524 left = (0,1) | 524 left = (0,1) |
525 if left[0]: | 525 if left[0]: |
526 str = str + rational_to_lily_skip (left) | 526 str = str + rational_to_lily_skip (left) |
527 | 527 |
528 str = str + ' |\n' | 528 str = str + ' |\n' |
529 return str | 529 return str |
530 | 530 |
531 def encodeint (i): | 531 def encodeint (i): |
532 return chr ( i + ord ('A')) | 532 return chr ( i + ord ('A')) |
533 | 533 |
534 class Staff: | 534 class Staff: |
535 def __init__ (self, number): | 535 def __init__ (self, number): |
536 self.number = number | 536 self.number = number |
537 self.measures = [] | 537 self.measures = [] |
538 | 538 |
539 def get_measure (self, no): | 539 def get_measure (self, no): |
540 fill_list_to (self.measures, no) | 540 fill_list_to (self.measures, no) |
541 | 541 |
542 if self.measures[no] == None: | 542 if self.measures[no] == None: |
543 m = Measure (no) | 543 m = Measure (no) |
544 self.measures [no] =m | 544 self.measures [no] =m |
545 m.staff = self | 545 m.staff = self |
546 | 546 |
547 return self.measures[no] | 547 return self.measures[no] |
548 def staffid (self): | 548 def staffid (self): |
549 return 'staff' + encodeint (self.number - 1) | 549 return 'staff' + encodeint (self.number - 1) |
550 def layerid (self, l): | 550 def layerid (self, l): |
551 return self.staffid() + 'layer%s' % chr (l -1 + ord ('A')) | 551 return self.staffid() + 'layer%s' % chr (l -1 + ord ('A')) |
552 | 552 |
553 def dump_time_key_sigs (self): | 553 def dump_time_key_sigs (self): |
554 k = '' | 554 k = '' |
555 last_key = None | 555 last_key = None |
556 last_time = None | 556 last_time = None |
557 last_clef = None | 557 last_clef = None |
558 gap = (0,1) | 558 gap = (0,1) |
559 for m in self.measures[1:]: | 559 for m in self.measures[1:]: |
560 if not m or not m.valid: | 560 if not m or not m.valid: |
561 continue # ugh. | 561 continue # ugh. |
562 | 562 |
563 g = m.global_measure | 563 g = m.global_measure |
564 e = '' | 564 e = '' |
565 | 565 |
566 if g: | 566 if g: |
567 if g.key_signature and not g.key_signature.equal(last_key): | 567 if g.key_signature and not g.key_signature.equal(last_key): |
568 pitch= g.key_signature.pitch | 568 pitch= g.key_signature.pitch |
569 e = e + "\\key %s %s " % (lily_notename (pitch), | 569 e = e + "\\key %s %s " % (lily_notename (pitch), |
570 g.key_signature.signature_type()) | 570 g.key_signature.signature_type()) |
571 | 571 |
572 last_key = g.key_signature | 572 last_key = g.key_signature |
573 if last_time != g.timesig : | 573 if last_time != g.timesig : |
574 e = e + "\\time %d/%d " % g.timesig | 574 e = e + "\\time %d/%d " % g.timesig |
575 last_time = g.timesig | 575 last_time = g.timesig |
576 | 576 |
577 if 'start' in g.repeats: | 577 if 'start' in g.repeats: |
578 e = e + ' \\bar ".|:" ' | 578 e = e + ' \\bar ".|:" ' |
579 | 579 |
580 | 580 |
581 # we don't attempt voltas since they fail easily. | 581 # we don't attempt voltas since they fail easily. |
582 if 0 : # and g.repeat_bar == '|:' or g.repeat_bar == ':|:' or g.
bracket: | 582 if 0 : # and g.repeat_bar == '|:' or g.repeat_bar == ':|:' or g.
bracket: |
583 strs = [] | 583 strs = [] |
584 if g.repeat_bar == '|:' or g.repeat_bar == ':|:' or g.bracke
t == 'end': | 584 if g.repeat_bar == '|:' or g.repeat_bar == ':|:' or g.bracke
t == 'end': |
585 strs.append ('#f') | 585 strs.append ('#f') |
586 | 586 |
587 | 587 |
588 if g.bracket == 'start': | 588 if g.bracket == 'start': |
589 strs.append ('"0."') | 589 strs.append ('"0."') |
590 | 590 |
591 str = ' '.join (['(volta %s)' % x for x in strs]) | 591 str = ' '.join (['(volta %s)' % x for x in strs]) |
592 | 592 |
593 e = e + ' \\set Score.repeatCommands = #\'(%s) ' % str | 593 e = e + ' \\set Score.repeatCommands = #\'(%s) ' % str |
594 | 594 |
595 if g.force_break: | 595 if g.force_break: |
596 e = e + ' \\break ' | 596 e = e + ' \\break ' |
597 | 597 |
598 if last_clef != m.clef : | 598 if last_clef != m.clef : |
599 e = e + '\\clef "%s"' % lily_clef (m.clef) | 599 e = e + '\\clef "%s"' % lily_clef (m.clef) |
600 last_clef = m.clef | 600 last_clef = m.clef |
601 if e: | 601 if e: |
602 if gap != (0,1): | 602 if gap != (0,1): |
603 k = k +' ' + rational_to_lily_skip (gap) + '\n' | 603 k = k +' ' + rational_to_lily_skip (gap) + '\n' |
604 gap = (0,1) | 604 gap = (0,1) |
605 k = k + e | 605 k = k + e |
606 | 606 |
607 if g: | 607 if g: |
608 gap = rat_add (gap, g.length ()) | 608 gap = rat_add (gap, g.length ()) |
609 if 'stop' in g.repeats: | 609 if 'stop' in g.repeats: |
610 k = k + ' \\bar ":|." ' | 610 k = k + ' \\bar ":|." ' |
611 | 611 |
612 k = '%sglobal = { %s }\n\n ' % (self.staffid (), k) | 612 k = '%sglobal = { %s }\n\n ' % (self.staffid (), k) |
613 return k | 613 return k |
614 | 614 |
615 def dump (self): | 615 def dump (self): |
616 str = '' | 616 str = '' |
617 | 617 |
618 | 618 |
619 layerids = [] | 619 layerids = [] |
620 for x in range (1,5): # 4 layers. | 620 for x in range (1,5): # 4 layers. |
621 laystr = '' | 621 laystr = '' |
622 last_frame = None | 622 last_frame = None |
623 first_frame = None | 623 first_frame = None |
624 gap = (0,1) | 624 gap = (0,1) |
(...skipping 20 matching lines...) Expand all Loading... |
645 else: | 645 else: |
646 sys.stderr.write ( \ | 646 sys.stderr.write ( \ |
647 "No global measure for staff %d measure %d\n" | 647 "No global measure for staff %d measure %d\n" |
648 % (self.number, m.number)) | 648 % (self.number, m.number)) |
649 if first_frame: | 649 if first_frame: |
650 l = self.layerid (x) | 650 l = self.layerid (x) |
651 laystr = '%s = { { %s } }\n\n' % (l, laystr) | 651 laystr = '%s = { { %s } }\n\n' % (l, laystr) |
652 str = str + laystr | 652 str = str + laystr |
653 layerids.append (l) | 653 layerids.append (l) |
654 | 654 |
655 str = str + self.dump_time_key_sigs () | 655 str = str + self.dump_time_key_sigs () |
656 stafdef = '\\%sglobal' % self.staffid () | 656 stafdef = '\\%sglobal' % self.staffid () |
657 for i in layerids: | 657 for i in layerids: |
658 stafdef = stafdef + ' \\' + i | 658 stafdef = stafdef + ' \\' + i |
659 | 659 |
660 | 660 |
661 str = str + '%s = \\context Staff = %s <<\n %s\n >>\n' % \ | 661 str = str + '%s = \\context Staff = %s <<\n %s\n >>\n' % \ |
662 (self.staffid (), self.staffid (), stafdef) | 662 (self.staffid (), self.staffid (), stafdef) |
663 return str | 663 return str |
664 | 664 |
665 | 665 |
666 | 666 |
667 def ziplist (l): | 667 def ziplist (l): |
668 if len (l) < 2: | 668 if len (l) < 2: |
669 return [] | 669 return [] |
670 else: | 670 else: |
671 return [(l[0], l[1])] + ziplist (l[2:]) | 671 return [(l[0], l[1])] + ziplist (l[2:]) |
672 | 672 |
673 | 673 |
674 class Chord: | 674 class Chord: |
675 def __init__ (self, number, contents): | 675 def __init__ (self, number, contents): |
676 self.pitches = [] | 676 self.pitches = [] |
677 self.frame = None | 677 self.frame = None |
678 self.finale = contents[:7] | 678 self.finale = contents[:7] |
679 | 679 |
680 self.notelist = ziplist (contents[7:]) | 680 self.notelist = ziplist (contents[7:]) |
681 self.duration = None | 681 self.duration = None |
682 self.next = None | 682 self.next = None |
683 self.prev = None | 683 self.prev = None |
684 self.number = number | 684 self.number = number |
685 self.note_prefix= '' | 685 self.note_prefix= '' |
686 self.note_suffix = '' | 686 self.note_suffix = '' |
687 self.chord_suffix = '' | 687 self.chord_suffix = '' |
688 self.chord_prefix = '' | 688 self.chord_prefix = '' |
689 self.tuplet = None | 689 self.tuplet = None |
690 self.grace = 0 | 690 self.grace = 0 |
691 | 691 |
692 def measure (self): | 692 def measure (self): |
693 if not self.frame: | 693 if not self.frame: |
694 return None | 694 return None |
695 return self.frame.measure | 695 return self.frame.measure |
696 | 696 |
697 def length (self): | 697 def length (self): |
698 if self.grace: | 698 if self.grace: |
699 return (0,1) | 699 return (0,1) |
700 | 700 |
701 l = (1, self.duration[0]) | 701 l = (1, self.duration[0]) |
702 | 702 |
703 d = 1 << self.duration[1] | 703 d = 1 << self.duration[1] |
704 | 704 |
705 dotfact = rat_subtract ((2,1), (1,d)) | 705 dotfact = rat_subtract ((2,1), (1,d)) |
706 mylen = rat_multiply (dotfact, l) | 706 mylen = rat_multiply (dotfact, l) |
707 | 707 |
708 if self.tuplet: | 708 if self.tuplet: |
709 mylen = rat_multiply (mylen, self.tuplet.factor()) | 709 mylen = rat_multiply (mylen, self.tuplet.factor()) |
710 return mylen | 710 return mylen |
711 | 711 |
712 | 712 |
713 def EDU_duration (self): | 713 def EDU_duration (self): |
714 return self.finale[2] | 714 return self.finale[2] |
715 def set_duration (self): | 715 def set_duration (self): |
716 self.duration = EDU_to_duration(self.EDU_duration ()) | 716 self.duration = EDU_to_duration(self.EDU_duration ()) |
717 | 717 |
718 def calculate (self): | 718 def calculate (self): |
719 self.find_realpitch () | 719 self.find_realpitch () |
720 self.set_duration () | 720 self.set_duration () |
721 | 721 |
722 flag = self.finale[4] | 722 flag = self.finale[4] |
723 if Chord.GRACE_MASK & flag: | 723 if Chord.GRACE_MASK & flag: |
724 self.grace = 1 | 724 self.grace = 1 |
725 | 725 |
726 | 726 |
727 def find_realpitch (self): | 727 def find_realpitch (self): |
728 | 728 |
729 meas = self.measure () | 729 meas = self.measure () |
730 tiestart = 0 | 730 tiestart = 0 |
731 if not meas or not meas.global_measure : | 731 if not meas or not meas.global_measure : |
732 sys.stderr.write ('note %d not in measure\n' % self.number) | 732 sys.stderr.write ('note %d not in measure\n' % self.number) |
733 elif not meas.global_measure.scale: | 733 elif not meas.global_measure.scale: |
734 sys.stderr.write ('note %d: no scale in this measure.' % self.number
) | 734 sys.stderr.write ('note %d: no scale in this measure.' % self.number
) |
735 else: | 735 else: |
736 | 736 |
737 for p in self.notelist: | 737 for p in self.notelist: |
738 (pitch, flag) = p | 738 (pitch, flag) = p |
739 | 739 |
740 | 740 |
741 nib1 = pitch & 0x0f | 741 nib1 = pitch & 0x0f |
742 | 742 |
743 if nib1 > 8: | 743 if nib1 > 8: |
744 nib1 = -(nib1 - 8) | 744 nib1 = -(nib1 - 8) |
745 rest = pitch / 16 | 745 rest = pitch / 16 |
746 | 746 |
747 scale = meas.global_measure.scale | 747 scale = meas.global_measure.scale |
748 (sn, sa) =scale[rest % 7] | 748 (sn, sa) =scale[rest % 7] |
749 sn = sn + (rest - (rest%7)) + 7 | 749 sn = sn + (rest - (rest%7)) + 7 |
750 acc = sa + nib1 | 750 acc = sa + nib1 |
751 self.pitches.append ((sn, acc)) | 751 self.pitches.append ((sn, acc)) |
752 tiestart = tiestart or (flag & Chord.TIE_START_MASK) | 752 tiestart = tiestart or (flag & Chord.TIE_START_MASK) |
753 if tiestart : | 753 if tiestart : |
754 self.chord_suffix = self.chord_suffix + ' ~ ' | 754 self.chord_suffix = self.chord_suffix + ' ~ ' |
755 | 755 |
756 REST_MASK = 0x40000000 | 756 REST_MASK = 0x40000000 |
757 TIE_START_MASK = 0x40000000 | 757 TIE_START_MASK = 0x40000000 |
758 GRACE_MASK = 0x00800000 | 758 GRACE_MASK = 0x00800000 |
759 | 759 |
760 def ly_string (self): | 760 def ly_string (self): |
761 s = '' | 761 s = '' |
762 | 762 |
763 rest = '' | 763 rest = '' |
764 | 764 |
765 | 765 |
766 if not (self.finale[4] & Chord.REST_MASK): | 766 if not (self.finale[4] & Chord.REST_MASK): |
767 rest = 'r' | 767 rest = 'r' |
768 | 768 |
769 for p in self.pitches: | 769 for p in self.pitches: |
770 (n,a) = p | 770 (n,a) = p |
771 o = n/ 7 | 771 o = n/ 7 |
772 n = n % 7 | 772 n = n % 7 |
773 | 773 |
774 nn = lily_notename ((n,a)) | 774 nn = lily_notename ((n,a)) |
775 | 775 |
776 if o < 0: | 776 if o < 0: |
777 nn = nn + (',' * -o) | 777 nn = nn + (',' * -o) |
778 elif o > 0: | 778 elif o > 0: |
779 nn = nn + ('\'' * o) | 779 nn = nn + ('\'' * o) |
780 | 780 |
781 if s: | 781 if s: |
782 s = s + ' ' | 782 s = s + ' ' |
783 | 783 |
784 if rest: | 784 if rest: |
785 nn = rest | 785 nn = rest |
786 | 786 |
787 s = s + nn | 787 s = s + nn |
788 | 788 |
789 if not self.pitches: | 789 if not self.pitches: |
790 s = 'r' | 790 s = 'r' |
791 if len (self.pitches) > 1: | 791 if len (self.pitches) > 1: |
792 s = '<%s>' % s | 792 s = '<%s>' % s |
793 | 793 |
794 s = s + '%d%s' % (self.duration[0], '.'* self.duration[1]) | 794 s = s + '%d%s' % (self.duration[0], '.'* self.duration[1]) |
795 s = self.note_prefix + s + self.note_suffix | 795 s = self.note_prefix + s + self.note_suffix |
796 | 796 |
797 s = self.chord_prefix + s + self.chord_suffix | 797 s = self.chord_prefix + s + self.chord_suffix |
798 | 798 |
799 return s | 799 return s |
800 | 800 |
801 | 801 |
802 def fill_list_to (list, no): | 802 def fill_list_to (list, no): |
803 """ | 803 """ |
804 Add None to LIST until it contains entry number NO. | 804 Add None to LIST until it contains entry number NO. |
805 """ | 805 """ |
806 while len (list) <= no: | 806 while len (list) <= no: |
807 list.extend ([None] * (no - len(list) + 1)) | 807 list.extend ([None] * (no - len(list) + 1)) |
808 return list | 808 return list |
809 | 809 |
810 def read_finale_value (str): | 810 def read_finale_value (str): |
811 """ | 811 """ |
812 Pry off one value from STR. The value may be $hex, decimal, or "string". | 812 Pry off one value from STR. The value may be $hex, decimal, or "string". |
813 Return: (value, rest-of-STR) | 813 Return: (value, rest-of-STR) |
814 """ | 814 """ |
815 while str and str[0] in ' \t\n': | 815 while str and str[0] in ' \t\n': |
816 str = str[1:] | 816 str = str[1:] |
817 | 817 |
818 if not str: | 818 if not str: |
819 return (None,str) | 819 return (None,str) |
820 | 820 |
821 if str[0] == '$': | 821 if str[0] == '$': |
822 str = str [1:] | 822 str = str [1:] |
823 | 823 |
824 hex = '' | 824 hex = '' |
825 while str and str[0] in '0123456789ABCDEF': | 825 while str and str[0] in '0123456789ABCDEF': |
826 hex = hex + str[0] | 826 hex = hex + str[0] |
827 str = str[1:] | 827 str = str[1:] |
828 | 828 |
829 | 829 |
830 return (int (hex, 16), str) | 830 return (int (hex, 16), str) |
831 elif str[0] == '"': | 831 elif str[0] == '"': |
832 str = str[1:] | 832 str = str[1:] |
833 s = '' | 833 s = '' |
834 while str and str[0] != '"': | 834 while str and str[0] != '"': |
835 s = s + str[0] | 835 s = s + str[0] |
836 str = str[1:] | 836 str = str[1:] |
837 | 837 |
838 return (s,str) | 838 return (s,str) |
839 elif str[0] in '-0123456789': | 839 elif str[0] in '-0123456789': |
840 dec = '' | 840 dec = '' |
841 while str and str[0] in '-0123456789': | 841 while str and str[0] in '-0123456789': |
842 dec = dec + str[0] | 842 dec = dec + str[0] |
843 str = str[1:] | 843 str = str[1:] |
844 | 844 |
845 return (int (dec), str) | 845 return (int (dec), str) |
846 else: | 846 else: |
847 sys.stderr.write ("cannot convert `%s'\n" % str) | 847 sys.stderr.write ("cannot convert `%s'\n" % str) |
848 return (None, str) | 848 return (None, str) |
849 | 849 |
850 | 850 |
851 | 851 |
852 | 852 |
853 def parse_etf_file (fn, tag_dict): | 853 def parse_etf_file (fn, tag_dict): |
854 | 854 |
855 """ Read FN, putting ETF info into | 855 """ Read FN, putting ETF info into |
856 a giant dictionary. The keys of TAG_DICT indicate which tags | 856 a giant dictionary. The keys of TAG_DICT indicate which tags |
857 to put into the dict. | 857 to put into the dict. |
858 """ | 858 """ |
859 | 859 |
860 sys.stderr.write ('parsing ... ' ) | 860 sys.stderr.write ('parsing ... ' ) |
861 f = open (fn) | 861 f = open (fn) |
862 | 862 |
863 gulp = re.sub ('[\n\r]+', '\n', f.read ()) | 863 gulp = re.sub ('[\n\r]+', '\n', f.read ()) |
864 ls = gulp.split ('\n^') | 864 ls = gulp.split ('\n^') |
865 | 865 |
866 etf_file_dict = {} | 866 etf_file_dict = {} |
867 for k in tag_dict: | 867 for k in tag_dict: |
868 etf_file_dict[k] = {} | 868 etf_file_dict[k] = {} |
869 | 869 |
870 last_tag = None | 870 last_tag = None |
871 last_numbers = None | 871 last_numbers = None |
872 | 872 |
(...skipping 27 matching lines...) Expand all Loading... |
900 tdict [indices].extend (parsed) | 900 tdict [indices].extend (parsed) |
901 | 901 |
902 last_indices = indices | 902 last_indices = indices |
903 last_tag = tag | 903 last_tag = tag |
904 | 904 |
905 continue | 905 continue |
906 | 906 |
907 # let's not do this: this really confuses when eE happens to be before a ^text. | 907 # let's not do this: this really confuses when eE happens to be before a ^text. |
908 # if last_tag and last_indices: | 908 # if last_tag and last_indices: |
909 # etf_file_dict[last_tag][last_indices].append (l) | 909 # etf_file_dict[last_tag][last_indices].append (l) |
910 | 910 |
911 sys.stderr.write ('\n') | 911 sys.stderr.write ('\n') |
912 return etf_file_dict | 912 return etf_file_dict |
913 | 913 |
914 ···· | |
915 | |
916 | 914 |
917 | 915 |
| 916 |
| 917 |
918 class Etf_file: | 918 class Etf_file: |
919 def __init__ (self, name): | 919 def __init__ (self, name): |
920 self.measures = [None] | 920 self.measures = [None] |
921 self.chords = [None] | 921 self.chords = [None] |
922 self.frames = [None] | 922 self.frames = [None] |
923 self.tuplets = [None] | 923 self.tuplets = [None] |
924 self.staffs = [None] | 924 self.staffs = [None] |
925 self.slurs = [None] | 925 self.slurs = [None] |
926 self.articulations = [None] | 926 self.articulations = [None] |
927 self.syllables = [None] | 927 self.syllables = [None] |
928 self.verses = [None] | 928 self.verses = [None] |
929 self.articulation_defs = [None] | 929 self.articulation_defs = [None] |
930 | 930 |
931 ## do it | 931 ## do it |
932 self.parse (name) | 932 self.parse (name) |
933 | 933 |
934 def get_global_measure (self, no): | 934 def get_global_measure (self, no): |
935 fill_list_to (self.measures, no) | 935 fill_list_to (self.measures, no) |
936 if self.measures[no] == None: | 936 if self.measures[no] == None: |
937 self.measures [no] = Global_measure (no) | 937 self.measures [no] = Global_measure (no) |
938 | 938 |
939 return self.measures[no] | 939 return self.measures[no] |
940 | 940 |
941 | 941 |
942 def get_staff(self,staffno): | 942 def get_staff(self,staffno): |
943 fill_list_to (self.staffs, staffno) | 943 fill_list_to (self.staffs, staffno) |
944 if self.staffs[staffno] == None: | 944 if self.staffs[staffno] == None: |
945 self.staffs[staffno] = Staff (staffno) | 945 self.staffs[staffno] = Staff (staffno) |
946 | 946 |
947 return self.staffs[staffno] | 947 return self.staffs[staffno] |
948 | 948 |
949 # staff-spec | 949 # staff-spec |
950 def try_IS (self, indices, contents): | 950 def try_IS (self, indices, contents): |
951 pass | 951 pass |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 except IndexError: | 999 except IndexError: |
1000 ix = Articulation_def (n,a,b) | 1000 ix = Articulation_def (n,a,b) |
1001 self.articulation_defs.append (Articulation_def (n, a, b)) | 1001 self.articulation_defs.append (Articulation_def (n, a, b)) |
1002 | 1002 |
1003 def try_GF(self, indices, contents): | 1003 def try_GF(self, indices, contents): |
1004 (staffno,measno) = indices | 1004 (staffno,measno) = indices |
1005 | 1005 |
1006 st = self.get_staff (staffno) | 1006 st = self.get_staff (staffno) |
1007 meas = st.get_measure (measno) | 1007 meas = st.get_measure (measno) |
1008 meas.finale = contents | 1008 meas.finale = contents |
1009 | 1009 |
1010 def try_FR(self, indices, contents): | 1010 def try_FR(self, indices, contents): |
1011 frameno = indices [0] | 1011 frameno = indices [0] |
1012 | 1012 |
1013 startnote = contents[0] | 1013 startnote = contents[0] |
1014 endnote = contents[1] | 1014 endnote = contents[1] |
1015 | 1015 |
1016 fill_list_to (self.frames, frameno) | 1016 fill_list_to (self.frames, frameno) |
1017 | 1017 |
1018 self.frames[frameno] = Frame ((frameno, startnote, endnote)) | 1018 self.frames[frameno] = Frame ((frameno, startnote, endnote)) |
1019 | 1019 |
1020 def try_MS (self, indices, contents): | 1020 def try_MS (self, indices, contents): |
1021 measno = indices[0] | 1021 measno = indices[0] |
1022 keynum = contents[1] | 1022 keynum = contents[1] |
1023 meas =self. get_global_measure (measno) | 1023 meas =self. get_global_measure (measno) |
1024 | 1024 |
1025 meas.set_key_sig (keynum) | 1025 meas.set_key_sig (keynum) |
1026 | 1026 |
1027 beats = contents[2] | 1027 beats = contents[2] |
1028 beatlen = contents[3] | 1028 beatlen = contents[3] |
1029 meas.set_timesig ((beats, beatlen)) | 1029 meas.set_timesig ((beats, beatlen)) |
(...skipping 11 matching lines...) Expand all Loading... |
1041 'IX': try_IX, | 1041 'IX': try_IX, |
1042 'Sx' : try_Sx, | 1042 'Sx' : try_Sx, |
1043 'eE' : try_eE, | 1043 'eE' : try_eE, |
1044 'verse' : try_verse, | 1044 'verse' : try_verse, |
1045 've' : try_ve, | 1045 've' : try_ve, |
1046 'IM' : try_IM, | 1046 'IM' : try_IM, |
1047 'TP' : try_TP, | 1047 'TP' : try_TP, |
1048 'BC' : try_BC, | 1048 'BC' : try_BC, |
1049 'IS' : try_IS, | 1049 'IS' : try_IS, |
1050 } | 1050 } |
1051 | 1051 |
1052 def parse (self, etf_dict): | 1052 def parse (self, etf_dict): |
1053 sys.stderr.write ('reconstructing ...') | 1053 sys.stderr.write ('reconstructing ...') |
1054 sys.stderr.flush () | 1054 sys.stderr.flush () |
1055 | 1055 |
1056 for (tag,routine) in list(Etf_file.routine_dict.items ()): | 1056 for (tag,routine) in list(Etf_file.routine_dict.items ()): |
1057 ks = list(etf_dict[tag].keys ()) | 1057 ks = list(etf_dict[tag].keys ()) |
1058 ks.sort () | 1058 ks.sort () |
1059 for k in ks: | 1059 for k in ks: |
1060 routine (self, k, etf_dict[tag][k]) | 1060 routine (self, k, etf_dict[tag][k]) |
1061 | 1061 |
1062 sys.stderr.write ('processing ...') | 1062 sys.stderr.write ('processing ...') |
1063 sys.stderr.flush () | 1063 sys.stderr.flush () |
1064 | 1064 |
1065 self.unthread_entries () | 1065 self.unthread_entries () |
1066 | 1066 |
1067 for st in self.staffs[1:]: | 1067 for st in self.staffs[1:]: |
1068 if not st: | 1068 if not st: |
1069 continue | 1069 continue |
1070 mno = 1 | 1070 mno = 1 |
1071 for m in st.measures[1:]: | 1071 for m in st.measures[1:]: |
1072 if not m: | 1072 if not m: |
1073 continue | 1073 continue |
1074 | 1074 |
1075 m.calculate() | 1075 m.calculate() |
1076 try: | 1076 try: |
1077 m.global_measure = self.measures[mno] | 1077 m.global_measure = self.measures[mno] |
1078 except IndexError: | 1078 except IndexError: |
1079 sys.stderr.write ("Non-existent global measure %d" % mno) | 1079 sys.stderr.write ("Non-existent global measure %d" % mno) |
1080 continue | 1080 continue |
1081 | 1081 |
1082 frame_obj_list = [None] | 1082 frame_obj_list = [None] |
1083 for frno in m.frames: | 1083 for frno in m.frames: |
1084 try: | 1084 try: |
1085 fr = self.frames[frno] | 1085 fr = self.frames[frno] |
1086 frame_obj_list.append (fr) | 1086 frame_obj_list.append (fr) |
1087 except IndexError: | 1087 except IndexError: |
1088 sys.stderr.write ("\nNon-existent frame %d" % frno) | 1088 sys.stderr.write ("\nNon-existent frame %d" % frno) |
1089 | 1089 |
1090 m.frames = frame_obj_list | 1090 m.frames = frame_obj_list |
1091 for fr in frame_obj_list[1:]: | 1091 for fr in frame_obj_list[1:]: |
1092 if not fr: | 1092 if not fr: |
1093 continue | 1093 continue |
1094 | 1094 |
1095 fr.set_measure (m) | 1095 fr.set_measure (m) |
1096 | 1096 |
1097 fr.chords = self.get_thread (fr.start, fr.end) | 1097 fr.chords = self.get_thread (fr.start, fr.end) |
1098 for c in fr.chords: | 1098 for c in fr.chords: |
1099 c.frame = fr | 1099 c.frame = fr |
1100 mno = mno + 1 | 1100 mno = mno + 1 |
1101 | 1101 |
1102 for c in self.chords[1:]: | 1102 for c in self.chords[1:]: |
1103 if c: | 1103 if c: |
1104 c.calculate() | 1104 c.calculate() |
1105 | 1105 |
1106 for f in self.frames[1:]: | 1106 for f in self.frames[1:]: |
1107 if f: | 1107 if f: |
1108 f.calculate () | 1108 f.calculate () |
1109 | 1109 |
1110 for t in self.tuplets[1:]: | 1110 for t in self.tuplets[1:]: |
1111 t.calculate (self.chords) | 1111 t.calculate (self.chords) |
1112 | 1112 |
1113 for s in self.slurs[1:]: | 1113 for s in self.slurs[1:]: |
1114 if s: | 1114 if s: |
1115 s.calculate (self.chords) | 1115 s.calculate (self.chords) |
1116 | 1116 |
1117 for s in self.articulations[1:]: | 1117 for s in self.articulations[1:]: |
1118 s.calculate (self.chords, self.articulation_defs) | 1118 s.calculate (self.chords, self.articulation_defs) |
1119 | 1119 |
1120 def get_thread (self, startno, endno): | 1120 def get_thread (self, startno, endno): |
1121 | 1121 |
1122 thread = [] | 1122 thread = [] |
1123 | 1123 |
1124 c = None | 1124 c = None |
1125 try: | 1125 try: |
1126 c = self.chords[startno] | 1126 c = self.chords[startno] |
1127 except IndexError: | 1127 except IndexError: |
1128 sys.stderr.write ("Huh? Frame has invalid bounds (%d,%d)\n" % (start
no, endno)) | 1128 sys.stderr.write ("Huh? Frame has invalid bounds (%d,%d)\n" % (start
no, endno)) |
1129 return [] | 1129 return [] |
1130 | 1130 |
1131 | 1131 |
1132 while c and c.number != endno: | 1132 while c and c.number != endno: |
1133 d = c # hack to avoid problem with scripts/build/grand-replace.py | 1133 d = c # hack to avoid problem with scripts/build/grand-replace.py |
1134 thread.append (d) | 1134 thread.append (d) |
1135 c = c.__next__ | 1135 c = c.__next__ |
1136 | 1136 |
1137 if c: | 1137 if c: |
1138 d = c # hack to avoid problem with scripts/build/grand-replace.py | 1138 d = c # hack to avoid problem with scripts/build/grand-replace.py |
1139 thread.append (d) | 1139 thread.append (d) |
1140 | 1140 |
1141 return thread | 1141 return thread |
1142 | 1142 |
1143 def dump (self): | 1143 def dump (self): |
1144 str = '' | 1144 str = '' |
1145 staffs = [] | 1145 staffs = [] |
1146 for s in self.staffs[1:]: | 1146 for s in self.staffs[1:]: |
1147 if s: | 1147 if s: |
1148 str = str + '\n\n' + s.dump () | 1148 str = str + '\n\n' + s.dump () |
1149 staffs.append ('\\' + s.staffid ()) | 1149 staffs.append ('\\' + s.staffid ()) |
1150 | 1150 |
1151 | 1151 |
1152 # should use \addlyrics ? | 1152 # should use \addlyrics ? |
1153 | 1153 |
1154 for v in self.verses[1:]: | 1154 for v in self.verses[1:]: |
1155 str = str + v.dump() | 1155 str = str + v.dump() |
1156 | 1156 |
1157 if len (self.verses) > 1: | 1157 if len (self.verses) > 1: |
1158 sys.stderr.write ("\nLyrics found; edit to use \\addlyrics to couple
to a staff\n") | 1158 sys.stderr.write ("\nLyrics found; edit to use \\addlyrics to couple
to a staff\n") |
1159 | 1159 |
1160 if staffs: | 1160 if staffs: |
1161 str += '\\version "2.3.25"\n' | 1161 str += '\\version "2.3.25"\n' |
1162 str = str + '<<\n %s\n>> } ' % ' '.join (staffs) | 1162 str = str + '<<\n %s\n>> } ' % ' '.join (staffs) |
1163 | 1163 |
1164 return str | 1164 return str |
1165 | 1165 |
1166 | 1166 |
1167 def __str__ (self): | 1167 def __str__ (self): |
1168 return 'ETF FILE %s %s' % (self.measures, self.entries) | 1168 return 'ETF FILE %s %s' % (self.measures, self.entries) |
1169 | 1169 |
1170 def unthread_entries (self): | 1170 def unthread_entries (self): |
1171 for e in self.chords[1:]: | 1171 for e in self.chords[1:]: |
1172 if not e: | 1172 if not e: |
1173 continue | 1173 continue |
1174 | 1174 |
1175 e.prev = self.chords[e.finale[0]] | 1175 e.prev = self.chords[e.finale[0]] |
1176 e.next = self.chords[e.finale[1]] | 1176 e.next = self.chords[e.finale[1]] |
1177 | 1177 |
1178 def identify(): | 1178 def identify(): |
1179 sys.stderr.write ("%s from LilyPond %s\n" % (program_name, version)) | 1179 sys.stderr.write ("%s from LilyPond %s\n" % (program_name, version)) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 for f in files: | 1236 for f in files: |
1237 if f == '-': | 1237 if f == '-': |
1238 f = '' | 1238 f = '' |
1239 | 1239 |
1240 sys.stderr.write ('Processing `%s\'\n' % f) | 1240 sys.stderr.write ('Processing `%s\'\n' % f) |
1241 | 1241 |
1242 dict = parse_etf_file (f, Etf_file.routine_dict) | 1242 dict = parse_etf_file (f, Etf_file.routine_dict) |
1243 e = Etf_file(dict) | 1243 e = Etf_file(dict) |
1244 if not out_filename: | 1244 if not out_filename: |
1245 out_filename = os.path.basename (re.sub ('(?i).etf$', '.ly', f)) | 1245 out_filename = os.path.basename (re.sub ('(?i).etf$', '.ly', f)) |
1246 | 1246 |
1247 if out_filename == f: | 1247 if out_filename == f: |
1248 out_filename = os.path.basename (f + '.ly') | 1248 out_filename = os.path.basename (f + '.ly') |
1249 | 1249 |
1250 sys.stderr.write ('Writing `%s\'' % out_filename) | 1250 sys.stderr.write ('Writing `%s\'' % out_filename) |
1251 ly = e.dump() | 1251 ly = e.dump() |
1252 | 1252 |
1253 fo = open (out_filename, 'w') | 1253 fo = open (out_filename, 'w') |
1254 fo.write ('%% lily was here -- automatically converted by etf2ly from %s\n'
% f) | 1254 fo.write ('%% lily was here -- automatically converted by etf2ly from %s\n'
% f) |
1255 fo.write(ly) | 1255 fo.write(ly) |
1256 fo.close () | 1256 fo.close () |
1257 | 1257 |
OLD | NEW |