From: Reinhold Kainhofer Date: Fri, 14 Sep 2007 21:58:51 +0000 (+0200) Subject: MusicXML: Implement pitched rests X-Git-Tag: release/2.11.35-1~116 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e0f230ea9f40e0231d80980c86cffff4def47799;p=lilypond.git MusicXML: Implement pitched rests In MusicXML, a rest can also have a pitch, given as A3 If given, convert these into ordinary lilypond pitches and print them out as "a4 \rest" instead of "r4". Signed-off-by: Reinhold Kainhofer --- diff --git a/python/musicexp.py b/python/musicexp.py index f4efdd54db..0b41d275c9 100644 --- a/python/musicexp.py +++ b/python/musicexp.py @@ -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): diff --git a/python/musicxml.py b/python/musicxml.py index b3306f7939..46473bf746 100644 --- a/python/musicxml.py +++ b/python/musicxml.py @@ -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 diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index cd9357afb8..9a291a223d 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -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 ()