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

Python corpus.parse函数代码示例

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

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



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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


示例16: testStreams02

    def testStreams02(self):

        # based on Stream.testAddSlurByMelisma(self):

        #from music21 import corpus, spanner
        nStart = None; nEnd = None
        
        ex = corpus.parse('luca/gloria').parts['cantus'].measures(1,11)        
        exFlatNotes = ex.flat.notesAndRests
        nLast = exFlatNotes[-1]
        
        for i, n in enumerate(exFlatNotes):
            if i < len(exFlatNotes) - 1:
                nNext = exFlatNotes[i+1]
            else: continue
        
            if n.hasLyrics():
                nStart = n
            # if next is a begin, then this is an end
            elif nStart is not None and nNext.hasLyrics() and n.tie is None:
                nEnd = n
            elif nNext is nLast:
                nEnd = n
            if nStart is not None and nEnd is not None:
                nStart.addLyric(nStart.beatStr)
                ex.insert(spanner.Slur(nStart, nEnd))
                nStart = None; nEnd = None
        
        for sp in ex.spanners.getElementsByClass('Slur'):  
            #environLocal.printDebug(['sp', n.nameWithOctave, sp])
            unused_dur = sp.getDurationBySite(exFlatNotes)
            n = sp.getFirst()
开发者ID:Wajih-O,项目名称:music21,代码行数:32,代码来源:icmc2011.py


示例17: testExtractionC

    def testExtractionC(self):
        from music21 import analysis, corpus
        # http://solomonsmusic.net/schenker.htm
        # shows extracting an Ursatz line
        
        # BACH pre;ide !, WTC

        src = corpus.parse('bwv846')
        chords = src.flattenParts().makeChords(minimumWindowSize=4, 
                                    makeRests=False)
        for c in chords.flat.notes:
            c.quarterLength = 4
        for m in chords.getElementsByClass('Measure'):
            m.clef = m.bestClef()
        
        chords.measure(1).notes[0].addLyric('::/p:e/o:5/nf:no/ta:3/g:Ursatz')
        chords.measure(1).notes[0].addLyric('::/p:c/o:4/nf:no/tb:I')
        
        chords.measure(24).notes[0].addLyric('::/p:d/o:5/nf:no/ta:2')
        chords.measure(24).notes[0].addLyric('::/p:g/o:3/nf:no/tb:V')
        
        chords.measure(30).notes[0].addLyric('::/p:f/o:4/tb:7')
        
        chords.measure(34).notes[0].addLyric('::/p:c/o:5/nf:no/v:1/ta:1')
        chords.measure(34).notes[0].addLyric('::/p:g/o:4/nf:no/v:2')
        chords.measure(34).notes[0].addLyric('::/p:c/o:4/nf:no/v:1/tb:I')
        
        sr = analysis.reduction.ScoreReduction()
        sr.chordReduction = chords
        #sr.score = src
        unused_post = sr.reduce()
开发者ID:Wajih-O,项目名称:music21,代码行数:31,代码来源:reduction.py


示例18: indexOnePath

def indexOnePath(filePath, *args, **kwds):
    if not os.path.isabs(filePath):
        scoreObj = corpus.parse(filePath)
    else:
        scoreObj = converter.parse(filePath)
    scoreDictEntry = indexScoreParts(scoreObj, *args, **kwds)
    return scoreDictEntry
开发者ID:keszybz,项目名称:music21,代码行数:7,代码来源:segment.py


示例19: xtestBusyCallback

 def xtestBusyCallback(self):
     '''
     tests to see if the busyCallback function is called properly
     '''
     
     from music21 import corpus
     import random
     
     def busyCounter(timeList):
         timeCounter = timeList[0]
         timeCounter.times += timeCounter.updateTime
         print("hi! waited %d milliseconds" % (timeCounter.times))
     
     class Mock():
         times = 0
     
     timeCounter = Mock()
     timeCounter.updateTime = 500
     
     b = corpus.parse('bach/bwv66.6')
     keyDetune = []
     for i in range(0, 127):
         keyDetune.append(random.randint(-30, 30))
     for n in b.flat.notes:
         n.microtone = keyDetune[n.midi]
     sp = StreamPlayer(b)
     sp.play(busyFunction=busyCounter, busyArgs=[timeCounter], busyWaitMilliseconds = 500)
开发者ID:Aminor7,项目名称:music21,代码行数:27,代码来源:realtime.py


示例20: run

 def run(self):
     score = corpus.parse(self.filename)
     self.debug('PARSED')
     if 2 < len(score.parts):
         self.debug('MORE THAN TWO PARTS')
         self.results = None
         return
     chordifiedScore = score.chordify()
     self.debug('CHORDIFIED')
     try:
         chordReducer = analysis.reduceChords.ChordReducer()
         reducedScore = chordReducer(score).parts[0]
     except AssertionError as e:
         self.debug('REDUCTION ERROR')
         print(e)
         return
     self.debug('REDUCED')
     self.results['chordified'] = []
     self.results['reduced'] = []
     for i in range(1, 5):
         ngrams = self.computeNGrams(reducedScore, nGramLength=i)
         self.results['chordified'].append(ngrams)
         self.debug('NGRAMS: {}'.format(i))
     for i in range(1, 5):
         ngrams = self.computeNGrams(chordifiedScore, nGramLength=i)
         self.results['reduced'].append(ngrams)
         self.debug('NGRAMS: {}'.format(i))
     self.debug('DONE!')
开发者ID:Wajih-O,项目名称:music21,代码行数:28,代码来源:elvis_trecento.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python corpus.parseWork函数代码示例发布时间:2022-05-27
下一篇:
Python corpus.getWork函数代码示例发布时间: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