This brief tutorial module illustrates how to import music notation files into the music21 environment.
There are two main approaches to importing notation: importing from a file on your computer, or from a file in the music21 corpus.
To import from a file (whether you created it or downloaded it), replace the directory in quotation marks with the location on your computer where your file is saved:
from music21 import * my_work = converter.parse('/Users/username/my_score_file.xml')
To import a file from the corpus (in this case, the song “Lift Every Voice and Sing” composed by J. Rosamond Johnson with lyrics by James Weldon Johnson):
from music21 import * my_work = corpus.parse('johnson_j_r/lift_every_voice.mxl')
If we want to view our notation, we can use the following code:
The notation should appear in the MusicXML reader you specified during the music21 configuration process.