]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/fundamental.itely
Merge branch 'master' of ssh://kainhofer@git.sv.gnu.org/srv/git/lilypond into kainhofer
[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 * Extending the templates::     
12 * Scores and parts::            
13 @end menu
14
15
16 @node How LilyPond files work
17 @section How LilyPond files work
18
19 The LilyPond input format is quite free-form, giving experienced
20 users a lot of flexibility to structure their files however they
21 wish.  However, this flexibility can make things confusing for new
22 users.  This section will explain some of this structure, but may
23 gloss over some details in favor of simplicity.  For a complete
24 description of the input format, see @ruser{File structure}.
25
26 @menu
27 * Introduction to the LilyPond file structure::  
28 * Score is a (single) compound musical expression::  
29 * Nesting Music Expressions::   
30 @end menu
31
32 @node Introduction to the LilyPond file structure
33 @subsection Introduction to the LilyPond file structure
34
35 A basic example of a lilypond input file is
36
37 @example
38 \version "2.11.23"
39 \score @{
40   @var{...compound music expression...}  % all the music goes here!
41   \header @{ @}
42   \layout @{ @}
43   \midi @{ @}
44 @}
45 @end example
46
47 @noindent
48 There are many variations of this basic pattern, but this
49 example serves as a useful starting place.
50
51 At this point, you may be confused, since you have never seen a
52 @code{\score@{@}} before.  This is because LilyPond automatically
53 adds the extra commands when you give it simple input.  LilyPond
54 treats input like this:
55
56 @example
57 \relative c'' @{
58   c4 a d c
59 @}
60 @end example
61
62 @noindent
63 as shorthand for this:
64
65 @example
66 \score @{
67   \relative c'' @{
68     c4 a b c
69   @}
70   \layout @{ @}
71 @}
72 @end example
73
74 In other words, if the input contains a single music expression,
75 LilyPond will interpret the file as though the music expression
76 was wrapped up inside a @code{\score@{@}}.
77
78 @smallspace
79
80 A @code{\score} must begin with a compound music expression.
81 Remember that a music expression could be anything from a single
82 note to a huge
83
84 @example
85 @{
86   \new GrandStaff <<
87     @var{...insert the whole score of a Wagner opera in here...}
88   >>
89 @}
90 @end example
91
92 @noindent
93 Since everything is inside @code{@{ ... @}}, it counts
94 as one music expression.
95
96 As we saw previously, the @code{\score} can contain other things,
97 such as
98
99 @example
100 \score @{
101   @{ c'4 a b c' @}
102   \header @{ @}
103   \layout @{ @}
104   \midi @{ @}
105 @}
106 @end example
107
108 @noindent
109 Some people put some of those commands outside the @code{\score}
110 block -- for example, @code{\header} is often placed above the
111 @code{\score}.  That's just another shorthand that LilyPond
112 accepts.
113
114 @smallspace
115
116 @cindex variables
117
118 Another great shorthand is the ability to define variables.  All
119 the templates use this
120
121 @example
122 melody = \relative c' @{
123   c4 a b c
124 @}
125
126 \score @{
127   @{ \melody @}
128 @}
129 @end example
130
131 When LilyPond looks at this file, it takes the value of
132 @code{melody} (everything after the equals sign) and inserts it
133 whenever it sees @code{\melody}.  There's nothing special about
134 the names -- it could be @code{melody}, @code{global},
135 @code{pianorighthand}, or @code{foofoobarbaz}.  You can use
136 whatever variable names you want as along as they contain just
137 alphabetic characters.  For more details, see
138 @ruser{Saving typing with variables and functions}.
139
140
141 @seealso
142
143 For a complete definition of the input format, see @ruser{File
144 structure}.
145
146
147 @node Score is a (single) compound musical expression
148 @subsection Score is a (single) compound musical expression
149
150 @cindex Compound music expression
151 @cindex Music expression, compound
152
153 We saw the general organization of LilyPond input files in the
154 previous section, @ref{How LilyPond files work}.  But we seemed to
155 skip over the most important part: how do we figure out what to
156 write after @code{\score}?
157
158 We didn't skip over it at all.  The big mystery is simply that
159 there @emph{is} no mystery.  This line explains it all:
160
161 @quotation
162 @emph{A @code{\score} must begin with a compound music expression.}
163 @end quotation
164
165 @noindent
166 You may find it useful to review @ref{Music expressions
167 explained}.  In that section, we saw how to build big music
168 expressions from small pieces -- we started from notes, then
169 chords, etc.  Now we're going to start from a big music expression
170 and work our way down.
171
172 @example
173 \score @{
174   @{ % this brace begins the overall compound music expression
175     \new GrandStaff <<
176       @var{...insert the whole score of a Wagner opera in here...}
177     >>
178   @} % this brace ends the overall compound music expression
179   \layout @{ @}
180 @}
181 @end example
182
183 A whole Wagner opera would easily double the length of this
184 manual, so let's just add a singer and piano.  We don't need a
185 @code{GrandStaff} for this ensemble, so we shall remove it.  We
186 @emph{do} need a singer and a piano, though.
187
188 @example
189 \score @{
190   @{
191     <<
192       \new Staff = "singer" <<
193       >>
194       \new PianoStaff = piano <<
195       >>
196     >>
197   @}
198   \layout @{ @}
199 @}
200 @end example
201
202 Remember that we use @code{<<} and @code{>>} to show simultaneous
203 music.  And we definitely want to show the vocal part and piano
204 part at the same time, not one after the other!
205
206 @example
207 \score @{
208   @{
209     <<
210       \new Staff = "singer" <<
211         \new Voice = "vocal" @{ @}
212       >>
213       \new Lyrics \lyricsto vocal \new Lyrics @{ @}
214       \new PianoStaff = "piano" <<
215         \new Staff = "upper" @{ @}
216         \new Staff = "lower" @{ @}
217       >>
218     >>
219   @}
220   \layout @{ @}
221 @}
222 @end example
223
224 Now we have a lot more details.  We have the singer's staff: it
225 contains a @code{Voice} (in LilyPond, this term refers to a set of
226 notes, not necessarily vocal notes -- for example, a violin
227 generally plays one voice) and some lyrics.  We also have a piano
228 staff: it contains an upper staff (right hand) and a lower staff
229 (left hand).
230
231 At this stage, we could start filling in notes.  Inside the curly
232 braces next to @code{\new Voice = vocal}, we could start writing
233
234 @example
235 \relative c'' @{
236   a4 b c d
237 @}
238 @end example
239
240 But if we did that, the @code{\score} section would get pretty
241 long, and it would be harder to understand what was happening.  So
242 let's use variables instead.
243
244 @example
245 melody = @{ @}
246 text   = @{ @}
247 upper  = @{ @}
248 lower  = @{ @}
249 \score @{
250   @{
251     <<
252       \new Staff = "singer" <<
253         \new Voice = "vocal" @{ \melody @}
254       >>
255       \new Lyrics \lyricsto vocal \new Lyrics @{ \text @}
256       \new PianoStaff = "piano" <<
257         \new Staff = "upper" @{ \upper @}
258         \new Staff = "lower" @{ \lower @}
259       >>
260     >>
261   @}
262   \layout @{ @}
263 @}
264 @end example
265
266 @noindent
267 Remember that you can use almost any name you like as long
268 as it contains just alphabetic characters.  The exact
269 limitations on variable names are detailed in @ruser{File
270 structure}.
271
272 When writing (or reading) a @code{\score} section, just take it
273 slowly and carefully.  Start with the outer layer, then work on
274 each smaller layer.  It also really helps to be strict with
275 indentation -- make sure that each item on the same layer starts
276 on the same horizontal position in your text editor.
277
278
279 @node Nesting Music Expressions
280 @subsection Nesting Music Expressions
281
282 New staves do not have to all be declared at the beginning; 
283 they may be introduced temporarily at any point.  This is
284 particularly useful for creating ossia sections 
285 (see @rglos{ossia}).  Here's a simple example showing how
286 to introduce a new staff temporarily for the duration of
287 three notes:
288
289 @lilypond[verbatim,quote,ragged-right]
290 \new Staff {
291   \relative g' {
292     r4 g8 g c4 c8 d |
293     e4 r8 
294     <<
295       { f c c }
296       \new Staff {
297         f8 f c
298       }
299     >>
300     r4 |
301   }
302 }
303 @end lilypond
304
305 The ossia section may be placed above the staff
306 as follows:
307
308 @lilypond[verbatim,quote,ragged-right]
309 \new Staff ="main" {
310   \relative g' {
311     r4 g8 g c4 c8 d |
312     e4 r8
313     <<
314       { f c c }
315       \new Staff \with {
316         alignAboveContext = "main" }
317       { f8 f c }
318     >>
319     r4 |
320   }
321 }
322 @end lilypond
323
324 Ossia are often written without clef and without
325 time signature and are usually in a smaller font.
326 These require commands which
327 have not yet been introduced.  See ...
328 TODO Add ref to tweaks section where this example should
329 be placed and explained.
330
331 @lilypond[verbatim,quote,ragged-right]
332 \new Staff = "main" {
333   \relative g' {
334     r4 g8 g c4 c8 d |
335     e4
336     <<  % Start main and ossia in parallel
337       { r8 f c c }  % Main music
338       \new Staff \with {  % Start ossia staff
339         \remove "Clef_engraver"
340         \remove "Time_signature_engraver"
341         % Reduce size of notes and staff
342         fontSize = #-2
343         \override StaffSymbol #'staff-space = #(magstep -2)
344         alignAboveContext = "main"  % Place above main staff
345       }
346       { s8 f f c }  % Ossia music
347     >>  % End parallel music
348     r4 |
349   }
350 }
351 @end lilypond
352
353
354
355
356 @node Voices contain music
357 @section Voices contain music
358
359 Singers need voices to sing, and so does LilyPond.
360 The actual music for all instruments in a score 
361 is contained in Voices - the most fundamental 
362 of all LilyPond's concepts.
363
364 @menu
365 * I'm hearing Voices::          
366 * Explicitly instantiating voices::  
367 * Voices and vocals::           
368 @end menu
369
370 @node I'm hearing Voices
371 @subsection I'm hearing Voices
372
373 @cindex polyphony
374 @cindex layers
375 @cindex Voice context
376
377 The lowest, most fundamental or innermost layers in a LilyPond 
378 score are called Voices.  Voices are sometimes
379 called @q{layers} in other notation packages.  In LilyPond they
380 are called @q{Voice contexts}.
381
382 In fact, a Voice layer or context is the only one which can
383 contain music.  If a Voice context is not explicitly declared
384 one is created automatically.  Some instruments such as an 
385 Oboe can play only one note at a time and music written for
386 such instruments is monophonic and requires just a single
387 voice.  Instruments which can play more than one note at a
388 time like the piano will often require multiple voices to
389 encode the different concurent notes and rhythms they are
390 capable of playing.  
391
392 A single voice can contain many notes in a chord, of course,
393 so when exactly are multiple voices needed? 
394 Let us analyse a short piece of music to see how many voices
395 are required.  Here are the notes from the first two bars
396 of the second of Chopin's Deux Nocturnes, Op 32.
397
398 @c The following should appear as music without code
399 @lilypond[quote,ragged-right]
400 \new Staff \relative c'' {
401   \key aes \major
402   <<
403     { \voiceOne
404       c2 aes4. bes8 } \\
405     { \voiceTwo
406       aes2 f4 fes } \\
407     { \voiceFour
408       \once \override NoteColumn #'force-hshift = #0 <ees c>2
409       \once \override NoteColumn #'force-hshift = #0.5 des2 }
410   >> |
411   <c ees aes c>1 |
412 }
413 @end lilypond
414
415 The direction of the stems is often used to indicate the
416 continuity of two simultaneous melodic lines.  Here the
417 stems of the highest notes are all pointing up and the
418 stems of the lower notes are all pointing down.
419 This is the first indication that more than one voice
420 is required.
421
422 But the real need for multiple voices arises when notes
423 which start at the same time have different durations.
424 Look at the notes which start at beat three in the first 
425 bar.  The a-flat is a dotted quarter note, the f is a
426 quarter note and the d-flat is a half note.  These 
427 cannot be written as a chord as all the notes in a chord
428 must have the same duration.  Neither can they be written
429 as sequential notes, as they must start at the same time.
430 This section of the bar requires three voices, and the
431 normal practice would be to write the whole bar as three
432 voices, as shown here, where we have coloured the three
433 voices differently.
434
435 @c The following should appear as music without code
436 @lilypond[quote,ragged-right]
437 \new Staff \relative c'' {
438   \key aes \major
439   <<
440     { \voiceOne
441       \override NoteHead #'color = #red
442       \override Stem #'color = #red
443       c2 aes4. bes8 } \\
444     { \voiceTwo
445       \override NoteHead #'color = #blue
446       \override Stem #'color = #blue
447       aes2 f4 fes } \\
448     { \voiceFour
449       \override NoteHead #'color = #green
450       \override Stem #'color = #green
451       \once \override NoteColumn #'force-hshift = #0 <ees c>2
452       \once \override NoteColumn #'force-hshift = #0.5 des2 }
453   >> |
454   <c ees aes c>1 |
455 }
456 @end lilypond
457
458 Let us see how this is done.
459
460 @funindex \\
461
462 The easiest way to enter fragments with more than one voice on a
463 staff is to enter each voice as a sequence (with @code{@{...@}}),
464 and combine them simultaneously with angle brackets, @code{<<...>>}.
465 The fragments must also be separated with double backward slashes, 
466 @code{\\}, to place them in separate voices.  Without these, the 
467 notes would be entered into a single voice, which would usually 
468 cause errors.  This technique is particularly suited to pieces of
469 music which are largely monophonic with occasional short sections
470 of polyphony.  Here's a simple example:
471
472 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
473 \key d \minor
474 %    Voice "1"             Voice "2"
475 << { r4 g g4. a8 }    \\ { d,2 d4 g }       >> |
476 << { bes4 bes c bes } \\ { g4 g g8( a) g4 } >> |
477 << { a2. r4 }         \\ { fis2. s4 }       >>
478 @end lilypond
479
480 This example has just two voices, but the same contruct may be
481 used to encode three or more voices by adding more back-slash
482 separators.
483
484 The Voice contexts bear the names @code{"1"}, @code{"2"}, etc.  
485 In each of these contexts, vertical direction of slurs, stems, ties,
486 dynamics etc., is set appropriately.
487
488 @lilypond[quote,verbatim,fragment]
489 \new Staff \relative c' {
490   % Main voice
491   c16 d e f
492   %    Voice "1"     Voice "2"                 Voice "3"
493   << { g4 f e } \\ { r8 e4 d c8 ~ } >> |
494   << { d2 e2 }  \\ { c8 b16 a b8 g ~ g2 } \\ { s4 b4 c2 } >> |
495 }
496 @end lilypond
497
498 These voices are all separate from the main voice that contains
499 the notes just outside the @code{<< \\ >>} construct.  Let's call
500 this the @emph{simultaneous construct}.  Slurs and ties may only
501 connect notes within the same voice, so slurs and ties cannot go
502 into or out of a simultaneous construct.  construct.  Conversely,
503 parallel voices from separate simultaneous constructs on the same
504 staff are the same voice.  Other voice- related properties also
505 carry across simultaneous constructs.  Here is the same example,
506 with different colors and noteheads for each voice.  Note that
507 changes in one Voice do not affect other voices, but they do
508 persist in the same Voice later.  Note also that tied notes may be
509 split across the same voices in two constructs, shown here in the
510 blue triangle voice.
511
512 @lilypond[quote,verbatim]
513 \new Staff \relative c' {
514   \voiceOneStyle
515   c16 d e f
516   << % Bar 1
517     { g4 f e } \\
518     { \voiceTwoStyle
519       r8 e4 d c8 ~ }
520   >> |
521   << % Bar 2
522     { d2 e2 } \\
523     { c8 b16 a b8 g ~ g2 } \\
524     { \voiceThreeStyle
525       s4 b4 c2 }
526   >>
527 }
528 @end lilypond
529
530 Polyphony does not change the relationship of notes within a
531 @code{\relative @{ @}} block.  Each note is calculated relative to
532 the note immediately preceding it, or to the first note of the
533 preceding chord.
534
535 @example
536 \relative @{ noteA << <noteB noteC> \\ noteD >> noteE @}
537 @end example
538
539 @code{noteB} is relative to @code{noteA}
540 @code{noteC} is relative to @code{noteB}, not @code{noteA};
541 @code{noteD} is relative to @code{noteB}, not @code{noteA} or
542 @code{noteC}.
543 @code{noteE} is relative to @code{noteD}, not @code{noteA}
544
545 We are now in a position to return to the first example from
546 the Chopin Nocturne to see how this might be encoded.  As we
547 shall see, this encounters some difficulties.  We begin as
548 we have learnt, using the @code{<< \\  >>} construct to 
549 enter the music of the first bar in three voices:
550
551 @lilypond[quote,verbatim,fragment,ragged-right]
552 \new Staff \relative c'' {
553   \key aes \major
554   << 
555     { c2 aes4. bes8 } \\ { aes2 f4 fes } \\ { <ees c>2 des2 }
556   >> |
557   <c ees aes c>1 |
558 }
559 @end lilypond
560
561 @cindex stem down
562 @cindex stem up
563 @funindex \stemDown
564 @funindex \stemUp
565
566 The stem directions are automatically assigned with the
567 odd-numbered voices taking upward stems and the even-numbered
568 voices downward ones.  The stems for voices 1 and 2 are right,
569 but the stems in voice 3 should go down in this particular piece
570 of music.  We can correct this
571 by telling LilyPond that this third voice is really a fourth
572 voice, with stems going down, using the @code{\voiceFour} 
573 command.  There are also corresponding @code{\voiceOne},
574 @code{\voiceTwo} and @code{voiceThree} commands.
575 This result in the following:
576
577 @lilypond[quote,verbatim,fragment,ragged-right]
578 \new Staff \relative c'' {
579   \key aes \major
580   << 
581     { c2 aes4. bes8 } \\ 
582     { aes2 f4 fes   } \\ 
583     { \voiceFour <ees c>2 des2 }
584   >> |
585   <c ees aes c>1 |
586 }
587 @end lilypond
588
589 @noindent
590 and exposes a problem commonly encountered with multiple
591 voices: the stems of notes can collide with noteheads
592 in other voices.  In laying out the notes, LilyPond allows the
593 notes or chords from two voices to occupy the same vertical
594 note column provided the stems are in opposite directions, but
595 the notes from a third voice are displaced to avoid the stems
596 colliding.  This often works well, but in this example the
597 notes of the third voice are clearly not well placed by default.
598 LilyPond provides several ways to adjust the horizontal placing
599 of notes.  We are not quite ready yet to see how to correct this,
600 so we shall leave this problem until a later section (see ... )
601
602 FIXME: Move the following words and example into Tweaks or
603 somewhere more suitable, leaving just a ref here. -td
604
605 Ways or correcting horizontal placings are described fully 
606 in the Notation Reference.  
607 We introduce just one here, the @code{force-hshift} property of 
608 @code{NoteColumn}.  The lower two notes of the first chord (i.e,
609 those in the third voice) should not be shifted away from the
610 note column of the higher two notes.  To correct this we set
611 @code{force-hshift} of these notes to zero.  
612 The lower note of the second chord is best placed just to the 
613 right of the higher notes.  We achieve this by setting
614 @code{force-hshift} of this note to 0.5, ie half a notehead's 
615 width to the right of the note column of the higher notes.
616
617 Here's the final result:
618     
619 @lilypond[quote,verbatim,fragment,ragged-right]
620 \new Staff \relative c'' {
621   \key aes \major
622   << 
623     { c2 aes4. bes8 } \\ 
624     { aes2 f4 fes   } \\ 
625     { \stemDown
626       \once \override NoteColumn #'force-hshift = #0 <ees c>2
627       \once \override NoteColumn #'force-hshift = #0.5 des2 
628     }
629   >> |
630   <c ees aes c>1 |
631 }
632 @end lilypond
633
634 @node Explicitly instantiating voices
635 @subsection Explicitly instantiating voices
636
637 Voice contexts can also be created manually
638 inside a @code{<< >>} block to create polyphonic music, using
639 @code{\voiceOne}, up to @code{\voiceFour} to automatically assign
640 the directions of stems, slurs, etc.
641
642 Specifically, the construct @code{<< \\  >>} which we used in
643 the previous section:
644
645 @example
646 << \upper \\ \lower >>
647 @end example
648
649 @noindent
650 where @code{upper} and @code{lower} are user-defined variables 
651 containing the music for the two voices, is equivalent to 
652
653 @example
654 <<
655   \new Voice = "1" @{ \voiceOne \upper @}
656   \new Voice = "2" @{ \voiceTwo \lower @}
657 >>
658 @end example
659
660 The @code{\voiceXXX} commands set the direction of stems, slurs,
661 ties, articulations, text annotations, augmentation dots of dotted
662 notes, and fingerings.  @code{\voiceOne} and @code{\voiceThree}
663 make these objects point upwards, while @code{\voiceTwo} and
664 @code{\voiceFour} make them point downwards.  These commands also
665 generate a horizontal shift for each voice when this is required 
666 to avoid clashes of note heads.  The command @code{\oneVoice} 
667 reverts the settings back to the normal values for a single voice.
668
669 An expression that appears directly inside a @code{<< >>} belongs
670 to the main voice.  This is useful when extra voices appear while
671 the main voice is playing.  Here is a more correct rendition of
672 the example from the previous section.  The red diamond-shaped
673 notes demonstrate that the main melody is now in a single
674 voice context, permitting a phrasing slur to be drawn over them.
675
676 @lilypond[quote,ragged-right,verbatim]
677 \new Staff \relative c' {
678   \voiceOneStyle
679   c16^( d e f  % These notes are monophonic
680   <<           % Start simultaneous section of three voices
681     { g4 f e | d2 e2) }  % Continue the main voice in parallel
682     \new Voice {         % Initiate second voice
683       \voiceTwo          % Set stems, etc, down
684       r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2
685     }
686     \new Voice {         % Initiate third voice
687       \voiceThree        % Set stems, etc, up
688       s2. | s4 b4 c2 
689     }
690   >>
691 }
692 @end lilypond
693
694 @cindex nesting music expressions
695 @cindex nesting simultaneous constructs
696
697 More deeply nested polyphony constructs are possible, and if a
698 voice appears only briefly this might be a more natural way to
699 typeset the music.
700
701 @lilypond[quote,ragged-right,verbatim]
702 \new Staff \relative c' {
703   c16^( d e f
704   <<
705     { g4 f e | d2 e2) }
706     \new Voice {
707       \voiceTwo
708       r8 e4 d c8 ~ |
709       <<
710         {c8 b16 a b8 g ~ g2}
711         \new Voice { 
712           \voiceThree
713           s4 b4 c2
714         }
715       >>
716     }
717   >>
718 }
719 @end lilypond
720
721
722 This method of nesting new voices briefly is useful 
723 when only small sections of the music
724 are polyphonic, but when the whole staff is largely polyphonic
725 it can be clearer to use multiple voices throughout, using 
726 spacing notes to step over sections where the voice is silent, 
727 as here:
728
729 @lilypond[quote,ragged-right,verbatim]
730 \new Staff \relative c' <<
731   \new Voice {   % Initiate first voice
732     \voiceOne
733     c16^( d e f g4 f e | d2 e2) |
734   }
735   \new Voice {   % Initiate second voice
736     \voiceTwo    % set stems, etc down
737     s4 r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2 |
738   }
739   \new Voice {   % Initiate third voice
740     \voiceThree  % set stems, etc up
741     s1 | s4 b4 c2 |
742   }
743 >>
744 @end lilypond
745
746
747
748 @node Voices and vocals
749 @subsection Voices and vocals
750
751 Vocal music presents a special difficulty: we need to combine two
752 expressions -- notes and lyrics.
753
754 You have already seen the @code{\lyricsAdd@{@}} command, which
755 handles simple cases for you.  However, this technique is
756 very limited.  For most music, you must explicitly link the lyrics
757 to the notes with @code{\lyricsto@{@}}, using the name assigned
758 to the Voice.
759
760 @lilypond[quote,verbatim,fragment]
761 <<
762   \new Voice = "one" \relative c'' {
763     \autoBeamOff
764     \time 2/4
765     c4 b8. a16 g4. f8 e4 d c2
766   }
767   \new Lyrics \lyricsto "one" {
768     No more let sins and sor -- rows grow.
769   }
770 >>
771 @end lilypond
772
773 Let us reuse the earlier example from Judas Maccabæus to 
774 illustrate this more flexible technique.  We first recast
775 it to use variables so the music and lyrics can be separated
776 from the staff structure.  We also introduce a choirstaff 
777 bracket.  The lyrics themselves must be introduced with 
778 @code{\lyricmode} to ensure they are interpreted as lyrics
779 rather than music.
780
781 @lilypond[quote,verbatim]
782 global = { \time 6/8 \partial 8 \key f \major}
783 SopOneMusic = \relative c'' {
784   c8 | c([ bes)] a a([ g)] f | f'4. b, | c4.~ c4 }
785 SopTwoMusic = \relative c' {
786   r8 | r4. r4 c8 | a'([ g)] f f([ e)] d | e([ d)] c bes' }
787 SopOneLyrics = \lyricmode {
788   Let | flee -- cy flocks the | hills a -- dorn, __ }
789 SopTwoLyrics = \lyricmode {
790   Let | flee -- cy flocks the | hills a -- dorn, }
791
792 \score {
793   \new ChoirStaff <<
794     \new Staff <<
795       \new Voice = "SopOne" {
796         \global
797         \SopOneMusic
798       }
799       \new Lyrics \lyricsto "SopOne" {
800         \SopOneLyrics
801       }
802     >>
803     \new Staff <<
804       \new Voice = "SopTwo" {
805         \SopTwoMusic
806       }
807       \new Lyrics \lyricsto "SopTwo" {
808         \SopTwoLyrics
809       }
810     >>
811   >>
812 }
813 @end lilypond
814
815 This is the basic structure of all vocal scores.  More staves may
816 be added as required, more voices may be added to the staves,
817 more verses may be added to the lyrics,
818 and the variables containing the music can easily be placed
819 in separate files should they become too long.
820
821 Here is a final example of the first line of a hymn with four
822 verses, set for SATB.  In this case the words for all four
823 parts are the same.
824
825 @lilypond[quote,verbatim]
826 global = { \time 4/4 \partial 4 \key c \major}
827 SopMusic   = \relative c' { c4 | e4. e8 g4  g  | a a g }
828 AltoMusic  = \relative c' { c4 | c4. c8 e4  e  | f f e }
829 TenorMusic = \relative c  { e4 | g4. g8 c4. b8 | a8 b c d e4 }
830 BassMusic  = \relative c  { c4 | c4. c8 c4  c  | f8 g a b c4 }
831 VerseOne   = \lyricmode { 
832   E -- | ter -- nal fa -- ther, | strong to save, }
833 VerseTwo   = \lyricmode { 
834   O | Christ, whose voice the | wa -- ters heard, }
835 VerseThree = \lyricmode { 
836   O | Ho -- ly Spi -- rit, | who didst brood }
837 VerseFour  = \lyricmode { 
838   O | Tri -- ni -- ty of | love and pow'r }
839
840 \score {
841   \new ChoirStaff <<
842     \new Staff <<
843       \clef "treble"
844       \new Voice = "Sop"  { \voiceOne \global \SopMusic }
845       \new Voice = "Alto" { \voiceTwo \AltoMusic }
846       \new Lyrics \lyricsto "Sop" { \VerseOne   }
847       \new Lyrics \lyricsto "Sop" { \VerseTwo   }
848       \new Lyrics \lyricsto "Sop" { \VerseThree }
849       \new Lyrics \lyricsto "Sop" { \VerseFour  }
850     >>
851     \new Staff <<
852       \clef "bass"
853       \new Voice = "Tenor" { \voiceOne \TenorMusic }
854       \new Voice = "Bass"  { \voiceTwo \BassMusic  }
855     >>
856   >>
857 }
858 @end lilypond
859
860 @node TODO new sec fundamental
861 @section TODO new sec fundamental
862
863 blh blah
864
865
866 @menu
867 * On the un-nestedness of brackets and ties::  
868 @end menu
869
870 @c my name start sucking the more docs I write. -gp
871 @node On the un-nestedness of brackets and ties
872 @subsection On the un-nestedness of brackets and ties
873
874 Different kinds of brackets and ties may be mixed freely,
875
876 TODO: improve this example
877
878 @lilypond[quote,verbatim,fragment,ragged-right]
879 {
880   r16[ g16 \times 2/3 {r16 e'8] }
881   g16( a \times 2/3 {b d e') }
882   g8[( a \times 2/3 {b d') e'~]}
883   \times 4/5 {e'32\( a b d' e'} a'4.\)
884 }
885 @end lilypond
886
887 TODO... add more info?  Fluff up the first sentence?
888
889
890 @node Extending the templates
891 @section Extending the templates
892
893 You've read the tutorial, you know how to write music.  But how can you
894 get the staves that you want?  The templates are ok, but what if you
895 want something that isn't covered?
896
897 @menu
898 * Soprano and cello::           
899 * TODO another example of extending templates::  
900 @end menu
901
902 @node Soprano and cello
903 @subsection Soprano and cello
904
905 Start off with the template that seems closest to what you want to end
906 up with.  Let's say that you want to write something for soprano and
907 cello.  In this case, we would start with @q{Notes and lyrics} (for the
908 soprano part).
909
910 @example
911 \version "2.11.23"
912 melody = \relative c' @{
913   \clef treble
914   \key c \major
915   \time 4/4
916
917   a4 b c d
918 @}
919
920 text = \lyricmode @{
921   Aaa Bee Cee Dee
922 @}
923
924 \score@{
925   <<
926     \new Voice = "one" @{
927       \autoBeamOff
928       \melody
929     @}
930     \new Lyrics \lyricsto "one" \text
931   >>
932   \layout @{ @}
933   \midi @{ @}
934 @}
935 @end example
936
937 Now we want to add a cello part.  Let's look at the @q{Notes only} example:
938
939 @example
940 \version "2.11.23"
941 melody = \relative c' @{
942   \clef treble
943   \key c \major
944   \time 4/4
945
946   a4 b c d
947 @}
948
949 \score @{
950 \new Staff \melody
951 \layout @{ @}
952 \midi @{ @}
953 @}
954 @end example
955
956 We don't need two @code{\version} commands.  We'll need the @code{melody}
957 section.  We don't want two @code{\score} sections -- if we had two
958 @code{\score}s, we'd get the two parts separately.  We want them together,
959 as a duet.  Within the @code{\score} section, we don't need two
960 @code{\layout} or @code{\midi}.
961
962 If we simply cut and paste the @code{melody} section, we would end up with
963 two @code{melody} sections.  So let's rename them.  We'll call the section
964 for the soprano @code{sopranoMusic} and the section for the cello
965 @code{celloMusic}.  While we're doing this, let's rename @code{text}
966 to be @code{sopranoLyrics}.  Remember to rename both instances of all
967 these names -- both the initial definition (the
968 @code{melody = relative c' @{ } part) and the name's use (in the
969 @code{\score} section).
970
971 While we're doing this, let's change the cello part's staff -- celli
972 normally use bass clef.  We'll also give the cello some different
973 notes.
974
975 @example
976 \version "2.11.23"
977 sopranoMusic = \relative c' @{
978   \clef treble
979   \key c \major
980   \time 4/4
981
982   a4 b c d
983 @}
984
985 sopranoLyrics = \lyricmode @{
986   Aaa Bee Cee Dee
987 @}
988
989 celloMusic = \relative c @{
990   \clef bass
991   \key c \major
992   \time 4/4
993
994   d4 g fis8 e d4
995 @}
996
997 \score@{
998   <<
999     \new Voice = "one" @{
1000       \autoBeamOff
1001       \sopranoMusic
1002     @}
1003     \new Lyrics \lyricsto "one" \sopranoLyrics
1004   >>
1005   \layout @{ @}
1006   \midi @{ @}
1007 @}
1008 @end example
1009
1010 This is looking promising, but the cello part won't appear in the
1011 score -- we haven't used it in the @code{\score} section.  If we
1012 want the cello part to appear under the soprano part, we need to add
1013
1014 @example
1015 \new Staff \celloMusic
1016 @end example
1017
1018 @noindent
1019 underneath the soprano stuff.  We also need to add @code{<<} and
1020 @code{>>} around the music -- that tells LilyPond that there's
1021 more than one thing (in this case, @code{Staff}) happening at once.  The
1022 @code{\score} looks like this now
1023
1024 @example
1025 \score@{
1026   <<
1027     <<
1028       \new Voice = "one" @{
1029         \autoBeamOff
1030         \sopranoMusic
1031       @}
1032       \new Lyrics \lyricsto "one" \sopranoLyrics
1033     >>
1034     \new Staff \celloMusic
1035   >>
1036   \layout @{ @}
1037   \midi @{ @}
1038 @}
1039 @end example
1040
1041 @noindent
1042 This looks a bit messy; the indentation is messed up now.  That is
1043 easily fixed.  Here's the complete soprano and cello template.
1044
1045 @lilypond[quote,verbatim,ragged-right]
1046 \version "2.11.23"
1047 sopranoMusic = \relative c' {
1048   \clef treble
1049   \key c \major
1050   \time 4/4
1051
1052   a4 b c d
1053 }
1054
1055 sopranoLyrics = \lyricmode {
1056   Aaa Bee Cee Dee
1057 }
1058
1059 celloMusic = \relative c {
1060   \clef bass
1061   \key c \major
1062   \time 4/4
1063
1064   d4 g fis8 e d4
1065 }
1066
1067 \score{
1068   <<
1069     <<
1070       \new Voice = "one" {
1071         \autoBeamOff
1072         \sopranoMusic
1073       }
1074       \new Lyrics \lyricsto "one" \sopranoLyrics
1075     >>
1076     \new Staff \celloMusic
1077   >>
1078   \layout { }
1079   \midi { }
1080 }
1081 @end lilypond
1082
1083
1084 @node TODO another example of extending templates
1085 @subsection TODO another example of extending templates
1086
1087 TODO: somebody else fill this in.  You guys like vocal stuff,
1088 right?  Get to it.  :)  -gp
1089
1090
1091
1092 @node Scores and parts
1093 @section Scores and parts
1094
1095 TODO: this is really old stuff from the really old tutorial.
1096 Rewrite, fix, etc.  Or maybe delete entirely.  -gp
1097
1098 In orchestral music, all notes are printed twice.  Once in a part for
1099 the musicians, and once in a full score for the conductor.  Variables can
1100 be used to avoid double work.  The music is entered once, and stored in
1101 a variable.  The contents of that variable is then used to generate
1102 both the part and the full score.
1103
1104 It is convenient to define the notes in a special file.  For example,
1105 suppose that the file @file{horn-music.ly} contains the following part
1106 of a horn/@/bassoon duo
1107
1108 @example
1109 hornNotes = \relative c @{
1110   \time 2/4
1111   r4 f8 a cis4 f e d
1112 @}
1113 @end example
1114
1115 @noindent
1116 Then, an individual part is made by putting the following in a file
1117
1118 @example
1119 \include "horn-music.ly"
1120 \header @{
1121   instrument = "Horn in F"
1122 @}
1123
1124 @{
1125  \transpose f c' \hornNotes
1126 @}
1127 @end example
1128
1129 The line
1130
1131 @example
1132 \include "horn-music.ly"
1133 @end example
1134
1135 @noindent
1136 substitutes the contents of @file{horn-music.ly} at this position in
1137 the file, so @code{hornNotes} is defined afterwards.  The command
1138 @code{\transpose f@tie{}c'} indicates that the argument, being
1139 @code{\hornNotes}, should be transposed by a fifth upwards.  Sounding
1140 @code{f} is denoted by notated @code{c'}, which corresponds with the
1141 tuning of a normal French Horn in@tie{}F.  The transposition can be seen
1142 in the following output
1143
1144 @lilypond[quote,ragged-right]
1145 \transpose f c' \relative c {
1146   \time 2/4
1147   r4 f8 a cis4 f e d
1148 }
1149 @end lilypond
1150
1151 In ensemble pieces, one of the voices often does not play for many
1152 measures.  This is denoted by a special rest, the multi-measure
1153 rest.  It is entered with a capital @code{R} followed by a duration
1154 (@code{1}@tie{}for a whole note, @code{2}@tie{}for a half note,
1155 etc.).  By multiplying the
1156 duration, longer rests can be constructed.  For example, this rest
1157 takes 3@tie{}measures in 2/4 time
1158
1159 @example
1160 R2*3
1161 @end example
1162
1163 When printing the part, multi-rests
1164 must be condensed.  This is done by setting a run-time variable
1165
1166 @example
1167 \set Score.skipBars = ##t
1168 @end example
1169
1170 @noindent
1171 This command sets the property @code{skipBars} in the
1172 @code{Score} context to true (@code{##t}).  Prepending the rest and
1173 this option to the music above, leads to the following result
1174
1175 @lilypond[quote,ragged-right]
1176 \transpose f c' \relative c {
1177   \time 2/4
1178   \set Score.skipBars = ##t
1179   R2*3
1180   r4 f8 a cis4 f e d
1181 }
1182 @end lilypond
1183
1184
1185 The score is made by combining all of the music together.  Assuming
1186 that the other voice is in @code{bassoonNotes} in the file
1187 @file{bassoon-music.ly}, a score is made with
1188
1189 @example
1190 \include "bassoon-music.ly"
1191 \include "horn-music.ly"
1192
1193 <<
1194   \new Staff \hornNotes
1195   \new Staff \bassoonNotes
1196 >>
1197 @end example
1198
1199 @noindent
1200 leading to
1201
1202 @lilypond[quote,ragged-right]
1203 \relative c <<
1204   \new Staff {
1205     \time 2/4 R2*3
1206     r4 f8 a cis4 f e d
1207   }
1208   \new Staff {
1209     \clef bass
1210     r4 d,8 f | gis4 c | b bes |
1211     a8 e f4 | g d | gis f
1212   }
1213 >>
1214 @end lilypond
1215
1216
1217