Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
abcTranslate,
abjTranslate,
# analysis.
analysisCorrelate,
analysisDiscrete,
analysisMetrical,
analysisPatel,
analysisWindowed,
articulations,
base,
beam,
brailleTranslate,
clef,
common,
#composition
compositionPhasing,
converter,
corpus,
chord,
duration,
dynamics,
editorial,
environment,
expressions,
features,
featuresJSymbolic,
featuresNative,
import copy
import unittest, doctest
import sys
import types
import inspect
import uuid
from music21 import common
from music21 import environment
_MOD = 'music21.base.py'
environLocal = environment.Environment(_MOD)
# get the right timer for windows
import time
if common.getPlatform() == "win":
defaultTimer = time.clock
else:
defaultTimer = time.time
# check external dependencies and display
_missingImport = []
try:
import matplotlib
except ImportError:
_missingImport.append('matplotlib')
try:
import numpy
except ImportError:
_missingImport.append('numpy')
def xtestImportSorgen(self):
ci = CapellaImporter()
capellaDirPath = common.getSourceFilePath() / 'capella'
oswaldPath = capellaDirPath / r'Nu_rue_mit_sorgen.capx'
ci.readCapellaXMLFile(oswaldPath)
ci.parseXMLText()
#firstSystemObject = ci.mainDom.documentElement.getElementsByTagName('system')[0]
#m21SystemObj = ci.systemFromSystem(firstSystemObject)
#m21SystemObj.show('text')
#scoreElement = ci.mainDom.documentElement.getElementsByTagName('score')[0]
scoreObj = ci.systemScoreFromScore(ci.mainDom.documentElement)
partScore = ci.partScoreFromSystemScore(scoreObj)
partScore.show()
#ci.walkNodes()
raise MeterException('cannot access from qLenPos %s where total duration is %s' % (qLenPos, self.duration.quarterLength))
qPos = 0
match = None
for i in range(len(self)):
start = qPos
end = qPos + self[i].duration.quarterLength
# if adjoing ends are permitted, first match is found
if includeCoincidentBoundaries:
if qLenPos >= start and qLenPos <= end:
match = i
break
else:
# note that this is >=, meaning that the first boundary
# is coincident
if (common.greaterThanOrEqual(qLenPos, start) and
common.lessThan(qLenPos, end)):
# if qLenPos >= start and qLenPos < end:
match = i
break
qPos += self[i].duration.quarterLength
return match
element = self.getElement(partName)
if hasattr(self.srcNameEval, '_DOC_ATTR'):
docAttr = self.srcNameEval._DOC_ATTR
else:
docAttr = {}
match = None
if partName in docAttr.keys():
match = docAttr[partName]
# if its an undocumented public attribute and basic python
# data structure, we do not want to show that documentation
elif (element.kind in ['data'] and (
common.isStr(element.object) or
common.isListLike(element.object) or
common.isNum(element.object)
)):
pass
else:
try:
match = element.object.__doc__
except AttributeError:
match = None
# the object object returns by default
# x.__init__(...) initializes x; see x.__class__.__doc__ for signature
# this should be returned as Documentation
if match == None or match.startswith('x.__init__(...) initializes x'):
return NO_DOC
# default for a dictionary
self.measureNumbering = None # can be None -- meaning no comment,
# 'none', 'measure', or 'system'...
self.measureNumberStyle = None
class BeamStyle(Style):
'''
Style for beams
'''
def __init__(self):
super().__init__()
self.fan = None
class StyleMixin(common.SlottedObjectMixin):
'''
Mixin for any class that wants to support style and editorial, since several
non-music21 objects, such as Lyrics and Accidentals will support Style.
Not used by Music21Objects because of the added trouble in copying etc. so
there is code duplication with base.Music21Object
'''
_styleClass = Style
__slots__ = ('_style', '_editorial')
def __init__(self):
super().__init__()
self._style = None
self._editorial = None
def _updateBasedOnXMLInput(self, keywords):
'''
This method must be called twice, once before the pitches
are rendered, and once after. This is because after the pitches
are rendered, the root() and bass() becomes reset by the chord class
but we want the objects to retain their initial root, bass, and inversion
'''
for kw in keywords:
if kw == 'root':
if isinstance(keywords[kw], str):
keywords[kw] = common.cleanedFlatNotation(keywords[kw])
self.root(pitch.Pitch(keywords[kw]))
else:
self.root(keywords[kw])
elif kw == 'bass':
if isinstance(keywords[kw], str):
keywords[kw] = common.cleanedFlatNotation(keywords[kw])
self.bass(pitch.Pitch(keywords[kw]))
else:
self.bass(keywords[kw])
elif kw == 'inversion':
self.inversion(int(keywords[kw]), transposeOnSet=False)
elif kw in ('duration', 'quarterLength'):
self.duration = duration.Duration(keywords[kw])
else:
pass
def testLoadFromFile(self):
fp = str(common.getSourceFilePath() / 'musedata' / 'testPrimitive')
mdw = MuseDataWork()
dirLib = os.path.join(fp, 'test01')
for fn in ['01.md', '02.md', '03.md', '04.md', '05.md']:
fp = os.path.join(dirLib, fn)
# environLocal.printDebug([fp])
mdw.addFile(fp)
mdpObjs = mdw.getParts()
self.assertEqual(len(mdpObjs), 5)
# first line of src strings
self.assertEqual(mdpObjs[0].src[4], 'WK#:581 MV#:3c')
self.assertEqual(mdpObjs[0].src[12], 'score: part 1 of 5')
'bach/bwv431.mxl'
>>> b = md5OfCorpusFile(s.corpusFilepath)
>>> b
'3b8c4b8db4288c43efde44ddcdb4d8d2'
>>> a == b
True
>>> md5OfCorpusFile('airdsAirs/book3.abc', '413')
'c1666c19d63fc0940f111008e2269f75.413'
'''
corpusFP = common.getCorpusFilePath() / pathlib.Path(fileDir)
with corpusFP.open('rb') as fileIn:
md5 = common.getMd5 ( fileIn.read() )
if scoreNumber:
return md5 + '.' + scoreNumber
else:
return md5
0
>>> searchResult = metadataBundle.search(
... 'cicon',
... field='composer',
... fileExtensions=('.xml'),
... )
>>> len(searchResult)
1
Searches can also use keyword args:
>>> metadataBundle.search(composer='cicon')
'''
if fileExtensions is not None and not common.isIterable(fileExtensions):
fileExtensions = [fileExtensions]
newMetadataBundle = MetadataBundle()
if query is None and field is None:
if not kwargs:
raise MetadataBundleException('Query cannot be empty')
field, query = kwargs.popitem()
for key in self._metadataEntries:
metadataEntry = self._metadataEntries[key]
# ignore stub entries
if metadataEntry.metadata is None:
continue
sp = metadataEntry.sourcePath
if not isinstance(sp, pathlib.Path):
sp = pathlib.Path(sp)