diff --git a/ly/musicxml/create_musicxml.py b/ly/musicxml/create_musicxml.py index e767689b..d4878331 100644 --- a/ly/musicxml/create_musicxml.py +++ b/ly/musicxml/create_musicxml.py @@ -609,6 +609,8 @@ def add_octave_shift(self, plac, octdir, size): def add_dirwords(self, words): """Add words in direction, e. g. a tempo mark.""" + if self.current_bar.find('direction') == None: + 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 6d6cf005..7bf513aa 100644 --- a/ly/musicxml/ly2xml_mediator.py +++ b/ly/musicxml/ly2xml_mediator.py @@ -355,6 +355,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_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) + def new_time(self, num, den, numeric=False): self.current_time = Fraction(num, den.denominator) if self.bar is None: diff --git a/ly/musicxml/lymus2musxml.py b/ly/musicxml/lymus2musxml.py index a3c5056b..fd4f2d0a 100644 --- a/ly/musicxml/lymus2musxml.py +++ b/ly/musicxml/lymus2musxml.py @@ -520,6 +520,15 @@ 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 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 3fa328d3..07a33fac 100644 --- a/ly/musicxml/xml_objs.py +++ b/ly/musicxml/xml_objs.py @@ -136,6 +136,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.""" @@ -450,6 +452,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 @@ -733,6 +742,7 @@ def __init__(self): self.staves = 0 self.multiclef = [] self.tempo = None + self.word = None self.new_system = None def __repr__(self): @@ -759,6 +769,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: diff --git a/tests/test_xml.py b/tests/test_xml.py index bb6f4b2f..04143ced 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -45,6 +45,10 @@ def test_church(): compare_output('church_modes') +def test_markup(): + compare_output('markup') + + def test_breathe(): compare_output('breathe') diff --git a/tests/test_xml_files/markup.ly b/tests/test_xml_files/markup.ly new file mode 100644 index 00000000..747d67ba --- /dev/null +++ b/tests/test_xml_files/markup.ly @@ -0,0 +1,9 @@ +\version "2.18.2" + +\score { + \relative { + a'1-\markup intenso | + a1-\markup intenso | + a2^\markup { poco più forte } + } +} \ No newline at end of file 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 + + + +