Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (and test) writing of multi-measure RepeatBrackets to MusicXML. #1401

Merged
merged 3 commits into from
Sep 6, 2022
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
32 changes: 18 additions & 14 deletions music21/musicxml/m21ToXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6244,22 +6244,26 @@ def setBarline(self, barline, position):
# TODO: coda
# TODO: fermata

if self.rbSpanners: # and self.rbSpanners[0].isFirst(m)???
mxEnding = Element('ending')
if position == 'left':
if self.rbSpanners:
if position == 'left' and self.rbSpanners[0].isFirst(self.stream):
endingType = 'start'
else:
elif position == 'right' and self.rbSpanners[0].isLast(self.stream):
endingType = 'stop'
numberList = self.rbSpanners[0].getNumberList()
numberStr = str(numberList[0])
# 0 is not a valid "ending-number"
if numberStr == '0':
numberStr = ''
for num in numberList[1:]:
numberStr += ',' + str(num) # comma-separated ending numbers
mxEnding.set('number', numberStr)
mxEnding.set('type', endingType)
mxBarline.append(mxEnding) # make sure it is after fermata but before repeat.
else:
endingType = ''

if endingType:
mxEnding = Element('ending')
numberList = self.rbSpanners[0].getNumberList()
numberStr = str(numberList[0])
# 0 is not a valid "ending-number"
if numberStr == '0':
numberStr = ''
for num in numberList[1:]:
numberStr += ',' + str(num) # comma-separated ending numbers
mxEnding.set('number', numberStr)
mxEnding.set('type', endingType)
mxBarline.append(mxEnding) # make sure it is after fermata but before repeat.

