diff options
author | John Gourlay <john@weathervanefarm.net> | 2016-05-12 20:53:49 -0400 |
---|---|---|
committer | John Gourlay <john@weathervanefarm.net> | 2016-05-12 20:53:49 -0400 |
commit | 8ba96c387d766e3466c51d0b416d05dcd0176edd (patch) | |
tree | 022d88a7fb1acb2478c28cf453d107c300222b9e /python | |
parent | 0398fdb9df24ac2e22a8cbff1b3c18ca04e9f221 (diff) |
Resurrect the file musicxml2ly_conversion.py, moving the few functions
and classes to it from musicxml2ly.py that are also used in
musicxml.py.
Diffstat (limited to 'python')
-rw-r--r-- | python/musicxml2ly_conversion.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/python/musicxml2ly_conversion.py b/python/musicxml2ly_conversion.py new file mode 100644 index 0000000000..dc6c641fa2 --- /dev/null +++ b/python/musicxml2ly_conversion.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +import lilylib as ly +import musicexp + +def rational_to_lily_duration(rational_len): + d = musicexp.Duration() + + rational_len.normalize_self() + 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) + + # Duration of the form 1/2^n or 3/2^n can be converted to a simple lilypond duration + dots = {1: 0, 3: 1, 7: 2, 15: 3, 31: 4, 63: 5, 127: 6}.get(rational_len.numerator(), -1) + if(d_log >= dots >= 0): + # account for the dots! + d.duration_log = d_log - dots + d.dots = dots + elif(d_log >= 0): + d.duration_log = d_log + d.factor = Rational(rational_len.numerator()) + else: + ly.warning(_("Encountered rational duration with denominator %s, " + "unable to convert to lilypond duration") % + rational_len.denominator()) + # TODO: Test the above error message + return None + + return d + +def musicxml_step_to_lily(step): + if step: + return (ord(step) - ord('A') + 7 - 2) % 7 + else: + return None + +class Marker(musicexp.Music): + def __init__(self): + self.direction = 0 + self.event = None + def print_ly(self, printer): + ly.warning(_("Encountered unprocessed marker %s\n") % self) + pass + def ly_expression(self): + return "" + +class RepeatMarker(Marker): + def __init__(self): + Marker.__init__(self) + self.times = 0 + +class EndingMarker(Marker): + pass |