[icon]

GNU LilyPond

Welcome to the home of the GNU Music Typesetter

What is LilyPond
General information
Simple examples
Complex examples
Download
GNU/Linux binaries
Windows
Source code
Documentation
Tutorial
Manual
Glossary
other ...

Support
Mailing lists
Search
WikiWiki
FAQs

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

Node:First steps, Next:, Up:Tutorial



First steps

This section shows how easy writing music with LilyPond actually is. If you have not seen LilyPond input source before, this section is for you.

The next section has a table (see Simple legend) of all symbols that are introduced here, you may want to keep an eye on that.

Writing music with LilyPond is explained below by a number of small examples. Each example has a small piece of text; the LilyPond input that you should type, with the resulting music printed below it.

You get a simple note by typing its note name, from a through g:


c d e f g a b

[picture of music]

***

The length of a note is specified by adding a number, "1" for a whole note, "2" for a halve note, and so on:


a1 a2 a4 a16 a32

[picture of music]

***

If you don't specify a duration, the previous duration is used:


a a a2 a

[picture of music]

***

A sharp (#) is made by adding "is", a flat (b) by adding "es":


cis1 ees fisis aeses

[picture of music]

***

Add a dot "." after the duration to get a dotted note:


a2. a4 a8. a16

[picture of music]

***

The meter (or time signature) can be set with the "\time" command:


\time 3/4
\time 6/8
\time 4/4

[picture of music]

***

The clef can be set using the "\clef" command:


\clef violin
\clef bass
\clef alto
\clef tenor

[picture of music]

***

From these commands and notes, a piece of music can be formed. A piece of music is made by enclosing it in "\notes { ... }". LilyPond then knows that music follows (and not lyrics, for example):


\notes {
   \time 3/4
   \clef bass
   c2 e4 g2.
   f4 e d c2.
}

***

At this point, the piece of music is ready to be printed. This is done by combining the music with a printing command.

The printing command is the so-called "\paper" block. You will see later that the \paper block is necessary to customize all kinds of printing specifics. The music and the \paper block are combined by enclosing them in "\score { ... }". This is what a full LilyPond source file looks like:


\score {
  \notes {
     \time 3/4
     \clef bass
     c2 e4 g2.
     f4 e d c2.
  }
  \paper { }
}

[picture of music]

***

We continue with the introduction of the remaining musical constructs.

Rests are entered just like notes with the name "r":


r2 r4 r8 r16

[picture of music]

***

To raise a note by an octave, add a high quote ' (apostrophe) to the note name, to lower a note one octave, add a "low quote" , (a comma). The central C is c':


c'4 c'' c''' \clef bass c c,

[picture of music]

***

A tie is created by entering a tilde "~" between the notes to be tied. A tie between two notes means that the second note must not be played separately, but just makes the first note sound longer:


g'4 ~ g' a'2 ~ a'4

[picture of music]

***

The key signature is set with the command "\key":


\key d \major
g'1
\key c \minor
g'

[picture of music]

This example shows notes, ties, octave marks, and rests in action. Don't worry about all the quotes.


\score {
  \notes {
    \time 4/4
    \clef violin
    \key d \minor
    r4 r8 d''8 cis''4 e''
    d''8 a'4. ~ a' b'8
    cis''4 cis''8 cis'' bis'4 d''8 cis'' ~
    cis''2 r2
  }
  \paper { }
}

[picture of music]

There are some interesting points to note in this example. Firstly, accidentals (sharps and flats) don't have to be marked explicitly: you just enter the note name, and LilyPond determines whether or not to print an accidental. Secondly, bar lines and beams are drawn automatically. Thirdly, LilyPond calculates line breaks for you; it doesn't matter where you make new lines in the source file.

The example also indicates that a piece of music written in a high register needs lots of quotes. This makes the input a bit unreadable, and is therefore also a potential source of errors.

***

The solution is to use "relative octave" mode. In practice, most music is entered using this mode.

To use relative mode, add \relative before the piece of music. You must also give a note from which relative starts, in this case c''.

If you type no octaviation quotes, relative mode chooses the note that is closest to the previous one, which is often just the one you need. For example: c f goes up; c g goes down:


\relative c'' {
  c f c g c
}

[picture of music]

***

You can make a large interval by adding octaviation quotes. Note that quotes or commas do not determine the absolute height of a note; the height of a note is relative to the previous one. For example: c f, goes down; f, f are both the same; c c' are the same; and c g' goes up:


\relative c'' {
  c f, f c' c g' c,
}

[picture of music]

***

A slur is drawn across many notes, and indicates bound articulation (legato). The starting note and ending note are marked with a "(" and a ")" respectively:


d4( )c16( cis d e c cis d )e( )d4

[picture of music]

***

If you need two slurs at the same time (one for articulation, one for phrasing), you can also make a phrasing slur with \( and \).


a8(\( ais b ) c cis2 b'2 a4 cis, \) c

[picture of music]

***

Beams are drawn automatically, but if you don't like the choices, you can enter beams by hand. Surround the notes to be grouped with [ and ]:


[a8 ais] [d es r d]

[picture of music]

***

To print more than one staff, each piece of music that makes up a staff is marked by adding \context Staff before it. These staffs can be grouped inside < and >, as is demonstrated here:


<
  \context Staff = staffA { \clef violin c'' }
  \context Staff = staffB { \clef bass c }
>

[picture of music]

In this example, staffA and staffB are names that are given to the staffs. For now, it doesn't matter what names you give, as long as each staff has a unique name.

***

We can typeset a melody with two staffs now:


\score {
  \notes
  < \context Staff = staffA {
      \time 3/4
      \clef violin
      \relative c'' { e2 ( d4 c2 b4 [a8 a] [b b] [g g] )a2. }
    }
    \context Staff = staffB {
       \clef bass
       c2 e4  g2.
       f4 e d c2.
    }
  >
  \paper {}
}

[picture of music]

Notice that the time signature is specified in one melody staff only (the top staff), but is printed on both. LilyPond knows that the time signature should be the same for all staffs.

***

Common accents can be added to a note using -., --, ->:


c-. c-- c->

[picture of music]

***

Dynamic signs are made by adding the markings to the note:


c-\ff c-\mf

[picture of music]

***

Crescendi are started with the commands \< and \>. The command \! finishes a crescendo on the following note.


c2\<  \!c2-\ff  \>c2  \!c2

[picture of music]

***

Chords can be made by surrounding notes with < and >:


r4 <c e g> <c f a>

[picture of music]

***

Of course, you can combine beams and ties with chords. Notice that beam and tie markings are placed outside the chord markers:


r4 [<c8 e g> <c8 f a>] ~ <c8 f a>

[picture of music]

When you want to combine chords with slurs and dynamics, an annoying technical detail crops up: you have type these commands next to the notes, which means that they have to be inside the < >:


r4 <c8 e g \> ( > <c e g> <c e g>  < ) \! c8 f a>

[picture of music]

***

A nasty technical detail also crops up when you start a score with a chord:


\score { \notes <c'1 e'1> }

[picture of music]

***

The program can not guess that you want the notes on only one staff. To force the chord on a staff, add \context Staff like this:


\score { \notes \context Staff <c'1 e'1> }

[picture of music]

***

This is the end of the simple tutorial. You know the basic ingredients of a music file, so this is the right moment to try your at hand at doing it yourself: try to type some simple examples, and experiment a little.

When you're comfortable with the basics, then you might want to read the rest of this chapter. It also a manual in tutorial-style, but it is much more in-depth. It will also be very intimidating if you're not familiar with the basics. It deals with some of the more advanced features of LilyPond. Topics include lyrics, chords, orchestral scores and parts, fine tuning output, polyphonic music, and integrating text and music.

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 lilypond@packages.debian.org

Copyright (c) 1997--2001 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.4.12 (stable-branch) by

Anthony Fok <lilypond@packages.debian.org>, Tue Mar 12 01:35:39 2002 HKT.