From 36ca8afcc6d4e3ce06df864a7a0744f3098a1420 Mon Sep 17 00:00:00 2001 From: felipperoza Date: Mon, 15 May 2017 11:31:50 -0300 Subject: [PATCH 1/4] Export \break to MusicXML --- ly/musicxml/create_musicxml.py | 3 +++ ly/musicxml/ly2xml_mediator.py | 4 ++++ ly/musicxml/lymus2musxml.py | 10 ++++++---- ly/musicxml/xml_objs.py | 6 ++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ly/musicxml/create_musicxml.py b/ly/musicxml/create_musicxml.py index 8fb82b7b..12b697ac 100644 --- a/ly/musicxml/create_musicxml.py +++ b/ly/musicxml/create_musicxml.py @@ -528,6 +528,9 @@ def add_clef(self, sign, line, nr=0, oct_ch=0): octchnode = etree.SubElement(clefnode, "clef-octave-change") octchnode.text = str(oct_ch) + def new_system(self, force_break): + etree.SubElement(self.current_bar, "print", new_system=force_break) + def add_barline(self, bl_type, repeat=None): barnode = etree.SubElement(self.current_bar, "barline", location="right") barstyle = etree.SubElement(barnode, "bar-style") diff --git a/ly/musicxml/ly2xml_mediator.py b/ly/musicxml/ly2xml_mediator.py index a9ec6951..47a1712e 100644 --- a/ly/musicxml/ly2xml_mediator.py +++ b/ly/musicxml/ly2xml_mediator.py @@ -867,6 +867,10 @@ def check_divs(self): mult = get_mult(a, b) self.divisions = divs*mult + def add_break(self): + if self.bar is None: + self.new_bar() + self.current_attr.add_break('yes') ## diff --git a/ly/musicxml/lymus2musxml.py b/ly/musicxml/lymus2musxml.py index 13dfb733..ef18850f 100644 --- a/ly/musicxml/lymus2musxml.py +++ b/ly/musicxml/lymus2musxml.py @@ -92,10 +92,10 @@ def __init__(self): def parse_text(self, ly_text, filename=None): """Parse the LilyPond source specified as text. - + If you specify a filename, it can be used to resolve \\include commands correctly. - + """ doc = ly.document.Document(ly_text) doc.filename = filename @@ -103,11 +103,11 @@ def parse_text(self, ly_text, filename=None): def parse_document(self, ly_doc, relative_first_pitch_absolute=False): """Parse the LilyPond source specified as a ly.document document. - + If relative_first_pitch_absolute is set to True, the first pitch in a \relative expression without startpitch is considered to be absolute (LilyPond 2.18+ behaviour). - + """ # The document is copied and the copy is converted to absolute mode to # facilitate the export. The original document is unchanged. @@ -497,6 +497,8 @@ def Command(self, command): if self.tupl_span: self.mediator.unset_tuplspan_dur() self.tupl_span = False + elif command.token == '\\break': + self.mediator.add_break() else: if command.token not in excls: print("Unknown command:", command.token) diff --git a/ly/musicxml/xml_objs.py b/ly/musicxml/xml_objs.py index bad1e057..fbb8bb04 100644 --- a/ly/musicxml/xml_objs.py +++ b/ly/musicxml/xml_objs.py @@ -122,6 +122,8 @@ def new_xml_bar_attr(self, obj): """Create bar attribute xml-nodes.""" if obj.has_attr(): self.musxml.new_bar_attr(obj.clef, obj.time, obj.key, obj.mode, obj.divs) + if obj.new_system: + self.musxml.new_system(obj.new_system) if obj.repeat: self.musxml.add_barline(obj.barline, obj.repeat) elif obj.barline: @@ -726,10 +728,14 @@ def __init__(self): self.staves = 0 self.multiclef = [] self.tempo = None + self.new_system = None def __repr__(self): return '<{0} {1}>'.format(self.__class__.__name__, self.time) + def add_break(self, force_break): + self.new_system = force_break + def set_key(self, muskey, mode): self.key = muskey self.mode = mode From b8b9ede95c67d065edd761f520b04d92480a1a2d Mon Sep 17 00:00:00 2001 From: felipperoza Date: Mon, 15 May 2017 11:45:38 -0300 Subject: [PATCH 2/4] Add break-export test --- tests/test_xml.py | 2 + tests/test_xml_files/break.ly | 4 ++ tests/test_xml_files/break.xml | 106 +++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 tests/test_xml_files/break.ly create mode 100644 tests/test_xml_files/break.xml diff --git a/tests/test_xml.py b/tests/test_xml.py index e25f6ae5..679cb5bd 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -30,6 +30,8 @@ def test_dynamics(): def test_tuplet(): compare_output('tuplet') +def test_break(): + compare_output('break') def ly_to_xml(filename): """Read Lilypond file and return XML string.""" diff --git a/tests/test_xml_files/break.ly b/tests/test_xml_files/break.ly new file mode 100644 index 00000000..565db371 --- /dev/null +++ b/tests/test_xml_files/break.ly @@ -0,0 +1,4 @@ +\relative c'' { + c4 c c c | \break + c4 c c c | +} \ No newline at end of file diff --git a/tests/test_xml_files/break.xml b/tests/test_xml_files/break.xml new file mode 100644 index 00000000..4cca3162 --- /dev/null +++ b/tests/test_xml_files/break.xml @@ -0,0 +1,106 @@ + + + + + + python-ly 0.9.5 + 2017-05-14 + + + + + + + + + + + 1 + + + G + 2 + + + + + C + 5 + + 1 + 1 + quarter + + + + C + 5 + + 1 + 1 + quarter + + + + C + 5 + + 1 + 1 + quarter + + + + C + 5 + + 1 + 1 + quarter + + + + + + C + 5 + + 1 + 1 + quarter + + + + C + 5 + + 1 + 1 + quarter + + + + C + 5 + + 1 + 1 + quarter + + + + C + 5 + + 1 + 1 + quarter + + + + + From 7cca9e5ea8e9fcc74b98719683f33373e46593a8 Mon Sep 17 00:00:00 2001 From: felipperoza Date: Wed, 17 May 2017 12:14:14 -0300 Subject: [PATCH 3/4] new-system typo --- ly/musicxml/create_musicxml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ly/musicxml/create_musicxml.py b/ly/musicxml/create_musicxml.py index 12b697ac..1972ab42 100644 --- a/ly/musicxml/create_musicxml.py +++ b/ly/musicxml/create_musicxml.py @@ -529,7 +529,7 @@ def add_clef(self, sign, line, nr=0, oct_ch=0): octchnode.text = str(oct_ch) def new_system(self, force_break): - etree.SubElement(self.current_bar, "print", new_system=force_break) + etree.SubElement(self.current_bar, "print", {'new-system':force_break}) def add_barline(self, bl_type, repeat=None): barnode = etree.SubElement(self.current_bar, "barline", location="right") From 5cac5cdc70423424bca2f95e1b769c23b15ea591 Mon Sep 17 00:00:00 2001 From: felipperoza Date: Wed, 17 May 2017 12:16:33 -0300 Subject: [PATCH 4/4] fix whitespace --- ly/musicxml/lymus2musxml.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ly/musicxml/lymus2musxml.py b/ly/musicxml/lymus2musxml.py index ef18850f..2e654622 100644 --- a/ly/musicxml/lymus2musxml.py +++ b/ly/musicxml/lymus2musxml.py @@ -92,10 +92,10 @@ def __init__(self): def parse_text(self, ly_text, filename=None): """Parse the LilyPond source specified as text. - + If you specify a filename, it can be used to resolve \\include commands correctly. - + """ doc = ly.document.Document(ly_text) doc.filename = filename @@ -103,11 +103,11 @@ def parse_text(self, ly_text, filename=None): def parse_document(self, ly_doc, relative_first_pitch_absolute=False): """Parse the LilyPond source specified as a ly.document document. - + If relative_first_pitch_absolute is set to True, the first pitch in a \relative expression without startpitch is considered to be absolute (LilyPond 2.18+ behaviour). - + """ # The document is copied and the copy is converted to absolute mode to # facilitate the export. The original document is unchanged.