]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Implement pitched rests
authorReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 14 Sep 2007 21:58:51 +0000 (23:58 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Wed, 3 Oct 2007 16:39:17 +0000 (18:39 +0200)
In MusicXML, a rest can also have a pitch, given as
<display-step>A</display-step><display-octave>3</display-octave>
If given, convert these into ordinary lilypond pitches and print them
out as "a4 \rest" instead of "r4".

Signed-off-by: Reinhold Kainhofer <reinhold@kainhofer.com>
python/musicexp.py
python/musicxml.py
scripts/musicxml2ly.py

index f4efdd54db16e37ff1649640405dda87baec6121..0b41d275c992e6a0df81d8cde3062434f9f437c1 100644 (file)
@@ -675,12 +675,23 @@ class RhythmicEvent(Event):
                 % self.duration.lisp_expression ())
     
 class RestEvent (RhythmicEvent):
+    def __init__ (self):
+        RhythmicEvent.__init__ (self)
+        self.pitch = None
     def ly_expression (self):
-        return 'r%s' % self.duration.ly_expression ()
+        if self.pitch:
+            return "%s%s\\rest" % (self.pitch.ly_expression (), self.duration.ly_expression ())
+        else:
+            return 'r%s' % self.duration.ly_expression ()
     
     def print_ly (self, printer):
-        printer('r')
-        self.duration.print_ly (printer)
+        if self.pitch:
+            self.pitch.print_ly (printer)
+            self.duration.print_ly (printer)
+            printer ('\\rest')
+        else:
+            printer('r')
+            self.duration.print_ly (printer)
 
 class SkipEvent (RhythmicEvent):
     def ly_expression (self):
index b3306f7939e6b435fd655248c1bffded700af785..46473bf7469acbdac4fcb80ad8c5e6bdbd0d816c 100644 (file)
@@ -629,6 +629,20 @@ class Rest (Music_xml_node):
         self._is_whole_measure = False
     def is_whole_measure (self):
         return self._is_whole_measure
+    def get_step (self):
+        ch = self.get_maybe_exist_typed_child (get_class (u'display-step'))
+        if ch:
+            step = ch.get_text ().strip ()
+            return step
+        else:
+            return None
+    def get_octave (self):
+        ch = self.get_maybe_exist_typed_child (get_class (u'display-octave'))
+        if ch:
+            step = ch.get_text ().strip ()
+            return int (step)
+        else:
+            return None
 
 class Type (Music_xml_node):
     pass
index cd9357afb84777094f96f37e814f7a0e5fbb77e8..9a291a223d8c3e7083a007d220c13c6cc197f846 100644 (file)
@@ -419,7 +419,12 @@ def musicxml_note_to_lily_main_event (n):
             event.cautionary = acc.editorial
         
     elif n.get_maybe_exist_typed_child (musicxml.Rest):
+        # rests can have display-octave and display-step, which are
+        # treated like an ordinary note pitch
+        rest = n.get_maybe_exist_typed_child (musicxml.Rest)
         event = musicexp.RestEvent()
+        pitch = musicxml_restdisplay_to_lily (rest)
+        event.pitch = pitch
     elif n.instrument_name:
         event = musicexp.NoteEvent ()
         drum_type = instrument_drumtype_dict.get (n.instrument_name)
@@ -780,6 +785,17 @@ def musicxml_pitch_to_lily (mxl_pitch):
     p.octave = mxl_pitch.get_octave () - 4
     return p
 
+def musicxml_restdisplay_to_lily (mxl_rest):
+    p = None
+    step = mxl_rest.get_step ()
+    if step:
+        p = musicexp.Pitch()
+        p.step = (ord (step) - ord ('A') + 7 - 2) % 7
+    octave = mxl_rest.get_octave ()
+    if octave and p:
+        p.octave = octave - 4
+    return p
+
 def voices_in_part (part):
     """Return a Name -> Voice dictionary for PART"""
     part.interpret ()