1 # -*- coding: utf-8 -*-
7 def rational_to_lily_duration(rational_len):
8 d = musicexp.Duration()
10 rational_len.normalize_self()
11 d_log = {1: 0, 2: 1, 4:2, 8:3, 16:4, 32:5, 64:6, 128:7, 256:8, 512:9}.get(rational_len.denominator(), -1)
13 # Duration of the form 1/2^n or 3/2^n can be converted to a simple lilypond duration
14 dots = {1: 0, 3: 1, 7: 2, 15: 3, 31: 4, 63: 5, 127: 6}.get(rational_len.numerator(), -1)
15 if(d_log >= dots >= 0):
16 # account for the dots!
17 d.duration_log = d_log - dots
20 d.duration_log = d_log
21 d.factor = Rational(rational_len.numerator())
23 ly.warning(_("Encountered rational duration with denominator %s, "
24 "unable to convert to lilypond duration") %
25 rational_len.denominator())
26 # TODO: Test the above error message
31 def musicxml_step_to_lily(step):
33 return (ord(step) - ord('A') + 7 - 2) % 7
37 class Marker(musicexp.Music):
41 def print_ly(self, printer):
42 ly.warning(_("Encountered unprocessed marker %s\n") % self)
44 def ly_expression(self):
47 class RepeatMarker(Marker):
52 class EndingMarker(Marker):