1 @c -*- coding: utf-8; mode: texinfo; -*-
3 @node Fundamental concepts
4 @chapter Fundamental concepts
7 * File structure (introduction)::
8 * How LilyPond files work::
9 * Score is a single musical expression::
13 @node File structure (introduction)
14 @section File structure (introduction)
16 A basic example of a lilypond input file is
21 @{ @} % this is a single music expression;
22 % all the music goes in here.
30 There are many variations of this basic pattern, but this
31 example serves as a useful starting place.
33 The major part of this manual is concerned with entering various
34 forms of music in LilyPond. However, many music expressions are not
35 valid input on their own, for example, a @code{.ly} file containing
42 will result in a parsing error. Instead, music should be inside other
43 expressions, which may be put in a file by themselves. Such
44 expressions are called toplevel expressions; see @ruser{File structure}, for
45 a list of all such expressions.
48 @node How LilyPond files work
49 @section How LilyPond files work
51 The LilyPond input format is quite free-form, giving experienced
52 users a lot of flexibility to structure their files however they
53 wish. However, this flexibility can make things confusing for
54 new users. This section will explain some of this structure, but
55 may gloss over some details in favor of simplicity. For a complete
56 description of the input format, see @ruser{File structure}.
58 Most examples in this manual are little snippets -- for example
64 As you are (hopefully) aware by now, this will not compile by
65 itself. These examples are shorthand for complete
66 examples. They all need at least curly braces to compile
74 Most examples also make use of the @code{\relative c'}
75 (or @code{c''}) command. This is not necessary to merely
76 compile the examples, but in most cases the output will
77 look very odd if you omit the @code{\relative c'}.
79 @lilypond[quote,fragment,ragged-right,verbatim]
85 Now we get to the only real stumbling block: LilyPond
86 input in this form is actually @emph{another}
87 shorthand. Although it compiles and displays the
88 correct output, it is shorthand for
98 A @code{\score} must begin with a single music
99 expression. Remember that a music expression could
100 be anything from a single note to a huge
105 insert the whole score of a Wagner opera in here
111 Since everything is inside @code{@{ ... @}}, it counts
112 as one music expression.
114 The @code{\score} can contain other things, such as
126 Some people put some of those commands outside the
127 @code{\score} block -- for example, @code{\header} is
128 often placed above the @code{\score}. That's just
129 another shorthand that LilyPond accepts.
134 Another great shorthand is the ability to define
135 variables. All the templates use this
138 melody = \relative c' @{
147 When LilyPond looks at this file, it takes the value of
148 @code{melody} (everything after the equals sign) and
149 inserts it whenever it sees
150 @code{\melody}. There's nothing special about the
151 names -- it could be @code{melody}, @code{global},
152 @code{pianorighthand}, or @code{foofoobarbaz}. You
153 can use whatever variable names you want. For
155 @ruser{Saving typing with identifiers and functions}.
157 For a complete definition
158 of the input format, see @ruser{File structure}.
161 @node Score is a single musical expression
162 @section Score is a single musical expression
164 In the previous section, @ruser{How LilyPond files work},
165 we saw the general organization of LilyPond input
166 files. But we seemed to skip over the most important
167 part: how do we figure out what to write after
170 We didn't skip over it at all. The big mystery is simply
171 that there @emph{is} no mystery. This line explains it
175 @emph{A @code{\score} must begin with a single music expression.}
179 You may find it useful to review
180 @ruser{Music expressions explained}. In that section, we
181 saw how to build big music expressions from small
182 pieces -- we started from notes, then chords, etc. Now
183 we're going to start from a big music expression and
188 @{ % this brace begins the overall music expression
190 insert the whole score of a Wagner opera in here
192 @} % this brace ends the overall music expression
197 A whole Wagner opera would easily double the length of
198 this manual, so let's just do a singer and piano. We
199 don't need a @code{GrandStaff} for this ensemble, so we
200 shall remove it. We @emph{do} need a singer and a piano,
207 \new Staff = "singer" <<
209 \new PianoStaff = piano <<
217 Remember that we use @code{<<} and @code{>>} to show
218 simultaneous music. And we definitely want to show
219 the vocal part and piano part at the same time!
225 \new Staff = "singer" <<
226 \new Voice = "vocal" @{ @}
228 \new Lyrics \lyricsto vocal \new Lyrics @{ @}
229 \new PianoStaff = "piano" <<
230 \new Staff = "upper" @{ @}
231 \new Staff = "lower" @{ @}
239 Now we have a lot more details. We have the singer's
240 staff: it contains a @code{Voice} (in LilyPond, this
241 term refers to a set of notes, not necessarily vocal
242 notes -- for example, a violin generally plays one
243 voice) and some lyrics. We also have a piano staff:
244 it contains an upper staff (right hand) and a lower
247 At this stage, we could start filling in notes. Inside
248 the curly braces next to @code{\new Voice = vocal},
249 we could start writing
257 But if we did that, the @code{\score} section would
258 get pretty long, and it would be harder to understand
259 what was happening. So let's use identifiers (or
270 \new Staff = "singer" <<
271 \new Voice = "vocal" @{ \melody @}
273 \new Lyrics \lyricsto vocal \new Lyrics @{ \text @}
274 \new PianoStaff = "piano" <<
275 \new Staff = "upper" @{ \upper @}
276 \new Staff = "lower" @{ \lower @}
285 Remember that you can use almost any name you like. The
286 limitations on identifier names are detailed in
287 @ruser{File structure}.
289 When writing a @code{\score} section, or when reading
290 one, just take it slowly and carefully. Start with
291 the outer layer, then work on each smaller
292 layer. It also really helps to be strict with
293 indentation -- make sure that each item on the same
294 layer starts on the same horizontal position in your