How to use the music21.corpus.parse function in music21

To help you get started, we’ve selected a few music21 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cuthbertLab / music21 / music21 / metadata / testMetadata.py View on Github external
def testRichMetadata02(self):
        from music21 import corpus
        from music21 import metadata

        score = corpus.parse('bwv66.6')
        richMetadata = metadata.RichMetadata()
        richMetadata.merge(score.metadata)
        richMetadata.update(score)
        self.assertEqual(richMetadata.noteCount, 165)
        self.assertEqual(richMetadata.quarterLength, 36.0)
github cuthbertLab / music21 / music21 / demos / ismir2011.py View on Github external
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)
github cuthbertLab / music21 / music21 / features / base.py View on Github external
def x_testRegionClassificationJSymbolicA(self):  # pragma: no cover
        '''
        Demonstrating writing out data files for feature extraction. Here,
        features are used from the jSymbolic library.
        '''
        from music21 import features

        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'], 'jSymbolic')

        oChina1 = corpus.parse('essenFolksong/han1')
        oChina2 = corpus.parse('essenFolksong/han2')

        oMitteleuropa1 = corpus.parse('essenFolksong/boehme10')
        oMitteleuropa2 = corpus.parse('essenFolksong/boehme20')

        ds = features.DataSet(classLabel='Region')
        ds.addFeatureExtractors(featureExtractors)

        # add works, defining the class value
        for o, name in [(oChina1, 'han1'),
                        (oChina2, 'han2')]:
            for w in o.scores:
                songId = 'essenFolksong/%s-%s' % (name, w.metadata.number)
                ds.addData(w, classValue='China', id=songId)

        for o, name in [(oMitteleuropa1, 'boehme10'),
                        (oMitteleuropa2, 'boehme20')]:
github cuthbertLab / music21 / music21 / corpus / base.py View on Github external
def testWTCImport01(self):
        from music21 import corpus
        score = corpus.parse('bach/bwv846', 1)
        self.assertEqual(
            score.metadata.title, 
            'WTC I: Prelude and Fugue in C major',
            )
        self.assertEqual(score.metadata.movementNumber, '1')
github cuthbertLab / music21 / music21 / graph / plots_old.py View on Github external
def testPlotHorizontalBarPitchSpaceOffset(self):
        a = corpus.parse('bach/bwv57.8')
        # do not need to call flat version
        b = PlotHorizontalBarPitchSpaceOffset(a.parts[0], title='Bach (soprano voice)')
        b.process()
        

        b = PlotHorizontalBarPitchSpaceOffset(a, title='Bach (all parts)')
        b.process()
github cuthbertLab / music21-tools / trecento / medren.py View on Github external
def xtestTransferTies(self):
        from music21 import corpus
        testPiece = corpus.parse('luca/gloria')
        transferTies(testPiece, inPlace=True)
        testPiece.show()
github cuthbertLab / music21 / music21 / midi / realtime.py View on Github external
from music21 import corpus
        import random

        def busyCounter(timeList):
            timeCounter_inner = timeList[0]
            timeCounter_inner.times += timeCounter_inner.updateTime
            print('hi! waited %d milliseconds' % (timeCounter_inner.times))

        class Mock:
            times = 0

        timeCounter = Mock()
        timeCounter.updateTime = 500  # pylint: disable=attribute-defined-outside-init

        b = corpus.parse('bach/bwv66.6')
        keyDetune = []
        for i in range(127):
            keyDetune.append(random.randint(-30, 30))
        for n in b.flat.notes:
            n.pitch.microtone = keyDetune[n.pitch.midi]
        sp = StreamPlayer(b)
        sp.play(busyFunction=busyCounter, busyArgs=[timeCounter], busyWaitMilliseconds=500)
github cuthbertLab / music21 / music21 / demos / icmc2011.py View on Github external
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.stream()
        nLast = exFlatNotes[-1]

        for i, n in enumerate(exFlatNotes):
            if i < len(exFlatNotes) - 1:
                nNext = exFlatNotes[i + 1]
            else: continue

            if n.lyrics:
                nStart = n
            # if next is a begin, then this is an end
            elif nStart is not None and nNext.lyrics and n.tie is None:
                nEnd = n
            elif nNext is nLast:
                nEnd = n
            if nStart is not None and nEnd is not None:
github cuthbertLab / music21 / music21 / alpha / trecento / quodJactatur.py View on Github external
def getQJ():
    '''
    loads Quod Jactatur from the corpus, transposes it to
    an easy to view range and stores it in the cache.

    >>> from music21.alpha.trecento import quodJactatur
    >>> qj = quodJactatur.getQJ()
    >>> qj.flat.notesAndRests[0]
    
    '''

    qj = corpus.parse("ciconia/quod_jactatur")
    qjPart = qj.getElementsByClass(stream.Part)[0]
    qjPart.transpose("P-8", inPlace=True)
    qjPart.replace(qjPart.flat.getElementsByClass(clef.Clef)[0], clef.BassClef())
    cachedParts['1-0-False-False'] = copy.deepcopy(qjPart)
    return qjPart
github cuthbertLab / music21 / music21 / demos / gatherAccidentals.py View on Github external
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'])