本文整理汇总了Python中music21.converter.parse函数的典型用法代码示例。如果您正苦于以下问题:Python parse函数的具体用法?Python parse怎么用?Python parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pitchQuarterLengthUsageWeightedScatter
def pitchQuarterLengthUsageWeightedScatter(show=True):
from music21 import converter, graph
from music21.musicxml import testFiles as xml
from music21.humdrum import testFiles as kern
mozartStream = converter.parse(xml.mozartTrioK581Excerpt)
notes = mozartStream.flat.stripTies()
g = graph.PlotScatterWeightedPitchSpaceQuarterLength(notes,
title='Mozart Trio K. 581 Excerpt')
g.process()
g = graph.PlotScatterWeightedPitchClassQuarterLength(notes,
title='Mozart Trio K. 581 Excerpt')
g.process()
chopinStream = converter.parse(kern.mazurka6)
notes = chopinStream.flat.stripTies()
g = graph.PlotScatterWeightedPitchSpaceQuarterLength(notes,
title='Chopin Mazurka 6 Excerpt')
g.process()
g = graph.PlotScatterWeightedPitchClassQuarterLength(notes,
title='Chopin Mazurka 6 Excerpt')
g.process()
示例2: testMeasureCopyingB
def testMeasureCopyingB(self):
from music21 import converter
from music21 import pitch
src = """m1 G: IV || b3 d: III b4 ii
m2 v b2 III6 b3 iv6 b4 ii/o6/5
m3 i6/4 b3 V
m4-5 = m2-3
m6-7 = m4-5
"""
s = converter.parse(src, format='romantext')
rnStream = s.flat.getElementsByClass('RomanNumeral')
for elementNumber in [0, 6, 12]:
self.assertEqual(rnStream[elementNumber + 4].figure, 'III6')
self.assertEqual(str(rnStream[elementNumber + 4].pitches), '[A4, C5, F5]')
x = rnStream[elementNumber + 4].pitches[2].accidental
if x == None: x = pitch.Accidental('natural')
self.assertEqual(x.alter, 0)
self.assertEqual(rnStream[elementNumber + 5].figure, 'iv6')
self.assertEqual(str(rnStream[elementNumber + 5].pitches), '[B-4, D5, G5]')
self.assertEqual(rnStream[elementNumber + 5].pitches[0].accidental.displayStatus, True)
from music21.romanText import testFiles
s = converter.parse(testFiles.monteverdi_3_13)
m25 = s.measure(25)
rn = m25.flat.getElementsByClass('RomanNumeral')
self.assertEqual(rn[1].figure, 'III')
self.assertEqual(str(rn[1].key), 'd minor')
示例3: runCorrectingMeasures
def runCorrectingMeasures(self,dirname):
path = dirname
resultS1File=self.getFileName(dirname, "result.S1.xml")
resultS1=converter.parse(resultS1File)
resultS2File=self.getFileName(dirname, "result.S2.xml")
resultS2=converter.parse(resultS2File)
oProcess=[]
oProcess.append(resultS1)
oProcess.append(resultS2)
processOMR=ProcessOMR()
alignedArrays=processOMR.align(oProcess)
resultS1=alignedArrays[0]
resultS2=alignedArrays[1]
cm=CorrectingMeasures()
measuresIndex=processOMR.flagIncorrectMeasures(resultS2)[0]
# measuresIndex=cm.getWrongMeasures(resultS2)
print measuresIndex
for mIndex in measuresIndex:
# if(resultS2.parts[0].getElementsByClass(stream.Measure)[mIndex].duration.quarterLength<4):
resultS2=cm.correctNotesInMeasure(resultS1,resultS2,mIndex)
m21F=Music21Functions()
resultS3=m21F.filterExtraMeasures(resultS2)
resultS3.write("musicxml", path+'/result.S3.xml')
示例4: makeExampleScore
def makeExampleScore():
r'''
Makes example score for use in stream-to-timespan conversion docs.
>>> score = timespans.makeExampleScore()
>>> score.show('text')
{0.0} <music21.stream.Part ...>
{0.0} <music21.instrument.Instrument PartA: : >
{0.0} <music21.stream.Measure 1 offset=0.0>
{0.0} <music21.clef.BassClef>
{0.0} <music21.meter.TimeSignature 2/4>
{0.0} <music21.note.Note C>
{1.0} <music21.note.Note D>
{2.0} <music21.stream.Measure 2 offset=2.0>
{0.0} <music21.note.Note E>
{1.0} <music21.note.Note F>
{4.0} <music21.stream.Measure 3 offset=4.0>
{0.0} <music21.note.Note G>
{1.0} <music21.note.Note A>
{6.0} <music21.stream.Measure 4 offset=6.0>
{0.0} <music21.note.Note B>
{1.0} <music21.note.Note C>
{2.0} <music21.bar.Barline style=final>
{0.0} <music21.stream.Part ...>
{0.0} <music21.instrument.Instrument PartB: : >
{0.0} <music21.stream.Measure 1 offset=0.0>
{0.0} <music21.clef.BassClef>
{0.0} <music21.meter.TimeSignature 2/4>
{0.0} <music21.note.Note C>
{2.0} <music21.stream.Measure 2 offset=2.0>
{0.0} <music21.note.Note G>
{4.0} <music21.stream.Measure 3 offset=4.0>
{0.0} <music21.note.Note E>
{6.0} <music21.stream.Measure 4 offset=6.0>
{0.0} <music21.note.Note D>
{2.0} <music21.bar.Barline style=final>
'''
from music21 import converter
from music21 import stream
streamA = converter.parse('tinynotation: 2/4 C4 D E F G A B C')
streamB = converter.parse('tinynotation: 2/4 C2 G E D')
streamA.makeMeasures(inPlace=True)
streamB.makeMeasures(inPlace=True)
partA = stream.Part()
for x in streamA:
partA.append(x)
instrumentA = partA.getInstrument()
instrumentA.partId = 'PartA'
partA.insert(0, instrumentA)
partB = stream.Part()
for x in streamB:
partB.append(x)
instrumentB = partB.getInstrument()
instrumentB.partId = 'PartB'
partB.insert(0, instrumentB)
score = stream.Score()
score.insert(0, partA)
score.insert(0, partB)
return score
示例5: testBasic
def testBasic(self):
from music21 import converter, corpus
a = converter.parse(corpus.getWork('haydn/opus74no2/movement4.xml'))
post = assembleLyrics(a)
self.assertEqual(post, '') # no lyrics!
a = converter.parse(corpus.getWork('luca/gloria'))
post = assembleLyrics(a)
self.assertEqual(post.startswith('Et in terra pax hominibus bone voluntatis'), True)
示例6: threeDimBoth
def threeDimBoth():
from music21.musicxml.testFiles import mozartTrioK581Excerpt # @UnresolvedImport
from music21.humdrum import testFiles as kernTest
mozartStream = converter.parse(mozartTrioK581Excerpt)
g = graph.Plot3DBarsPitchSpaceQuarterLength(mozartStream.flat)
g.process()
chopinStream = converter.parse(kernTest.mazurka6)
g = graph.Plot3DBarsPitchSpaceQuarterLength(chopinStream.flat)
g.process()
示例7: 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
示例8: pitchQuarterLengthUsage3D
def pitchQuarterLengthUsage3D(show=True):
from music21.musicxml import testFiles as xml
from music21.humdrum import testFiles as kern
mozartStream = converter.parse(xml.mozartTrioK581Excerpt) # @UndefinedVariable
g = graph.Plot3DBarsPitchSpaceQuarterLength(mozartStream.flat.stripTies(), colors=["r"])
g.process()
chopinStream = converter.parse(kern.mazurka6)
g = graph.Plot3DBarsPitchSpaceQuarterLength(chopinStream.flat.stripTies(), colors=["b"])
g.process()
示例9: loadTrainSample
def loadTrainSample(sampleName):
scoreName = sampleName+ ".score.xml";
metaName = sampleName+ ".meta";
perfName = sampleName+ ".perf.mid";
score = converter.parse(scoreName);
meta = loadMetadata(metaName)
perf = converter.parse(perfName);
name = os.path.basename(sampleName)
return {'name': name, 'score':score, 'meta':meta, 'perf':perf}
示例10: demoGraphMozartChopin
def demoGraphMozartChopin():
from music21.musicxml import testFiles as xmlTest
from music21.humdrum import testFiles as kernTest
dpi = 300
mozartStream = converter.parse(xmlTest.mozartTrioK581Excerpt) # @UndefinedVariable
g = graph.Plot3DBarsPitchSpaceQuarterLength(mozartStream.stripTies(), dpi=dpi, title='Mozart Trio K. 581, Excerpt', colors=['#CD4F39'], alpha=.8)
g.process()
chopinStream = converter.parse(kernTest.mazurka6)
g = graph.Plot3DBarsPitchSpaceQuarterLength(chopinStream.stripTies(), dpi=dpi, title='Chopin Mazurka 6, Excerpt', colors=['#6495ED'], alpha=.8)
g.process()
示例11: testLandiniCadence
def testLandiniCadence(self):
from music21 import converter, features
s = converter.parse('tinynotation: 3/4 f#4 f# e g2')
fe = features.native.LandiniCadence(s)
self.assertEqual(fe.extract().vector[0], 1)
s = converter.parse('tinynotation: 3/4 f#4 f# f# g2')
fe = features.native.LandiniCadence(s)
self.assertEqual(fe.extract().vector[0], 0)
s = converter.parse('tinynotation: 3/4 f#4 e a g2')
fe = features.native.LandiniCadence(s)
self.assertEqual(fe.extract().vector[0], 0)
示例12: testRepeatBracketsB
def testRepeatBracketsB(self):
from music21.abcFormat import testFiles
from music21 import converter
from music21 import corpus
s = converter.parse(testFiles.morrisonsJig)
# TODO: get
self.assertEqual(len(s.flat.getElementsByClass('RepeatBracket')), 2)
#s.show()
# four repeat brackets here; 2 at beginning, 2 at end
s = converter.parse(testFiles.hectorTheHero)
self.assertEqual(len(s.flat.getElementsByClass('RepeatBracket')), 4)
s = corpus.parse('JollyTinkersReel')
self.assertEqual(len(s.flat.getElementsByClass('RepeatBracket')), 4)
示例13: testLandiniCadence
def testLandiniCadence(self):
from music21 import converter, features, corpus, graph
s = converter.parse(['f#4 f# e g2', '3/4'])
fe = features.native.LandiniCadence(s)
self.assertEqual(fe.extract().vector[0], 1)
s = converter.parse(['f#4 f# f# g2', '3/4'])
fe = features.native.LandiniCadence(s)
self.assertEqual(fe.extract().vector[0], 0)
s = converter.parse(['f#4 e a g2', '3/4'])
fe = features.native.LandiniCadence(s)
self.assertEqual(fe.extract().vector[0], 0)
示例14: searchSegment
def searchSegment(querymidi):
qstream = converter.parse(querymidi)
qmelo = melody_extractor.extractMelody(qstream)
results = []
# get similarity scores for each segment
for filename in os.listdir(segments_folder):
if filename.endswith('.mid'):
filepath = os.path.join(segments_folder, filename)
stream = converter.parse(filepath)
melo = melody_extractor.extractMelody(stream)
score = similarity_scores.ioir_edit_distance_norm(qmelo,melo)
results.append((score, filename))
return sorted(results)
示例15: demoGettingWorks
def demoGettingWorks():
# Can obtain works from an integrated corpus
s1 = corpus.parseWork('bach/bwv103.6') # @UnusedVariable
s2 = corpus.parseWork('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
# Can parse data stored in Kern files locally or online:
s = converter.parse('http://kern.ccarh.org/cgi-bin/ksdata?l=cc/bach/371chorales&file=chor120.krn') # @UnusedVariable