Skip to content

Commit

Permalink
fix bug in beams, restore standardDeviation as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
mscuthbert committed Mar 17, 2018
1 parent a32b559 commit 8753ba9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
21 changes: 21 additions & 0 deletions music21/common/numberTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from fractions import Fraction
from music21 import defaults
from music21.common.decorators import deprecated

__all__ = ['ordinals', 'musicOrdinals',

Expand All @@ -41,6 +42,7 @@

'fromRoman', 'toRoman',
'ordinalAbbreviation',
'standardDeviation',
]

ordinals = ['Zeroth', 'First', 'Second', 'Third', 'Fourth', 'Fifth',
Expand Down Expand Up @@ -597,6 +599,25 @@ def nearestMultiple(n, unit):
return matchHigh, round(matchHigh - n, 7), round(n - matchHigh, 7)


@deprecated('2018-01-01 v5', '2018-08-01', 'use statistics.stdev instead')
def standardDeviation(coll, bassel=False):
'''
DEPRECATED: use statistics.stdev instead.
Given a collection of values, return the standard deviation.
:rtype: float
'''
avg = sum(coll) / float(len(coll))
diffColl = [math.pow(val - avg, 2) for val in coll]
# with a sample standard deviation (not a whole population)
# subtract 1 from the length
# this is bassel's correction
if bassel:
return math.sqrt(sum(diffColl) / float(len(diffColl) - 1))
else:
return math.sqrt(sum(diffColl) / float(len(diffColl)))

def dotMultiplier(dots):
'''
dotMultiplier(dots) returns how long to multiply the note
Expand Down
17 changes: 11 additions & 6 deletions music21/meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@


validDenominators = [1, 2, 4, 8, 16, 32, 64, 128] # in order
beamableDurationTypes = (duration.typeFromNumDict[8],
duration.typeFromNumDict[16], duration.typeFromNumDict[32],
duration.typeFromNumDict[64], duration.typeFromNumDict[128])
beamableDurationTypes = (
duration.typeFromNumDict[8],
duration.typeFromNumDict[16], duration.typeFromNumDict[32],
duration.typeFromNumDict[64], duration.typeFromNumDict[128],
duration.typeFromNumDict[256],
)

# also [pow(2,x) for x in range(8)]
MIN_DENOMINATOR_TYPE = '128th'
Expand Down Expand Up @@ -2259,13 +2262,14 @@ def _getLevelList(self, levelCount, flat=True):
'''
Recursive utility function
>>> b = meter.MeterSequence('4/4', 4)
>>> b[1] = b[1].subdivide(2)
>>> b[3] = b[3].subdivide(2)
>>> b[3][0] = b[3][0].subdivide(2)
>>> b
<MeterSequence {1/4+{1/8+1/8}+1/4+{{1/16+1/16}+1/8}}>
>>> b._getLevelList(0)
[<MeterTerminal 1/4>, <MeterTerminal 1/4>, <MeterTerminal 1/4>, <MeterTerminal 1/4>]
>>> meter.MeterSequence(b._getLevelList(0))
<MeterSequence {1/4+1/4+1/4+1/4}>
>>> meter.MeterSequence(b._getLevelList(1))
Expand Down Expand Up @@ -3780,6 +3784,8 @@ def fixBeamsOneElementDepth(i, el, depth):
# not archetypeSpanNext
#environLocal.printDebug(['matching partial left'])
beamType = 'partial-left'
elif (beamNext is None or beamNumber not in beamNext.getNumbers()):
beamType = 'partial-right'
else:
beamType = 'start'

Expand Down Expand Up @@ -3870,7 +3876,7 @@ def _naiveBeams(srcList):
staticmethod, does not need instance:
>>> durList = [0, -1, -2, -3]
>>> srcList = [note.Note(quarterLength=2**x) for x in durList]
>>> srcList = [note.Note(quarterLength=2 ** x) for x in durList]
>>> srcList.append(note.Rest(type='32nd'))
>>> meter.TimeSignature._naiveBeams(srcList)
[None,
Expand Down Expand Up @@ -4057,7 +4063,6 @@ def _mergeConnectingPartialBeams(beamsList):
thisBeam.direction = None
prevBeam.type = 'continue'


return beamsList

def setDisplay(self, value, partitionRequest=None):
Expand Down
6 changes: 3 additions & 3 deletions music21/stream/makeNotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def makeBeams(s, *, inPlace=False):
offset = 0.0
if m.paddingLeft != 0.0:
offset = opFrac(m.paddingLeft)
elif (noteStream.highestTime < lastTimeSignature.barDuration.quarterLength):
offset = (lastTimeSignature.barDuration.quarterLength - noteStream.highestTime)
elif (noteStream.highestTime < barQL):
offset = barQL - noteStream.highestTime

beamsList = lastTimeSignature.getBeams(noteStream, measureStartOffset=offset)

Expand All @@ -173,7 +173,7 @@ def makeBeams(s, *, inPlace=False):

del mColl # remove Stream no longer needed

s.streamStatus.beams = True
returnObj.streamStatus.beams = True
if inPlace is not True:
return returnObj

Expand Down

0 comments on commit 8753ba9

Please sign in to comment.