1 # -*- coding: utf-8 -*-
5 def rational_to_lily_duration(rational_len):
6 d = musicexp.Duration()
8 rational_len.normalize_self()
9 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)
11 # Duration of the form 1/2^n or 3/2^n can be converted to a simple lilypond duration
12 dots = {1: 0, 3: 1, 7: 2, 15: 3, 31: 4, 63: 5, 127: 6}.get(rational_len.numerator(), -1)
13 if(d_log >= dots >= 0):
14 # account for the dots!
15 d.duration_log = d_log - dots
18 d.duration_log = d_log
19 d.factor = Rational(rational_len.numerator())
21 ly.warning(_("Encountered rational duration with denominator %s, "
22 "unable to convert to lilypond duration") %
23 rational_len.denominator())
24 # TODO: Test the above error message
29 def musicxml_step_to_lily(step):
31 return (ord(step) - ord('A') + 7 - 2) % 7
35 class Marker(musicexp.Music):
39 def print_ly(self, printer):
40 ly.warning(_("Encountered unprocessed marker %s\n") % self)
42 def ly_expression(self):
45 class RepeatMarker(Marker):
50 class EndingMarker(Marker):