Exemplo n.º 1
0
    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,
            -1,
        )

        self.assertEqual(str(richMetadata.timeSignatureFirst), '2/4')

        score = corpus.parse('bwv66.6')
        richMetadata = metadata.RichMetadata()
        richMetadata.merge(score.metadata)

        richMetadata.update(score)
        self.assertEqual(
            richMetadata.keySignatureFirst,
            3,
        )
        self.assertEqual(str(richMetadata.timeSignatureFirst), '4/4')
Exemplo n.º 2
0
    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>',
        )
Exemplo n.º 3
0
 def parseScoreInsideOpus(self, score, scoreNumber):
     # scoreNumber is a zeroIndexed value.
     # score.metadata.number is the retrieval code; which is
     # probably 1 indexed, and might have gaps
     from music21 import metadata
     try:
         # upgrade metadata to richMetadata
         richMetadata = metadata.RichMetadata()
         richMetadata.merge(score.metadata)
         richMetadata.update(score)  # update based on Stream
         if score.metadata is None or score.metadata.number is None:
             environLocal.printDebug(
                 'addFromPaths: got Opus that contains '
                 'Streams that do not have work numbers: '
                 '{0}'.format(self.filePath))
         else:
             # update path to include work number
             corpusPath = metadata.bundles.MetadataBundle.corpusPathToKey(
                 self.cleanFilePath,
                 number=score.metadata.number,
             )
             environLocal.printDebug(f'addFromPaths: storing: {corpusPath}')
             metadataEntry = metadata.bundles.MetadataEntry(
                 sourcePath=self.cleanFilePath,
                 number=score.metadata.number,
                 metadataPayload=richMetadata,
             )
             self.results.append(metadataEntry)
     except Exception as exception:  # pylint: disable=broad-except
         environLocal.warn('Had a problem with extracting metadata '
                           'for score {0} in {1}, whole opus ignored: '
                           '{2}'.format(scoreNumber, self.filePath,
                                        str(exception)))
         environLocal.printDebug(traceback.format_exc())
Exemplo n.º 4
0
 def parseNonOpus(self, parsedObject):
     from music21 import metadata
     try:
         corpusPath = metadata.bundles.MetadataBundle.corpusPathToKey(
             self.cleanFilePath)
         if parsedObject.metadata is not None:
             richMetadata = metadata.RichMetadata()
             richMetadata.merge(parsedObject.metadata)
             richMetadata.update(parsedObject)  # update based on Stream
             environLocal.printDebug(
                 f'updateMetadataCache: storing: {corpusPath}')
             metadataEntry = metadata.bundles.MetadataEntry(
                 sourcePath=self.cleanFilePath,
                 metadataPayload=richMetadata,
                 corpusName=self.corpusName,
             )
             self.results.append(metadataEntry)
         else:
             environLocal.printDebug(
                 'addFromPaths: got stream without metadata, '
                 'creating stub: {0}'.format(
                     common.relativepath(self.cleanFilePath)))
             metadataEntry = metadata.bundles.MetadataEntry(
                 sourcePath=self.cleanFilePath,
                 metadataPayload=None,
                 corpusName=self.corpusName,
             )
             self.results.append(metadataEntry)
     except Exception:  # wide catch is fine. pylint: disable=broad-except
         environLocal.warn('Had a problem with extracting metadata '
                           'for {0}, piece ignored'.format(self.filePath))
         environLocal.warn(traceback.format_exc())
Exemplo n.º 5
0
 def testRichMetadata02(self):
     from music21 import VERSION
     from music21 import corpus
     from music21 import metadata
     from music21 import test
     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)
     self.assertMultiLineEqual(
         freezeThaw.JSONFreezer(richMetadata).prettyJson,
         test.dedent(
             '''
             {
                 "__attr__": {
                     "_urls": [],
                     "_workIds": {
                         "movementName": {
                             "__attr__": {
                                 "_data": "bwv66.6.mxl"
                             },
                             "__class__": "music21.metadata.primitives.Text"
                         }
                     },
                     "ambitus": {
                         "__attr__": {
                             "_priority": 0,
                             "offset": 0.0
                         },
                         "__class__": "music21.interval.Interval"
                     },
                     "contributors": [],
                     "keySignatureFirst": "<music21.key.Key of f# minor>",
                     "keySignatures": [
                         "<music21.key.Key of f# minor>"
                     ],
                     "noteCount": 165,
                     "numberOfParts": 4,
                     "pitchHighest": "E5",
                     "pitchLowest": "F#2",
                     "quarterLength": 36.0,
                     "sourcePath": "bach/bwv66.6.mxl",
                     "tempos": [],
                     "timeSignatureFirst": "4/4",
                     "timeSignatures": [
                         "4/4"
                     ]
                 },
                 "__class__": "music21.metadata.RichMetadata",
                 "__version__": [
                     ''' + str(VERSION[0]) + ''',
                     ''' + str(VERSION[1]) + ''',
                     ''' + str(VERSION[2]) + '''
                 ]
             }
             ''', ))
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    def testWorkIds(self):
        from music21 import corpus
        from music21 import metadata

        opus = corpus.parse('essenFolksong/teste')
        self.assertEqual(len(opus), 8)

        score = opus.getScoreByNumber(4)
        self.assertEqual(score.metadata.localeOfComposition,
                         'Asien, Ostasien, China, Sichuan')

        richMetadata = metadata.RichMetadata()
        richMetadata.merge(score.metadata)
        richMetadata.update(score)

        self.assertEqual(richMetadata.localeOfComposition,
                         'Asien, Ostasien, China, Sichuan')