[icon]

GNU LilyPond

-- --

What is LilyPond
Home
Examples
Templates
Download
GNU/Linux binaries
Windows binaries
Source code
Documentation
Tutorial
Manual
Glossary
Index

Support
Mailing lists
Search
WikiWiki

External sites
lilypond.org/stable
lilypond.org/development
savannah.gnu.org
ftp.lilypond.org
Mutopia
Other music online

A melody with chords

In this section we show how to typeset a melody with chord accompaniment. This file is included as input/tutorial/flowing.ly.

     \include "paper16.ly"
     melody = \notes \relative c' {
             \partial 8
             \key c \minor
             g8 |
             c4 c8 d es-[ -( d-]-) c4 | f4 f8 g es-[-( d-)-] c g |
             c4 c8 d es-[ -( d-]-) c4 | d4 es8 d c4.
             \bar "|."
     }
     
     accompaniment =\chords {
             r8
             c2:3- f:3-.7 d:min es4 c8:min r8
             c2:min f:min7 g:7^3.5 c:min }
     
     \score {
             \simultaneous {
               %\accompaniment
               \context ChordNames \accompaniment
                 \context Staff = mel {
                   \melody
                 }
     
             }
             \midi  { \tempo 4=72 }
             \paper { linewidth = 10.0\cm }
     }
     

The result would look this.

[picture of music]

We will dissect this file line by line.



     
             \include "paper16.ly"
     
     
Smaller size (suitable for inclusion in a book).



     
             melody = \notes \relative c' {
     
     
The structure of the file will be the same as the previous one: a \score block with music in it. To keep things readable, we will give different names to the different parts of music, and use the names to construct the music within the score block.



             \partial 8
     

The piece starts with an anacrusis (or "pickup") of one eighth.





     
             c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
             c4 c8 d [es () d] c4 | d4 es8 d c4.
             \bar "|."
     
     

We use explicit beaming. Since this is a song, we turn automatic beams off and use explicit beaming where needed.



     
             }
     
     
This ends the definition of melody.



     
             text = \lyrics {
     
     
This defines the lyrics, similar to what we have seen before.



     
             accompaniment =\chords {
     
     
We'll put chords over the music. To enter them, we use a special mode analogous to \lyrics and \notes mode, where you can give the names of the chords you want instead of listing the notes comprising the chord.



     
             r8
     
     
There is no accompaniment during the anacrusis.



     
             c2:3-
     
     

This is a c minor chord, lasting for a half note. Chords are entered using the tonic. Notes can be changed to create different chords. In this case, a lowered third is used (making a C major chord into a C minor chord). The code for this is 3-.



     f:3-.7
     
Similarly, 7 modifies (adds) a seventh, which is small by default to create the f a c es chord. Multiple modifiers must be separated by dots.



     
             d:min es4 c8:min r8
     
     
Some modifiers have predefined names, e.g. min is the same as 3-, so d-min is a minor d chord.



     
             c2:min f:min7 g:7^3.5 c:min }
     
     

A named modifier min and a normal modifier 7 do not have to be separated by a dot. Tones from a chord are removed with chord subtractions. Subtractions are started with a caret, and they are also separated by dots. In this example, g:7^3.5 produces a minor seventh (a G7 chord without the third or the fifth). The brace ends the sequential music.



     
             \score {
                     \simultaneous {
     
     
We assemble the music in the \score block. Melody, lyrics and accompaniment have to sound at the same time, so they should be \simultaneous.



     
             %\accompaniment
     
     
Chord mode generates notes grouped in \simultaneous music. If you remove the comment sign, you can see the chords in normal notation: they will be printed as note heads on a separate staff. To print them as chords names, they have to be interpreted as being chords, not notes. This is done with the following command:



     
             \context ChordNames \accompaniment
     
     

Normally the notes that you enter are transformed into note heads. Note heads alone make no sense, so they need surrounding information: a key signature, a clef, staff lines, etc. They need context. In LilyPond, these symbols are created by objects called `interpretation contexts'. Interpretation contexts exist for generating notation (`notation context') and for generating sound (`performance context'). These objects only exist while LilyPond is executing.

When LilyPond interprets music, it will create a Staff context. If the % sign in the previous line were removed, you could see that mechanism in action.

We don't want that default here, because we want chord names. The command above explicitly creates an interpretation context of ChordNames type to interpret the music \accompaniment.



     
             \context Staff = mel {
     
     

We place the melody on a staff called mel. We give it a name to differentiate it from the one that would contain note heads for the chords, if you would remove the comment before the "note heads" version of the accompaniment. By giving this staff a name, it is forced to be different.



     
             \property Staff.autoBeaming = ##f
     
     
An interpretation context has variables, called properties, that tune its behavior. One of the variables is autoBeaming. Setting this Staff's property to ##f, which is the boolean value false, turns the automatic beaming mechanism off for the current staff.



     
               \melody
             }
     
     
Finally, we put the melody on the current staff. Note that the \property directives and \melody are grouped in sequential music, so the property settings are done before the melody is processed.



     
             \midi  { \tempo 4=72}
     
     
MIDI (Musical Instrument Digital Interface) is a standard for connecting and recording digital instruments. So a MIDI file is like a tape recording of an instrument. The \midi block makes the music go to a MIDI file, so you can listen to the music you entered. It is great for checking the music. Whenever you hear something weird, you probably hear a typing error.

Syntactically, \midi is similar to \paper { }, since it also specifies an output method. You can specify the tempo using the \tempo command, in this case the tempo of quarter notes is set to 72 beats per minute.



     
             \paper { linewidth = 10.0\cm }
     
     
We also want notation output. The linewidth is short so that the piece will be set in two lines.
Go back to index of LilyPond.

Please send GNU LilyPond questions and comments to lilypond-user@gnu.org.

Please send comments on these web pages to (address unknown)

Copyright (c) 1997--2002 Han-Wen Nienhuys and Jan Nieuwenhuizen.

Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.


This page was built from LilyPond-1.7.14 (development-branch) by

Buchan Milne <(address unknown)>, Thu Mar 6 21:11:35 2003 CET.