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
74 changes: 72 additions & 2 deletions music21/musicxml/testPrimitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -17808,6 +17808,77 @@
</score-partwise>
"""

hiddenRests = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!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 print-object="no">MusicXML Part</part-name>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>2</divisions>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note>
<pitch>
<step>E</step>
<octave>5</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>half</type>
<stem>up</stem>
</note>
<forward>
<duration>2</duration>
<voice>1</voice>
</forward>
<note>
<pitch>
<step>E</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<voice>1</voice>
<type>quarter</type>
<stem>up</stem>
</note>
<backup>
<duration>8</duration>
</backup>
<forward>
<duration>4</duration>
<voice>2</voice>
</forward>
<note>
<pitch>
<step>F</step>
<octave>4</octave>
</pitch>
<duration>2</duration>
<voice>2</voice>
<type>quarter</type>
<stem>down</stem>
</note>
<forward>
<duration>2</duration>
<voice>2</voice>
</forward>
</measure>
</part>
</score-partwise>
"""

multiDigitEnding = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.1">
Expand Down Expand Up @@ -17860,7 +17931,6 @@
</score-partwise>
"""


ALL = [
articulations01, pitches01a, directions31a, lyricsMelisma61d, notations32a, # 0
restsDurations02a, rhythmDurations03a, chordsThreeNotesDuration21c, # 5
Expand All @@ -17876,7 +17946,7 @@
mixedVoices1a, mixedVoices1b, mixedVoices2, # 37
colors01, triplets01, textBoxes01, otaveShifts33d, # 40
unicodeStrNoNonAscii, unicodeStrWithNonAscii, # 44
tremoloTest, multiDigitEnding # 46
tremoloTest, hiddenRests, multiDigitEnding # 46
]


Expand Down
20 changes: 19 additions & 1 deletion music21/musicxml/xmlToM21.py
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,10 @@ def parse(self):
if self.useVoices is True:
for v in self.stream.iter.voices:
if v: # do not bother with empty voices
v.makeRests(inPlace=True, hideRests=True)
# Fill mid-measure gaps, and find end of measure gaps by ref to measure stream
# https://github.com/cuthbertlab/music21/issues/444
v.makeRests(refStreamOrTimeRange=self.stream, fillGaps=True,
inPlace=True, hideRests=True)
v.coreElementsChanged()
self.stream.coreElementsChanged()

Expand Down Expand Up @@ -6463,6 +6466,21 @@ def testFretIndication(self):
self.assertIsInstance(notes[3].articulations[1], articulations.FretIndication)
self.assertEqual(notes[3].articulations[1].number, 3)

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

# Voice 1: Half note, <forward> (quarter), quarter note
# Voice 2: <forward> (half), quarter note, <forward> (quarter)
s = converter.parse(testPrimitive.hiddenRests)
v1, v2 = s.recurse().voices
self.assertEqual(v1.duration.quarterLength, v2.duration.quarterLength)

restV1 = [r for r in v1.getElementsByClass(note.Rest)][0]
self.assertTrue(restV1.style.hideObjectOnPrint)
restsV2 = [r for r in v2.getElementsByClass(note.Rest)]
self.assertEqual([r.style.hideObjectOnPrint for r in restsV2], [True, True])

def testMultiDigitEnding(self):
from music21 import converter
from music21.musicxml import testPrimitive
Expand Down