From 7ef6a016c6fa4ced85383f9af1317c57dd099ad4 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Sat, 4 Apr 2009 15:19:51 +0200 Subject: [PATCH] MusicXML: Implement page and system breaks --- input/regression/musicxml/52b-Breaks.xml | 64 ++++++++++++++++++++++++ python/musicexp.py | 8 +++ python/musicxml.py | 8 ++- scripts/musicxml2ly.py | 30 +++++++++++ 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 input/regression/musicxml/52b-Breaks.xml diff --git a/input/regression/musicxml/52b-Breaks.xml b/input/regression/musicxml/52b-Breaks.xml new file mode 100644 index 0000000000..623261829a --- /dev/null +++ b/input/regression/musicxml/52b-Breaks.xml @@ -0,0 +1,64 @@ + + + + + + System and page breaks, given in + a <print> element + + + + + MusicXML Part + + + + + + + 1 + + + + + C + 5 + + 4 + 1 + whole + + + + + + + + C + 5 + + 4 + 1 + whole + + + + + + + + C + 5 + + 4 + 1 + whole + + + + + diff --git a/python/musicexp.py b/python/musicexp.py index 0e8b212c85..61598f28e5 100644 --- a/python/musicexp.py +++ b/python/musicexp.py @@ -1707,6 +1707,14 @@ class MultiMeasureRest(Music): return 'R%s' % self.duration.ly_expression () +class Break (Music): + def __init__ (self, tp="break"): + Music.__init__ (self) + self.type = tp + def print_ly (self, printer): + if self.type: + printer.dump ("\\%s" % self.type) + class StaffGroup: def __init__ (self, command = "StaffGroup"): self.stafftype = command diff --git a/python/musicxml.py b/python/musicxml.py index b6a5bbeac8..db53bc4910 100644 --- a/python/musicxml.py +++ b/python/musicxml.py @@ -828,7 +828,7 @@ class Part (Music_xml_node): if not (isinstance (n, Note) or isinstance (n, Attributes) or isinstance (n, Direction) or isinstance (n, Partial) or isinstance (n, Barline) or isinstance (n, Harmony) or - isinstance (n, FiguredBass) ): + isinstance (n, FiguredBass) or isinstance (n, Print)): continue if isinstance (n, Attributes) and not start_attr: @@ -844,7 +844,7 @@ class Part (Music_xml_node): voices[v].add_element (staff_attributes) continue - if isinstance (n, Partial) or isinstance (n, Barline): + if isinstance (n, Partial) or isinstance (n, Barline) or isinstance (n, Print): for v in voices.keys (): voices[v].add_element (n) continue @@ -1147,6 +1147,9 @@ class BeatUnitDot (Music_xml_node): class PerMinute (Music_xml_node): pass +class Print (Music_xml_node): + pass + ## need this, not all classes are instantiated @@ -1197,6 +1200,7 @@ class_dict = { 'pedal': Pedal, 'per-minute': PerMinute, 'pitch': Pitch, + 'print': Print, 'rest': Rest, 'root': Root, 'score-part': Score_part, diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py index 33c0aca039..5ac94e9359 100644 --- a/scripts/musicxml2ly.py +++ b/scripts/musicxml2ly.py @@ -930,6 +930,30 @@ def musicxml_attributes_to_lily (attrs): elts.append (ev) return elts + +def musicxml_print_to_lily (el): + # TODO: Implement other print attributes + # + # + elts = [] + if (hasattr (el, "new-system")): + val = getattr (el, "new-system") + if (val == "yes"): + elts.append (musicexp.Break ("break")) + if (hasattr (el, "new-page")): + val = getattr (el, "new-page") + if (val == "yes"): + elts.append (musicexp.Break ("pageBreak")) + return elts + class Marker (musicexp.Music): def __init__ (self): @@ -2126,6 +2150,12 @@ def musicxml_voice_to_lily_voice (voice): chordnames_builder.add_barline (a, False) continue + + if isinstance (n, musicxml.Print): + for a in musicxml_print_to_lily (n): + voice_builder.add_command (a, False) + continue + # Continue any multimeasure-rests before trying to add bar checks! # Don't handle new MM rests yet, because for them we want bar checks! rest = n.get_maybe_exist_typed_child (musicxml.Rest) -- 2.39.2