[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:A piano excerpt, Next:, Previous:More movements, Up:Tutorial



A piano excerpt

Our fourth subject is a piece of piano music. The fragment in the input file is a piano reduction of the G major Sinfonia by Giovanni Battista Sammartini. It was composed around 1740. It's in the source package under the name sammartini.ly.

\include "paper16.ly"

stemDown = \property Voice.Stem \override #'direction = #-1
stemUp = \property Voice.Stem \override #'direction = #1
stemBoth = \property Voice.Stem \revert #'direction

viola = \notes \relative c' \context Voice = viola {
    <c4-\f-\arpeggio g' c>
    \stemDown g'8. b,16
    s1 s2. r4
    g
}

oboes = \notes \relative c'' \context Voice = oboe {
    \stemUp s4  g8. b,16 c8 r <e'8.^\p g> <f16 a>
    \grace <e8( g> <d4 )f> <c2 e>
    \times 2/3 { <d8 \< f> <e g> <f a> }
    <
        { \times 2/3 { a8 g c } \! c2 }
        \context Voice = oboeTwo {
            \stemDown
            \grace {
                \property Grace.Stem \override #'direction = #-1
                [f,16 g] }
            f8 e e2
        }
    >
    \stemBoth
    \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |
    [<d ( f> < )f8. a>] <)b,8 d> r [<d16( f> <f8. )a>] <b,8 d> r  |
    [<c16( e>  < )e8. g>] <c8 e,>
}

hoomPah = \repeat unfold 8 \notes
    \transpose c' { \stemUp c8 \stemBoth \stemDown c'8 \stemBoth }

bassvoices = \notes \relative c' {
    c4 g8. b,16
    \autochange Staff \hoomPah
    \translator Staff = down
    \stemDown [c8 c'8] r4
    <g d'> r4
    < {\stemUp r2 <e4 c'> <c8 g'> }
        \context Voice = reallyLow  {\stemDown g2 ~ | g4 c8 } >
}

\score {
    \context PianoStaff \notes <
        \context Staff = up < \time 2/2
            \viola
            \oboes
        >
        \context Staff = down < \time 2/2 \clef bass
            \bassvoices
        >
    >
    \midi { }
    \paper {
        indent = 0.0
        linewidth = 15.0 \cm }
}

[picture of music]

If this looks like incomprehensible gibberish to you, you are right. This example has been doctored to have as many quirks as possible.

As you can see, this example features multiple voices on one staff. To make room for those voices, their notes have to be stemmed in opposite directions.

Printed symbols are internally represented by so-called Graphical Objects (more colloquially: Grobs). These statements concern the grob called `Stem'. Each grob is described by a bunch of settings. These setting determine the fonts, offsets, sub-routines to be called on the grob, etc. The initial values of these settings are set in the Scheme file scm/grob-description.scm.

***


  stemDown = \property Voice.Stem \override #'direction = #-1

Set a property for all Stem grobs in the current Voice: direction is set to -1, which encodes down. The setting remains in effect until it is reverted.

***


 \property Voice.Stem \revert #'direction

Revert the to the previous setting. The effect of precisely one \stemDown or \stemUp is neutralized.

LilyPond includes the identifiers \stemUp, \stemDown along with some other commonly used formatting instructions, but to explain how it works, we wrote our own here. Of course, you should use predefined identifiers like these if possible: then you will be affected less by the implementation changes we occasionally make.

***


viola = \notes \relative c'  \context Voice = viola {
In this example, you can see multiple parts on a staff. Each part is associated with one notation context. This notation context handles stems and dynamics (among others). The type name of this context is Voice. For each part we have to make sure that there is precisely one Voice context, so we give it a unique name (`viola').

***


<c4-\f-\arpeggio g' c>
The delimiters < and > are shorthands for \simultaneous { and }. The expression enclosed in < and > is a chord.

\f places a forte symbol under the chord. The forte applies to the whole chord, but the syntax requires that commands like forte and arpeggio are attached to a note, so here we attach them to the first note.

\arpeggio typesets an arpeggio sign (a wavy vertical line) before the chord.

***


   \stemDown

***


        g'8. b,16
Relative octaves work a little differently with chords. The starting point for the note following a chord is the first note of the chord. So the g gets an octave up quote: it is a fifth above the starting note of the previous chord (the central C).

