diff --git a/music21/_version.py b/music21/_version.py index 8f0c843b0..a479e115f 100644 --- a/music21/_version.py +++ b/music21/_version.py @@ -50,7 +50,7 @@ ''' from __future__ import annotations -__version__ = '9.7.1' +__version__ = '9.7.2a6' def get_version_tuple(vv): v = vv.split('.') diff --git a/music21/base.py b/music21/base.py index dcddb37f4..9ac0a1589 100644 --- a/music21/base.py +++ b/music21/base.py @@ -27,7 +27,7 @@ >>> music21.VERSION_STR -'9.7.1' +'9.7.2a6' Alternatively, after doing a complete import, these classes are available under the module "base": diff --git a/music21/stream/makeNotation.py b/music21/stream/makeNotation.py index cdcabf151..46e1dfeaa 100644 --- a/music21/stream/makeNotation.py +++ b/music21/stream/makeNotation.py @@ -761,14 +761,17 @@ def makeRests( >>> b = a.makeRests(inPlace=False) >>> len(b) - 2 + 3 >>> b.lowestOffset 0.0 >>> b.show('text') - {0.0} + {0.0} + {16.0} {20.0} >>> b[0].duration.quarterLength - 20.0 + 16.0 + >>> b[1].duration.quarterLength + 4.0 Same thing, but this time, with gaps, and hidden rests: @@ -784,13 +787,15 @@ def makeRests( {30.0} >>> b = a.makeRests(fillGaps=True, inPlace=False, hideRests=True) >>> len(b) - 4 + 6 >>> b.lowestOffset 0.0 >>> b.show('text') - {0.0} + {0.0} + {16.0} {20.0} - {21.0} + {21.0} + {29.0} {30.0} >>> b[0].style.hideObjectOnPrint True @@ -949,9 +954,13 @@ def oHighTargetForMeasure( r = note.Rest() r.duration.quarterLength = qLen r.style.hideObjectOnPrint = hideRests + rList = r.splitAtDurations() # environLocal.printDebug(['makeRests(): add rests', r, r.duration]) # place at oLowTarget to reach to oLow - component.insert(oLowTarget, r) + off: OffsetQL = oLowTarget + for r in rList: + component.insert(off, r) + off = opFrac(off + r.quarterLength) # create rest from end to highest qLen = oHighTarget - oHigh @@ -959,8 +968,12 @@ def oHighTargetForMeasure( r = note.Rest() r.duration.quarterLength = qLen r.style.hideObjectOnPrint = hideRests + rList = r.splitAtDurations() # place at oHigh to reach to oHighTarget - component.insert(oHigh, r) + off = oHigh + for r in rList: + component.insert(off, r) + off = opFrac(off + r.quarterLength) if fillGaps: gapStream = component.findGaps() @@ -969,7 +982,11 @@ def oHighTargetForMeasure( r = note.Rest() r.duration.quarterLength = e.duration.quarterLength r.style.hideObjectOnPrint = hideRests - component.insert(e.offset, r) + rList = r.splitAtDurations() + off = e.offset + for r in rList: + component.insert(off, r) + off = opFrac(off + r.quarterLength) if returnObj.hasMeasures(): # split rests at measure boundaries diff --git a/music21/stream/tests.py b/music21/stream/tests.py index 8c336783d..821d6bd3b 100644 --- a/music21/stream/tests.py +++ b/music21/stream/tests.py @@ -2143,7 +2143,15 @@ def testContextNestedD(self): def testMakeRestsA(self): a = ['c', 'g#', 'd-', 'f#', 'e', 'f'] * 4 partOffsetShift = 1.25 - partOffset = 2 # start at non zero + partOffset = 2. # start at non zero + partOffsetToNumRests = { + 2.: 1, # half rest + 3.25: 3, # half rest, quarter rest, 16th rest + 4.5: 2, # whole rest, eighth rest + 5.75: 2, # whole rest, double-dotted quarter rest + 7.0: 1, # double dotted whole rest + 8.25: 2, # breve rest, 16th rest + } for unused_part in range(6): p = Stream() for pitchName in a: @@ -2162,12 +2170,11 @@ def testMakeRestsA(self): # environLocal.printDebug(['first element', p[0], p[0].duration]) # by default, initial rest should be made sub = p.getElementsByClass(note.Rest).stream() - self.assertEqual(len(sub), 1) - + self.assertEqual(len(sub), partOffsetToNumRests[partOffset]) self.assertEqual(sub.duration.quarterLength, partOffset) - # first element should have offset of first dur - self.assertEqual(p[1].offset, sub.duration.quarterLength) + # first element after rests should have offset of first dur + self.assertEqual(p[len(sub)].offset, sub.duration.quarterLength) partOffset += partOffsetShift @@ -5860,16 +5867,21 @@ def testVoicesC(self): sPost = s.makeRests(fillGaps=True, inPlace=False) self.assertEqual(str(list(sPost.voices[0].notesAndRests)), '[, , ' - + ', ' + + ', ' + + ', ' + ', ' - + ', ' + + ', ' + + ', ' + ', ' - + ', ' + + ', ' + + ', ' + ', ' + ']') self.assertEqual(str(list(sPost.voices[1].notesAndRests)), '[, , ' - + ', ' + + ', ' + + ', ' + + ', ' + ', ' + ', , ' + ', ]')