Exemple #1
0
    def testTuplets(self):

        from music21 import abc
        from music21.abc import testFiles

        tf = testFiles.testPrimitiveTuplet
        af = abc.ABCFile()
        s = abcToStreamScore(af.readstr(tf))
        match = []
        # match strings for better comparison
        for n in s.flat.notesAndRests:
            match.append(str(n.quarterLength))
        self.assertEqual(match, [
            '0.333333333333', '0.333333333333', '0.333333333333', '0.2', '0.2',
            '0.2', '0.2', '0.2', '0.166666666667', '0.166666666667',
            '0.166666666667', '0.166666666667', '0.166666666667',
            '0.166666666667', '0.142857142857', '0.142857142857',
            '0.142857142857', '0.142857142857', '0.142857142857',
            '0.142857142857', '0.142857142857', '0.666666666667',
            '0.666666666667', '0.666666666667', '0.666666666667',
            '0.666666666667', '0.666666666667', '0.0833333333333',
            '0.0833333333333', '0.0833333333333', '0.0833333333333',
            '0.0833333333333', '0.0833333333333', '0.0833333333333',
            '0.0833333333333', '0.0833333333333', '0.0833333333333',
            '0.0833333333333', '0.0833333333333', '2.0'
        ])
Exemple #2
0
    def testChords(self):

        from music21 import abc
        from music21.abc import testFiles

        tf = testFiles.aleIsDear
        af = abc.ABCFile()
        s = abcToStreamScore(af.readstr(tf))
        #s.show()
        self.assertEqual(len(s.parts), 2)
        self.assertEqual(len(s.parts[0].flat.notesAndRests), 111)
        self.assertEqual(len(s.parts[1].flat.notesAndRests), 127)

        # chords are defined in second part here
        self.assertEqual(len(s.parts[1].flat.getElementsByClass('Chord')), 32)

        # check pitches in chords; sharps are applied due to key signature
        match = [
            p.nameWithOctave
            for p in s.parts[1].flat.getElementsByClass('Chord')[4].pitches
        ]
        self.assertEqual(match, ['F#4', 'D4', 'B3'])

        match = [
            p.nameWithOctave
            for p in s.parts[1].flat.getElementsByClass('Chord')[3].pitches
        ]
        self.assertEqual(match, ['E4', 'C#4', 'A3'])
Exemple #3
0
    def testGetMetaData(self):
        '''
        NB -- only title is checked. not meter or key
        '''

        from music21 import abc
        from music21.abc import testFiles

        for (tf, titleEncoded, unused_meterEncoded, unused_keyEncoded) in [
            (testFiles.fyrareprisarn, 'Fyrareprisarn', '3/4', 'F'),
            (testFiles.mysteryReel, 'Mystery Reel', 'C|', 'G'),
            (
                testFiles.aleIsDear,
                'The Ale is Dear',
                '4/4',
                'D',
            ),
            (testFiles.kitchGirl, 'Kitchen Girl', '4/4', 'D'),
            (testFiles.williamAndNancy, 'William and Nancy', '6/8', 'G'),
        ]:

            af = abc.ABCFile()
            ah = af.readstr(tf)  # returns an ABCHandler object
            s = abcToStreamScore(ah)

            self.assertEqual(s.metadata.title, titleEncoded)
Exemple #4
0
    def testBasic(self):
        from music21 import abc
        #from music21.abc import testFiles

        for tf in [
                #             testFiles.fyrareprisarn,
                #             testFiles.mysteryReel,
                #             testFiles.aleIsDear,
                #             testFiles.testPrimitive,
                #            testFiles.fullRiggedShip,
                #            testFiles.kitchGirl,
                #testFiles.morrisonsJig,
                #            testFiles.hectorTheHero,
                #             testFiles.williamAndNancy,
                #            testFiles.theAleWifesDaughter,
                #            testFiles.theBeggerBoy,
                #            testFiles.theAleWifesDaughter,
                #            testFiles.draughtOfAle,

                #            testFiles.testPrimitiveTuplet,
                #            testFiles.testPrimitivePolyphonic,
        ]:
            af = abc.ABCFile()
            ah = af.readstr(tf)  # return handler, processes tokens
            s = abcToStreamScore(ah)
            s.show()
Exemple #5
0
    def testLyrics(self):
        # TODO

        from music21 import abc
        from music21.abc import testFiles

        tf = testFiles.sicutRosa
        af = abc.ABCFile()
        unused_s = abcToStreamScore(af.readstr(tf))
Exemple #6
0
    def testBasic(self):
        from music21 import abc
        from music21.abc import translate
        from music21.musicxml import m21ToString

        af = abc.ABCFile()

        for tf in ALL:
            ah = af.readstr(tf)
            environLocal.printDebug([ah.getTitle()])
            s = translate.abcToStreamScore(ah)
            # run musicxml processing to look for internal errors
            unused_out = m21ToString.fromMusic21Object(s)
Exemple #7
0
    def testMultiVoice(self):

        from music21 import abc
        from music21.abc import testFiles

        tf = testFiles.testPrimitivePolyphonic

        af = abc.ABCFile()
        s = abcToStreamScore(af.readstr(tf))

        self.assertEqual(len(s.parts), 3)
        # must flatten b/c  there are measures
        self.assertEqual(len(s.parts[0].flat.notesAndRests), 6)
        self.assertEqual(len(s.parts[1].flat.notesAndRests), 17)
        self.assertEqual(len(s.parts[2].flat.notesAndRests), 6)
Exemple #8
0
    def testOpusImport(self):
        from music21 import corpus
        from music21 import abc

        # replace w/ ballad80, smaller or erk5
        fp = corpus.getWork('essenFolksong/teste')
        self.assertTrue(
            fp.endswith('essenFolksong/teste.abc')
            or fp.endswith(r'essenFolksong\teste.abc'))

        af = abc.ABCFile()
        af.open(fp)  # return handler, processes tokens
        ah = af.read()
        af.close()

        op = abcToStreamOpus(ah)
        #op.scores[3].show()
        self.assertEqual(len(op), 8)