Skip to content

Commit

Permalink
Preserve multiple articulations on chords in musicxml import
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Oct 28, 2022
1 parent d77f405 commit 7fc1b61
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 3 deletions.
95 changes: 94 additions & 1 deletion music21/musicxml/testPrimitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18953,6 +18953,99 @@
</score-partwise>
''')

multipleFingeringsOnChord = """
<?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">
<part-list>
<score-part id="P1">
<part-name>Piano</part-name>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<staves>2</staves>
<clef number="1">
<sign>G</sign>
<line>2</line>
</clef>
<clef number="2">
<sign>F</sign>
<line>4</line>
</clef>
</attributes>
<note>
<pitch>
<step>C</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
<staff>1</staff>
<notations>
<technical>
<fingering>1</fingering>
</technical>
</notations>
</note>
<note>
<chord/>
<pitch>
<step>E</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
<staff>1</staff>
<notations>
<technical>
<fingering>3</fingering>
</technical>
</notations>
</note>
<note>
<chord/>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
<staff>1</staff>
<notations>
<technical>
<fingering>5</fingering>
</technical>
</notations>
</note>
<backup>
<duration>4</duration>
</backup>
<note>
<rest measure="yes"/>
<duration>4</duration>
<voice>5</voice>
<staff>2</staff>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
"""

ALL = [
articulations01, pitches01a, directions31a, lyricsMelisma61d, notations32a, # 0
Expand All @@ -18971,7 +19064,7 @@
unicodeStrNoNonAscii, unicodeStrWithNonAscii, # 44
tremoloTest, hiddenRests, multiDigitEnding, tupletsImplied, pianoStaffPolymeter, # 46
arpeggio32d, multiStaffArpeggios, multiMeasureEnding, # 51
pianoStaffPolymeterWithClefOctaveChange, # 54
pianoStaffPolymeterWithClefOctaveChange, multipleFingeringsOnChord # 54
]


Expand Down
8 changes: 8 additions & 0 deletions music21/musicxml/test_xmlToM21.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,14 @@ def testStringIndication(self):
self.assertIsInstance(notes[3].articulations[0], articulations.StringIndication)
self.assertEqual(notes[3].articulations[0].number, 2)

def testArticulationsOnChord(self):
from music21 import converter
from music21.musicxml import testPrimitive

s = converter.parse(testPrimitive.multipleFingeringsOnChord)
c = s[chord.Chord].first()
self.assertEqual(len(c.articulations), 3)

def testFretIndication(self):
from music21 import converter

Expand Down
5 changes: 3 additions & 2 deletions music21/musicxml/xmlToM21.py
Original file line number Diff line number Diff line change
Expand Up @@ -2875,7 +2875,7 @@ def xmlToChord(self, mxNoteList: list[ET.Element]) -> chord.ChordBase:

# move spanners, expressions, articulations from first note to Chord.
# See slur in m2 of schoenberg/op19 #2
# but move only one of each class
# but move only one of each class, unless a fingering.
# Is there anything else that should be moved???

seenArticulations = set()
Expand All @@ -2892,7 +2892,8 @@ def xmlToChord(self, mxNoteList: list[ET.Element]) -> chord.ChordBase:
if type(art) in seenArticulations: # pylint: disable=unidiomatic-typecheck
continue
c.articulations.append(art)
seenArticulations.add(type(art))
if not isinstance(art, articulations.Fingering):
seenArticulations.add(type(art))
for exp in n.expressions:
if type(exp) in seenExpressions: # pylint: disable=unidiomatic-typecheck
continue
Expand Down

0 comments on commit 7fc1b61

Please sign in to comment.