X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fmusicxml2ly.py;h=2f4b807080b82b615973bef22e00988dd4697d24;hb=2be50a355fc735ee7dedb6b8964888bb3d6934af;hp=e89c94811e9c9a8a36d5c2c001c49fdc7522d804;hpb=e18d10cda43e9c2d477a4ac224c1f07980b0efff;p=lilypond.git diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index e89c94811e..2f4b807080 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -165,7 +165,7 @@ compoundMeter = \set Timing.measureLength = $mlen \set Timing.timeSignatureFraction = #(cons (ly:moment-main-numerator $mlen) (ly:moment-main-denominator $mlen)) -\set Timing.beatLength = $beat +\set Timing.baseMoment = $beat % TODO: Implement beatGrouping and auto-beam-settings!!! #} )) @@ -401,6 +401,8 @@ def staff_attributes_to_lily_staff (mxl_attr): if staff_lines: lines = string.atoi (staff_lines.get_text ()) + # TODO: Handle other staff attributes like staff-space, etc. + staff = None if clef_sign == "percussion" and lines == 1: staff = musicexp.RhythmicStaff () @@ -412,8 +414,11 @@ def staff_attributes_to_lily_staff (mxl_attr): staff.string_tunings = staff_attributes_to_string_tunings (attributes) # staff.tablature_format = ??? else: - # TODO: Handle case with lines <> 5! staff = musicexp.Staff () + # TODO: Handle case with lines <> 5! + if (lines != 5): + staff.add_context_modification ("\\override StaffSymbol #'line-count = #%s" % lines) + return staff @@ -926,6 +931,22 @@ def musicxml_transpose_to_lily (attributes): transposition.pitch = musicexp.Pitch ().transposed (shift) return transposition +def musicxml_staff_details_to_lily (attributes): + details = attributes.get_maybe_exist_named_child ('staff-details') + if not details: + return None + + ## TODO: Handle staff-type, staff-lines, staff-tuning, capo, staff-size + ret = [] + + stafflines = details.get_maybe_exist_named_child ('staff-lines') + if stafflines: + lines = string.atoi (stafflines.get_text ()); + lines_event = musicexp.StaffLinesEvent (lines); + ret.append (lines_event); + + return ret; + def musicxml_attributes_to_lily (attrs): elts = [] @@ -934,12 +955,16 @@ def musicxml_attributes_to_lily (attrs): 'time': musicxml_time_to_lily, 'key': musicxml_key_to_lily, 'transpose': musicxml_transpose_to_lily, + 'staff-details': musicxml_staff_details_to_lily, } for (k, func) in attr_dispatch.items (): children = attrs.get_named_children (k) if children: ev = func (attrs) - if ev: + if isinstance (ev, list): + for e in ev: + elts.append (e) + elif ev: elts.append (ev) return elts @@ -973,6 +998,14 @@ def musicxml_print_to_lily (el): val = getattr (el, "new-page") if (val == "yes"): elts.append (musicexp.Break ("pageBreak")) + child = el.get_maybe_exist_named_child ("part-name-display") + if child: + elts.append (musicexp.SetEvent ("Staff.instrumentName", + "\"%s\"" % extract_display_text (child))) + child = el.get_maybe_exist_named_child ("part-abbreviation-display") + if child: + elts.append (musicexp.SetEvent ("Staff.shortInstrumentName", + "\"%s\"" % extract_display_text (child))) return elts @@ -1376,7 +1409,7 @@ def musicxml_accordion_to_markup (mxl_event): if high: commandname += "H" command += """\\combine - \\raise #2.5 \\musicglyph #\"accordion.accDot\" + \\raise #2.5 \\musicglyph #\"accordion.dot\" """ middle = mxl_event.get_maybe_exist_named_child ('accordion-middle') if middle: @@ -1390,32 +1423,32 @@ def musicxml_accordion_to_markup (mxl_event): if txt == 3: commandname += "MMM" command += """\\combine - \\raise #1.5 \\musicglyph #\"accordion.accDot\" + \\raise #1.5 \\musicglyph #\"accordion.dot\" \\combine - \\raise #1.5 \\translate #(cons 1 0) \\musicglyph #\"accordion.accDot\" + \\raise #1.5 \\translate #(cons 1 0) \\musicglyph #\"accordion.dot\" \\combine - \\raise #1.5 \\translate #(cons -1 0) \\musicglyph #\"accordion.accDot\" + \\raise #1.5 \\translate #(cons -1 0) \\musicglyph #\"accordion.dot\" """ elif txt == 2: commandname += "MM" command += """\\combine - \\raise #1.5 \\translate #(cons 0.5 0) \\musicglyph #\"accordion.accDot\" + \\raise #1.5 \\translate #(cons 0.5 0) \\musicglyph #\"accordion.dot\" \\combine - \\raise #1.5 \\translate #(cons -0.5 0) \\musicglyph #\"accordion.accDot\" + \\raise #1.5 \\translate #(cons -0.5 0) \\musicglyph #\"accordion.dot\" """ elif not txt <= 0: commandname += "M" command += """\\combine - \\raise #1.5 \\musicglyph #\"accordion.accDot\" + \\raise #1.5 \\musicglyph #\"accordion.dot\" """ low = mxl_event.get_maybe_exist_named_child ('accordion-low') if low: commandname += "L" command += """\\combine - \\raise #0.5 \musicglyph #\"accordion.accDot\" + \\raise #0.5 \musicglyph #\"accordion.dot\" """ - command += "\musicglyph #\"accordion.accDiscant\"" + command += "\musicglyph #\"accordion.discant\"" command = "\\markup { \\normalsize %s }" % command # Define the newly built command \accReg[H][MMM][L] additional_definitions[commandname] = "%s = %s" % (commandname, command) @@ -1566,6 +1599,7 @@ def musicxml_direction_to_lily (n): if ev: # TODO: set the correct direction! Unfortunately, \mark in ly does # not seem to support directions! + ev.force_direction = dir res.append (ev) continue @@ -1834,7 +1868,9 @@ def musicxml_note_to_lily_main_event (n): acc = n.get_maybe_exist_named_child ('accidental') if acc: # let's not force accs everywhere. - event.cautionary = acc.editorial + event.cautionary = acc.cautionary + # TODO: Handle editorial accidentals + # TODO: Handle the level-display setting for displaying brackets/parentheses elif n.get_maybe_exist_typed_child (musicxml.Unpitched): # Unpitched elements have display-step and can also have @@ -2971,7 +3007,7 @@ def main (): # Allow the user to leave out the .xml or xml on the filename basefilename = args[0].decode('utf-8') if basefilename == "-": # Read from stdin - basefilename = "-" + filename = "-" else: filename = get_existing_filename_with_extension (basefilename, "xml") if not filename: