• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python converter.parse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中music21.converter.parse函数的典型用法代码示例。如果您正苦于以下问题:Python parse函数的具体用法?Python parse怎么用?Python parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:msampaio,项目名称:music21,代码行数:26,代码来源:ismir2010.py


示例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')
开发者ID:msampaio,项目名称:music21,代码行数:34,代码来源:translate.py


示例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')
开发者ID:MultiOMR,项目名称:ProcessingOMRs,代码行数:25,代码来源:mainGDI.py


示例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
开发者ID:Wajih-O,项目名称:music21,代码行数:60,代码来源:__init__.py


示例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) 
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:10,代码来源:text.py


示例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()
开发者ID:00gavin,项目名称:music21,代码行数:11,代码来源:seaverOct2009.py


示例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
开发者ID:antoniopessotti,项目名称:music21,代码行数:11,代码来源:ismir2010.py


示例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()
开发者ID:antoniopessotti,项目名称:music21,代码行数:11,代码来源:ismir2010.py


示例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}
开发者ID:shinglyu,项目名称:MusicPupil,代码行数:11,代码来源:sampleLoader.py


示例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()
开发者ID:00gavin,项目名称:music21,代码行数:13,代码来源:ismir2010.py


示例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)        
开发者ID:Wajih-O,项目名称:music21,代码行数:14,代码来源:native.py


示例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)
开发者ID:antoniopessotti,项目名称:music21,代码行数:14,代码来源:translate.py


示例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)        
开发者ID:msampaio,项目名称:music21,代码行数:14,代码来源:native.py


示例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)
开发者ID:cemyld,项目名称:gnotestic,代码行数:14,代码来源:suggester_cmd.py


示例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
开发者ID:Aminor7,项目名称:music21,代码行数:15,代码来源:ismir2010.py


示例16: fbFeatureExtraction

def fbFeatureExtraction():
    exampleFB = converter.parse("ismir2011_fb_example1b.xml")
    fe1 = features.jSymbolic.PitchClassDistributionFeature(exampleFB)
    print fe1.extract().vector
    # [0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.6666666666666666, 0.0, 0.0, 1.0, 0.0, 0.0]
    n1 = exampleFB.parts[0][1][5]
    n1.expressions.append(expressions.Turn())
    x = expressions.realizeOrnaments(n1)
    n2 = exampleFB.parts[0][2][2]
    n2.expressions.append(expressions.Mordent())
    y = expressions.realizeOrnaments(n2)

    exampleFB.parts[0][1].elements = [exampleFB.parts[0][1][4]]
    exampleFB.parts[0][1].append(x)
    exampleFB.parts[0][2].elements = [exampleFB.parts[0][2][0], exampleFB.parts[0][2][1]]
    exampleFB.parts[0][2].append(y)

    fb1 = figuredBass.realizer.figuredBassFromStream(exampleFB.parts[1])
    # realization = fb1.realize()
    sol1 = fb1.generateRandomRealization()

    exampleFBOut = stream.Score()
    exampleFBOut.insert(0, exampleFB.parts[0])
    exampleFBOut.insert(0, sol1.parts[0])
    exampleFBOut.insert(0, sol1.parts[1])

    fe1.setData(exampleFBOut)
    print fe1.extract().vector
开发者ID:JoeCodeswell,项目名称:music21,代码行数:28,代码来源:ismir2011.py


示例17: xtest003

    def xtest003(self):
        '''Add key velocities to some MIDI data that reflect accent levels arising from the meter.

        Modify this to just adjust dynamics based on meter; this should be 
        reflected in musical output
        '''
        from music21 import articulations
        from music21 import converter

        partStream = converter.parse("dicterliebe1.xml")
        #for part in partStream.partData:
        # a part stream could have an iterator that partitions itself
        # into measure-length part streams
        for measure in partStream.getElementsByClass('Measure')():  # () ? 
            # measure is a partStream isolated for just the desired measure
            # assuming only one meter per measure
            meterObj = measure['meter']
            # get a list of pairs, specifying offset and accent
            for offset, accent in meterObj.accentPattern():
                if accent > 'mf': # assuming symbolic representation
                    # get all relevant elements
                    subStream = measure.getElementsByOffset(offset, 
                                    offset + meterObj.denominator)
                    # get a stream of just dynamics
                    dynamics = subStream.filterClass(articulations.DynamicArticulation)
                    for obj in dynamics:
                        # can we increment dynamics by dynamics?
                        obj += 'pppp'
