Skip to content

Commit

Permalink
Merge branch 'fixTesting' into m21_2
Browse files Browse the repository at this point in the history
  • Loading branch information
mscuthbert committed Oct 4, 2015
2 parents 4f6fbd1 + 9dda3f2 commit 51e9ef6
Show file tree
Hide file tree
Showing 19 changed files with 451 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ install:
- python -m compileall music21

script:
- python -c 'from music21.test.testSingleCoreAll import main as tm; tm()'
- python -c 'from music21.test.testSingleCoreAll import travisMain as tm; tm()'

after_success:
coveralls
4 changes: 3 additions & 1 deletion music21/alpha/counterpoint/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,17 @@ def findHiddenOctaves(self, stream1, stream2):
>>> n2 = note.Note('A3')
>>> n3 = note.Note('A3')
>>> n4 = note.Note('C4')
>>> m1 = note.Note('G4')
>>> m2 = note.Note('A4')
>>> m3 = note.Note('B4')
>>> m4 = note.Note('C5')
>>> bass = stream.Stream()
>>> bass.append([n1, n2, n3, n4])
>>> sop = stream.Stream()
>>> sop.append([m1, m2, m3, m4])
>>> cp = alpha.counterpoint.species.ModalCounterpoint(stream1 = bass, stream2 = sop)
>>> cp = alpha.counterpoint.species.ModalCounterpoint(stream1=bass, stream2=sop)
>>> cp.findHiddenOctaves(cp.stream1, cp.stream2)
2
>>> n2.editorial.misc['Hidden Octave']
Expand Down
4 changes: 2 additions & 2 deletions music21/alpha/medren.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def _getTranslator(self, mensurationOrDivisione = None, surroundingStream = None
measure, index = self._getSurroundingMeasure(mensurationOrDivisione = mOrD, activeSite = surroundingStream)

self._gettingDuration = True
if self.measure and 'Divisione' in mOrD.classes:
if measure and 'Divisione' in mOrD.classes:
if index == 0:
self.lenList = trecento.notation.BrevisLengthTranslator(mOrD, measure).getKnownLengths()
elif index != -1:
Expand Down Expand Up @@ -591,7 +591,7 @@ def __init__(self, *arguments, **keywords):
self._gettingDuration = False
self._mensuralType = 'brevis'

if self.arguments:
if arguments:
tOrA = arguments[0]
if tOrA in _validMensuralTypes:
self._mensuralType = tOrA
Expand Down
12 changes: 6 additions & 6 deletions music21/alpha/webapps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def ModWSGIApplication(environ, start_response):
>>> environ['CONTENT_TYPE'] = "application/json"
>>> start_response = lambda status, headers: None # usually called by mod_wsgi server. Used to initiate response
>>> alpha.webapps.ModWSGIApplication(environ, start_response)
[b'{"dataDict": {"a": {...}}, "errorList": [], "status": "success"}']
[...'{"dataDict": {"a": ...}, "errorList": [], "status": "success"}']
'''

# Get content of request: is in a file-like object that will need to be .read() to get content
Expand Down Expand Up @@ -1015,12 +1015,12 @@ def getResultObject(self):
return_obj['dataDict'] = {}
return_obj['errorList'] = []

if self.errorList:
if len(self.errorList) > 0:
return_obj['status'] = "error"
return_obj['errorList'] = self.errorList
return return_obj

if self.returnDict:
if len(self.returnDict) == 0:
iterItems = [(k, 'str') for k in sorted(list(self.parsedDataDict.items()))]
else:
iterItems = sorted(list(self.returnDict.items()))
Expand All @@ -1047,7 +1047,7 @@ def getResultObject(self):
return_obj['dataDict'][dataName] = {"fmt":fmt, "data":dataStr}


if self.errorList:
if len(self.errorList) > 0:
return_obj['status'] = "error"
return_obj['errorList'] = self.errorList
return return_obj
Expand Down Expand Up @@ -1164,7 +1164,7 @@ def getOutput(self):
to the server:
"text/plain", "application/json", "text/html", etc.
'''
if self.errorList:
if len(self.errorList) > 0:
output = "<br />".join([":".join(e) for e in self.errorList])
outputType = 'text/html'

Expand Down Expand Up @@ -1291,4 +1291,4 @@ def testAgenda(self):
music21.mainTest(Test)

#------------------------------------------------------------------------------
# eof
# eof
4 changes: 2 additions & 2 deletions music21/braille/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

from music21.common import opFrac

try:
try: # gives Py2 the zip of Py3
from future_builtins import zip
except ImportError: # not 2.6+ or is 3.x
except ImportError:
pass

import collections
Expand Down
4 changes: 2 additions & 2 deletions music21/braille/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@
if six.PY3:
unicode = str # @ReservedAssignment

try:
try: # gives Py2 the zip of Py3
from future_builtins import zip
except ImportError: # not 2.6+ or is 3.x
except ImportError:
pass


Expand Down
113 changes: 84 additions & 29 deletions music21/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
class LayoutBase(base.Music21Object):
classSortOrder = -10
def __init__(self, *args, **keywords):
base.Music21Object.__init__(self)
super(LayoutBase, self).__init__()


#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -133,7 +133,7 @@ class ScoreLayout(LayoutBase):
'''
def __init__(self, *args, **keywords):
LayoutBase.__init__(self)
super(ScoreLayout, self).__init__()

self.scalingMillimeters = None
self.scalingTenths = None
Expand Down Expand Up @@ -213,7 +213,7 @@ class PageLayout(LayoutBase):
'''
def __init__(self, *args, **keywords):
LayoutBase.__init__(self)
super(PageLayout, self).__init__()

self.pageNumber = None
self.leftMargin = None
Expand Down Expand Up @@ -271,7 +271,7 @@ class SystemLayout(LayoutBase):
True
'''
def __init__(self, *args, **keywords):
LayoutBase.__init__(self)
super(SystemLayout, self).__init__()

self.leftMargin = None
self.rightMargin = None
Expand Down Expand Up @@ -350,7 +350,7 @@ class StaffLayout(LayoutBase):
'''
def __init__(self, *args, **keywords):
LayoutBase.__init__(self)
super(StaffLayout, self).__init__()

# this is the distance between adjacent staves
self.distance = None
Expand All @@ -374,7 +374,8 @@ def __init__(self, *args, **keywords):
self.hidden = True

def __repr__(self):
return "<music21.layout.StaffLayout distance %r, staffNumber %r, staffSize %r, staffLines %r>" % (self.distance, self.staffNumber, self.staffSize, self.staffLines)
return "<music21.layout.StaffLayout distance %r, staffNumber %r, staffSize %r, staffLines %r>" % (
self.distance, self.staffNumber, self.staffSize, self.staffLines)

#-------------------------------------------------------------------------------
class LayoutException(exceptions21.Music21Exception):
Expand Down Expand Up @@ -419,7 +420,7 @@ class StaffGroup(spanner.Spanner):
'''
def __init__(self, *arguments, **keywords):
spanner.Spanner.__init__(self, *arguments, **keywords)
super(StaffGroup, self).__init__(*arguments, **keywords)

self.name = None # if this group has a name
self.abbreviation = None
Expand Down Expand Up @@ -594,12 +595,12 @@ def divideByPages(scoreIn, printUpdates=False, fastMeasures=False):

pageNumber = 0
systemNumber = 0
scoreStaffNumber = 0

for pageStartM, pageEndM in pageMeasureTuples:
pageNumber += 1
if printUpdates is True:
print("updating page", pageNumber)
#thisPage = scoreIn.measures(pageStartM, pageEndM)
#thisPage.__class__ = Page
thisPage = Page()
thisPage.measureStart = pageStartM
thisPage.measureEnd = pageEndM
Expand All @@ -617,26 +618,45 @@ def divideByPages(scoreIn, printUpdates=False, fastMeasures=False):
if 'PageLayout' in el.classes:
thisPage.pageLayout = el


pageSystemNumber = 0
for systemStartM, systemEndM in systemMeasureTuples:
if systemStartM < pageStartM or systemEndM > pageEndM:
continue
systemNumber += 1
systemNumber += 1 # global, not on this page...
pageSystemNumber += 1
if fastMeasures is True:
thisSystem = scoreIn.measures(systemStartM, systemEndM, collect=[], gatherSpanners=False)
measureStacks = scoreIn.measures(systemStartM, systemEndM, collect=[], gatherSpanners=False)
else:
thisSystem = scoreIn.measures(systemStartM, systemEndM)
thisSystem.__class__ = System
measureStacks = scoreIn.measures(systemStartM, systemEndM)
thisSystem = System()
thisSystem.systemNumber = systemNumber
thisSystem.pageNumber = pageNumber
thisSystem.pageSystemNumber = pageSystemNumber
thisSystem.mergeAttributes(measureStacks)
thisSystem.elements = measureStacks
thisSystem.measureStart = systemStartM
thisSystem.measureEnd = systemEndM

for p in thisSystem.parts:
p.__class__ = Staff
allStaffLayouts = p.iter.getElementsByClass('StaffLayout')
if allStaffLayouts:
systemStaffNumber = 0

for p in list(thisSystem.parts):
scoreStaffNumber += 1
systemStaffNumber += 1

staffObject = Staff()
staffObject.mergeAttributes(p)
staffObject.scoreStaffNumber = scoreStaffNumber
staffObject.staffNumber = systemStaffNumber
staffObject.pageNumber = pageNumber
staffObject.pageSystemNumber = pageSystemNumber

staffObject.elements = p
thisSystem.replace(p, staffObject)
allStaffLayouts = p.recurse().getElementsByClass('StaffLayout')
if len(allStaffLayouts) > 0:
#if len(allStaffLayouts) > 1:
# print("Got many staffLayouts")
p.staffLayout = allStaffLayouts[0]
staffObject.staffLayout = allStaffLayouts[0]

allSystemLayouts = thisSystem.recurse().getElementsByClass('SystemLayout')
if allSystemLayouts:
Expand Down Expand Up @@ -707,7 +727,7 @@ class LayoutScore(stream.Opus):
If the score does not change between calls to the various getPosition calls, it is much faster as it uses a cache.
'''
def __init__(self, *args, **keywords):
stream.Opus.__init__(self, *args, **keywords)
super(LayoutScore, self).__init__(*args, **keywords)
self.scoreLayout = None
self.measureStart = None
self.measureEnd = None
Expand Down Expand Up @@ -938,7 +958,7 @@ def getPositionForStaff(self, pageId, systemId, staffId):
>>> lt = corpus.parse('demos/layoutTest.xml')
>>> ls = layout.divideByPages(lt, fastMeasures = True)
>>> ls = layout.divideByPages(lt, fastMeasures=True)
The first staff (staff 0) of each page/system always begins at height 0 and should end at
height 40 if it is a 5-line staff (not taken into account) with no staffSize changes
Expand Down Expand Up @@ -1104,12 +1124,12 @@ def getStaffDistanceFromPrevious(self, pageId, systemId, staffId):
# override global information with staff specific pageLayout
thisStaff = self.pages[pageId].systems[systemId].staves[staffId]
try:
firstMeasureOfStaff = thisStaff.getElementsByClass('Measure', returnStreamSubClass='list')[0]
firstMeasureOfStaff = thisStaff.iter.getElementsByClass('Measure')[0]
except IndexError:
firstMeasureOfStaff = stream.Stream()
environLocal.warn("No measures found in pageId %d, systemId %d, staffId %d" % (pageId, systemId, staffId))

allStaffLayouts = firstMeasureOfStaff.getElementsByClass('StaffLayout', returnStreamSubClass='list')
allStaffLayouts = firstMeasureOfStaff.iter.getElementsByClass('StaffLayout')
if len(allStaffLayouts) > 0:
#print("Got staffLayouts: ")
for sltemp in allStaffLayouts:
Expand Down Expand Up @@ -1442,7 +1462,7 @@ class Page(stream.Opus):
belongs on a single notated page.
'''
def __init__(self, *args, **keywords):
stream.Opus.__init__(self, *args, **keywords)
super(Page, self).__init__(*args, **keywords)
self.pageNumber = 1
self.measureStart = None
self.measureEnd = None
Expand All @@ -1462,12 +1482,21 @@ class System(stream.Score):
belongs on a single notated system.
'''
def __init__(self, *args, **keywords):
stream.Score.__init__(self, *args, **keywords)
self.systemNumber = 1
super(System, self).__init__(*args, **keywords)
self.systemNumber = 0

self.pageNumber = 0
self.pageSystemNumber = 0

self.systemLayout = None
self.measureStart = None
self.measureEnd = None

def __repr__(self):
return "<{0}.{1} {2}: p.{3}, sys.{4}>".format(self.__module__, self.__class__.__name__,
self.systemNumber,
self.pageNumber, self.pageSystemNumber)

def _getStaves(self):
return self.getElementsByClass(Staff)

Expand All @@ -1480,13 +1509,27 @@ class Staff(stream.Part):
belongs on a single Staff.
'''
def __init__(self, *args, **keywords):
stream.Part.__init__(self, *args, **keywords)
self.staffNumber = 1
super(Staff, self).__init__(*args, **keywords)
self.staffNumber = 1 # number in this system NOT GLOBAL

self.scoreStaffNumber = 0
self.pageNumber = 0
self.pageSystemNumber = 0

self.optimized = 0
self.height = None # None = undefined
self.inheritedHeight = None
self.staffLayout = None

def __repr__(self):
return "<{0}.{1} {2}: p.{3}, sys.{4}, st.{5}>".format(
self.__module__,
self.__class__.__name__,
self.scoreStaffNumber,
self.pageNumber, self.pageSystemNumber,
self.staffNumber)


_DOC_ORDER = [ScoreLayout, PageLayout, SystemLayout, StaffLayout, LayoutBase,
LayoutScore, Page, System, Staff]
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -1556,10 +1599,22 @@ def xtestGetPageMeasureNumbers(self):
# print(retStr)
self.assertEqual(retStr, '1: 1, 2: 23, 3: 50, 4: 80, 5: 103, ')

def testGetStaffLayoutFromStaff(self):
'''
we have had problems with attributes disappearing.
'''
from music21 import corpus
lt = corpus.parse('demos/layoutTest.xml')
ls = divideByPages(lt, fastMeasures=True)

hiddenStaff = ls.pages[0].systems[3].staves[1]
self.assertTrue(hiddenStaff.__repr__().endswith('Staff 11: p.1, sys.4, st.2>'))
self.assertIsNotNone(hiddenStaff.staffLayout)

#-------------------------------------------------------------------------------
if __name__ == "__main__":
import music21
music21.mainTest(Test)
music21.mainTest(Test) #, runTest='getStaffLayoutFromStaff')



Expand Down
2 changes: 1 addition & 1 deletion music21/midi/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ def _prepareStreamForMidi(s):
s = copy.deepcopy(s)
if s.hasPartLikeStreams():
# check for tempo indications in the score
mmTopLevel = s.iter.getElementsByClass('MetronomeMark')
mmTopLevel = s.iter.getElementsByClass('MetronomeMark').stream()
if mmTopLevel: # place in top part
target = s.iter.getElementsByClass('Stream')[0]
for mm in mmTopLevel:
Expand Down
Loading

0 comments on commit 51e9ef6

Please sign in to comment.