Skip to content

Commit

Permalink
Merge pull request #1334 from gregchapman-dev/gregc/clefOctaveChangeFix
Browse files Browse the repository at this point in the history
Fix a bug in musicxml/partStaffExporter.py where a clef-octave-change…
  • Loading branch information
mscuthbert authored Jul 4, 2022
2 parents e0266ab + b22df10 commit dfb7300
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
11 changes: 8 additions & 3 deletions music21/musicxml/partStaffExporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def setEarliestAttributesAndClefsPartStaff(self, group: StaffGroup):
Multiple meters (not very well supported by MusicXML readers):
>>> from music21.musicxml import testPrimitive
>>> s = converter.parse(testPrimitive.pianoStaffPolymeter)
>>> s = converter.parse(testPrimitive.pianoStaffPolymeterWithClefOctaveChange)
>>> SX = musicxml.m21ToXml.ScoreExporter(s)
>>> root = SX.parse()
>>> m1 = root.find('part/measure')
Expand All @@ -529,8 +529,9 @@ def setEarliestAttributesAndClefsPartStaff(self, group: StaffGroup):
<line>2</line>
</clef>
<clef number="2">
<sign>F</sign>
<line>4</line>
<sign>G</sign>
<line>2</line>
<clef-octave-change>-1</clef-octave-change>
</clef>
</attributes>
...
Expand Down Expand Up @@ -615,6 +616,10 @@ def isMultiAttribute(m21Class: t.Type[M21ObjType],
newLine.text = (foundLine.text
if (foundLine := oldClef.find('line')) is not None
else '')
foundOctave = oldClef.find('clef-octave-change')
if foundOctave is not None:
newOctave = SubElement(newClef, 'clef-octave-change')
newOctave.text = foundOctave.text
helpers.insertBeforeElements(
mxAttributes,
newClef,
Expand Down
53 changes: 53 additions & 0 deletions music21/musicxml/testPrimitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18115,6 +18115,59 @@
</score-partwise>
'''

# pianoStaffPolymeterWithClefOctaveChange is a copy of pianoStaffPolymeter (above)
# with clef #2 changed from BassClef to Treble8vbClef.

pianoStaffPolymeterWithClefOctaveChange = (
'''<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 0.6b Partwise//EN"
"http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
<identification>
<miscellaneous>
<miscellaneous-field name="description">Polymeter on a grand staff</miscellaneous-field>
</miscellaneous>
</identification>
<part-list>
<score-part id="P1">
<part-name>MusicXML Part</part-name>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>96</divisions>
<key><fifths>0</fifths></key>
<time number="1"><beats>4</beats><beat-type>4</beat-type></time>
<time number="2"><beats>2</beats><beat-type>2</beat-type></time>
<staves>2</staves>
<clef number="1"><sign>G</sign><line>2</line></clef>
<clef number="2">
<sign>G</sign>
<line>2</line>
<clef-octave-change>-1</clef-octave-change>
</clef>
</attributes>
<note>
<pitch><step>F</step><octave>4</octave></pitch>
<duration>384</duration>
<voice>1</voice>
<type>whole</type>
<staff>1</staff>
</note>
<backup><duration>384</duration></backup>
<note>
<pitch><step>B</step><octave>2</octave></pitch>
<duration>384</duration>
<voice>2</voice>
<type>whole</type>
<staff>2</staff>
</note>
</measure>
</part>
</score-partwise>
''')


ALL = [
articulations01, pitches01a, directions31a, lyricsMelisma61d, notations32a, # 0
Expand Down

0 comments on commit dfb7300

Please sign in to comment.