if mxRepeat is not None:
mxBarline.append(mxRepeat)
Expand Down
331 changes: 330 additions & 1 deletion music21/musicxml/testPrimitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18627,6 +18627,334 @@
</score-partwise>
''')

multiMeasureEnding = (
'''<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN"
"http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.1">
<work>
<work-title>Trio (snippet)</work-title>
</work>
<movement-number>1</movement-number>
<identification>
<creator type="composer">Chopin, Fryderyk</creator>
<encoding>
<encoding-date>2022-08-27</encoding-date>
<software>music21 v.8.0.0a12</software>
</encoding>
</identification>
<defaults>
<scaling>
<millimeters>7</millimeters>
<tenths>40</tenths>
</scaling>
</defaults>
<part-list>
<score-part id="P2c54d8474d928bcfb818261a5e9fa301">
<part-name>ALLEGRO | CON | FUOCO.</part-name>
</score-part>
</part-list>
<!--=========================== Part 1 ===========================-->
<part id="P2c54d8474d928bcfb818261a5e9fa301">
<!--========================= Measure 1 =========================-->
<measure number="1">
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>10080</duration>
<voice>1</voice>
<type>quarter</type>
</note>
<note>
<rest />
<duration>10080</duration>
<voice>1</voice>
<type>quarter</type>
</note>
<note>
<rest />
<duration>20160</duration>
<voice>1</voice>
<type>half</type>
</note>
<barline location="right">
<bar-style>regular</bar-style>
</barline>
</measure>
<!--========================= Measure 2 =========================-->
<measure number="2">
<barline location="left">
<ending number="1" type="start" />
</barline>
<note>
<rest />
<duration>20160</duration>
<voice>1</voice>
<type>half</type>
</note>
<direction>
<direction-type>
<dynamics>
<p />
</dynamics>
</direction-type>
<sound dynamics="44" />
</direction>
<direction placement="below">
<direction-type>
<wedge number="3" spread="0" type="crescendo" />
</direction-type>
</direction>
<note>
<pitch>
<step>F</step>
<alter>1</alter>
<octave>4</octave>
</pitch>
<duration>20160</duration>
<tie type="start" />
<voice>1</voice>
<type>half</type>
<accidental>sharp</accidental>
<notations>
<tied type="start" />
</notations>
</note>
<direction placement="below">
<direction-type>
<wedge number="3" spread="15" type="stop" />
</direction-type>
</direction>
<barline location="right">
<bar-style>regular</bar-style>
</barline>
</measure>
<!--========================= Measure 3 =========================-->
<measure number="3">
<direction placement="below">
<direction-type>
<wedge number="4" spread="15" type="diminuendo" />
</direction-type>
</direction>
<note>
<pitch>
<step>F</step>
<alter>1</alter>
<octave>4</octave>
</pitch>
<duration>40320</duration>
<tie type="stop" />
<tie type="start" />
<voice>1</voice>
<type>whole</type>
<accidental>sharp</accidental>
<notations>
<tied type="stop" />
<tied type="start" />
</notations>
</note>
<direction placement="below">
<direction-type>
<wedge number="4" spread="0" type="stop" />
</direction-type>
</direction>
<barline location="right">
<bar-style>regular</bar-style>
</barline>
</measure>
<!--========================= Measure 4 =========================-->
<measure number="4">
<note>
<pitch>
<step>F</step>
<alter>1</alter>
<octave>4</octave>
</pitch>
<duration>40320</duration>
<tie type="stop" />
<voice>1</voice>
<type>whole</type>
<accidental>sharp</accidental>
<notations>
<tied type="stop" />
</notations>
</note>
<barline location="right">
<ending number="1" type="stop" />
<repeat direction="backward" />
</barline>
</measure>
<!--========================= Measure 5 =========================-->
<measure number="5">
<barline location="left">
<ending number="2" type="start" />
</barline>
<note>
<rest />
<duration>20160</duration>
<voice>1</voice>
<type>half</type>
</note>
<direction>
<direction-type>
<dynamics>
<p />
</dynamics>
</direction-type>
<sound dynamics="44" />
</direction>
<direction placement="below">
<direction-type>
<wedge number="5" spread="15" type="diminuendo" />
</direction-type>
</direction>
<note>
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>20160</duration>
<tie type="start" />
<voice>1</voice>
<type>half</type>
<notations>
<tied type="start" />
</notations>
</note>
<barline location="right">
<bar-style>regular</bar-style>
</barline>
</measure>
<!--========================= Measure 6 =========================-->
<measure number="6">
<note>
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>20160</duration>
<tie type="stop" />
<voice>1</voice>
<type>half</type>
<notations>
<tied type="stop" />
</notations>
</note>
<direction placement="below">
<direction-type>
<wedge number="5" spread="0" type="stop" />
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<alter>1</alter>
<octave>4</octave>
</pitch>
<duration>20160</duration>
<voice>1</voice>
<type>half</type>
<accidental>sharp</accidental>
</note>
<barline location="right">
<bar-style>regular</bar-style>
</barline>
</measure>
<!--========================= Measure 7 =========================-->
<measure number="7">
<note>
<pitch>
<step>G</step>
<alter>0</alter>
<octave>4</octave>
</pitch>
<duration>40320</duration>
<voice>1</voice>
<type>whole</type>
<accidental>natural</accidental>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
<ending number="2" type="stop" />
</barline>
</measure>
<!--========================= Measure 8 =========================-->
<measure number="8">
<direction>
<direction-type>
<words enclosure="none" font-style="italic" font-weight="bold">Risoluto.</words>
</direction-type>
</direction>
<direction>
<direction-type>
<dynamics>
<f />
</dynamics>
</direction-type>
<sound dynamics="88" />
</direction>
<note>
<pitch>
<step>F</step>
<octave>4</octave>
</pitch>
<duration>20160</duration>
<voice>1</voice>
<type>half</type>
</note>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>10080</duration>
<voice>1</voice>
<type>quarter</type>
<notations>
<articulations>
<staccato />
</articulations>
</notations>
</note>
<note>
<pitch>
<step>A</step>
<octave>4</octave>
</pitch>
<duration>5040</duration>
<voice>1</voice>
<type>eighth</type>
<notations>
<articulations>
<staccato />
</articulations>
</notations>
</note>
<note>
<rest />
<duration>2520</duration>
<voice>1</voice>
<type>16th</type>
</note>
<note>
<pitch>
<step>D</step>
<octave>5</octave>
</pitch>
<duration>2520</duration>
<voice>1</voice>
<type>16th</type>
</note>
<barline location="right">
<bar-style>regular</bar-style>
</barline>
</measure>
</part>
</score-partwise>
''')


ALL = [
articulations01, pitches01a, directions31a, lyricsMelisma61d, notations32a, # 0
Expand All @@ -18644,7 +18972,8 @@
colors01, triplets01, textBoxes01, octaveShifts33d, # 40
unicodeStrNoNonAscii, unicodeStrWithNonAscii, # 44
tremoloTest, hiddenRests, multiDigitEnding, tupletsImplied, pianoStaffPolymeter, # 46
arpeggio32d, multiStaffArpeggios # 51
arpeggio32d, multiStaffArpeggios, multiMeasureEnding, # 51
pianoStaffPolymeterWithClefOctaveChange, # 54
]


Expand Down
Loading