Skip to content
Closed
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
2 changes: 1 addition & 1 deletion music21/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
'''
from __future__ import annotations

__version__ = '9.7.1'
__version__ = '9.7.2a6'

def get_version_tuple(vv):
v = vv.split('.')
Expand Down
2 changes: 1 addition & 1 deletion music21/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<class 'music21.base.Music21Object'>

>>> music21.VERSION_STR
'9.7.1'
'9.7.2a6'

Alternatively, after doing a complete import, these classes are available
under the module "base":
Expand Down
35 changes: 26 additions & 9 deletions music21/stream/makeNotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,14 +761,17 @@ def makeRests(

>>> b = a.makeRests(inPlace=False)
>>> len(b)
2
3
>>> b.lowestOffset
0.0
>>> b.show('text')
{0.0} <music21.note.Rest 20ql>
{0.0} <music21.note.Rest 16ql>
{16.0} <music21.note.Rest whole>
{20.0} <music21.note.Note C>
>>> b[0].duration.quarterLength
20.0
16.0
>>> b[1].duration.quarterLength
4.0

Same thing, but this time, with gaps, and hidden rests:

Expand All @@ -784,13 +787,15 @@ def makeRests(
{30.0} <music21.note.Note D>
>>> b = a.makeRests(fillGaps=True, inPlace=False, hideRests=True)
>>> len(b)
4
6
>>> b.lowestOffset
0.0
>>> b.show('text')
{0.0} <music21.note.Rest 20ql>
{0.0} <music21.note.Rest 16ql>
{16.0} <music21.note.Rest whole>
{20.0} <music21.note.Note C>
{21.0} <music21.note.Rest 9ql>
{21.0} <music21.note.Rest breve>
{29.0} <music21.note.Rest quarter>
{30.0} <music21.note.Note D>
>>> b[0].style.hideObjectOnPrint
True
Expand Down Expand Up @@ -949,18 +954,26 @@ 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
if qLen > 0:
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()
Expand All @@ -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
Expand Down
30 changes: 21 additions & 9 deletions music21/stream/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -5860,16 +5867,21 @@ def testVoicesC(self):
sPost = s.makeRests(fillGaps=True, inPlace=False)
self.assertEqual(str(list(sPost.voices[0].notesAndRests)),
'[<music21.note.Rest half>, <music21.note.Note C>, '
+ '<music21.note.Rest 2.25ql>, '
+ '<music21.note.Rest half>, '
+ '<music21.note.Rest 16th>, '
+ '<music21.note.Note C>, '
+ '<music21.note.Rest 2.5ql>, '
+ '<music21.note.Rest half>, '
+ '<music21.note.Rest eighth>, '
+ '<music21.note.Note C>, '
+ '<music21.note.Rest 4.25ql>, '
+ '<music21.note.Rest whole>, '
+ '<music21.note.Rest 16th>, '
+ '<music21.note.Note C>, '
+ '<music21.note.Rest half>]')
self.assertEqual(str(list(sPost.voices[1].notesAndRests)),
'[<music21.note.Rest 16th>, <music21.note.Note C>, '
+ '<music21.note.Rest 3.25ql>, '
+ '<music21.note.Rest half>, '
+ '<music21.note.Rest quarter>, '
+ '<music21.note.Rest 16th>, '
+ '<music21.note.Note C>, '
+ '<music21.note.Rest dotted-quarter>, <music21.note.Note C>, '
+ '<music21.note.Rest breve>, <music21.note.Note C>]')
Expand Down