本文整理汇总了Python中music21.corpus.parse函数的典型用法代码示例。如果您正苦于以下问题:Python parse函数的具体用法?Python parse怎么用?Python parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testGetAccidentalCountSumAdvanced
def testGetAccidentalCountSumAdvanced(self):
s1 = corpus.parse('bach/bwv7.7')
s2 = corpus.parse('bach/bwv66.6')
totalNotes = len(s1.flat.notes) + len(s2.flat.notes)
tally = getAccidentalCountSum([s1, s2], True)
self.assertEqual(tally, {'sharp': 195, 'natural': 324})
self.assertEqual(totalNotes, tally['sharp'] + tally['natural'])
示例2: testFictaFeature
def testFictaFeature():
luca = corpus.parse("luca/gloria.mxl")
fe = MusicaFictaFeature(luca)
print fe.extract().vector
mv = corpus.parse("monteverdi/madrigal.3.1.xml")
fe.setData(mv)
print fe.extract().vector
示例3: testRichMetadata01
def testRichMetadata01(self):
from music21 import corpus
from music21 import metadata
score = corpus.parse('jactatur')
self.assertEqual(score.metadata.composer, 'Johannes Ciconia')
richMetadata = metadata.RichMetadata()
richMetadata.merge(score.metadata)
self.assertEqual(richMetadata.composer, 'Johannes Ciconia')
# update richMetadata with stream
richMetadata.update(score)
self.assertEqual(
richMetadata.keySignatureFirst,
'<music21.key.Key of F major>',
)
self.assertEqual(str(richMetadata.timeSignatureFirst), '2/4')
score = corpus.parse('bwv66.6')
richMetadata = metadata.RichMetadata()
richMetadata.merge(score.metadata)
richMetadata.update(score)
self.assertEqual(
str(richMetadata.keySignatureFirst),
'<music21.key.Key of f# minor>',
)
self.assertEqual(str(richMetadata.timeSignatureFirst), '4/4')
示例4: testBvSvS
def testBvSvS(self):
from music21 import corpus
h = Hasher()
h.hashDuration = False
h.hashOffset = False
s1 = corpus.parse('schoenberg', 6).parts[0]
s2 = corpus.parse('schoenberg', 2).parts[0]
s3 = corpus.parse('bwv66.6').parts[0]
hashes1 = h.hashStream(s1)
hashes2 = h.hashStream(s2)
hashes3 = h.hashStream(s3)
print (difflib.SequenceMatcher(a=hashes1, b=hashes2).ratio())
print (difflib.SequenceMatcher(a=hashes1, b=hashes3).ratio())
print (difflib.SequenceMatcher(a=hashes2, b=hashes3).ratio())
s2.show()
h.hashPitch = False
h.hashDuration = True
h.hashOffset = True
hashes1 = h.hashStream(s1)
hashes2 = h.hashStream(s2)
hashes3 = h.hashStream(s3)
print (difflib.SequenceMatcher(a=hashes1, b=hashes2).ratio())
print (difflib.SequenceMatcher(a=hashes1, b=hashes3).ratio())
print (difflib.SequenceMatcher(a=hashes2, b=hashes3).ratio())
示例5: parse
def parse(self):
from music21 import corpus
if self.number is not None:
return corpus.parse(self.sourcePath, number=self.number)
else:
return corpus.parse(self.sourcePath)
示例6: demoMakeChords
def demoMakeChords():
# wtc no 1
#src = corpus.parse('bwv65.2').measures(0, 5)
src = corpus.parse('opus18no1/movement3.xml').measures(0, 10)
src.flattenParts().makeChords(minimumWindowSize=3).show()
src = corpus.parse('opus18no1/movement3.xml').measures(0, 10)
src.chordify().show()
示例7: monteverdiParallels
def monteverdiParallels(books=(3,), start=1, end=20, show=True, strict=False):
'''
find all instances of parallel fifths or octaves in Monteverdi madrigals.
'''
for book in books:
for i in range(start, end + 1):
filename = 'monteverdi/madrigal.%s.%s.xml' % (book, i)
if strict == True:
c = corpus.parse(filename)
print (book,i)
else:
try:
c = corpus.parse(filename)
print (book,i)
except:
print ("Cannot parse %s, maybe it does not exist..." % (filename))
continue
displayMe = False
for i in range(len(c.parts) - 1):
#iName = c.parts[i].id
ifn = c.parts[i].flat.notesAndRests.stream()
omi = ifn.offsetMap()
for j in range(i + 1, len(c.parts)):
jName = c.parts[j].id
jfn = c.parts[j].flat.notesAndRests.stream()
for k in range(len(omi) - 1):
n1pi = omi[k]['element']
n2pi = omi[k + 1]['element']
n1pjAll = jfn.getElementsByOffset(offsetStart=omi[k]['endTime'] - .001,
offsetEnd=omi[k]['endTime'] - .001,
mustBeginInSpan=False)
if len(n1pjAll) == 0:
continue
n1pj = n1pjAll[0]
n2pjAll = jfn.getElementsByOffset(offsetStart=omi[k + 1]['offset'],
offsetEnd=omi[k + 1]['offset'],
mustBeginInSpan=False)
if len(n2pjAll) == 0:
continue
n2pj = n2pjAll[0]
if n1pj is n2pj:
continue # no oblique motion
if n1pi.isRest or n2pi.isRest or n1pj.isRest or n2pj.isRest:
continue
if n1pi.isChord or n2pi.isChord or n1pj.isChord or n2pj.isChord:
continue
vlq = voiceLeading.VoiceLeadingQuartet(n1pi, n2pi, n1pj, n2pj)
if vlq.parallelMotion('P8') is False and vlq.parallelMotion('P5') is False:
continue
displayMe = True
n1pi.addLyric('par ' + str(vlq.vIntervals[0].name))
n2pi.addLyric(' w/ ' + jName)
if displayMe and show:
c.show()
示例8: demoGraphBach
def demoGraphBach():
dpi = 300
# loping off first measure to avoid pickup
s1 = corpus.parse('bach/bwv103.6').measures(1,None)
s2 = corpus.parse('bach/bwv18.5-lz').measures(1,None)
s1.plot('key', dpi=dpi, title='Windowed Key Analysis, Bach, BWV 103.6', windowStep='pow2')
s2.plot('key', dpi=dpi, title='Windowed Key Analysis, Bach, BWV 18.5', windowStep='pow2')
示例9: demoGraphBach
def demoGraphBach():
dpi = 300
# loping off first measure to avoid pickup
s1 = corpus.parse("bach/bwv103.6").measures(1, None)
s2 = corpus.parse("bach/bwv18.5-lz").measures(1, None)
s1.plot("key", dpi=dpi, title="Windowed Key Analysis, Bach, BWV 103.6", windowStep="pow2")
s2.plot("key", dpi=dpi, title="Windowed Key Analysis, Bach, BWV 18.5", windowStep="pow2")
示例10: demoGettingWorks
def demoGettingWorks():
# Can obtain works from an integrated corpus
s1 = corpus.parse("bach/bwv103.6") # @UnusedVariable
s2 = corpus.parse("bach/bwv18.5-lz") # @UnusedVariable
# Can parse data stored in MusicXML files locally or online:
s = converter.parse("http://www.musicxml.org/xml/elite.xml") # @UnusedVariable
# Can parse data stored in MIDI files locally or online:
s = converter.parse("http://www.jsbchorales.net/down/midi/010306b_.mid") # @UnusedVariable
示例11: demoMakeChords
def demoMakeChords():
from music21 import corpus, stream, scale, bar, layout
# wtc no 1
#src = corpus.parse('bwv65.2').measures(0, 5)
src = corpus.parse('opus18no1/movement3.xml').measures(0, 10)
src.flattenParts().makeChords(minimumWindowSize=3).show()
src = corpus.parse('opus18no1/movement3.xml').measures(0, 10)
src.chordify().show()
示例12: testRichMetadata01
def testRichMetadata01(self):
from music21 import corpus
from music21 import metadata
score = corpus.parse('jactatur')
self.assertEqual(score.metadata.composer, 'Johannes Ciconia')
richMetadata = metadata.RichMetadata()
richMetadata.merge(score.metadata)
self.assertEqual(richMetadata.composer, 'Johannes Ciconia')
# update richMetadata with stream
richMetadata.update(score)
self.assertEqual(
richMetadata.keySignatureFirst,
'<music21.key.KeySignature of 1 flat, mode major>',
)
self.assertEqual(str(richMetadata.timeSignatureFirst), '2/4')
rmdNew = metadata.RichMetadata()
jsonString = freezeThaw.JSONFreezer(richMetadata).json
freezeThaw.JSONThawer(rmdNew).json = jsonString
self.assertEqual(rmdNew.composer, 'Johannes Ciconia')
self.assertEqual(str(rmdNew.timeSignatureFirst), '2/4')
self.assertEqual(
str(rmdNew.keySignatureFirst),
'<music21.key.KeySignature of 1 flat, mode major>',
)
score = corpus.parse('bwv66.6')
richMetadata = metadata.RichMetadata()
richMetadata.merge(score.metadata)
richMetadata.update(score)
self.assertEqual(
str(richMetadata.keySignatureFirst),
'<music21.key.KeySignature of 3 sharps, mode minor>',
)
self.assertEqual(str(richMetadata.timeSignatureFirst), '4/4')
jsonString = freezeThaw.JSONFreezer(richMetadata).json
freezeThaw.JSONThawer(rmdNew).json = jsonString
self.assertEqual(str(rmdNew.timeSignatureFirst), '4/4')
self.assertEqual(
str(rmdNew.keySignatureFirst),
'<music21.key.KeySignature of 3 sharps, mode minor>',
)
示例13: testTonalAmbiguityA
def testTonalAmbiguityA(self):
from music21 import corpus, stream
# s = corpus.parse('bwv64.2')
# k = s.analyze('KrumhanslSchmuckler')
# k.tonalCertainty(method='correlationCoefficient')
#
s = corpus.parse('bwv66.6')
k = s.analyze('KrumhanslSchmuckler')
ta = k.tonalCertainty(method='correlationCoefficient')
self.assertEqual(ta < 2 and ta > 0.1, True)
s = corpus.parse('schoenberg/opus19', 6)
k = s.analyze('KrumhanslSchmuckler')
ta = k.tonalCertainty(method='correlationCoefficient')
self.assertEqual(ta < 2 and ta > 0.1, True)
sc1 = scale.MajorScale('g')
sc2 = scale.MajorScale('d')
sc3 = scale.MajorScale('a')
sc5 = scale.MajorScale('f#')
s = stream.Stream()
for p in sc1.pitches:
s.append(note.Note(p))
k = s.analyze('KrumhanslSchmuckler')
ta = k.tonalCertainty(method='correlationCoefficient')
self.assertEqual(ta < 2 and ta > 0.1, True)
s = stream.Stream()
for p in sc1.pitches + sc2.pitches + sc2.pitches + sc3.pitches:
s.append(note.Note(p))
k = s.analyze('KrumhanslSchmuckler')
ta = k.tonalCertainty(method='correlationCoefficient')
self.assertEqual(ta < 2 and ta > 0.1, True)
s = stream.Stream()
for p in sc1.pitches + sc5.pitches:
s.append(note.Note(p))
k = s.analyze('KrumhanslSchmuckler')
ta = k.tonalCertainty(method='correlationCoefficient')
self.assertEqual(ta < 2 and ta > 0.1, True)
s = stream.Stream()
for p in ('c', 'g', 'c', 'c', 'e'):
s.append(note.Note(p))
k = s.analyze('KrumhanslSchmuckler')
ta = k.tonalCertainty(method='correlationCoefficient')
self.assertEqual(ta < 2 and ta > 0.1, True)
示例14: testMuseDataImportTempoA
def testMuseDataImportTempoA(self):
from music21 import corpus
# a small file
s = corpus.parse('movement2-09.md')
self.assertEqual(len(s.parts), 5)
# the tempo is found in the 4th part here
self.assertEqual(str(
s.parts[3].flat.getElementsByClass('TempoIndication')[0]),
'<music21.tempo.MetronomeMark Largo e piano Quarter=46>')
#s.show()
s = corpus.parse('movement2-07.md')
self.assertEqual(str(
s.flat.getElementsByClass('TempoIndication')[0]),
'<music21.tempo.MetronomeMark Largo Quarter=46>')
示例15: prepareChinaEurope1
def prepareChinaEurope1():
featureExtractors = features.extractorsById(
[
"r31",
"r32",
"r33",
"r34",
"r35",
"p1",
"p2",
"p3",
"p4",
"p5",
"p6",
"p7",
"p8",
"p9",
"p10",
"p11",
"p12",
"p13",
"p14",
"p15",
"p16",
"p19",
"p20",
"p21",
]
)
# featureExtractors = features.extractorsById('all')
oChina1 = corpus.parse("essenFolksong/han1")
oCEurope1 = corpus.parse("essenFolksong/boehme10")
ds = features.DataSet(classLabel="Region")
ds.addFeatureExtractors(featureExtractors)
# add works, defining the class value
for w in oChina1.scores:
sid = "essenFolksong/%s-%s" % ("han1", w.metadata.number)
ds.addData(w, classValue="China", id=sid)
for w in oCEurope1.scores:
sid = "essenFolksong/%s-%s" % ("europe1", w.metadata.number)
ds.addData(w, classValue="CentralEurope", id=sid)
# process with all feature extractors, store all features
ds.process()
ds.write("d:/desktop/folkTrain.tab")