]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/fundamental.itely
Add info about compound music expressions, clarify file structure.
[lilypond.git] / Documentation / user / fundamental.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond-learning.tely
3
4 @node Fundamental concepts
5 @chapter Fundamental concepts
6
7 @menu
8 * How LilyPond files work::     
9 * Voices contain music::        
10 * TODO new sec fundamental::    
11 @end menu
12
13
14 @node How LilyPond files work
15 @section How LilyPond files work
16
17 The LilyPond input format is quite free-form, giving experienced
18 users a lot of flexibility to structure their files however they
19 wish.  However, this flexibility can make things confusing for new
20 users.  This section will explain some of this structure, but may
21 gloss over some details in favor of simplicity.  For a complete
22 description of the input format, see @ruser{File structure}.
23
24 @menu
25 * Introduction to the LilyPond file structure::  
26 * Score is a (single) compound musical expression::  
27 @end menu
28
29 @node Introduction to the LilyPond file structure
30 @subsection Introduction to the LilyPond file structure
31
32 A basic example of a lilypond input file is
33
34 @example
35 \version "2.11.23"
36 \score @{
37   @var{...compound music expression...}  % all the music goes here!
38   \header @{ @}
39   \layout @{ @}
40   \midi @{ @}
41 @}
42 @end example
43
44 @noindent
45 There are many variations of this basic pattern, but this
46 example serves as a useful starting place.
47
48 At this point, you may be confused, since you have never seen a
49 @code{\score@{@}} before.  This is because LilyPond automatically
50 adds the extra commands when you give it simple input.  LilyPond
51 treats input like this:
52
53 @example
54 \relative c'' @{
55   c4 a d c
56 @}
57 @end example
58
59 @noindent
60 as shorthand for this:
61
62 @example
63 \score @{
64   \relative c'' @{
65     c4 a b c
66   @}
67   \layout @{ @}
68 @}
69 @end example
70
71 In other words, if the input contains a single music expression,
72 LilyPond will interpret the file as though the music expression
73 was wrapped up inside a @code{\score@{@}}.
74
75 @smallspace
76
77 A @code{\score} must begin with a compound music expression.
78 Remember that a music expression could be anything from a single
79 note to a huge
80
81 @example
82 @{
83   \new GrandStaff <<
84     @var{...insert the whole score of a Wagner opera in here...}
85   >>
86 @}
87 @end example
88
89 @noindent
90 Since everything is inside @code{@{ ... @}}, it counts
91 as one music expression.
92
93 As we saw previously, the @code{\score} can contain other things,
94 such as
95
96 @example
97 \score @{
98   @{ c'4 a b c' @}
99   \header @{ @}
100   \layout @{ @}
101   \midi @{ @}
102 @}
103 @end example
104
105 @noindent
106 Some people put some of those commands outside the @code{\score}
107 block -- for example, @code{\header} is often placed above the
108 @code{\score}.  That's just another shorthand that LilyPond
109 accepts.
110
111 @smallspace
112
113 @cindex variables
114 @cindex identifiers
115
116 Another great shorthand is the ability to define identifiers.  All
117 the templates use this
118
119 @example
120 melody = \relative c' @{
121   c4 a b c
122 @}
123
124 \score @{
125   @{ \melody @}
126 @}
127 @end example
128
129 When LilyPond looks at this file, it takes the value of
130 @code{melody} (everything after the equals sign) and inserts it
131 whenever it sees @code{\melody}.  There's nothing special about
132 the names -- it could be @code{melody}, @code{global},
133 @code{pianorighthand}, or @code{foofoobarbaz}.  You can use
134 whatever variable names you want.  For more details, see
135 @ruser{Saving typing with identifiers and functions}.
136
137
138 @seealso
139
140 For a complete definition of the input format, see @ruser{File
141 structure}.
142
143
144 @node Score is a (single) compound musical expression
145 @subsection Score is a (single) compound musical expression
146
147 @cindex Compound music expression
148 @cindex Music expression, compound
149
150 We saw the general organization of LilyPond input files in the
151 previous section, @ref{How LilyPond files work}.  But we seemed to
152 skip over the most important part: how do we figure out what to
153 write after @code{\score}?
154
155 We didn't skip over it at all.  The big mystery is simply that
156 there @emph{is} no mystery.  This line explains it all:
157
158 @quotation
159 @emph{A @code{\score} must begin with a compound music expression.}
160 @end quotation
161
162 @noindent
163 You may find it useful to review @ruser{Music expressions
164 explained}.  In that section, we saw how to build big music
165 expressions from small pieces -- we started from notes, then
166 chords, etc.  Now we're going to start from a big music expression
167 and work our way down.
168
169 @example
170 \score @{
171   @{ % this brace begins the overall compound music expression
172     \new GrandStaff <<
173       @var{...insert the whole score of a Wagner opera in here...}
174     >>
175   @} % this brace ends the overall compound music expression
176   \layout @{ @}
177 @}
178 @end example
179
180 A whole Wagner opera would easily double the length of this
181 manual, so let's just add a singer and piano.  We don't need a
182 @code{GrandStaff} for this ensemble, so we shall remove it.  We
183 @emph{do} need a singer and a piano, though.
184
185 @example
186 \score @{
187   @{
188     <<
189       \new Staff = "singer" <<
190       >>
191       \new PianoStaff = piano <<
192       >>
193     >>
194   @}
195   \layout @{ @}
196 @}
197 @end example
198
199 Remember that we use @code{<<} and @code{>>} to show simultaneous
200 music.  And we definitely want to show the vocal part and piano
201 part at the same time, not one after the other!
202
203 @example
204 \score @{
205   @{
206     <<
207       \new Staff = "singer" <<
208         \new Voice = "vocal" @{ @}
209       >>
210       \new Lyrics \lyricsto vocal \new Lyrics @{ @}
211       \new PianoStaff = "piano" <<
212         \new Staff = "upper" @{ @}
213         \new Staff = "lower" @{ @}
214       >>
215     >>
216   @}
217   \layout @{ @}
218 @}
219 @end example
220
221 Now we have a lot more details.  We have the singer's staff: it
222 contains a @code{Voice} (in LilyPond, this term refers to a set of
223 notes, not necessarily vocal notes -- for example, a violin
224 generally plays one voice) and some lyrics.  We also have a piano
225 staff: it contains an upper staff (right hand) and a lower staff
226 (left hand).
227
228 At this stage, we could start filling in notes.  Inside the curly
229 braces next to @code{\new Voice = vocal}, we could start writing
230
231 @example
232 \relative c'' @{
233   a4 b c d
234 @}
235 @end example
236
237 But if we did that, the @code{\score} section would get pretty
238 long, and it would be harder to understand what was happening.  So
239 let's use identifiers (or variables) instead.
240
241 @example
242 melody = @{ @}
243 text = @{ @}
244 upper = @{ @}
245 lower = @{ @}
246 \score @{
247   @{
248     <<
249       \new Staff = "singer" <<
250         \new Voice = "vocal" @{ \melody @}
251       >>
252       \new Lyrics \lyricsto vocal \new Lyrics @{ \text @}
253       \new PianoStaff = "piano" <<
254         \new Staff = "upper" @{ \upper @}
255         \new Staff = "lower" @{ \lower @}
256       >>
257     >>
258   @}
259   \layout @{ @}
260 @}
261 @end example
262
263 @noindent
264 Remember that you can use almost any name you like.  The
265 limitations on identifier names are detailed in @ruser{File
266 structure}.
267
268 When writing (or reading) a @code{\score} section, just take it
269 slowly and carefully.  Start with the outer layer, then work on
270 each smaller layer.  It also really helps to be strict with
271 indentation -- make sure that each item on the same layer starts
272 on the same horizontal position in your text editor.
273
274
275 @node Voices contain music
276 @section Voices contain music
277
278 TODO: something cheesy and vaguely witty about voices being the
279 fundamental thing that includes music in lilypond.
280
281 @menu
282 * I'm seeing Voices::           
283 * Explicitly instantiating voices::  
284 * Voices and vocals::           
285 @end menu
286
287 @c too cheesy?  I'm not certain.  -gp
288 @node I'm seeing Voices
289 @subsection I'm seeing Voices
290
291 @cindex polyphony
292
293 TODO: add intro about voices vs. layers vs. whatever.
294
295 TODO: sex this up with colors and stuff.  -gp 
296
297 TODO: actually, a general rewrite is needed.  -gp
298
299
300 The easiest way to enter fragments with more than one voice on a
301 staff is to enter each voice as a sequence (with @code{@{...@}}),
302 and combine them simultaneously, separating the voices with
303 @code{\\}
304
305 @funindex \\
306
307 @lilypond[quote,verbatim,fragment]
308 \new Staff \relative c' {
309   c16 d e f
310   <<
311     { g4 f e | d2 e2 } \\
312     { r8 e4 d c8 ~ | c b16 a b8 g ~ g2 } \\
313     { s2. | s4 b4 c2 }
314   >>
315 }
316 @end lilypond
317
318 @cindex layers
319
320 The separator causes @internalsref{Voice}
321 contexts@footnote{Polyphonic voices are sometimes
322 called @q{layers} in other notation packages} to be instantiated.
323 They bear the names @code{"1"}, @code{"2"}, etc.  In each of these
324 contexts, vertical direction of slurs, stems, etc., is set
325 appropriately.
326
327 These voices are all separate from the voice that contains the
328 notes just outside the @code{<< \\ >>} construct.  This should be
329 noted when making changes at the voice level.  This also means
330 that slurs and ties cannot go into or out of a @code{<< \\ >>}
331 construct.  Conversely, parallel voices from separate @code{<< \\
332 >>} constructs on the same staff are the same voice.  Here is the
333 same example, with different noteheads and colors for each voice.
334 Note that the change to the note-head style in the main voice does
335 not affect the inside of the @code{<< \\ >>} constructs.  Also,
336 the change to the second voice in the first @code{<< \\ >>}
337 construct is effective in the second @code{<< \\ >>}, and the
338 voice is tied across the two constructs.
339
340 @cindex note heads, styles
341
342 @lilypond[quote,verbatim,fragment]
343 \new Staff \relative c' {
344   \override NoteHead #'style = #'cross
345   \override NoteHead #'color = #red
346   c16 d e f
347   <<
348     { g4 f e } \\
349     { \override NoteHead #'style = #'triangle
350       \override NoteHead #'color = #blue
351     r8 e4 d c8 ~ }
352   >> |
353   <<
354     { d2 e2 } \\
355     { c8 b16 a b8 g ~ g2 } \\
356     { \override NoteHead #'style = #'slash 
357       \override NoteHead #'color = #green
358       s4 b4 c2 }
359   >>
360 }
361 @end lilypond
362
363 Polyphony does not change the relationship of notes within a
364 @code{\relative @{ @}} block.  Each note is calculated relative to
365 the note immediately preceding it.
366
367 @example
368 \relative @{ noteA << noteB \\ noteC >> noteD @}
369 @end example
370
371 @code{noteC} is relative to @code{noteB}, not @code{noteA};
372 @code{noteD} is relative to @code{noteC}, not @code{noteB} or
373 @code{noteA}.
374
375
376 @node Explicitly instantiating voices
377 @subsection Explicitly instantiating voices
378
379 TODO: more colors and stuff.
380
381 @internalsref{Voice} contexts can also be instantiated manually
382 inside a @code{<< >>} block to create polyphonic music, using
383 @code{\voiceOne}, up to @code{\voiceFour} to assign stem
384 directions and a horizontal shift for each part.
385
386 Specifically,
387 @example
388 << \upper \\ \lower >>
389 @end example
390
391 @noindent
392 is equivalent to
393
394 @example
395 <<
396   \new Voice = "1" @{ \voiceOne \upper @}
397   \new Voice = "2" @{ \voiceTwo \lower @}
398 >>
399 @end example
400
401 The @code{\voiceXXX} commands set the direction of stems, slurs,
402 ties, articulations, text annotations, augmentation dots of dotted
403 notes, and fingerings.  @code{\voiceOne} and @code{\voiceThree}
404 make these objects point upwards, while @code{\voiceTwo} and
405 @code{\voiceFour} make them point downwards.  The command
406 @code{\oneVoice} will revert back to the normal setting.
407
408 An expression that appears directly inside a @code{<< >>} belongs
409 to the main voice.  This is useful when extra voices appear while
410 the main voice is playing.  Here is a more correct rendition of
411 the example from the previous section.  The crossed colored
412 noteheads demonstrate that the main melody is now in a single
413 voice context.
414
415 @lilypond[quote,ragged-right,verbatim]
416 \new Staff \relative c' {
417   \override NoteHead #'style = #'cross
418   \override NoteHead #'color = #red
419   c16 d e f
420   \voiceOne
421   <<
422     { g4 f e | d2 e2 }
423     \new Voice="1" { \voiceTwo
424       r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2
425       \oneVoice
426     }
427     \new Voice { \voiceThree
428       s2. | s4 b4 c2
429       \oneVoice
430     }
431   >>
432   \oneVoice
433 }
434 @end lilypond
435
436 The correct definition of the voices allows the melody to be
437 slurred.
438
439 @lilypond[quote,ragged-right,verbatim]
440 \new Staff \relative c' {
441   c16^( d e f
442   \voiceOne
443   <<
444     { g4 f e | d2 e2) }
445     \context Voice="1" { \voiceTwo
446       r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2
447       \oneVoice
448     }
449     \new Voice { \voiceThree
450       s2. s4 b4 c2
451       \oneVoice
452     }
453   >>
454   \oneVoice
455 }
456 @end lilypond
457
458 Avoiding the @code{\\} separator also allows nesting polyphony
459 constructs, which in some case might be a more natural way to
460 typeset the music.
461
462 @lilypond[quote,ragged-right,verbatim]
463 \new Staff \relative c' {
464   c16^( d e f
465   \voiceOne
466   <<
467     { g4 f e | d2 e2) }
468     \context Voice="1" { \voiceTwo
469       r8 e4 d c8 ~ |
470       <<
471         {c8 b16 a b8 g ~ g2}
472         \new Voice { \voiceThree
473           s4 b4 c2
474           \oneVoice
475         }
476       >>
477     \oneVoice
478     }
479   >>
480   \oneVoice
481 }
482 @end lilypond
483
484
485 @node Voices and vocals
486 @subsection Voices and vocals
487
488 Vocal music presents a special difficulty: we need to combine two
489 expressions -- notes and lyrics.
490
491 You have already seen the @code{\lyricsAdd@{@}} command, which
492 handles simple cases for you.  However, @code{\lyricsAdd@{@}} is
493 very limited.  For most music, you must explicitly link the lyrics
494 to the notes with @code{\lyricsTo@{@}}
495
496 @lilypond[quote,verbatim,fragment]
497 <<
498   \new Voice = "one" \relative c'' {
499     \autoBeamOff
500     \time 2/4
501     c4 b8. a16 g4. f8 e4 d c2
502   }
503   \new Lyrics \lyricsto "one" {
504     No more let sins and sor -- rows grow.
505   }
506 >>
507 @end lilypond
508
509 TODO: get some vocal person to write more.
510
511
512 @node TODO new sec fundamental
513 @section TODO new sec fundamental
514
515 blh blah
516
517
518 @menu
519 * On the un-nestedness of brackets and ties::  
520 @end menu
521
522 @c my name start sucking the more docs I write. -gp
523 @node On the un-nestedness of brackets and ties
524 @subsection On the un-nestedness of brackets and ties
525
526 Different kinds of brackets and ties may be mixed freely,
527
528 TODO: improve this example
529
530 @lilypond[quote,verbatim,fragment,ragged-right]
531 {
532   r16[ g16 \times 2/3 {r16 e'8] }
533   g16( a \times 2/3 {b d e') }
534   g8[( a \times 2/3 {b d') e'~]}
535   \times 4/5 {e'32\( a b d' e'} a'4.\)
536 }
537 @end lilypond
538
539 TODO... add more info?  Fluff up the first sentence?
540
541
542
543