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::
11 * On the un-nestedness of brackets and ties::
15 @node How LilyPond files work
16 @section How LilyPond files work
18 The LilyPond input format is quite free-form, giving experienced
19 users a lot of flexibility to structure their files however they
20 wish. However, this flexibility can make things confusing for new
21 users. This section will explain some of this structure, but may
22 gloss over some details in favor of simplicity. For a complete
23 description of the input format, see @ruser{File structure}.
25 A basic example of a lilypond input file is
30 @{@var{...music expression...}@} % all the music goes here!
38 There are many variations of this basic pattern, but this
39 example serves as a useful starting place.
41 At this point, you may be confused, since you have never seen a
42 @code{\score@{@}} before. This is because LilyPond automatically
43 adds the extra commands when you give it simple input. LilyPond
44 treats input like this:
53 as shorthand for this:
64 In other words, if the input contains a single music expression,
65 LilyPond will interpret the file as though the music expression
66 was wrapped up inside a @code{\score@{@}}.
70 A @code{\score} must begin with a single music
71 expression. Remember that a music expression could
72 be anything from a single note to a huge
77 @var{...insert the whole score of a Wagner opera in here...}
83 Since everything is inside @code{@{ ... @}}, it counts
84 as one music expression.
86 As we saw previously, the @code{\score} can contain other things,
99 Some people put some of those commands outside the @code{\score}
100 block -- for example, @code{\header} is often placed above the
101 @code{\score}. That's just another shorthand that LilyPond
109 Another great shorthand is the ability to define identifiers. All
110 the templates use this
113 melody = \relative c' @{
122 When LilyPond looks at this file, it takes the value of
123 @code{melody} (everything after the equals sign) and inserts it
124 whenever it sees @code{\melody}. There's nothing special about
125 the names -- it could be @code{melody}, @code{global},
126 @code{pianorighthand}, or @code{foofoobarbaz}. You can use
127 whatever variable names you want. For more details, see
128 @ruser{Saving typing with identifiers and functions}.
133 For a complete definition of the input format, see @ruser{File
137 @node Score is a single musical expression
138 @section Score is a single musical expression
140 We saw the general organization of LilyPond input files in the
141 previous section, @ref{How LilyPond files work}. But we seemed to
142 skip over the most important part: how do we figure out what to
143 write after @code{\score}?
145 We didn't skip over it at all. The big mystery is simply that
146 there @emph{is} no mystery. This line explains it all:
149 @emph{A @code{\score} must begin with a single music expression.}
153 You may find it useful to review @ruser{Music expressions
154 explained}. In that section, we saw how to build big music
155 expressions from small pieces -- we started from notes, then
156 chords, etc. Now we're going to start from a big music expression
157 and work our way down.
161 @{ % this brace begins the overall music expression
163 @var{...insert the whole score of a Wagner opera in here...}
165 @} % this brace ends the overall music expression
170 A whole Wagner opera would easily double the length of this
171 manual, so let's just add a singer and piano. We don't need a
172 @code{GrandStaff} for this ensemble, so we shall remove it. We
173 @emph{do} need a singer and a piano, though.
179 \new Staff = "singer" <<
181 \new PianoStaff = piano <<
189 Remember that we use @code{<<} and @code{>>} to show simultaneous
190 music. And we definitely want to show the vocal part and piano
191 part at the same time, not one after the other!
197 \new Staff = "singer" <<
198 \new Voice = "vocal" @{ @}
200 \new Lyrics \lyricsto vocal \new Lyrics @{ @}
201 \new PianoStaff = "piano" <<
202 \new Staff = "upper" @{ @}
203 \new Staff = "lower" @{ @}
211 Now we have a lot more details. We have the singer's staff: it
212 contains a @code{Voice} (in LilyPond, this term refers to a set of
213 notes, not necessarily vocal notes -- for example, a violin
214 generally plays one voice) and some lyrics. We also have a piano
215 staff: it contains an upper staff (right hand) and a lower staff
218 At this stage, we could start filling in notes. Inside the curly
219 braces next to @code{\new Voice = vocal}, we could start writing
227 But if we did that, the @code{\score} section would get pretty
228 long, and it would be harder to understand what was happening. So
229 let's use identifiers (or variables) instead.
239 \new Staff = "singer" <<
240 \new Voice = "vocal" @{ \melody @}
242 \new Lyrics \lyricsto vocal \new Lyrics @{ \text @}
243 \new PianoStaff = "piano" <<
244 \new Staff = "upper" @{ \upper @}
245 \new Staff = "lower" @{ \lower @}
254 Remember that you can use almost any name you like. The
255 limitations on identifier names are detailed in @ruser{File
258 When writing (or reading) a @code{\score} section, just take it
259 slowly and carefully. Start with the outer layer, then work on
260 each smaller layer. It also really helps to be strict with
261 indentation -- make sure that each item on the same layer starts
262 on the same horizontal position in your text editor.
266 @c too cheesy? I'm not certain. -gp
267 @node I'm seeing Voices
268 @section I'm seeing Voices
272 @c TODO: sex this up with colors and stuff. -gp
273 @c TODO: actually, a general rewrite is needed. -gp
275 The easiest way to enter fragments with more than one voice on a
276 staff is to enter each voice as a sequence (with @code{@{...@}}),
277 and combine them simultaneously, separating the voices with
282 @lilypond[quote,verbatim,fragment]
283 \new Staff \relative c' {
286 { g4 f e | d2 e2 } \\
287 { r8 e4 d c8 ~ | c b16 a b8 g ~ g2 } \\
295 The separator causes @internalsref{Voice}
296 contexts@footnote{Polyphonic voices are sometimes
297 called @q{layers} in other notation packages} to be instantiated.
298 They bear the names @code{"1"}, @code{"2"}, etc. In each of these
299 contexts, vertical direction of slurs, stems, etc., is set
302 These voices are all separate from the voice that contains the
303 notes just outside the @code{<< \\ >>} construct. This should be
304 noted when making changes at the voice level. This also means
305 that slurs and ties cannot go into or out of a @code{<< \\ >>}
306 construct. Conversely, parallel voices from separate @code{<< \\
307 >>} constructs on the same staff are the same voice. Here is the
308 same example, with different noteheads and colors for each voice.
309 Note that the change to the note-head style in the main voice does
310 not affect the inside of the @code{<< \\ >>} constructs. Also,
311 the change to the second voice in the first @code{<< \\ >>}
312 construct is effective in the second @code{<< \\ >>}, and the
313 voice is tied across the two constructs.
315 @cindex note heads, styles
317 @lilypond[quote,verbatim,fragment]
318 \new Staff \relative c' {
319 \override NoteHead #'style = #'cross
320 \override NoteHead #'color = #red
324 { \override NoteHead #'style = #'triangle
325 \override NoteHead #'color = #blue
330 { c8 b16 a b8 g ~ g2 } \\
331 { \override NoteHead #'style = #'slash
332 \override NoteHead #'color = #green
338 Polyphony does not change the relationship of notes within a
339 @code{\relative @{ @}} block. Each note is calculated relative to
340 the note immediately preceding it.
343 \relative @{ noteA << noteB \\ noteC >> noteD @}
346 @code{noteC} is relative to @code{noteB}, not @code{noteA};
347 @code{noteD} is relative to @code{noteC}, not @code{noteB} or
351 @c my name start sucking the more docs I write. -gp
352 @node On the un-nestedness of brackets and ties
353 @section On the un-nestedness of brackets and ties
355 Different kinds of brackets and ties may be mixed freely,
357 TODO: improve this example
359 @lilypond[quote,verbatim,fragment,ragged-right]
361 r16[ g16 \times 2/3 {r16 e'8] }
362 g16( a \times 2/3 {b d e') }
363 g8[( a \times 2/3 {b d') e'~]}
364 \times 4/5 {e'32\( a b d' e'} a'4.\)
368 TODO... add more info? Fluff up the first sentence?