Next: Nesting music expressions, Previous: Introduction to the LilyPond file structure, Up: How LilyPond files work
We saw the general organization of LilyPond input files in the
previous section, How LilyPond files work. But we seemed to
skip over the most important part: how do we figure out what to
write after \score
?
We didn't skip over it at all. The big mystery is simply that there is no mystery. This line explains it all:
A \score
block must begin with a compound music expression.
You may find it useful to review Music expressions explained. In that section, we saw how to build big music expressions from small pieces – we started from notes, then chords, etc. Now we're going to start from a big music expression and work our way down.
\score { { % this brace begins the overall compound music expression \new GrandStaff << ...insert the whole score of a Wagner opera in here... >> } % this brace ends the overall compound music expression \layout { } }
A whole Wagner opera would easily double the length of this
manual, so let's just add a singer and piano. We don't need a
GrandStaff
for this ensemble, which simply groups a number
of staves together with a brace at the left, so we shall remove
it. We do need a singer and a piano, though.
\score { << \new Staff = "singer" << >> \new PianoStaff = piano << >> >> \layout { } }
Remember that we use << ... >>
instead of
{ ... }
to show simultaneous
music. And we definitely want to show the vocal part and piano
part at the same time, not one after the other! However, the
<< ... >>
construct is not really necessary for the Singer
staff, as it contains only one music expression, but Staves often
do require simultaneous Voices within them, so using
<< ... >>
rather than braces is a good habit to adopt. We'll add some real
music later; for now let's just put in some dummy notes and lyrics.
\score { << \new Staff = "singer" << \new Voice = "vocal" { c'1 } \addlyrics { And } >> \new PianoStaff = "piano" << \new Staff = "upper" { c'1 } \new Staff = "lower" { c'1 } >> >> \layout { } }
Now we have a lot more details. We have the singer's staff: it
contains a Voice
(in LilyPond, this term refers to a set of
notes, not necessarily vocal notes – for example, a violin
generally plays one voice) and some lyrics. We also have a piano
staff: it contains an upper staff (right hand) and a lower staff
(left hand).
At this stage, we could start filling in notes. Inside the curly
braces next to \new Voice = vocal
, we could start writing
\relative c'' { r4 d8\noBeam g, c4 r }
But if we did that, the \score
section would get pretty
long, and it would be harder to understand what was happening. So
let's use variables instead. These were introduced at the end
of the previous section, remember? So, adding a few notes, we
now have a piece of real music:
melody = \relative c'' { r4 d8\noBeam g, c4 r } text = \lyricmode { And God said, } upper = \relative c'' { <g d g,>2~ <g d g,> } lower = \relative c { b2 e2 } \score { << \new Staff = "singer" << \new Voice = "vocal" { \melody } \addlyrics { \text } >> \new PianoStaff = "piano" << \new Staff = "upper" { \upper } \new Staff = "lower" { \clef "bass" \lower } >> >> \layout { } }
Be careful about the difference between notes, which are introduced
with \relative
, and lyrics, which are introduced with
\lyricmode
. These are essential to tell LilyPond
to interpret the following content as music and text
respectively.
When writing (or reading) a \score
section, just take it
slowly and carefully. Start with the outer layer, then work on
each smaller layer. It also really helps to be strict with
indentation – make sure that each item on the same layer starts
on the same horizontal position in your text editor.
Next: Nesting music expressions, Previous: Introduction to the LilyPond file structure, Up: How LilyPond files work
Diese Seite ist für LilyPond-2.11.40 (Entwicklungszweig).
Fehler bitte an http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs melden.
Ihre Vorschläge für die Dokumentation sind willkommen.
Other languages: français.