From 962e4e8e4272e04034d249d07ae4a82a0ea9a056 Mon Sep 17 00:00:00 2001 From: felipperoza Date: Sat, 10 Jun 2017 23:13:25 -0300 Subject: [PATCH 1/9] added test file --- tests/test_xml_files/markup.ly | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/test_xml_files/markup.ly diff --git a/tests/test_xml_files/markup.ly b/tests/test_xml_files/markup.ly new file mode 100644 index 00000000..16352943 --- /dev/null +++ b/tests/test_xml_files/markup.ly @@ -0,0 +1,13 @@ +\version "2.18.2" + +\score { + \relative { + a'1-\markup intenso +% a2^\markup { poco \italic più forte } +% c e1 +% d2_\markup { \italic "string. assai" } +% e +% b1^\markup { \bold { molto \italic agitato } } +% c + } +} \ No newline at end of file From 05f90834bec0aa420841ecc2778330740e366894 Mon Sep 17 00:00:00 2001 From: felipperoza Date: Sun, 11 Jun 2017 13:51:21 -0300 Subject: [PATCH 2/9] added markup and markupWord support --- ly/musicxml/create_musicxml.py | 2 ++ ly/musicxml/ly2xml_mediator.py | 11 +++++++++++ ly/musicxml/lymus2musxml.py | 6 ++++++ ly/musicxml/xml_objs.py | 8 ++++++++ 4 files changed, 27 insertions(+) diff --git a/ly/musicxml/create_musicxml.py b/ly/musicxml/create_musicxml.py index 8fb82b7b..09ec529c 100644 --- a/ly/musicxml/create_musicxml.py +++ b/ly/musicxml/create_musicxml.py @@ -598,6 +598,8 @@ def add_octave_shift(self, plac, octdir, size): def add_dirwords(self, words): """Add words in direction, e. g. a tempo mark.""" + if not hasattr(self,'direction'): + self.add_direction() dirtypenode = etree.SubElement(self.direction, "direction-type") wordsnode = etree.SubElement(dirtypenode, "words") wordsnode.text = words diff --git a/ly/musicxml/ly2xml_mediator.py b/ly/musicxml/ly2xml_mediator.py index a9ec6951..5e31bb47 100644 --- a/ly/musicxml/ly2xml_mediator.py +++ b/ly/musicxml/ly2xml_mediator.py @@ -76,6 +76,7 @@ def __init__(self): self.prev_tremolo = 8 self.tupl_dur = 0 self.tupl_sum = 0 + self.word = None def new_header_assignment(self, name, value): """Distributing header information.""" @@ -346,6 +347,16 @@ def new_key(self, key_name, mode): else: self.current_attr.set_key(get_fifths(key_name, mode), mode) + def new_word(self, word): + if self.bar is None: + self.new_bar() + if self.bar.has_music(): + new_bar_attr = xml_objs.BarAttr() + new_bar_attr.set_word(word) + self.add_to_bar(new_bar_attr) + else: + self.current_attr.set_word(word) + def new_time(self, num, den, numeric=False): if self.bar is None: self.new_bar() diff --git a/ly/musicxml/lymus2musxml.py b/ly/musicxml/lymus2musxml.py index 13dfb733..5f97444c 100644 --- a/ly/musicxml/lymus2musxml.py +++ b/ly/musicxml/lymus2musxml.py @@ -506,6 +506,12 @@ def UserCommand(self, usercommand): if usercommand.name() == 'tupletSpan': self.tupl_span = True + def Markup(self, markup): + pass + + def MarkupWord(self, markupWord): + self.mediator.new_word(markupWord.token) + def String(self, string): prev = self.get_previous_node(string) if prev and prev.token == '\\bar': diff --git a/ly/musicxml/xml_objs.py b/ly/musicxml/xml_objs.py index bad1e057..fbfe4751 100644 --- a/ly/musicxml/xml_objs.py +++ b/ly/musicxml/xml_objs.py @@ -134,6 +134,8 @@ def new_xml_bar_attr(self, obj): if obj.tempo: self.musxml.create_tempo(obj.tempo.text, obj.tempo.metr, obj.tempo.midi, obj.tempo.dots) + if obj.word: + self.musxml.add_dirwords(obj.word) def before_note(self, obj): """Xml-nodes before note.""" @@ -726,6 +728,7 @@ def __init__(self): self.staves = 0 self.multiclef = [] self.tempo = None + self.word = None def __repr__(self): return '<{0} {1}>'.format(self.__class__.__name__, self.time) @@ -748,6 +751,11 @@ def set_barline(self, bl): def set_tempo(self, unit=0, unittype='', beats=0, dots=0, text=""): self.tempo = TempoDir(unit, unittype, beats, dots, text) + def set_word(self, words): + if self.word == None: + self.word = '' + self.word += words + def has_attr(self): check = False if self.key is not None: From f9a27cb6e949895d448ac1470d6c55830e40ac08 Mon Sep 17 00:00:00 2001 From: felipperoza Date: Sun, 11 Jun 2017 21:47:41 -0300 Subject: [PATCH 3/9] fixed multiple directions in a bar bug --- 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 09ec529c..f6da3ee9 100644 --- a/ly/musicxml/create_musicxml.py +++ b/ly/musicxml/create_musicxml.py @@ -598,7 +598,7 @@ def add_octave_shift(self, plac, octdir, size): def add_dirwords(self, words): """Add words in direction, e. g. a tempo mark.""" - if not hasattr(self,'direction'): + if self.current_bar.find('direction') == None: self.add_direction() dirtypenode = etree.SubElement(self.direction, "direction-type") wordsnode = etree.SubElement(dirtypenode, "words") From f8993cef9cd47b27d005cbae978e4ab79f63e713 Mon Sep 17 00:00:00 2001 From: felipperoza Date: Sun, 11 Jun 2017 21:58:56 -0300 Subject: [PATCH 4/9] updated test file. Closes #31 --- tests/test_xml_files/markup.ly | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/test_xml_files/markup.ly b/tests/test_xml_files/markup.ly index 16352943..2d2e65a4 100644 --- a/tests/test_xml_files/markup.ly +++ b/tests/test_xml_files/markup.ly @@ -2,12 +2,7 @@ \score { \relative { + a'1-\markup intenso | a'1-\markup intenso -% a2^\markup { poco \italic più forte } -% c e1 -% d2_\markup { \italic "string. assai" } -% e -% b1^\markup { \bold { molto \italic agitato } } -% c } } \ No newline at end of file From dbf0627ca0249bd5e8ea33b66e74780d943eb327 Mon Sep 17 00:00:00 2001 From: felipperoza Date: Thu, 22 Jun 2017 18:32:34 -0300 Subject: [PATCH 5/9] updated test file --- tests/test_xml_files/markup.ly | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_xml_files/markup.ly b/tests/test_xml_files/markup.ly index 2d2e65a4..e72d50d1 100644 --- a/tests/test_xml_files/markup.ly +++ b/tests/test_xml_files/markup.ly @@ -3,6 +3,7 @@ \score { \relative { a'1-\markup intenso | - a'1-\markup intenso + a'1-\markup intenso | + a2^\markup { poco \italic piu forte } } } \ No newline at end of file From 1f687e7e68e260559dfe03740d5d3269856736c0 Mon Sep 17 00:00:00 2001 From: felipperoza Date: Fri, 30 Jun 2017 11:06:47 -0300 Subject: [PATCH 6/9] updated test file --- tests/test_xml_files/markup.ly | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_xml_files/markup.ly b/tests/test_xml_files/markup.ly index e72d50d1..747d67ba 100644 --- a/tests/test_xml_files/markup.ly +++ b/tests/test_xml_files/markup.ly @@ -3,7 +3,7 @@ \score { \relative { a'1-\markup intenso | - a'1-\markup intenso | - a2^\markup { poco \italic piu forte } + a1-\markup intenso | + a2^\markup { poco più forte } } } \ No newline at end of file From 8e912f2f6dce018390b43b8c4eaefa15bb8a526e Mon Sep 17 00:00:00 2001 From: felipperoza Date: Fri, 30 Jun 2017 11:09:23 -0300 Subject: [PATCH 7/9] added markuplist support --- ly/musicxml/ly2xml_mediator.py | 6 +++--- ly/musicxml/lymus2musxml.py | 3 +++ ly/musicxml/xml_objs.py | 9 ++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ly/musicxml/ly2xml_mediator.py b/ly/musicxml/ly2xml_mediator.py index 5e31bb47..307d2f1a 100644 --- a/ly/musicxml/ly2xml_mediator.py +++ b/ly/musicxml/ly2xml_mediator.py @@ -350,12 +350,12 @@ def new_key(self, key_name, mode): def new_word(self, word): if self.bar is None: self.new_bar() - if self.bar.has_music(): + if self.bar.has_attr(): + self.current_attr.set_word(word) + else: new_bar_attr = xml_objs.BarAttr() new_bar_attr.set_word(word) self.add_to_bar(new_bar_attr) - else: - self.current_attr.set_word(word) def new_time(self, num, den, numeric=False): if self.bar is None: diff --git a/ly/musicxml/lymus2musxml.py b/ly/musicxml/lymus2musxml.py index 5f97444c..32dc34dd 100644 --- a/ly/musicxml/lymus2musxml.py +++ b/ly/musicxml/lymus2musxml.py @@ -512,6 +512,9 @@ def Markup(self, markup): def MarkupWord(self, markupWord): self.mediator.new_word(markupWord.token) + def MarkupList(self, markuplist): + pass + def String(self, string): prev = self.get_previous_node(string) if prev and prev.token == '\\bar': diff --git a/ly/musicxml/xml_objs.py b/ly/musicxml/xml_objs.py index fbfe4751..c4366456 100644 --- a/ly/musicxml/xml_objs.py +++ b/ly/musicxml/xml_objs.py @@ -449,6 +449,13 @@ def has_music(self): return True return False + def has_attr(self): + """ Check if bar contains attribute. """ + for obj in self.obj_list: + if isinstance(obj, BarAttr): + return True + return False + def create_backup(self): """ Calculate and create backup object.""" b = 0 @@ -754,7 +761,7 @@ def set_tempo(self, unit=0, unittype='', beats=0, dots=0, text=""): def set_word(self, words): if self.word == None: self.word = '' - self.word += words + self.word += words + ' ' def has_attr(self): check = False From b1bd9f01d09fb44b5e1c733578a1c6eed01a5862 Mon Sep 17 00:00:00 2001 From: felipperoza Date: Fri, 30 Jun 2017 11:12:58 -0300 Subject: [PATCH 8/9] resulting xml --- tests/test_xml.py | 4 ++ tests/test_xml_files/markup.xml | 77 +++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 tests/test_xml_files/markup.xml diff --git a/tests/test_xml.py b/tests/test_xml.py index e25f6ae5..44821c5b 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -31,6 +31,10 @@ def test_tuplet(): compare_output('tuplet') +def test_markup(): + compare_output('markup') + + def ly_to_xml(filename): """Read Lilypond file and return XML string.""" writer = ly.musicxml.writer() diff --git a/tests/test_xml_files/markup.xml b/tests/test_xml_files/markup.xml new file mode 100644 index 00000000..fdfe22b3 --- /dev/null +++ b/tests/test_xml_files/markup.xml @@ -0,0 +1,77 @@ + + + + + + python-ly 0.9.5 + 2017-06-30 + + + + + + + + + + + 1 + + + G + 2 + + + + + intenso + + + + + A + 4 + + 4 + 1 + whole + + + + + + intenso + + + + + A + 4 + + 4 + 1 + whole + + + + + + poco più forte + + + + + A + 4 + + 2 + 1 + half + + + + From 7fe8d013e338c412b6df1b56ff246b7f238c6d44 Mon Sep 17 00:00:00 2001 From: felipperoza Date: Tue, 5 Sep 2017 16:08:01 -0300 Subject: [PATCH 9/9] removed unused class --- ly/musicxml/ly2xml_mediator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ly/musicxml/ly2xml_mediator.py b/ly/musicxml/ly2xml_mediator.py index 38b01b6a..7bf513aa 100644 --- a/ly/musicxml/ly2xml_mediator.py +++ b/ly/musicxml/ly2xml_mediator.py @@ -77,7 +77,6 @@ def __init__(self): self.prev_tremolo = 8 self.tupl_dur = 0 self.tupl_sum = 0 - self.word = None self.bar_is_pickup = False self.stem_dir = None