From: Reinhold Kainhofer Date: Sat, 29 Nov 2008 19:20:33 +0000 (+0100) Subject: MusicXML: Implement elisions (multiple lyrics syllables assigned to one note) X-Git-Tag: release/2.12.0-1~40^2~18 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=7a154de04023d59019bdd498b525580890fd2152;p=lilypond.git MusicXML: Implement elisions (multiple lyrics syllables assigned to one note) --- diff --git a/input/regression/musicxml/06j-Lyrics-Elisions.xml b/input/regression/musicxml/06j-Lyrics-Elisions.xml new file mode 100644 index 0000000000..f525d10377 --- /dev/null +++ b/input/regression/musicxml/06j-Lyrics-Elisions.xml @@ -0,0 +1,103 @@ + + + + + + Multiple lyrics syllables + assigned to a single note are implemented either using a space in + the lyrics or by using the <elision> lyrics element. This + testcase checks both of them. First, a note with on syllable is + given, then a note with two syllables separated by a spcae and finally + a note with two and one with three syllables implemented using + <elision> is given. + + + + + MusicXML Part + + + + + + + 1 + + 0 + major + + + + G + 2 + + + + + C + 5 + + 1 + 1 + quarter + down + + a + + + + + C + 5 + + 1 + 1 + quarter + down + + b c + + + + + C + 5 + + 1 + 1 + quarter + down + + d + + e + + + + + C + 5 + + 1 + 1 + quarter + down + + f + + g + + h + + + + light-heavy + + + + + diff --git a/python/musicxml.py b/python/musicxml.py index 0c06264812..1c159924b0 100644 --- a/python/musicxml.py +++ b/python/musicxml.py @@ -462,6 +462,8 @@ class Syllabic (Music_xml_node): def continued (self): text = self.get_text() return (text == "begin") or (text == "middle") +class Elision (Music_xml_node): + pass class Text (Music_xml_node): pass @@ -472,32 +474,6 @@ class Lyric (Music_xml_node): else: return -1 - def lyric_to_text (self): - continued = False - syllabic = self.get_maybe_exist_typed_child (Syllabic) - if syllabic: - continued = syllabic.continued () - text = self.get_maybe_exist_typed_child (Text) - - if text: - text = text.get_text() - # We need to convert soft hyphens to -, otherwise the ascii codec as well - # as lilypond will barf on that character - text = string.replace( text, u'\xad', '-' ) - - if text == "-" and continued: - return "--" - elif text == "_" and continued: - return "__" - elif continued and text: - return escape_ly_output_string (text) + " --" - elif continued: - return "--" - elif text: - return escape_ly_output_string (text) - else: - return "" - class Musicxml_voice: def __init__ (self): self._elements = [] @@ -1122,6 +1098,7 @@ class_dict = { 'direction': Direction, 'direction-type': DirType, 'duration': Duration, + 'elision': Elision, 'frame': Frame, 'frame-note': Frame_Note, 'figured-bass': FiguredBass, diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index f29fa3ecbc..c4926da8ac 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -1732,6 +1732,34 @@ def musicxml_note_to_lily_main_event (n): return event +def musicxml_lyrics_to_text (lyrics): + # TODO: Implement text styles for lyrics syllables + continued = False + text = '' + for e in lyrics.get_all_children (): + if isinstance (e, musicxml.Syllabic): + continued = e.continued () + elif isinstance (e, musicxml.Text): + # We need to convert soft hyphens to -, otherwise the ascii codec as well + # as lilypond will barf on that character + text += string.replace( e.get_text(), u'\xad', '-' ) + elif isinstance (e, musicxml.Elision): + if text: + text += " " + continued = False + + if text == "-" and continued: + return "--" + elif text == "_" and continued: + return "__" + elif continued and text: + return musicxml.escape_ly_output_string (text) + " --" + elif continued: + return "--" + elif text: + return musicxml.escape_ly_output_string (text) + else: + return "" ## TODO class NegativeSkip: @@ -2255,10 +2283,10 @@ def musicxml_voice_to_lily_voice (voice): for l in note_lyrics_elements: if l.get_number () < 0: for k in lyrics.keys (): - lyrics[k].append (l.lyric_to_text ()) + lyrics[k].append (musicxml_lyrics_to_text (l)) note_lyrics_processed.append (k) else: - lyrics[l.number].append(l.lyric_to_text ()) + lyrics[l.number].append(musicxml_lyrics_to_text (l)) note_lyrics_processed.append (l.number) for lnr in lyrics.keys (): if not lnr in note_lyrics_processed: