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. To see complete listing of works in the music21 corpus, visit Corpus Reference Index.
Search the corpus, then the virtual corpus, for a work. Return a parsed music21.stream.Stream. 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, then the virtual corpus, for a work. This method will 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
Return all Bach chorales.
>>> a = getBachChorales()
>>> len(a) > 10
True
>>> a = getBachChorales('krn')
>>> len(a) > 10
False
>>> a = getBachChorales('xml')
>>> len(a) > 400
True
Return all Beethoven String Quartets.
>>> 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 a work name, search all virtual works and return a list of URLs for any matches.
>>> getVirtualWorkList('bach/bwv1007/prelude')
['http://kern.ccarh.org/cgi-bin/ksdata?l=cc/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
Return a data dictionary for all works in the corpus and (optionally) the virtual corpus. Returns a lost of reference dictionaries, each each dictionary for a each composer. A ‘works’ dictionary for each composer provides references to dictionaries for all associated works.
>>> post = getWorkReferences()