Music21: Loading a Humdrum file

From CCARH Wiki
Revision as of 00:01, 5 August 2011 by Craig (talk | contribs) (Created page with 'From the music21 documentation page: http://mit.edu/music21/doc/html/overviewFormats.html#parsing-humdrum-files To read a Humdrum file into Music21, first you must import…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

From the music21 documentation page:

  http://mit.edu/music21/doc/html/overviewFormats.html#parsing-humdrum-files

To read a Humdrum file into Music21, first you must import the music21 module in python:

  from music21 import *

You can see what functions/variables were imported from music21 by typing this command in the python interpreter:

  dir(music21)

If you want basic online help for a particular function use the help() command:

  help(music21.converter)
NAME
   music21.converter - Public interface for importing 
   various file formats into music21.
  
FILE
   /usr/lib/python2.6/site-packages/music21/converter.py
  
DESCRIPTION
   The most powerful and easy to use tool is the 
   :func:`~music21.converter.parse` function. Simply provide a 
   URL and, if the format is supported, a :class:`~music21.stream.Stream` 
   will be returned.


The music21.converter is used to load in a Humdrum file, either from the hard disk or from a URL:

  work = converter.parse('http://kern.ccarh.org/data?l=beethoven/sonatas&file=sonata01-1.krn')

Note that in order to download data from the internet you must first allow auto-downloading in the music21 environment.

or in the shell, download a humdrum file to the hard disk:

  wget 'http://kern.ccarh.org/data?l=beethoven/sonatas&file=sonata01-1.krn' -O sonata01-1.krn

or with the Humdrum Extras tool humcat:

  humcat h://beethoven/sonatas/sonata01-1.krn > sonata01-1.krn

and then type in python:

  work = converter.parse('sonata01-1.krn')


Once the file has been loaded you can display it with the show command:

  work.show()