Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ly/musicxml/create_musicxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions ly/musicxml/ly2xml_mediator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions ly/musicxml/lymus2musxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
15 changes: 15 additions & 0 deletions ly/musicxml/xml_objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def test_church():
compare_output('church_modes')


def test_markup():
compare_output('markup')


def test_breathe():
compare_output('breathe')

Expand Down
9 changes: 9 additions & 0 deletions tests/test_xml_files/markup.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
\version "2.18.2"

\score {
\relative {
a'1-\markup intenso |
a1-\markup intenso |
a2^\markup { poco più forte }
}
}
77 changes: 77 additions & 0 deletions tests/test_xml_files/markup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 2.0 Partwise//EN"
"http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.0">
<identification>
<encoding>
<software>python-ly 0.9.5</software>
<encoding-date>2017-06-30</encoding-date>
</encoding>
</identification>
<part-list>
<score-part id="P1">
<part-name />
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<time symbol="common">
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<direction placement="above">
<direction-type>
<words>intenso </words>
</direction-type>
</direction>
<note>
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="2">
<direction placement="above">
<direction-type>
<words>intenso </words>
</direction-type>
</direction>
<note>
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="3">
<direction placement="above">
<direction-type>
<words>poco più forte </words>
</direction-type>
</direction>
<note>
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>half</type>
</note>
</measure>
</part>
</score-partwise>