The music21 corpus provides a collection of freely distributable music in MusicXML, Humdrum, and other representations. The corpus package provides an interface to this data.
Return a parsed stream from a converter by providing only a work name. If forceSource is True, the original file will always be loaded and pickled files, if available, will be ignored.
>>> aStream = parseWork('opus74no1/movement3')
Search the corpus and return either a list of file paths or, if there is a single match, a single file path. If no matches are found an Exception is raised.
>>> import os
>>> a = getWork('opus74no2', 4)
>>> a.endswith(os.path.sep.join(['haydn', 'opus74no2', 'movement4.xml']))
True
>>> a = getWork(['haydn', 'opus74no2', 'movement4.xml'])
>>> a.endswith(os.path.sep.join(['haydn', 'opus74no2', 'movement4.xml']))
True
>>> a = getBachChorales()
>>> len(a) > 10
True
>>> a = getBachChorales('krn')
>>> len(a) > 10
False
>>> a = getBachChorales('xml')
>>> len(a) > 400
True
>>> a = getBeethovenStringQuartets()
>>> len(a) > 10
True
>>> a = getBeethovenStringQuartets('krn')
>>> len(a) < 10 and len(a) > 0
True
>>> a = getBeethovenStringQuartets('xml')
>>> len(a) > 400
False
Return all components of the corpus that match a composer’s name. An extList, if provided, defines which extensions are returned. An extList of None returns all extensions.
>>> a = getComposer('beethoven')
>>> len(a) > 10
True
>>> a = getComposer('mozart')
>>> len(a) > 10
True
>>> a = getComposer('bach', 'krn')
>>> len(a) < 10
True
>>> a = getComposer('bach', 'xml')
>>> len(a) > 10
True
Given the name of a composer, get the path to the top-level directory of that composer
>>> import os
>>> a = getComposerDir('beethoven')
>>> a.endswith(os.path.join('corpus', os.sep, 'beethoven'))
True
>>> a = getComposerDir('bach')
>>> a.endswith(os.path.join('corpus', os.sep, 'bach'))
True
>>> a = getComposerDir('mozart')
>>> a.endswith(os.path.join('corpus', os.sep, 'mozart'))
True
>>> a = getComposerDir('luca')
>>> a.endswith(os.path.join('corpus', os.sep, 'luca'))
True
Get all paths in the corpus that match a known extension, or an extenion provided by an argument.
>>> a = getPaths()
>>> len(a) > 30
True
>>> a = getPaths('krn')
>>> len(a) >= 4
True
Get all paths in the virtual corpus that match a known extension. An extension of None will return all known extensions.
>>> len(getVirtualPaths()) > 6
True
Given as work name, search all virtual works and see if there is a match. Return a list of one or more work URLs.
>>> getVirtualWorkList('bach/bwv1007/prelude')
['http://kern.ccarh.org/cgi-bin/ksdata?l=users/craig/classical/bach/cello&file=bwv1007-01.krn&f=xml']
>>> getVirtualWorkList('junk')
[]
Search the corpus and return a list of works, always in a list. If no matches are found, an empty list is returned.
>>> len(getWorkList('beethoven/opus18no1'))
8
>>> len(getWorkList('beethoven/opus18no1', 1))
2
>>> len(getWorkList('beethoven/opus18no1', 1, '.krn'))
1
>>> len(getWorkList('beethoven/opus18no1', 1, '.xml'))
1
>>> len(getWorkList('beethoven/opus18no1', 0, '.xml'))
0