Music Level 1

In this first exercise you will learn how to encode music in MEI. All of the exercises below will have to be encoded within the <music> element. In the tutorial "Creating a new MEI Document" you learned how to start a new MEI file. Take the file you created there or start another new document (for now, don't worry about the <meiHead> part, which can remain empty. You will learn how to create the header in the tutorial "Exploring the MEI Header". Your empty file should look like this:

<mei>
    <meiHead>
        <fileDesc>
            <titleStmt>
                <title></title>
            </titleStmt>
            <pubStmt/>
        </fileDesc>
    </meiHead>
    <music/>
</mei>

We will now start to encode some notes of the song "Don't worry, be happy".

1) Encoding of preliminary information

As has been mentioned several times in the previous sections of the tutorial, it is necessary to encode a number of elements before encoding the notes themselves. You may recall that we covered the child elements from <body> to <section> and explained the use of the <section> element in the chapter "Common Structure and Elements". So you should now add the elements <body>, <mdiv>, <score> and <section> (in this sequence) into the <music> element of your empty MEI file. Next, insert a <measure> element into the <section> element (recall that <section> contains the actual musical data). A <measure> element always requires a <staff> child element. Of course, you could encode multiple staves, but for now let's start with just one. The <staff> element requires a <layer> child element. Once again, you could encode more than one layer, but to keep things simple, we’ll begin with a single layer, which contains a stream of musical events on a staff. So, at this point, your <measure> element should contain a <staff> and <layer> element.


2) Note

A note has to be defined with its elementary attributes: @pname (pitch name), @oct(octave) and @dur (duration). The first note of the example looks like this:

music notation

The Acoustical Society of America adopted a system that numbers the octaves from the lowest to the highest. The following octave would be designated as C4 to B4:

music notation

Special hint for German encoders: Each "H" is designated as a "B" (<note pname="b">). What is called "B" in German would be encoded like this: <note pname="b" accid="f">.

Key signatures are encoded by using the @accid (accidental) attribute. The "f" stands for "flat", "s" for "sharp" and "n" for "natural".

To see the result, click the button below. But first try it yourself.


3) Beam

music notation

The first note of the measure, which you've already encoded, is followed by two beamed eighth notes. The <beam> element is realized as a grouping element around the two notes. Encode the two notes first and nest a <beam> element around them afterwards.

Note for oXygen users: If you select the note elements and use the short cut Ctrl + E (or Cmd + E on the Mac), you will get a list of elements which can be legitimately wrapped around them. The <beam> element will be in that list.


4) Rest

To complete the measure, we need two quarter rests. Like a note, the <rest> element will be encoded with specific attributes. In this case, we need to encode the durations of the rests.

music notation


5) Staff Definition (staffDef)

As you might have noticed, we haven't yet encoded the clef and meter information notated at the beginning of the measure. In MEI it is recommended that a staff definition, represented by the <staffDef> element, be encoded directly preceding the <section> element. Please add a <staffDef> element with its common attributes to your MEI file.


6) Name or number (@n)

The next step will be to add another measure. The second one has the same content as the first measure and will be encoded right after the first one. To distinguish them, we will use the @n attribute to number the measures.

music notation


7) Lyrics

So far, so good! But to be able to sing the song, we need some text. So the next step will deal with some lyrics.

The easiest way to encode lyrics is to add @syl attributes to <note> elements.

music notation


8) Chords

Now you have successfully encoded two measures of notes and text in MEI. Congratulations!

In the next step we will expand upon this a bit:

Measure 10 of the song includes some chords, accidentals and dotted rhythm. To simplify matters, the first image will show only the notes, without rhythm or accidentals. Chords must be encoded with a <chord> element around the <note> elements. If there are beamed chords, encode the beam first, then the chords, and finally the notes.

Try to encode the measure yourself.

music notation


9) Rhythm

Now let´s encode the dotted rhythms by adding a @dots attribute to the <note> element. The value represents the number of augmentation dots accompanying the note and must be an integer less than or equal to 4. Note also that the number of beamed groups has changed. Insert the second beam and add a @dots attribute to the relevant notes. Don't worry about the accidentals yet; we'll get to those in step 10.

music notation


10) Accidentals

music notation

Finally, let's add the accidentals, starting with the E flat:

music notation

MEI offers a lot of choices in the encoding of musical phenomena. In this case, you get to decide whether the accidental should be encoded as an attribute or as an element. Have a look at step 2 of this level again to refresh your knowledge of the encoding of accidentals as attributes. If you prefer to encode the accidental as an element - perhaps if you'd like to specify the location of the accidental by the use of the @place attribute - you'll have to encode an <accid> child element inside the <note> element.

Now you've encoded the entire measure. Well done!

If you'd like to learn more about the encoding of music with MEI, please continue on to level 2!