Next: How LilyPond files work, Up: Putting it all together
You've read the tutorial, you know how to write music. But how can you get the staves that you want? The templates are ok, but what if you want something that isn't covered?
Start off with the template that seems closest to what you want to end up with. Let's say that you want to write something for soprano and cello. In this case, we would start with “Notes and lyrics” (for the soprano part).
\version "2.10.10" melody = \relative c' { \clef treble \key c \major \time 4/4 a4 b c d } text = \lyricmode { Aaa Bee Cee Dee } \score{ << \new Voice = "one" { \autoBeamOff \melody } \new Lyrics \lyricsto "one" \text >> \layout { } \midi { } }
Now we want to add a cello part. Let's look at the “Notes only” example:
\version "2.10.10" melody = \relative c' { \clef treble \key c \major \time 4/4 a4 b c d } \score { \new Staff \melody \layout { } \midi { } }
We don't need two \version
commands. We'll need the melody
section. We don't want two \score
sections – if we had two
\score
s, we'd get the two parts separately. We want them together,
as a duet. Within the \score
section, we don't need two
\layout
or \midi
.
If we simply cut and paste the melody
section, we would end up with
two melody
sections. So let's rename them. We'll call the section
for the soprano sopranoMusic
and the section for the cello
celloMusic
. While we're doing this, let's rename text
to be sopranoLyrics
. Remember to rename both instances of all
these names – both the initial definition (the
melody = relative c' {
part) and the name's use (in the
\score
section).
While we're doing this, let's change the cello part's staff – celli normally use bass clef. We'll also give the cello some different notes.
\version "2.10.10" sopranoMusic = \relative c' { \clef treble \key c \major \time 4/4 a4 b c d } sopranoLyrics = \lyricmode { Aaa Bee Cee Dee } celloMusic = \relative c { \clef bass \key c \major \time 4/4 d4 g fis8 e d4 } \score{ << \new Voice = "one" { \autoBeamOff \sopranoMusic } \new Lyrics \lyricsto "one" \sopranoLyrics >> \layout { } \midi { } }
This is looking promising, but the cello part won't appear in the
score – we haven't used it in the \score
section. If we
want the cello part to appear under the soprano part, we need to add
\new Staff \celloMusic
underneath the soprano stuff. We also need to add <<
and
>>
around the music – that tells LilyPond that there's
more than one thing (in this case, Staff
) happening at once. The
\score
looks like this now
\score{ << << \new Voice = "one" { \autoBeamOff \sopranoMusic } \new Lyrics \lyricsto "one" \sopranoLyrics >> \new Staff \celloMusic >> \layout { } \midi { } }
This looks a bit messy; the indentation is messed up now. That is easily fixed. Here's the complete soprano and cello template.
\version "2.10.10" sopranoMusic = \relative c' { \clef treble \key c \major \time 4/4 a4 b c d } sopranoLyrics = \lyricmode { Aaa Bee Cee Dee } celloMusic = \relative c { \clef bass \key c \major \time 4/4 d4 g fis8 e d4 } \score{ << << \new Voice = "one" { \autoBeamOff \sopranoMusic } \new Lyrics \lyricsto "one" \sopranoLyrics >> \new Staff \celloMusic >> \layout { } \midi { } }
Next: How LilyPond files work, Up: Putting it all together
This page is for LilyPond-2.10.33 (stable-branch).
Other languages: French.