From 0a1995204688e33589437ec61845ceeb88f69d3b Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Mon, 1 Jun 2020 07:48:32 -0400 Subject: [PATCH 1/3] Find hidden rests mid-measure and at end --- music21/musicxml/testPrimitive.py | 72 ++++++++++++++++++++++++++++++- music21/musicxml/xmlToM21.py | 20 ++++++++- 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/music21/musicxml/testPrimitive.py b/music21/musicxml/testPrimitive.py index 0f20b2309c..9f6d31a76e 100644 --- a/music21/musicxml/testPrimitive.py +++ b/music21/musicxml/testPrimitive.py @@ -17808,6 +17808,76 @@ """ +hiddenRests = """ + + + + + MusicXML Part + + + + + + 2 + + + G + 2 + + + + + E + 5 + + 4 + 1 + half + up + + + 2 + 1 + + + + E + 4 + + 2 + 1 + quarter + up + + + 8 + + + 4 + 2 + + + + F + 4 + + 2 + 2 + quarter + down + + + 2 + 2 + + + + +""" ALL = [ articulations01, pitches01a, directions31a, lyricsMelisma61d, notations32a, # 0 @@ -17824,7 +17894,7 @@ mixedVoices1a, mixedVoices1b, mixedVoices2, # 37 colors01, triplets01, textBoxes01, otaveShifts33d, # 40 unicodeStrNoNonAscii, unicodeStrWithNonAscii, # 44 - tremoloTest # 46 + tremoloTest, hiddenRests # 46 ] diff --git a/music21/musicxml/xmlToM21.py b/music21/musicxml/xmlToM21.py index 7f6ee23111..f5a6b59be8 100644 --- a/music21/musicxml/xmlToM21.py +++ b/music21/musicxml/xmlToM21.py @@ -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() @@ -5406,6 +5409,7 @@ def parseMeasureNumbers(self, mNumRaw=None): self.measureNumber = m.number self.numberSuffix = m.numberSuffix + def updateVoiceInformation(self): ''' Finds all the "voice" information in tags and updates the set of @@ -6463,6 +6467,20 @@ 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, (quarter), quarter note + # Voice 2: (half), quarter note, (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]) if __name__ == '__main__': import music21 From bf79234a69f46940cdacb6d8e0f0cc046f331884 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Mon, 1 Jun 2020 07:52:05 -0400 Subject: [PATCH 2/3] remove whitespace --- music21/musicxml/xmlToM21.py | 1 - 1 file changed, 1 deletion(-) diff --git a/music21/musicxml/xmlToM21.py b/music21/musicxml/xmlToM21.py index f5a6b59be8..839b1e2d5a 100644 --- a/music21/musicxml/xmlToM21.py +++ b/music21/musicxml/xmlToM21.py @@ -5409,7 +5409,6 @@ def parseMeasureNumbers(self, mNumRaw=None): self.measureNumber = m.number self.numberSuffix = m.numberSuffix - def updateVoiceInformation(self): ''' Finds all the "voice" information in tags and updates the set of From e1e6c874698661e88cb6c0ff0fbc3ace2600f0bc Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Mon, 1 Jun 2020 08:19:34 -0400 Subject: [PATCH 3/3] Add whitespace after class --- music21/musicxml/xmlToM21.py | 1 + 1 file changed, 1 insertion(+) diff --git a/music21/musicxml/xmlToM21.py b/music21/musicxml/xmlToM21.py index 839b1e2d5a..a2a18c2122 100644 --- a/music21/musicxml/xmlToM21.py +++ b/music21/musicxml/xmlToM21.py @@ -6481,6 +6481,7 @@ def testHiddenRests(self): restsV2 = [r for r in v2.getElementsByClass(note.Rest)] self.assertEqual([r.style.hideObjectOnPrint for r in restsV2], [True, True]) + if __name__ == '__main__': import music21 music21.mainTest(Test) # , runTest='testRehearsalMarks')