开发者ID:ABC-B,项目名称:music21,代码行数:28,代码来源:questions.py


示例18: testJSONSerializationMetadata

    def testJSONSerializationMetadata(self):
        from music21 import converter
        from music21.musicxml import testFiles as mTF
        from music21 import metadata

        md = metadata.Metadata(
            title='Concerto in F',
            date='2010',
            composer='Frank',
            )
        # environLocal.printDebug([str(md.json)])
        self.assertEqual(md.composer, 'Frank')
        self.assertEqual(md.date, '2010/--/--')
        self.assertEqual(md.composer, 'Frank')
        self.assertEqual(md.title, 'Concerto in F')

        # test getting meta data from an imported source
        c = converter.parse(mTF.mozartTrioK581Excerpt)  # @UndefinedVariable
        md = c.metadata

        self.assertEqual(md.movementNumber, '3')
        self.assertEqual(
            md.movementName, 'Menuetto (Excerpt from Second Trio)')
        self.assertEqual(md.title, 'Quintet for Clarinet and Strings')
        self.assertEqual(md.number, 'K. 581')
        self.assertEqual(md.composer, 'Wolfgang Amadeus Mozart')
开发者ID:cuthbertLab,项目名称:music21,代码行数:26,代码来源:testMetadata.py


示例19: testMIDIParse

def testMIDIParse():
    from music21 import converter, common
    from music21 import freezeThaw

    #a = 'https://github.com/ELVIS-Project/vis/raw/master/test_corpus/prolationum-sanctus.midi'
    #c = converter.parse(a)
#     c = corpus.parse('bwv66.6', forceSource=True)
#     v = freezeThaw.StreamFreezer(c)
#     v.setupSerializationScaffold()
#     return v.writeStr() # returns a string
    import os
    a = os.path.join(common.getSourceFilePath(),
                     'midi',
                     'testPrimitive',
                     'test03.mid')

    #a = 'https://github.com/ELVIS-Project/vis/raw/master/test_corpus/prolationum-sanctus.midi'
    c = converter.parse(a)
    v = freezeThaw.StreamFreezer(c)
    v.setupSerializationScaffold()


    mockType = lambda x: x.__class__.__name__ == 'weakref'
    ty = TreeYielder(mockType)
    for val in ty.run(c):
        print(val, ty.currentLevel())
开发者ID:ELVIS-Project,项目名称:music21,代码行数:26,代码来源:treeYield.py


示例20: get_note_rep_array

    def get_note_rep_array(self, file_name, one_hot):
        """
        Converts a MIDI file into a suitable representation for use in the neural network.

        :param file_name: path and file name for a MIDI file that will be used for training.
        :param one_hot: determines if the representation used for notes will be one-hot (1-of-n)
        :return: an array with the appropriate number of steps to represent each note.
        """
        midi_stream = converter.parse(file_name)
        note_list_arr = []

        for note in self.get_note_objects(midi_stream):

            duration = self.get_note_duration(note)

            if duration < self.T_STEP_LENGTH:
                steps = 1
            else:
                steps = int(duration / self.T_STEP_LENGTH)

            temp_note = [self.get_midi_representation(note)]
            for num_steps in range(steps):
                if one_hot:
                    note_list_arr.append(self.to_onehot_1d(temp_note))
                else:
                    note_list_arr.append(temp_note)
        return note_list_arr
开发者ID:mzokov,项目名称:dissertation,代码行数:27,代码来源:DataHandler.py



注:本文中的music21.converter.parse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python converter.parseData函数代码示例发布时间:2022-05-27
下一篇:
Python common.wrapWeakref函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap