def testBasic(self): from music21 import converter, corpus a = converter.parse(corpus.getWork('haydn/opus1no1/movement4.xml')) post = assembleLyrics(a) self.assertEqual(post, '') # no lyrics! a = converter.parse(corpus.getWork('luca/gloria')) post = assembleLyrics(a) self.assertTrue(post.startswith('Et in terra pax hominibus bone voluntatis'))
def testBasic(self): from music21 import converter, corpus a = converter.parse(corpus.getWork('haydn/opus74no2/movement4.xml')) post = assembleLyrics(a) self.assertEqual(post, '') # no lyrics! a = converter.parse(corpus.getWork('luca/gloria')) post = assembleLyrics(a) self.assertEqual(post.startswith('Et in terra pax hominibus bone voluntatis'), True)
def testHandelImport(self): # can get a single file just by file name unused_fp = corpus.getWork('hwv56/movement1-01')# fpCollection = corpus.getComposer('handel') self.assertEqual(len(fpCollection) >= 1, True) fpCollection = corpus.getComposer('handel', ['md']) self.assertEqual(len(fpCollection) >= 1, True)
def testHandelImport(self): # can get a single file just by file name unused_fp = corpus.getWork('hwv56/movement1-01') # fpCollection = corpus.getComposer('handel') self.assertEqual(len(fpCollection) >= 1, True) fpCollection = corpus.getComposer('handel', ['md']) self.assertEqual(len(fpCollection) >= 1, True)
def testEssenImport(self): # can get a single file just by file name filePath = corpus.getWork('altdeu10') self.assertEqual(filePath.name, 'altdeu10.abc') self.assertEqual(filePath.parent.name, 'essenFolksong') filePathCollection = corpus.getComposer('essenFolksong') self.assertEqual(len(filePathCollection), 31) filePathCollection = corpus.getComposer('essenFolksong', ['abc']) self.assertEqual(len(filePathCollection), 31)
def testDesPrezImport(self): # can get a single file just by file name filePath = corpus.getWork("fortunaDunGranTempo") filePath = re.sub(r"\\", "/", filePath) self.assertEqual(filePath.endswith("josquin/fortunaDunGranTempo.abc"), True) filePathCollection = corpus.getComposer("josquin") self.assertEqual(len(filePathCollection) >= 8, True) filePathCollection = corpus.getComposer("josquin", ["abc"]) self.assertEqual(len(filePathCollection) >= 8, True)
def testDesPrezImport(self): # can get a single file just by file name filePath = str(corpus.getWork('fortunaDunGranTempo')) filePath = re.sub(r'\\', '/', filePath) self.assertTrue(filePath.endswith('josquin/fortunaDunGranTempo.abc')) filePathCollection = corpus.getComposer('josquin') self.assertGreaterEqual(len(filePathCollection), 8) filePathCollection = corpus.getComposer('josquin', ['abc']) self.assertGreaterEqual(len(filePathCollection), 8)
def testEssenImport(self): # can get a single file just by file name filePath = corpus.getWork('altdeu10') self.assertTrue(filePath.endswith('essenFolksong/altdeu10.abc') or filePath.endswith(r'essenFolksong\altdeu10.abc')) filePathCollection = corpus.getComposer('essenFolksong') self.assertEqual(len(filePathCollection), 31) filePathCollection = corpus.getComposer('essenFolksong', ['abc']) self.assertEqual(len(filePathCollection), 31)
def testDesPrezImport(self): # can get a single file just by file name filePath = str(corpus.getWork('fortunaDunGranTempo')) filePath = re.sub(r'\\', '/', filePath) self.assertEqual(filePath.endswith('josquin/fortunaDunGranTempo.abc'), True) filePathCollection = corpus.getComposer('josquin') self.assertEqual(len(filePathCollection) >= 8, True) filePathCollection = corpus.getComposer('josquin', ['abc']) self.assertEqual(len(filePathCollection) >= 8, True)
def testEssenImport(self): # can get a single file just by file name filePath = corpus.getWork("altdeu10") self.assertTrue( filePath.endswith("essenFolksong/altdeu10.abc") or filePath.endswith(r"essenFolksong\altdeu10.abc") ) filePathCollection = corpus.getComposer("essenFolksong") self.assertEqual(len(filePathCollection), 31) filePathCollection = corpus.getComposer("essenFolksong", ["abc"]) self.assertEqual(len(filePathCollection), 31)
def testGetPaths(self): for known in [ 'schumann_clara/opus17/movement3.xml', 'schoenberg/opus19/movement2.mxl', 'palestrina/agnus_02.krn', ]: a = corpus.getWork(known) # make sure it is not an empty list self.assertTrue(a) workSlashes = re.sub(r'\\', '/', str(a)) self.assertTrue(workSlashes.lower().endswith(known.lower()), (workSlashes, known))
def testGetPaths(self): for known in [ "schumann_clara/opus17/movement3.xml", "schoenberg/opus19/movement2.mxl", "palestrina/agnus_0.krn", ]: a = corpus.getWork(known) # make sure it is not an empty list self.assertNotEqual(len(a), 0) workSlashes = re.sub(r"\\", "/", a) self.assertTrue(workSlashes.lower().endswith(known.lower()), (workSlashes, known))
def testGetPaths(self): for known in ['haydn/opus74no2/movement4.mxl', 'beethoven/opus18no3.mxl', 'beethoven/opus59no1/movement2.mxl', 'mozart/k80/movement4.mxl', 'schumann/opus41no1/movement5.mxl', ]: a = corpus.getWork(known) # make sure it is not an empty list self.assertNotEqual(len(a), 0) workSlashes = re.sub(r'\\', '/', a) self.assertEqual(workSlashes.endswith(known), True)
def testGetPaths(self): for known in [ 'haydn/opus74no2/movement4.mxl', 'beethoven/opus18no3.mxl', 'beethoven/opus59no1/movement2.mxl', 'mozart/k80/movement4.mxl', 'schumann/opus41no1/movement5.mxl', ]: a = corpus.getWork(known) # make sure it is not an empty list self.assertNotEqual(len(a), 0) workSlashes = re.sub(r'\\', '/', a) self.assertEqual(workSlashes.endswith(known), True)
def main(): trecentoFiles = corpus.getWork('trecento') for t in trecentoFiles: print(t) tparsed = converter.parse(t) for p in tparsed.parts: ambi = p.analyze('ambitus') distance = ambi.diatonic.generic.undirected if distance >= 15: print("************ GOT ONE!: {0} ************".format(ambi)) elif distance >= 9: print(ambi) else: pass
def main(): trecentoFiles = corpus.getWork("trecento") for t in trecentoFiles: print(t) tparsed = converter.parse(t) for p in tparsed.parts: ambi = p.analyze("ambitus") distance = ambi.diatonic.generic.undirected if distance >= 15: print("************ GOT ONE!: %r ************".format(ambi)) elif distance >= 9: print(ambi) else: pass
def simple4g(): # question 62: Determine how often a pitch is followed immediately by the same pitch work = 'opus18no1' movements = corpus.getWork(work) movementNumber = 3 s = converter.parse(movements[movementNumber - 1]) count = 0 for part in s: noteStream = part.flat.getElementsByClass(music21.note.Note) for i in range(len(noteStream) - 1): # assuming spelling does not count if noteStream[i].midi == noteStream[i + 1].midi: count += 1 print('repeated pitches for %s, movement %s: %s counts' % (work, movementNumber, count))
def simple4g(): # question 62: Determine how often a pitch is followed immediately by the same pitch work = 'opus18no1' movements = corpus.getWork(work) movementNumber = 3 s = converter.parse(movements[movementNumber-1]) count = 0 for part in s: noteStream = part.flat.getElementsByClass(note.Note) for i in range(len(noteStream)-1): # assuming spelling does not count if noteStream[i].midi == noteStream[i+1].midi: count += 1 print('repeated pitches for %s, movement %s: %s counts' % (work, movementNumber, count))
def testOpusImport(self): from music21 import corpus from music21 import abcFormat # 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 = abcFormat.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)
# DISCLAIMER ABOUT THE CODE ############################### # Andrea Poltronieri 2020 import numpy as np from vis.models.indexed_piece import Importer import music21 from music21 import instrument, corpus import csv DATASET_PATH = "" OUTPUT_PATH = "" score_1 = "/Users/andrea/Documents/DHDK/Thesis/Ontology Data/BWV_1.6.mxl" score_2 = corpus.getWork('bwv1.6') def get_metadata(music_score): song = music21.converter.parse(music_score) undefined = 'undefined' if song.metadata.composers: composers = ('composers', song.metadata.composers) elif not song.metadata.composers: composers = ('composers', undefined) if song.metadata.title: title = ('title', song.metadata.composers) elif not song.metadata.title: title = ('title', undefined) if song.metadata.alternativeTitle: alternativeTitle = ('alternativeTitle', song.metadata.alternativeTitle) elif not song.metadata.alternativeTitle: