当前位置: 首页>>代码示例>>Python>>正文


Python corpus.parseWork函数代码示例

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


在下文中一共展示了parseWork函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: demoGraphBach

def demoGraphBach():

    dpi = 300

    # loping off first measure to avoid pickup
    s1 = corpus.parseWork('bach/bwv103.6').measures(1,None)
    s2 = corpus.parseWork('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:msampaio,项目名称:music21,代码行数:10,代码来源:ismir2010.py

示例2: demoGraphBach

def demoGraphBach():

    dpi = 300

    # loping off first measure to avoid pickup
    s1 = corpus.parseWork("bach/bwv103.6").measures(1, None)
    s2 = corpus.parseWork("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:JoeCodeswell,项目名称:music21,代码行数:10,代码来源:ismir2010.py

示例3: 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

示例4: testMultiWorkImported

    def testMultiWorkImported(self):

        from music21 import corpus
        # defines multiple works, will return an opus
        o = corpus.parseWork('josquin/milleRegrets')
        self.assertEqual(len(o), 4)
        # each score in the opus is a Stream that contains a Part and metadata
        p1 = o.getScoreByNumber(1).parts[0] 
        self.assertEqual(p1.offset, 0.0)
        self.assertEqual(len(p1.flat.notes), 89)

        p2 = o.getScoreByNumber(2).parts[0] 
        self.assertEqual(p2.offset, 0.0)
        self.assertEqual(len(p2.flat.notes), 81)

        p3 = o.getScoreByNumber(3).parts[0] 
        self.assertEqual(p3.offset, 0.0)
        self.assertEqual(len(p3.flat.notes), 83)

        p4 = o.getScoreByNumber(4).parts[0] 
        self.assertEqual(p4.offset, 0.0)
        self.assertEqual(len(p4.flat.notes), 79)


        sMerged = o.mergeScores()
        self.assertEqual(sMerged.metadata.title, 'Mille regrets')
        self.assertEqual(sMerged.metadata.composer, 'Josquin des Prez')
        self.assertEqual(len(sMerged.parts), 4)


        self.assertEqual(sMerged.parts[0].getElementsByClass('Clef')[0].sign, 'G')
        self.assertEqual(sMerged.parts[1].getElementsByClass('Clef')[0].sign, 'G')
        self.assertEqual(sMerged.parts[2].getElementsByClass('Clef')[0].sign, 'G')
        self.assertEqual(sMerged.parts[2].getElementsByClass('Clef')[0].octaveChange, -1)
        self.assertEqual(sMerged.parts[3].getElementsByClass('Clef')[0].sign, 'F')
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:35,代码来源:translate.py

示例5: testExamplesD

    def testExamplesD(self):
        from music21 import corpus
        # Parse an Opus, a collection of Scores
        o = corpus.parseWork('josquin/laDeplorationDeLaMorteDeJohannesOckeghem')
        # Create a Score from a Measure range
        sExcerpt = o.mergeScores().measures(127, 133)
        # Create a reduction of Chords
        reduction = sExcerpt.chordify()
        # Iterate over the Chords and prepare presentation
        for c in reduction.flat.getElementsByClass('Chord'):
            c.closedPosition(forceOctave=4, inPlace=True)
            c.removeRedundantPitches(inPlace=True)
            c.annotateIntervals()
        # Add the reduction and display the results
        sExcerpt.insert(0, reduction)
        #sExcerpt.show()

        self.assertEqual(len(sExcerpt.flat.getElementsByClass('Chord')), 13)

        self.assertEqual(str(sExcerpt.flat.getElementsByClass('Chord')[1]), '<music21.chord.Chord E4 G4 B4 E5>')

        self.assertEqual(str(sExcerpt.flat.getElementsByClass('Chord')[2]), '<music21.chord.Chord E4 G4 E5>')
        self.assertEqual(str(sExcerpt.flat.getElementsByClass('Chord')[3]), '<music21.chord.Chord D4 F4 A4 D5>')
        self.assertEqual(str(sExcerpt.flat.getElementsByClass('Chord')[4]), '<music21.chord.Chord D4 F4 A4 D5>')
        self.assertEqual(str(sExcerpt.flat.getElementsByClass('Chord')[5]), '<music21.chord.Chord D4 F4 A4 D5>')
        self.assertEqual(str(sExcerpt.flat.getElementsByClass('Chord')[6]), '<music21.chord.Chord A4 C5 E5>')
        self.assertEqual(str(sExcerpt.flat.getElementsByClass('Chord')[7]), '<music21.chord.Chord A4 C5>')

        self.assertEqual(str(sExcerpt.flat.getElementsByClass('Chord')[8]), '<music21.chord.Chord G4 A4 B4 C5>')
        self.assertEqual(str(sExcerpt.flat.getElementsByClass('Chord')[9]), '<music21.chord.Chord F4 A4 D5>')

        self.assertEqual(str(sExcerpt.flat.getElementsByClass('Chord')[10]), '<music21.chord.Chord F4 G4 A4 D5>')

        self.assertEqual(str(sExcerpt.flat.getElementsByClass('Chord')[11]), '<music21.chord.Chord F4 A4 D5>')
        self.assertEqual(str(sExcerpt.flat.getElementsByClass('Chord')[12]), '<music21.chord.Chord E4 G4 B4 E5>')
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:35,代码来源:testDocumentation.py

示例6: testOverviewMeterB

    def testOverviewMeterB(self):

        sSrc = corpus.parseWork('bach/bwv13.6.xml')

        sPart = sSrc.getElementById('Alto')
        ts = meter.TimeSignature('6/8')

        sMeasures = sPart.flat.notes.makeMeasures(ts)
        #sMeasures.show('t')

        sMeasures.makeTies(inPlace=True)

        # we have the same time signature value, but not the same object
        self.assertEquals(sMeasures[0].timeSignature.numerator, ts.numerator)
        self.assertEquals(sMeasures[0].timeSignature.denominator,
                         ts.denominator)
        # only have ts in first bar
        self.assertEquals(sMeasures[1].timeSignature, None)

        beatStrList = []
        for n in sMeasures.flat.notes:
            bs = n.beatStr
            n.addLyric(bs)
            beatStrList.append(bs)
            #environLocal.printDebug(['offset/parent', n, n.offset, n.parent, beatStr, 'bestMeasure:', beatMeasure])

        self.assertEquals(beatStrList[:10], ['1', '1 2/3', '2 1/3', '1', '1 2/3', '2 1/3', '1', '1 2/3', '2 1/3', '2 2/3'] )

        # TODO: there is a problem here with tied notes
        # the tied note gets the same offset as its origin
        # need to investigate
        #self.assertEquals(beatStrList, ['1', '1 2/3', '2 1/3', '1', '1 2/3', '2 1/3', '1', '1 2/3', '2 1/3', '2 2/3', '1', '1 1/3', '1 2/3', '2', '2 1/3', '1', '1 2/3', '1', '1 2/3', '2 1/3', '1', '1 2/3', '2 1/3', '1', '1', '1 2/3', '2 1/3', '1', '1 2/3', '2 1/3', '1', '1 2/3', '2 1/3', '1', '1 1/3', '1 2/3', '2', '2 1/3', '2 2/3', '1', '1 1/3', '1 2/3', '2 1/3', '1', '1 2/3', '2 1/3', '1', '1 1/3', '1 2/3', '2 1/3', '2 2/3', '1', '1 2/3', '2', '2 1/3'])

        #sMeasures.show()
        post = sMeasures.musicxml
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:35,代码来源:testDocumentation.py

示例7: testIntervalDiversity

    def testIntervalDiversity(self):
        from music21 import note, stream, corpus
        
        s = stream.Stream()
        s.append(note.Note('g#3'))
        s.append(note.Note('a3'))
        s.append(note.Note('g4'))

        id = MelodicIntervalDiversity()
        self.assertEqual(str(id.countMelodicIntervals(s)), "{'m7': [<music21.interval.Interval m7>, 1], 'm2': [<music21.interval.Interval m2>, 1]}")


        s = stream.Stream()
        s.append(note.Note('c3'))
        s.append(note.Note('d3'))
        s.append(note.Note('c3'))
        s.append(note.Note('d3'))

        id = MelodicIntervalDiversity()
        self.assertEqual(str(id.countMelodicIntervals(s)), "{'M2': [<music21.interval.Interval M2>, 3]}")

        self.assertEqual(str(id.countMelodicIntervals(s, ignoreDirection=False)), """{'M-2': [<music21.interval.Interval M-2>, 1], 'M2': [<music21.interval.Interval M2>, 2]}""")

        id = MelodicIntervalDiversity()
        s = corpus.parseWork('hwv56', '1-08')
        #s.show()

        self.assertEqual(str(id.countMelodicIntervals(s.parts[1])), "{'P5': [<music21.interval.Interval P5>, 1], 'P4': [<music21.interval.Interval P4>, 1], 'm3': [<music21.interval.Interval m3>, 1], 'M2': [<music21.interval.Interval M2>, 2]}")

        self.assertEqual(str(id.countMelodicIntervals(s)), "{'M3': [<music21.interval.Interval M3>, 1], 'P4': [<music21.interval.Interval P4>, 5], 'P5': [<music21.interval.Interval P5>, 2], 'M2': [<music21.interval.Interval M2>, 8], 'm3': [<music21.interval.Interval m3>, 3], 'm2': [<music21.interval.Interval m2>, 1]}")
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:30,代码来源:discrete.py

示例8: ex02

def ex02(show=True, *arguments, **keywords):

    
    # This example searches the second violin part for adjacent non-redundant pitch classes that form dominant seventh chords.
    
    from music21 import corpus, chord, stream
    
    if 'op133' in keywords.keys():
        sStream = keywords['op133']
    else:
        sStream = corpus.parseWork('opus133.xml') # load a MusicXML file

    v2Part = sStream[1].getElementsByClass('Measure') # get all measures from the first violin
    
    # First, collect all non-redundant adjacent pitch classes, and store these pitch classes in a list. 
    pitches = []
    for i in range(len(v2Part.pitches)):
        pn = v2Part.pitches[i].name
        if i > 0 and pitches[-1] == pn: continue
        else: pitches.append(pn)
    
    # Second, compare all adjacent four-note groups of pitch classes and determine which are dominant sevenths; store this in a list and display the results. 
    found = stream.Stream()
    for i in range(len(pitches)-3):
        testChord = chord.Chord(pitches[i:i+4])
        if testChord.isDominantSeventh():
            found.append(testChord)
    if show:
        found.show()
开发者ID:msampaio,项目名称:music21,代码行数:29,代码来源:smt2010.py

示例9: januaryThankYou

def januaryThankYou():
    names = ['opus132', 'opus133', 'opus18no3', 'opus18no4', 'opus18no5', 'opus74']
    names += ['opus59no1', 'opus59no2', 'opus59no3']

    for workName in names:
        beethovenScore = corpus.parseWork('beethoven/' + workName, 1)
        for partNum in range(4):
            print(workName, str(partNum))
            thisPart = beethovenScore[partNum]
            display = stream.Stream()
            notes = thisPart.flat.findConsecutiveNotes(skipUnisons = True, skipChords = True,
                       skipOctaves = True, skipRests = True, noNone = True )
            for i in range(len(notes) - 4):
#                if (notes[i].name == 'E-' or notes[i].name == "D#") and notes[i+1].name == 'E' and notes[i+2].name == 'A':
                if notes[i].name == 'E-' and notes[i+1].name == 'E' and notes[i+2].name == 'A':
                        measureNumber = 0
                        for site in notes[i]._definedContexts.getSites():
                            if isinstance(site, stream.Measure):
                                measureNumber = site.number
                                display.append(site)
                        notes[i].lyric = workName + " " + str(thisPart.id) + " " + str(measureNumber)
                        m = stream.Measure()
                        m.append(notes[i])
                        m.append(notes[i+1])
                        m.append(notes[i+2])
                        m.append(notes[i+3])
                        m.insert(0, m.bestClef())
                        display.append(m)
            try:
                display.show()
            except:
                pass
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:32,代码来源:seaverOct2009.py

示例10: runMusicxmlOutPartsBeethoven

 def runMusicxmlOutPartsBeethoven(self):
     '''Loading file and rendering musicxml output for each part: beethoven/opus59no2/movement3
     '''
     x = corpus.parseWork('beethoven/opus59no2/movement3', forceSource=True)
     #problem: doing each part is much faster than the whole score
     for p in x.parts:
         post = p.musicxml
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:7,代码来源:testPerformance.py

示例11: schumann

def schumann(show = True):
    streamObject = corpus.parseWork('schumann/opus41no1', 3)
    streamObject.plot('pitch')

    from music21.humdrum import testFiles as tf
    streamObject = converter.parse(tf.mazurka6)
    streamObject.plot('pitch')
开发者ID:msampaio,项目名称:music21,代码行数:7,代码来源:ismir2010.py

示例12: ex01

def ex01(show=True, *arguments, **keywords):
    # This example extracts first a part, then a measure from a complete score. Next, pitches are isolated from this score as pitch classes. Finally, consecutive pitches from this measure are extracted, made into a chord, and shown to be a dominant seventh chord. 
    
    from music21 import corpus, chord

    if 'op133' in keywords.keys():
        sStream = keywords['op133']
    else:
        sStream = corpus.parseWork('opus133.xml') # load a MusicXML file

    v2Part = sStream[1].getElementsByClass('Measure') # get all measures from the second violin
    if show:
        v2Part[48].show() # render the 48th measure as notation
    
    # create a list of pitch classes in this measure
    pcGroup = [n.pitchClass for n in v2Part[48].pitches] 

    if show:
        print(pcGroup) # display the collected pitch classes as a list
    # extract from the third pitch until just before the end
    pnGroup = [n.nameWithOctave for n in v2Part[48].pitches[2:-1]] 
    qChord = chord.Chord(pnGroup) # create a chord from these pitches
    
    if show:
        qChord.show() # render this chord as notation
        print(qChord.isDominantSeventh()) # find if this chord is a dominant
开发者ID:msampaio,项目名称:music21,代码行数:26,代码来源:smt2010.py

示例13: findRaisedSevenths

def findRaisedSevenths(show=True):
    import music21
    from music21 import corpus, meter, stream

    score = corpus.parseWork('bach/bwv366.xml')  
    ts = score.flat.getElementsByClass(
        meter.TimeSignature)[0]
    #ts.beat.partition(3)

    found = stream.Stream()
    count = 0
    for part in score.getElementsByClass(stream.Part):
        found.insert(count, 
            part.flat.getElementsByClass(
            music21.clef.Clef)[0])
        for i in range(len(part.measures)):
            m = part.measures[i]
            for n in m.notes:
                if n.name == 'C#': 
                    n.addLyric('%s, m. %s' % (          
        part.getInstrument().partName[0], 
        m.measureNumber))
                    n.addLyric('beat %s' %
        ts.getBeat(n.offset))
                    found.insert(count, n)
                    count += 4
    if show:
        found.show('musicxml')
开发者ID:knuton,项目名称:music21,代码行数:28,代码来源:icmc2010.py

示例14: simple4e

def simple4e(show=True):
    # 250.    Identify the longest note in a score
    from music21 import stream
    
    qLenMax = 0
    beethovenQuartet = corpus.parseWork('opus18no1', 3, extList=['xml'])
    maxNote = None
    for part in beethovenQuartet.getElementsByClass(stream.Part):
#         lily.LilyString("{ \\time 2/4 " + str(part.bestClef().lily) + " " + str(part.lily) + "}").showPNG()

        # note: this probably is not re-joining tied notes
        pf = part.flat.notes
        for n in pf:
            if n.quarterLength >= qLenMax and n.isNote==True:
                qLenMax = n.quarterLength
                maxNote = n
        maxNote.color = 'red'

        offset = part.flat.getOffsetByElement(maxNote)
        if offset == None:
            raise Exception('cannot find this note in the Stream: %s' % offset)
        display = part.flat.extractContext(maxNote, before = 4.0, after = 6.0)
               
    if show:
        print('longest duration was: %s quarters long' % (qLenMax))
        lily.LilyString("{ \\time 2/4 " + str(display.bestClef().lily) + " " + str(display.lily) + "}").showPNG()
        display.show()
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:27,代码来源:seaverOct2009.py

示例15: simple4f

def simple4f(show=True):
    # question 19: Calculate pitch-class sets for melodic passages segmented by rests.
    work = 'opus18no1'
    movementNumber = 3
    s = corpus.parseWork(work, movementNumber, extList=['xml'])

    foundSets = []
    candidateSet = []
    for part in s.getElementsByClass(stream.Part):
        eventStream = part.flat.notes
        for i in range(len(eventStream)):
            e = eventStream[i]
            if isinstance(e, music21.note.Rest) or i == len(eventStream)-1:
                if len(candidateSet) > 0:
                    candidateSet.sort()
                    # this removes redundancies for simplicity
                    if candidateSet not in foundSets:
                        foundSets.append(candidateSet)
                    candidateSet = []
            elif isinstance(e, music21.note.Note):      
                if e.pitchClass not in candidateSet:
                    candidateSet.append(e.pitchClass)
    foundSets.sort()

    if show:
        print(foundSets)
开发者ID:bewest,项目名称:music21-bewest.clone,代码行数:26,代码来源:seaverOct2009.py


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