1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond-learning.tely
4 @node Fundamental concepts
5 @chapter Fundamental concepts
8 * How LilyPond files work::
9 * Score is a single musical expression::
13 @node How LilyPond files work
14 @section How LilyPond files work
16 The LilyPond input format is quite free-form, giving experienced
17 users a lot of flexibility to structure their files however they
18 wish. However, this flexibility can make things confusing for new
19 users. This section will explain some of this structure, but may
20 gloss over some details in favor of simplicity. For a complete
21 description of the input format, see @ruser{File structure}.
23 A basic example of a lilypond input file is
28 @{@var{...music expression...}@} % all the music goes here!
36 There are many variations of this basic pattern, but this
37 example serves as a useful starting place.
39 At this point, you may be confused, since you have never seen a
40 @code{\score@{@}} before. This is because LilyPond automatically
41 adds the extra commands when you give it simple input. LilyPond
42 treats input like this:
51 as shorthand for this:
62 In other words, if the input contains a single music expression,
63 LilyPond will interpret the file as though the music expression
64 was wrapped up inside a @code{\score@{@}}.
68 A @code{\score} must begin with a single music
69 expression. Remember that a music expression could
70 be anything from a single note to a huge
75 @var{...insert the whole score of a Wagner opera in here...}
81 Since everything is inside @code{@{ ... @}}, it counts
82 as one music expression.
84 As we saw previously, the @code{\score} can contain other things,
97 Some people put some of those commands outside the @code{\score}
98 block -- for example, @code{\header} is often placed above the
99 @code{\score}. That's just another shorthand that LilyPond
107 Another great shorthand is the ability to define identifiers. All
108 the templates use this
111 melody = \relative c' @{
120 When LilyPond looks at this file, it takes the value of
121 @code{melody} (everything after the equals sign) and inserts it
122 whenever it sees @code{\melody}. There's nothing special about
123 the names -- it could be @code{melody}, @code{global},
124 @code{pianorighthand}, or @code{foofoobarbaz}. You can use
125 whatever variable names you want. For more details, see
126 @ruser{Saving typing with identifiers and functions}.
131 For a complete definition of the input format, see @ruser{File
135 @node Score is a single musical expression
136 @section Score is a single musical expression
138 We saw the general organization of LilyPond input files in the
139 previous section, @ref{How LilyPond files work}. But we seemed to
140 skip over the most important part: how do we figure out what to
141 write after @code{\score}?
143 We didn't skip over it at all. The big mystery is simply that
144 there @emph{is} no mystery. This line explains it all:
147 @emph{A @code{\score} must begin with a single music expression.}
151 You may find it useful to review @ruser{Music expressions
152 explained}. In that section, we saw how to build big music
153 expressions from small pieces -- we started from notes, then
154 chords, etc. Now we're going to start from a big music expression
155 and work our way down.
159 @{ % this brace begins the overall music expression
161 @var{...insert the whole score of a Wagner opera in here...}
163 @} % this brace ends the overall music expression
168 A whole Wagner opera would easily double the length of this
169 manual, so let's just add a singer and piano. We don't need a
170 @code{GrandStaff} for this ensemble, so we shall remove it. We
171 @emph{do} need a singer and a piano, though.
177 \new Staff = "singer" <<
179 \new PianoStaff = piano <<
187 Remember that we use @code{<<} and @code{>>} to show simultaneous
188 music. And we definitely want to show the vocal part and piano
189 part at the same time, not one after the other!
195 \new Staff = "singer" <<
196 \new Voice = "vocal" @{ @}
198 \new Lyrics \lyricsto vocal \new Lyrics @{ @}
199 \new PianoStaff = "piano" <<
200 \new Staff = "upper" @{ @}
201 \new Staff = "lower" @{ @}
209 Now we have a lot more details. We have the singer's staff: it
210 contains a @code{Voice} (in LilyPond, this term refers to a set of
211 notes, not necessarily vocal notes -- for example, a violin
212 generally plays one voice) and some lyrics. We also have a piano
213 staff: it contains an upper staff (right hand) and a lower staff
216 At this stage, we could start filling in notes. Inside the curly
217 braces next to @code{\new Voice = vocal}, we could start writing
225 But if we did that, the @code{\score} section would get pretty
226 long, and it would be harder to understand what was happening. So
227 let's use identifiers (or variables) instead.
237 \new Staff = "singer" <<
238 \new Voice = "vocal" @{ \melody @}
240 \new Lyrics \lyricsto vocal \new Lyrics @{ \text @}
241 \new PianoStaff = "piano" <<
242 \new Staff = "upper" @{ \upper @}
243 \new Staff = "lower" @{ \lower @}
252 Remember that you can use almost any name you like. The
253 limitations on identifier names are detailed in @ruser{File
256 When writing (or reading) a @code{\score} section, just take it
257 slowly and carefully. Start with the outer layer, then work on
258 each smaller layer. It also really helps to be strict with
259 indentation -- make sure that each item on the same layer starts
260 on the same horizontal position in your text editor.