***


s1 s2. r4
s is a spacer rest. It does not print anything, but it does have the duration of a rest. It is useful for filling up voices that temporarily don't play. In this case, the viola doesn't come until one and a half measure later.

***


oboes = \notes \relative c'' \context Voice = oboe {
Now comes a part for two oboes. They play homophonically, so we print the notes as one voice that makes chords. Again, we insure that these notes are indeed processed by precisely one context with \context.

***


\stemUp s4  g8. b,16 c8 r <e'8.-\p g> <f16 a>
\stemUp is a reference to the \property \override command defined above.

***


\grace <e8 g> < d4 f> <c2 e>

\grace introduces grace notes. It takes one argument, in this case a chord.

***


\times 2/3
Tuplets are made with the \times keyword. It takes two arguments: a fraction and a piece of music. The duration of the piece of music is multiplied by the fraction. Triplets make notes occupy 2/3 of their notated duration, so in this case the fraction is 2/3.

***


{ <d8 \< f> <e g> <f a> }
The piece of music to be `tripletted' is sequential music containing three notes. On the first chord, a crescendo is started with \<. To be precise, the crescendo start is syntactically attached to the preceding note, the d.

***


<
At this point, the homophonic music splits into two rhythmically different parts. We can't use a sequence of chords to enter this, so we make a `chord' of sequences to do it. We start with the upper voice, which continues with upward stems:

***


 { \times 2/3 { a8 g c } \! c2 }

The crescendo is ended at the half note by the escaped exclamation mark \!.

***


\context Voice = oboeTwo {
\stemDown
We can't share stems with the other voice, so we have to create a new Voice context. We give it the name oboeTwo to distinguish it from the other context. Stems go down in this voice.

***


\grace {
When a grace section is processed, a Grace context is created. This context acts like a miniature score of its own. It has its own time bookkeeping, and you can make notes, beams, slurs etc. Here we fiddle with a property and make a beam. The argument of \grace is sequential music.

***


\property Grace.Stem \override #'direction = #-1
[f,16 g] }

Normally, grace notes are always stem up, but in this case, the upper voice interferes, so we set the stems down here.

As far as relative mode is concerned, the previous note is the c'''2 of the upper voice, so we have to go an octave down for the f.

***


  f8 e e2
} >
This ends the two-part section.

***


\stemBoth
\grace <c,8( e> <)b8. d8.-\trill> <c16 e> |

\stemBoth ends the forced stem directions. From here, stems are positioned as if it were single part music.

The bass has a little hoom-pah melody to demonstrate parts switching between staffs. Since it is repetitive, we use repeats:

***


hoomPah  =  \repeat unfold 8
The unfolded repeat prints the notes in its argument as if they were written out in full eight times.

***


\notes \transpose c' {

Transposing can be done with \transpose, which takes two arguments. The first specifies what central C should be transposed to. The second is the to-be-transposed music. As you can see, in this case, the transposition has no effect, as central C stays at central C.

The purpose of this no-op is circumventing relative mode. Relative mode can not be used together with transposition, so \relative will leave the contents of \hoomPah alone. We can use it without having to worry about getting the motive in a wrong octave.

***


bassvoices = \notes \relative c' {
c4 g8. b,16
\autochange Staff \hoomPah

Voices can switch between staffs. The easiest way to get this, is to use \autochange. This command looks at the pitch of each note, and if necessary, will cross to the other staff. For this to work, the two staffs must be called "up" and "down".

***


        \translator Staff = down
We want the remaining part of this melody on the lower staff, so we do a manual staff switch here.

***


\context Voice = reallyLow  {\stemDown g2 ~ | g4 c8 } >
After skipping some lines, we see ~. This mark makes ties. Note that ties and slurs are different things. A tie can only connect two note heads of the same pitch, whereas a slur can connect many chords with one curve.

***


\context PianoStaff
A special context is needed to get cross staff beaming right. This context is called PianoStaff.

***


\context Staff = bottom < \time 2/2 \clef bass
The bottom staff must have a different clef.

***


indent = 0.0
To make some more room on the line, the first (in this case the only) line is not indented. The line still looks very cramped, but that is due to the page layout of this document.
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.