X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fmusicxml2ly.py;h=ba7be37a65f025d71dd24164803af20af35aab52;hb=39c0e8adb498996f5e414b1d0bc3a20ac81aa619;hp=2313f6c864c0198dfe9f38aa58ed1edec82b6cd5;hpb=50a2ccb3d32509ab8e0beb359515be0c0d19d4d3;p=lilypond.git diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index 2313f6c864..ba7be37a65 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -945,11 +945,11 @@ def musicxml_print_to_lily (el): # page-number CDATA #IMPLIED # > elts = [] - if (hasattr (el, "new-system")): + if (hasattr (el, "new-system") and conversion_settings.convert_page_layout): val = getattr (el, "new-system") if (val == "yes"): elts.append (musicexp.Break ("break")) - if (hasattr (el, "new-page")): + if (hasattr (el, "new-page") and conversion_settings.convert_page_layout): val = getattr (el, "new-page") if (val == "yes"): elts.append (musicexp.Break ("pageBreak")) @@ -1338,7 +1338,7 @@ def musicxml_words_to_lily_event (words): # TODO: How should I best convert the font-family attribute? # TODO: How can I represent the underline, overline and line-through - # attributes in Lilypond? Values of these attributes indicate + # attributes in LilyPond? Values of these attributes indicate # the number of lines return event @@ -1710,7 +1710,7 @@ def musicxml_harmony_to_lily_chordname (n): ev.bass = musicxml_chordpitch_to_lily (bass) inversion = n.get_maybe_exist_named_child ('inversion') if inversion: - # TODO: Lilypond does not support inversions, does it? + # TODO: LilyPond does not support inversions, does it? # Mail from Carl Sorensen on lilypond-devel, June 11, 2008: # 4. LilyPond supports the first inversion in the form of added @@ -2108,6 +2108,7 @@ def musicxml_voice_to_lily_voice (voice): voice_builder.set_measure_length (current_measure_length) for n in voice._elements: + tie_started = False if n.get_name () == 'forward': continue staff = n.get_maybe_exist_named_child ('staff') @@ -2350,6 +2351,7 @@ def musicxml_voice_to_lily_voice (voice): if mxl_tie and mxl_tie.type == 'start': ev_chord.append (musicexp.TieEvent ()) is_tied = True + tie_started = True else: is_tied = False @@ -2445,7 +2447,13 @@ def musicxml_voice_to_lily_voice (voice): if not lnr in note_lyrics_processed: lyrics[lnr].append ("\skip4") - ## force trailing mm rests to be written out. + # Assume that a element only lasts for one note. + # This might not be correct MusicXML interpretation, but works for + # most cases and fixes broken files, which have the end tag missing + if is_tied and not tie_started: + is_tied = False + + ## force trailing mm rests to be written out. voice_builder.add_music (musicexp.ChordEvent (), Rational (0)) ly_voice = group_tuplets (voice_builder.elements, tuplet_events) @@ -2551,7 +2559,17 @@ def voices_in_part (part): def voices_in_part_in_parts (parts): """return a Part -> Name -> Voice dictionary""" - return dict([(p.id, voices_in_part (p)) for p in parts]) + # don't crash if p doesn't have an id (that's invalid MusicXML, + # but such files are out in the wild! + dictionary = {} + for p in parts: + voices = voices_in_part (p) + if (hasattr (p, "id")): + dictionary[p.id] = voices + else: + # TODO: extract correct part id from other sources + dictionary[None] = voices + return dictionary; def get_all_voices (parts): @@ -2647,6 +2665,12 @@ information.""") % 'lilypond') dest = "convert_rest_positions", help = _ ("do not convert exact vertical positions of rests")) + p.add_option ('--npl', '--no-page-layout', + action = "store_false", + default = True, + dest = "convert_page_layout", + help = _ ("do not convert the exact page layout and breaks")) + p.add_option ('--no-beaming', action = "store_false", default = True, @@ -2883,7 +2907,7 @@ def convert (filename, options): print_ly_additional_definitions (printer, filename) if score_information: score_information.print_ly (printer) - if paper_information: + if paper_information and conversion_settings.convert_page_layout: paper_information.print_ly (printer) if layout_information: layout_information.print_ly (printer) @@ -2922,6 +2946,7 @@ def main (): needed_additional_definitions.append (options.language) additional_definitions[options.language] = "\\include \"%s.ly\"\n" % options.language conversion_settings.ignore_beaming = not options.convert_beaming + conversion_settings.convert_page_layout = options.convert_page_layout # Allow the user to leave out the .xml or xml on the filename basefilename = args[0].decode('utf-8')