Music21: Loading a Humdrum file

From CCARH Wiki
Jump to navigation Jump to search

From the music21 documentation page:

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:


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

   music21.converter - Public interface for importing 
   various file formats into music21.
   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:`` 
   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('')

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 '' -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: