]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/fundamental.itely
Trevor updates.
[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 You've seen in the Tutorial how to produce beautifully printed
8 music from a simple text file.  This section introduces the
9 concepts and techniques required to produce equally beautiful
10 but more complex scores.
11
12 @menu
13 * How LilyPond files work::     
14 * Voices contain music::        
15 * Contexts and engravers::      
16 * Extending the templates::     
17 @end menu
18
19
20 @node How LilyPond files work
21 @section How LilyPond files work
22
23 The LilyPond input format is quite free-form, giving experienced
24 users a lot of flexibility to structure their files however they
25 wish.  But this flexibility can make things confusing for new
26 users.  This section will explain some of this structure, but may
27 gloss over some details in favor of simplicity.  For a complete
28 description of the input format, see @ruser{File structure}.
29
30 @menu
31 * Introduction to the LilyPond file structure::  
32 * Score is a (single) compound musical expression::  
33 * Nesting music expressions::   
34 * On the un-nestedness of brackets and ties::  
35 @end menu
36
37 @node Introduction to the LilyPond file structure
38 @subsection Introduction to the LilyPond file structure
39
40 A basic example of a lilypond input file is
41
42 @example
43 \version "2.11.23"
44 \score @{
45   @var{...compound music expression...}  % all the music goes here!
46   \header @{ @}
47   \layout @{ @}
48   \midi @{ @}
49 @}
50 @end example
51
52 @noindent
53 There are many variations of this basic pattern, but this
54 example serves as a useful starting place.
55
56 Up to this point none of the examples you have seen have used a
57 @code{\score@{@}} command.  This is because LilyPond automatically
58 adds the extra commands which are needed when you give it simple 
59 input.  LilyPond treats input like this:
60
61 @example
62 \relative c'' @{
63   c4 a d c
64 @}
65 @end example
66
67 @noindent
68 as shorthand for this:
69
70 @example
71 \book @{
72   \score @{
73     \new Staff @{
74       \new Voice @{
75         \relative c'' @{
76           c4 a b c
77         @}
78       @}
79     @}
80     \layout @{ @}
81   @}
82 @}
83 @end example
84
85 In other words, if the input contains a single music expression,
86 LilyPond will interpret the file as though the music expression
87 was wrapped up inside the commands shown above.  For now, though,
88 let us return to the first example and examine the @code{\score}
89 command, leaving the others to default.
90
91 A @code{\score} block must always contain just one music 
92 expression, and
93 this must appear first within the @code{\score @{..@}} block.
94 Remember that a music expression could be anything from a single
95 note to a huge compound expression like
96
97 @example
98 @{
99   \new GrandStaff <<
100     @var{...insert the whole score of a Wagner opera in here...}
101   >>
102 @}
103 @end example
104
105 @noindent
106 Since everything is inside @code{@{ ... @}}, it counts
107 as one music expression.
108
109 As we saw previously, the @code{\score} can contain other things,
110 such as
111
112 @example
113 \score @{
114   @{ c'4 a b c' @}
115   \header @{ @}
116   \layout @{ @}
117   \midi @{ @}
118 @}
119 @end example
120
121 @noindent
122 Some people put some of those commands outside the @code{\score}
123 block -- for example, @code{\header} is often placed above the
124 @code{\score}.  That's just another shorthand that LilyPond
125 accepts.
126
127 Two more commands you have not previously seen are
128 @code{\layout @{ @}} and @code{\midi @{@}}.  If these appear as 
129 shown they will cause LilyPond to produce a printed output and a 
130 MIDI out respectively.  They are described fully in the
131 Notation Reference -- @ruser{Score layout} and 
132 @ruser{Creating MIDI files}.
133
134 The @code{\book} command allows
135 several @code{\score} blocks to be combined into one output.
136 If there are several @code{\book} blocks each one produces a
137 separate output file.  For details see @ruser{Multiple scores
138 in a book}.
139
140 @cindex variables
141
142 Another great shorthand is the ability to define variables.  All
143 the templates use this
144
145 @example
146 melody = \relative c' @{
147   c4 a b c
148 @}
149
150 \score @{
151   \melody
152 @}
153 @end example
154
155 When LilyPond looks at this file, it takes the value of
156 @code{melody} (everything after the equals sign) and inserts it
157 whenever it sees @code{\melody}.  There's nothing special about
158 the names -- it could be @code{melody}, @code{global}, 
159 @code{TimeKey},
160 @code{pianorighthand}, or @code{foofoobarbaz}.  For more details,
161 see @ruser{Saving typing with variables and functions}.
162 Remember that you can use almost any name you like as long
163 as it contains just alphabetic characters and is distinct from
164 LilyPond command names.  The exact
165 limitations on variable names are detailed in 
166 @ruser{File structure}.
167
168
169
170 @seealso
171
172 For a complete definition of the input format, see
173 @ruser{File structure}.
174
175 @node Score is a (single) compound musical expression
176 @subsection Score is a (single) compound musical expression
177
178 @cindex Compound music expression
179 @cindex Music expression, compound
180
181 We saw the general organization of LilyPond input files in the
182 previous section, @ref{How LilyPond files work}.  But we seemed to
183 skip over the most important part: how do we figure out what to
184 write after @code{\score}?
185
186 We didn't skip over it at all.  The big mystery is simply that
187 there @emph{is} no mystery.  This line explains it all:
188
189 @quotation
190 @emph{A @code{\score} must begin with a compound music expression.}
191 @end quotation
192
193 @noindent
194 You may find it useful to review
195 @ref{Music expressions explained}.  In that section, we saw how to
196 build big music expressions from small pieces -- we started from
197 notes, then chords, etc.  Now we're going to start from a big
198 music expression and work our way down.
199
200 @example
201 \score @{
202   @{ % this brace begins the overall compound music expression
203     \new GrandStaff <<
204       @var{...insert the whole score of a Wagner opera in here...}
205     >>
206   @} % this brace ends the overall compound music expression
207   \layout @{ @}
208 @}
209 @end example
210
211 A whole Wagner opera would easily double the length of this
212 manual, so let's just add a singer and piano.  We don't need a
213 @code{GrandStaff} for this ensemble, which simply groups a number
214 of staves together with a brace at the left, so we shall remove 
215 it.  We @emph{do} need a singer and a piano, though.
216
217 @example
218 \score @{
219   @{
220     <<
221       \new Staff = "singer" <<
222       >>
223       \new PianoStaff = piano <<
224       >>
225     >>
226   @}
227   \layout @{ @}
228 @}
229 @end example
230
231 Remember that we use @code{<<} and @code{>>} to show simultaneous
232 music.  And we definitely want to show the vocal part and piano
233 part at the same time, not one after the other!  However, the
234 @code{<< .. >>} construct is not really necessary for the Singer
235 staff, as it contains only one music expression, but Staves often
236 do require simultaneous Voices within them, so using @code{<< .. >>}
237 rather than braces is a good habit to adopt.
238
239 @example
240 \score @{
241   @{
242     <<
243       \new Staff = "singer" <<
244         \new Voice = "vocal" @{ @}
245         \addlyrics @{ @}
246       >>
247       \new PianoStaff = "piano" <<
248         \new Staff = "upper" @{ @}
249         \new Staff = "lower" @{ @}
250       >>
251     >>
252   @}
253   \layout @{ @}
254 @}
255 @end example
256
257 Now we have a lot more details.  We have the singer's staff: it
258 contains a @code{Voice} (in LilyPond, this term refers to a set of
259 notes, not necessarily vocal notes -- for example, a violin
260 generally plays one voice) and some lyrics.  We also have a piano
261 staff: it contains an upper staff (right hand) and a lower staff
262 (left hand).
263
264 At this stage, we could start filling in notes.  Inside the curly
265 braces next to @code{\new Voice = vocal}, we could start writing
266
267 @example
268 \relative c'' @{
269   a4 b c d
270 @}
271 @end example
272
273 But if we did that, the @code{\score} section would get pretty
274 long, and it would be harder to understand what was happening.  So
275 let's use variables instead.
276
277 @example
278 melody = \relative c'' @{ @}
279 text   = \lyricmode @{ @}
280 upper  = \relative c'' @{ @}
281 lower  = \relative c @{ @}
282 \score @{
283   @{
284     <<
285       \new Staff = "singer" <<
286         \new Voice = "vocal" @{ \melody @}
287         \addlyrics @{ \text @}
288       >>
289       \new PianoStaff = "piano" <<
290         \new Staff = "upper" @{ \upper @}
291         \new Staff = "lower" @{ \lower @}
292       >>
293     >>
294   @}
295   \layout @{ @}
296 @}
297 @end example
298
299 Be careful about the difference between notes, which are introduced
300 with @code{\relative}, and lyrics, which are introduced with
301 @code{\lyricmode}.  These are essential to tell LilyPond
302 to interpret the following content as music and text
303 respectively.
304
305 When writing (or reading) a @code{\score} section, just take it
306 slowly and carefully.  Start with the outer layer, then work on
307 each smaller layer.  It also really helps to be strict with
308 indentation -- make sure that each item on the same layer starts
309 on the same horizontal position in your text editor.
310
311
312 @node Nesting music expressions
313 @subsection Nesting music expressions
314
315 It is not essential to declare all staves at the beginning; 
316 they may be introduced temporarily at any point.  This is
317 particularly useful for creating ossia sections 
318 (see @rglos{ossia}).  Here is a simple example showing how
319 to introduce a new staff temporarily for the duration of
320 three notes:
321
322 @lilypond[verbatim,quote,ragged-right]
323 \new Staff {
324   \relative g' {
325     r4 g8 g c4 c8 d |
326     e4 r8 
327     <<
328       { f c c }
329       \new Staff {
330         f8 f c
331       }
332     >>
333     r4 |
334   }
335 }
336 @end lilypond
337
338 @noindent
339 Note that the size of the clef is the same as a clef printed
340 following a clef change -- slightly smaller than the clef
341 at the begining of the line.  This is usual for clefs printed
342 in the middle of a line.
343
344 The ossia section may be placed above the staff
345 as follows:
346
347 @lilypond[verbatim,quote,ragged-right]
348 \new Staff ="main" {
349   \relative g' {
350     r4 g8 g c4 c8 d |
351     e4 r8
352     <<
353       { f c c }
354       \new Staff \with {
355         alignAboveContext = "main" }
356       { f8 f c }
357     >>
358     r4 |
359   }
360 }
361 @end lilypond
362
363 This example uses @code{\with}, which will be explained more 
364 fully later.  It is a means of modifying the default behaviour
365 of a Staff.  Here it says that the new staff should be placed
366 above the staff called @qq{main} instead of the default position
367 which is below.
368
369 Ossia are often written without clef and without
370 time signature and are usually in a smaller font.
371 These require further commands which
372 have not yet been introduced.  See @ref{Size of objects}
373
374 @node On the un-nestedness of brackets and ties
375 @subsection On the un-nestedness of brackets and ties
376
377 You have already met a number of different types of bracket in
378 writing the input file to LilyPond.  These obey different rules
379 which can be confusing at first.  Before we explain the rules 
380 let's first review the different types of bracket.
381
382 @c attempt to force this onto a new page
383 @need 50
384 @multitable @columnfractions .3 .7
385 @headitem Bracket Type
386   @tab Function
387 @item @code{@{ .. @}}
388   @tab Encloses a sequential segment of music
389 @item @code{< .. >}
390   @tab Encloses the notes of a chord
391 @item @code{<< .. >>}
392   @tab Encloses concurrent or simultaneous sections
393 @item @code{( .. )}
394   @tab Marks the start and end of a slur
395 @item @code{\( .. \)}
396   @tab Marks the start and end of a phrase mark
397 @item @code{[ .. ]}
398   @tab Marks the start and end of a manual beam
399 @end multitable
400
401 To these we should add other constructs which generate lines
402 between or across notes: ties (marked by a tilde, @code{~}),
403 tuplets written as @code{\times x/y @{..@}}, and grace notes
404 written as @code{\grace@{..@}}.
405
406 Outside LilyPond, the conventional use of brackets requires
407 the different types to be properly nested, like this,
408 @code{<< [ @{ ( .. ) @} ] >>}, with the closing brackets being
409 encountered in exactly the opposite order to the opening
410 brackets.  This @strong{is} a requirement for the three types of
411 bracket described by the word @q{Encloses} in the table above --
412 they must nest properly.
413 However, the remaining brackets, described with the word
414 @q{Marks} in the table above together with ties and tuplets,
415 do @strong{not} have to nest
416 properly with any of the brackets.  In fact, these are not
417 brackets in the sense that
418 they enclose something -- they are simply markers to indicate
419 where something starts and ends.
420
421 So, for example, a phrasing slur can start before a manually
422 inserted beam and end before the end of the beam -- not very
423 musical, perhaps, but possible:
424
425 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
426  { g8\( a b[ c b\) a] }
427 @end lilypond
428
429 In general, different kinds of brackets, and those implied by
430 tuplets, ties and grace notes, may be mixed freely.
431 This example shows a beam extending into a tuplet (line 1),
432 a slur extending into a tuplet (line 2),
433 a beam and a slur extending into a tuplet, a tie crossing
434 two tuplets, and a phrasing slur extending out of a tuplet
435 (lines 3 and 4).
436
437 @lilypond[quote,verbatim,fragment,ragged-right]
438 {
439   r16[ g16 \times 2/3 {r16 e'8] }
440   g16( a \times 2/3 {b d) e' }
441   g8[( a \times 2/3 {b d') e'~]}
442   \times 4/5 {e'32\( a b d' e'} a'4.\)
443 }
444 @end lilypond
445
446
447 @node Voices contain music
448 @section Voices contain music
449
450 Singers need voices to sing, and so does LilyPond.
451 The actual music for all instruments in a score 
452 is contained in Voices -- the most fundamental 
453 of all LilyPond's concepts.
454
455 @menu
456 * I'm hearing Voices::          
457 * Explicitly instantiating voices::  
458 * Voices and vocals::           
459 @end menu
460
461 @node I'm hearing Voices
462 @subsection I'm hearing Voices
463
464 @cindex polyphony
465 @cindex layers
466 @cindex Voice context
467
468 The lowest, most fundamental or innermost layers in a LilyPond 
469 score are called @q{Voice contexts} or just @q{Voices} for short.
470 Voices are sometimes called @q{layers} in other notation 
471 packages.
472
473 In fact, a Voice layer or context is the only one which can
474 contain music.  If a Voice context is not explicitly declared
475 one is created automatically, as we saw at the beginning of
476 this chapter.  Some instruments such as an 
477 Oboe can play only one note at a time.  Music written for
478 such instruments is monophonic and requires just a single
479 voice.  Instruments which can play more than one note at a
480 time like the piano will often require multiple voices to
481 encode the different concurrent notes and rhythms they are
482 capable of playing.  
483
484 A single voice can contain many notes in a chord, of course,
485 so when exactly are multiple voices needed? 
486 Let us analyse a short piece of music to see how many voices
487 are required.  Here are the notes from the first two bars
488 of the second of Chopin's Deux Nocturnes, Op 32.
489
490 @c The following should appear as music without code
491 @lilypond[quote,ragged-right]
492 \new Staff \relative c'' {
493   \key aes \major
494   <<
495     { \voiceOne
496       c2 aes4. bes8 } \\
497     { \voiceTwo
498       aes2 f4 fes } \\
499     { \voiceFour
500       \once \override NoteColumn #'force-hshift = #0 <ees c>2
501       \once \override NoteColumn #'force-hshift = #0.5 des2 }
502   >> |
503   <c ees aes c>1 |
504 }
505 @end lilypond
506
507 The direction of the stems is often used to indicate the
508 continuity of two simultaneous melodic lines.  Here the
509 stems of the highest notes are all pointing up and the
510 stems of the lower notes are all pointing down.
511 This is the first indication that more than one voice
512 is required.
513
514 But the real need for multiple voices arises when notes
515 which start at the same time have different durations.
516 Look at the notes which start at beat three in the first 
517 bar.  The a-flat is a dotted quarter note, the f is a
518 quarter note and the d-flat is a half note.  These 
519 cannot be written as a chord as all the notes in a chord
520 must have the same duration.  Neither can they be written
521 as sequential notes, as they must start at the same time.
522 This section of the bar requires three voices, and the
523 normal practice would be to write the whole bar as three
524 voices, as shown here, where we have used different noteheads
525 and colors for the three voices.
526
527 @c The following should appear as music without code
528 @c The three voice styles should be defined in -init
529 @lilypond[quote,ragged-right]
530 \new Staff \relative c'' {
531   \key aes \major
532   <<
533     { \voiceOne
534       \voiceOneStyle 
535       c2 aes4. bes8 } \\
536     { \voiceTwo
537       \voiceTwoStyle
538       aes2 f4 fes } \\
539     { \voiceFour
540       \voiceThreeStyle
541       \once \override NoteColumn #'force-hshift = #0 <ees c>2
542       \once \override NoteColumn #'force-hshift = #0.5 des2 }
543   >> |
544   <c ees aes c>1 |
545 }
546 @end lilypond
547
548 Let us see how this is done.
549 @smallspace
550
551 @funindex \\
552
553 The easiest way to enter fragments with more than one voice on a
554 staff is to enter each voice as a sequence (with @code{@{...@}}),
555 and combine them simultaneously with angle brackets, @code{<<...>>}.
556 The fragments must also be separated with double backward slashes, 
557 @code{\\}, to place them in separate voices.  Without these, the 
558 notes would be entered into a single voice, which would usually 
559 cause errors.  This technique is particularly suited to pieces of
560 music which are largely monophonic with occasional short sections
561 of polyphony.  Here's a simple example:
562
563 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
564 \key d \minor
565 %    Voice "1"             Voice "2"
566 << { r4 g g4. a8 }    \\ { d,2 d4 g }       >> |
567 << { bes4 bes c bes } \\ { g4 g g8( a) g4 } >> |
568 << { a2. r4 }         \\ { fis2. s4 }       >>
569 @end lilypond
570
571 It is not necessary to use a separate @code{<< \\ >>} construct
572 for each bar. For music with few notes in each bar this layout
573 can help the legibility of the code, but if there are many
574 notes in each bar it may be better to split out each voice
575 separately, like this:
576
577 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
578 \key d \minor
579 << {
580   % Voice "1"
581   r4 g g4. a8 |
582   bes4 bes c bes |
583   a2. r4 |
584 } \\ {
585   % Voice "2"
586   d,2 d4 g |
587   g4 g g8( a) g4 |
588   fis2. s4 |
589 } >>
590 @end lilypond
591
592
593 This example has just two voices, but the same contruct may be
594 used to encode three or more voices by adding more back-slash
595 separators.
596
597 The Voice contexts bear the names @code{"1"}, @code{"2"}, etc.  
598 In each of these contexts, the vertical direction of slurs, 
599 stems, ties, dynamics etc., is set appropriately.
600
601 @lilypond[quote,verbatim,fragment]
602 \new Staff \relative c' {
603   % Main voice
604   c16 d e f
605   %    Voice "1"     Voice "2"                 Voice "3"
606   << { g4 f e } \\ { r8 e4 d c8 ~ } >> |
607   << { d2 e2 }  \\ { c8 b16 a b8 g ~ g2 } \\ { s4 b4 c2 } >> |
608 }
609 @end lilypond
610
611 These voices are all separate from the main voice that contains
612 the notes just outside the @code{<< .. >>} construct.  Let's call
613 this the @emph{simultaneous construct}.  Slurs and ties may only
614 connect notes within the same voice, so slurs and ties cannot go
615 into or out of a simultaneous construct.  Conversely,
616 parallel voices from separate simultaneous constructs on the same
617 staff are the same voice.  Other voice-related properties also
618 carry across simultaneous constructs.  Here is the same example,
619 with different colors and noteheads for each voice.  Note that
620 changes in one Voice do not affect other voices, but they do
621 persist in the same Voice later.  Note also that tied notes may be
622 split across the same voices in two constructs, shown here in the
623 blue triangle voice.
624
625 @lilypond[quote,verbatim]
626 \new Staff \relative c' {
627   \voiceOneStyle
628   c16 d e f
629   << % Bar 1
630     { g4 f e } \\
631     {
632       \voiceTwoStyle
633       r8 e4 d c8 ~
634     }
635   >> |
636   << % Bar 2
637     { d2 e2 } \\
638     { c8 b16 a b8 g ~ g2 } \\
639     {
640       \voiceThreeStyle
641       s4 b4 c2
642      }
643   >>
644 }
645 @end lilypond
646
647 The commands @code{\voiceXXXStyle} are mainly intended for use in
648 educational documents such as this one.  They modify the color
649 of the notehead, the stem and the beams, and the style of the
650 notehead, so that the voices may be easily distinguished.
651 Voice one is set to red diamonds, voice two to blue triangles,
652 voice three to green crossed circles, and voice four (not used
653 here) to magenta crosses.  We shall see later how commands like 
654 these may be created by the user.  
655 See @ref{Visibility and color of objects}
656 TODO Add link to using variables for tweaks
657
658 Polyphony does not change the relationship of notes within a
659 @code{\relative @{ @}} block.  Each note is still calculated 
660 relative to the note immediately preceding it, or to the first 
661 note of the preceding chord.  So in
662
663 @example
664 \relative c' @{ noteA << < noteB noteC > \\ noteD >> noteE @}
665 @end example
666
667 @noindent
668 @code{noteB} is relative to @code{noteA}                      @*
669 @code{noteC} is relative to @code{noteB}, not @code{noteA};   @*
670 @code{noteD} is relative to @code{noteB}, not @code{noteA} or
671 @code{noteC}.                                                 @*
672 @code{noteE} is relative to @code{noteD}, not @code{noteA}
673
674 We are now in a position to return to the first example from
675 the Chopin Nocturne to see how this might be encoded.  As we
676 shall see, this encounters some difficulties.  We begin as
677 we have learnt, using the @code{<< \\  >>} construct to 
678 enter the music of the first bar in three voices:
679
680 @lilypond[quote,verbatim,fragment,ragged-right]
681 \new Staff \relative c'' {
682   \key aes \major
683   << 
684     { c2 aes4. bes8 } \\ { aes2 f4 fes } \\ { <ees c>2 des2 }
685   >> |
686   <c ees aes c>1 |
687 }
688 @end lilypond
689
690 @cindex stem down
691 @cindex stem up
692 @funindex \voiceOne
693 @funindex \voiceTwo
694 @funindex \voiceThree
695 @funindex \voiceFour
696
697 The stem directions are automatically assigned with the
698 odd-numbered voices taking upward stems and the even-numbered
699 voices downward ones.  The stems for voices 1 and 2 are right,
700 but the stems in voice 3 should go down in this particular piece
701 of music.  We can correct this
702 by telling LilyPond that this third voice is really a fourth
703 voice, with stems going down, using the @code{\voiceFour} 
704 command.  There are also corresponding @code{\voiceOne},
705 @code{\voiceTwo}, and @code{\voiceThree} 
706 commands.  This results in the following:
707
708 @lilypond[quote,verbatim,fragment,ragged-right]
709 \new Staff \relative c'' {
710   \key aes \major
711   << 
712     { c2 aes4. bes8 } \\ 
713     { aes2 f4 fes   } \\ 
714     { \voiceFour <ees c>2 des2 }
715   >> |
716   <c ees aes c>1 |
717 }
718 @end lilypond
719
720 @noindent
721 and exposes a problem commonly encountered with multiple
722 voices: the stems of notes can collide with noteheads
723 in other voices.  In laying out the notes, LilyPond allows the
724 notes or chords from two voices to occupy the same vertical
725 note column provided the stems are in opposite directions, but
726 the notes from a third voice are displaced to avoid the stems
727 colliding.  This often works well, but in this example the
728 notes of the third voice are clearly not well placed by default.
729 LilyPond provides several ways to adjust the horizontal placing
730 of notes.  We are not quite ready yet to see how to correct this,
731 so we shall leave this problem until a later section (see ... )
732
733 TODO link.
734
735 @node Explicitly instantiating voices
736 @subsection Explicitly instantiating voices
737
738 Voice contexts can also be created manually
739 inside a @code{<< >>} block to create polyphonic music, using
740 @code{\voiceOne} ... @code{\voiceFour} to indicate the required
741 directions of stems, slurs, etc.  In longer scores this method
742 is clearer, as it permits the voices to be separated and to be
743 given more descriptive names.
744
745 Specifically, the construct @code{<< \\ >>} which we used in
746 the previous section:
747
748 @example
749 \new Staff @{
750   \relative c' @{
751     << @{ e4 f g a @} \\ @{ c,4 d e f @} >>
752   @}
753 @}
754 @end example
755
756 @noindent
757 is equivalent to 
758
759 @example
760 \new Staff <<
761   \new Voice = "1" @{ \voiceOne \relative c' @{ e4 f g a @} @}
762   \new Voice = "2" @{ \voiceTwo \relative c' @{ c4 d e f @} @}
763 >>
764 @end example
765
766 Both of the above would produce
767
768 @c The following example should not display the code
769 FIXME: weird compiling bug!  Leave for gp.
770 @c @lilypond{ragged-right,quote]
771 @c \relative c' {
772 @c %  << { e4 f g a } \\ { c,4 d e f } >>
773 @c }
774 @c @end lilypond
775
776 The @code{\voiceXXX} commands set the direction of stems, slurs,
777 ties, articulations, text annotations, augmentation dots of dotted
778 notes, and fingerings.  @code{\voiceOne} and @code{\voiceThree}
779 make these objects point upwards, while @code{\voiceTwo} and
780 @code{\voiceFour} make them point downwards.  These commands also
781 generate a horizontal shift for each voice when this is required 
782 to avoid clashes of note heads.  The command @code{\oneVoice} 
783 reverts the settings back to the normal values for a single voice.
784
785 Let us see in some simple examples exactly what effect 
786 @code{\oneVoice}, @code{\voiceOne} and @code{voiceTwo} have on
787 markup, ties, slurs, and dynamics:
788
789 @lilypond[quote,ragged-right,verbatim]
790 \relative c'{ 
791   c-"default" d8 ~ d e4 ( f g a ) b-> c
792 }
793 @end lilypond
794
795 @lilypond[quote,ragged-right,verbatim]
796 \relative c'{
797   \voiceOne
798   c d8 ~ d e4 ( f g a ) b-> c
799   \oneVoice
800   c, d8 ~ d e4 ( f g a ) b-> c
801 }
802 @end lilypond
803
804 @lilypond[quote,ragged-right,verbatim]
805 \relative c'{
806   \voiceTwo
807   c d8 ~ d e4 ( f g a ) b-> c
808   \oneVoice
809   c, d8 ~ d e4 ( f g a ) b-> c
810 }
811 @end lilypond
812
813 An expression that appears directly inside a @code{<< >>} belongs
814 to the main voice (but, note, @strong{not} in a @code{<< \\ >>}
815 construct).  This is useful when extra voices appear while the
816 main voice is playing.  Here is a more correct rendition of the
817 example from the previous section.  The red diamond-shaped notes
818 demonstrate that the main melody is now in a single voice context,
819 permitting a phrasing slur to be drawn over them.
820
821 @lilypond[quote,ragged-right,verbatim]
822 \new Staff \relative c' {
823   \voiceOneStyle
824   c16^( d e f  % These notes are monophonic
825   <<           % Start simultaneous section of three voices
826     { g4 f e | d2 e2) }  % Continue the main voice in parallel
827     \new Voice {         % Initiate second voice
828       \voiceTwo          % Set stems, etc, down
829       r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2
830     }
831     \new Voice {         % Initiate third voice
832       \voiceThree        % Set stems, etc, up
833       s2. | s4 b4 c2 
834     }
835   >>
836 }
837 @end lilypond
838
839 @cindex nesting music expressions
840 @cindex nesting simultaneous constructs
841
842 More deeply nested polyphony constructs are possible, and if a
843 voice appears only briefly this might be a more natural way to
844 typeset the music.
845
846 @lilypond[quote,ragged-right,verbatim]
847 \new Staff \relative c' {
848   c16^( d e f
849   <<
850     { g4 f e | d2 e2) }
851     \new Voice {
852       \voiceTwo
853       r8 e4 d c8 ~ |
854       <<
855         {c8 b16 a b8 g ~ g2}
856         \new Voice { 
857           \voiceThree
858           s4 b4 c2
859         }
860       >>
861     }
862   >>
863 }
864 @end lilypond
865
866
867 This method of nesting new voices briefly is useful 
868 when only small sections of the music
869 are polyphonic, but when the whole staff is largely polyphonic
870 it can be clearer to use multiple voices throughout, using 
871 spacing notes to step over sections where the voice is silent, 
872 as here:
873
874 @lilypond[quote,ragged-right,verbatim]
875 \new Staff \relative c' <<
876   \new Voice {   % Initiate first voice
877     \voiceOne
878     c16^( d e f g4 f e | d2 e2) |
879   }
880   \new Voice {   % Initiate second voice
881     \voiceTwo    % set stems, etc down
882     s4 r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2 |
883   }
884   \new Voice {   % Initiate third voice
885     \voiceThree  % set stems, etc up
886     s1 | s4 b4 c2 |
887   }
888 >>
889 @end lilypond
890
891
892 @node Voices and vocals
893 @subsection Voices and vocals
894
895 Vocal music presents a special difficulty: we need to combine two
896 expressions -- notes and lyrics.
897
898 You have already seen the @code{\addlyrics@{@}} command, which
899 handles simple scores well.  However, this technique is
900 quite limited.  For more complex music, you must introduce the
901 lyrics in a @code{Lyrics} context using @code{\new Lyrics} and
902 explicitly link
903 the lyrics to the notes with @code{\lyricsto@{@}}, using the 
904 name assigned to the Voice.
905
906 @lilypond[quote,verbatim,fragment]
907 <<
908   \new Voice = "one" \relative c'' {
909     \autoBeamOff
910     \time 2/4
911     c4 b8. a16 g4. f8 e4 d c2
912   }
913   \new Lyrics \lyricsto "one" {
914     No more let sins and sor -- rows grow.
915   }
916 >>
917 @end lilypond
918
919 The automatic beaming which LilyPond uses by default works well
920 for instrumental music, but not so well for music with lyrics,
921 where beaming is either not required at all or is used to indicate
922 melismata in the lyrics.  In the example above we use the command
923 @code{\autoBeamOff} to turn off the automatic beaming.
924
925 Let us reuse the earlier example from Judas Maccabæus to 
926 illustrate this more flexible technique.  We first recast
927 it to use variables so the music and lyrics can be separated
928 from the staff structure.  We also introduce a ChoirStaff 
929 bracket.  The lyrics themselves must be introduced with 
930 @code{\lyricmode} to ensure they are interpreted as lyrics
931 rather than music.
932
933 @lilypond[quote,verbatim]
934 global = { \time 6/8 \partial 8 \key f \major}
935 SopOneMusic = \relative c'' {
936   c8 | c([ bes)] a a([ g)] f | f'4. b, | c4.~ c4 }
937 SopTwoMusic = \relative c' {
938   r8 | r4. r4 c8 | a'([ g)] f f([ e)] d | e([ d)] c bes' }
939 SopOneLyrics = \lyricmode {
940   Let | flee -- cy flocks the | hills a -- dorn, __ }
941 SopTwoLyrics = \lyricmode {
942   Let | flee -- cy flocks the | hills a -- dorn, }
943
944 \score {
945   \new ChoirStaff <<
946     \new Staff <<
947       \new Voice = "SopOne" {
948         \global
949         \SopOneMusic
950       }
951       \new Lyrics \lyricsto "SopOne" {
952         \SopOneLyrics
953       }
954     >>
955     \new Staff <<
956       \new Voice = "SopTwo" {
957         \SopTwoMusic
958       }
959       \new Lyrics \lyricsto "SopTwo" {
960         \SopTwoLyrics
961       }
962     >>
963   >>
964 }
965 @end lilypond
966
967 This is the basic structure of all vocal scores.  More staves may
968 be added as required, more voices may be added to the staves,
969 more verses may be added to the lyrics,
970 and the variables containing the music can easily be placed
971 in separate files should they become too long.
972
973 Here is a final example of the first line of a hymn with four
974 verses, set for SATB.  In this case the words for all four
975 parts are the same.
976
977 @lilypond[quote,verbatim]
978 TimeKey = { \time 4/4 \partial 4 \key c \major}
979 SopMusic   = \relative c' { c4 | e4. e8 g4  g  | a a g }
980 AltoMusic  = \relative c' { c4 | c4. c8 e4  e  | f f e }
981 TenorMusic = \relative c  { e4 | g4. g8 c4. b8 | a8 b c d e4 }
982 BassMusic  = \relative c  { c4 | c4. c8 c4  c  | f8 g a b c4 }
983 VerseOne   = \lyricmode { 
984   E -- | ter -- nal fa -- ther, | strong to save, }
985 VerseTwo   = \lyricmode { 
986   O | Christ, whose voice the | wa -- ters heard, }
987 VerseThree = \lyricmode { 
988   O | Ho -- ly Spi -- rit, | who didst brood }
989 VerseFour  = \lyricmode { 
990   O | Tri -- ni -- ty of | love and pow'r }
991
992 \score {
993   \new ChoirStaff <<
994     \new Staff <<
995       \clef "treble"
996       \new Voice = "Sop"  { \voiceOne \TimeKey \SopMusic }
997       \new Voice = "Alto" { \voiceTwo \AltoMusic }
998       \new Lyrics \lyricsto "Sop" { \VerseOne   }
999       \new Lyrics \lyricsto "Sop" { \VerseTwo   }
1000       \new Lyrics \lyricsto "Sop" { \VerseThree }
1001       \new Lyrics \lyricsto "Sop" { \VerseFour  }
1002     >>
1003     \new Staff <<
1004       \clef "bass"
1005       \new Voice = "Tenor" { \voiceOne \TenorMusic }
1006       \new Voice = "Bass"  { \voiceTwo \BassMusic  }
1007     >>
1008   >>
1009 }
1010 @end lilypond
1011
1012 @node Contexts and engravers
1013 @section Contexts and engravers
1014
1015 Contexts and engravers have been mentioned informally
1016 in earlier sections; we now must look at 
1017 these concepts in more detail, as they are important
1018 in the fine-tuning of LilyPond output.
1019
1020
1021 @menu
1022 * Contexts explained::          
1023 * Creating contexts::           
1024 * Engravers explained::         
1025 * Modifying context properties::  
1026 * Adding and removing engravers::  
1027 @end menu
1028
1029 @node Contexts explained
1030 @subsection Contexts explained
1031
1032 When music is printed, many notational elements which do not 
1033 appear explicitly in the input file must be added to the
1034 output.  For example, compare the input and output of the 
1035 following example:
1036
1037 @lilypond[quote,verbatim,relative=2,fragment]
1038 cis4 cis2. g4
1039 @end lilypond
1040
1041 The input is rather sparse, but in the output, bar lines, 
1042 accidentals, clef, and time signature have been added.  When 
1043 LilyPond @emph{interprets} the input the musical information 
1044 is inspected in time order, similar to reading a score from left 
1045 to right.  While reading the input, the program remembers where 
1046 measure boundaries are, and which pitches require explicit 
1047 accidentals.  This information must be held on several levels.  
1048 For example, the effect of an accidental is limited
1049 to a single staff, while a bar line must be synchronized across 
1050 the entire score.
1051
1052 Within LilyPond, these rules and bits of information are grouped
1053 in @emph{Contexts}.  We have already met the 
1054 @code{Voice} context. 
1055 Others are the @code{Staff} and @code{Score} contexts.  
1056 Contexts are hierarchical to reflect the heirarchical nature of 
1057 a musical score.  
1058 For example: a @code{Staff} context can contain many 
1059 @code{Voice} contexts, and a @code{Score} context can 
1060 contain many @code{Staff} contexts.
1061
1062 @quotation
1063 @image{context-example,5cm,,}
1064 @end quotation
1065
1066 Each context has the responsibility for enforcing some notation rules,
1067 creating some notation objects and maintaining the associated
1068 properties.  For example, the @code{Voice} context may introduce an
1069 accidental and then the @code{Staff} context maintains the rule to
1070 show or suppress the accidental for the remainder of the measure.
1071
1072 As another example, the synchronization of bar lines is, by default, 
1073 handled in the @code{Score} context.
1074 However, in some music we may not want the bar lines to be
1075 synchronized -- consider a polymetric score in 4/4 and 3/4 time.
1076 In such cases, we must modify the default settings of the 
1077 @code{Score} and @code{Staff} contexts.
1078
1079 For very simple scores, contexts are created implicitly, and you need
1080 not be aware of them.  For larger pieces, such as anything with more
1081 than one staff, they must be
1082 created explicitly to make sure that you get as many staves as you
1083 need, and that they are in the correct order.  For typesetting pieces
1084 with specialized notation, it is usual to modify existing, or
1085 even to define totally new, contexts.
1086
1087 In addition to the @code{Score,} @code{Staff} and 
1088 @code{Voice} contexts there are contexts which fit between
1089 the score and staff levels to control staff groups, such as the
1090 @code{PianoStaff} and @code{ChoirStaff} contexts.  There
1091 are also alternative staff and voice contexts, and contexts for
1092 lyrics, percussion, fret boards, figured bass, etc.  A complete
1093 list is shown in the Notation Reference.
1094 TODO: Add link
1095
1096 The names of all context types are formed from one or more 
1097 words, each word being capitalised and joined immediately to the 
1098 preceding word with no hyphen or underscore, e.g., 
1099 @code{GregorianTranscriptionStaff}.
1100
1101 @node Creating contexts
1102 @subsection Creating contexts
1103
1104 There can be only one top level context: the 
1105 @code{Score} 
1106 context.  This is created with the @code{\score} command, 
1107 or, in simple scores, it is created automatically.
1108
1109 For scores with only one voice and one staff, the 
1110 @code{Voice} and @code{Staff} contexts may be left to be 
1111 created automatically, but for more complex scores it is 
1112 necessary to create them by hand.  
1113 The simplest command that does this is @code{\new}.  
1114 It is prepended to a music expression, for example
1115
1116 @funindex \new
1117 @cindex new contexts
1118 @cindex Context, creating
1119
1120 @example
1121 \new @var{type} @var{music-expression}
1122 @end example
1123
1124 @noindent
1125 where @var{type} is a context name (like @code{Staff} or
1126 @code{Voice}).  This command creates a new context, and starts
1127 interpreting the @var{music-expression} within that context.
1128
1129 Note that there is no @code{\new Score} command;
1130 the single top-level @code{Score} context is introduced 
1131 with @code{\score}.  
1132
1133 The @code{\new} command may also give a identifying name to the 
1134 context to distinguish it from other contexts of the same type,
1135
1136 @example
1137 \new @var{type} = @var{id} @var{music-expression}
1138 @end example
1139
1140 Note the distinction between the name of the context type,
1141 @code{Staff}, @code{Voice}, etc, and
1142 the identifying name of a particular instance of that type,
1143 which can be any sequence of letters invented by the user.
1144 The identifying name is used to refer back to that particular
1145 instance of a context.  We saw this in use in the section on 
1146 lyrics in @ref{Voices and vocals}.
1147
1148
1149 @node Engravers explained
1150 @subsection Engravers explained
1151
1152 @cindex engravers
1153
1154 Every mark on the printed output of a score produced by LilyPond
1155 is produced by an @code{Engraver}.  Thus there is an engraver
1156 to print staves, one to print noteheads, one for stems, one for
1157 beams, etc, etc.  In total there are over 120 such engravers!
1158 Fortunately, for most scores it is not necessary to know about 
1159 more than a few, and for simple scores you do not need to know 
1160 about any.  
1161
1162 Engravers live and operate in Contexts.
1163 Engravers such as the @code{Metronome_mark_engraver}, whose
1164 action and output applies to the score as a whole, operate in
1165 the highest level context -- the @code{Score} context.
1166
1167 The @code{Clef_engraver} and @code{Key_engraver} are to be
1168 found in every Staff Context, as different staves may require 
1169 different clefs and keys.
1170
1171 The @code{Note_heads_engraver} and @code{Stem_engraver} live
1172 in each @code{Voice} context, the lowest level context of all.
1173
1174 Each engraver processes the particular objects associated
1175 with its function, and maintains the properties that relate
1176 to that function.  These properties, like the properties
1177 associated with contexts, may be modified to change the
1178 operation of the engraver or the appearance of those elements
1179 in the printed score.
1180    
1181 Engravers all have compound names formed from words which
1182 describe their function.  Just the first word is capitalised, 
1183 and the remainder are joined to it with underscores.  Thus
1184 the @code{Staff_symbol_engraver} is responsible for creating the
1185 lines of the staff, the @code{Clef_engraver} determines and sets
1186 the pitch reference point on the staff by drawing a clef symbol.
1187
1188 Here are some of the most common engravers together with their
1189 function.  You will see it is easy to guess the function from 
1190 the name, or vice versa.
1191
1192 @multitable @columnfractions .3 .7 
1193 @headitem Engraver
1194   @tab Function
1195 @item Accidental_engraver
1196   @tab Makes accidentals, cautionary and suggested accidentals
1197 @item Beam_engraver
1198   @tab Engraves beams
1199 @item Clef_engraver
1200   @tab Engraves clefs
1201 @item Dynamic_engraver
1202   @tab Creates hairpins and dynamic texts
1203 @item Key_engraver
1204   @tab Creates the key signature
1205 @item Metronome_mark_engraver
1206   @tab Engraves metronome marking
1207 @item Note_heads_engraver
1208   @tab Engraves noteheads
1209 @item Rest_engraver
1210   @tab Engraves rests
1211 @item Staff_symbol_engraver
1212   @tab Engraves the five (by default) lines of the staff
1213 @item Stem_engraver
1214   @tab Creates stems and single-stem tremulos
1215 @item Time_signature_engraver
1216   @tab Creates time signatures
1217 @end multitable
1218
1219 @smallspace
1220
1221 We shall see later how the output of LilyPond can be changed
1222 by modifying the action of Engravers.
1223   
1224
1225 @node Modifying context properties
1226 @subsection Modifying context properties
1227
1228 @cindex context properties
1229 @funindex \set
1230 @funindex \unset
1231
1232 Contexts are responsible for holding the values of a number of
1233 context @emph{properties}.  Many of them can be changed to
1234 influence the interpretation of the input and so change the
1235 appearance of the output.  They are changed by the 
1236 @code{\set} command.  This takes the form
1237
1238 @example
1239 \set @emph{ContextName}.@emph{propertyName} = #@emph{value}
1240 @end example
1241
1242 Where the @emph{ContextName} is usually @code{Score},
1243 @code{Staff} or @code{Voice}.  It may be omitted,
1244 in which case @code{Voice} is assumed.
1245
1246 The names of context properties consist of words joined
1247 together with no hyphens or underscores, all except the
1248 first having a capital letter.  Here are a few examples
1249 of some commonly used ones.  There are many more.
1250
1251 @c attempt to force this onto a new page
1252 @need 50
1253 @multitable @columnfractions .25 .2 .4 .15
1254 @headitem propertyName
1255   @tab Value
1256   @tab Function
1257   @tab Example
1258 @item extraNatural
1259   @tab Boolean
1260   @tab If true, set extra natural signs before accidentals
1261   @tab @code{#t}, @code{#f}
1262 @item currentBarNumber
1263   @tab Integer
1264   @tab Set the current bar number
1265   @tab @code{50}
1266 @item doubleSlurs
1267   @tab Boolean
1268   @tab If true, print slurs both above and below notes
1269   @tab @code{#t}, @code{#f}
1270 @item instrumentName
1271   @tab Text
1272   @tab Set the name to be placed at the start of the staff
1273   @tab @code{"Cello I"}
1274 @item fontSize
1275   @tab Real
1276   @tab Increase or decrease the font size
1277   @tab @code{2.4}
1278 @item stanza
1279   @tab Text
1280   @tab Set the text to print before the start of a verse
1281   @tab @code{"2"}
1282 @end multitable
1283 @noindent
1284 where a Boolean is either True (@code{#t}) or False (@code{#f}),
1285 an Integer is a positive whole number, a Real is a positive
1286 or negative decimal number, and text is enclosed in double
1287 apostrophes.  Note the occurrence of hash signs,
1288 (@code{#}), in two different places -- as part of the Boolean 
1289 value before the @code{t} or @code{f}, and before @emph{value}
1290 in the @code{\set} statement.  So when a Boolean is being 
1291 entered you need to code two hash signs, e.g., @code{##t}.
1292
1293 @smallspace   
1294
1295 Before we can set any of these properties we need to know
1296 in which context they operate.  Sometimes this is obvious,
1297 but occasionally it can be tricky.  If the wrong context
1298 is specified, no error message is produced, but the expected
1299 action will not be taken.  For example, the 
1300 @code{instrumentName} clearly lives in the Staff context, since
1301 it is the staff that is to be named.
1302 In this example the first staff is labelled, but not the second,
1303 because we omitted the context name.
1304
1305 @lilypond[quote,verbatim,ragged-right]
1306 <<
1307   \new Staff \relative c'' {
1308     \set Staff.instrumentName = "Soprano"
1309     c4 c
1310  }
1311   \new Staff \relative c' {
1312   \set instrumentName = "Alto"  % Wrong!
1313   d4 d 
1314  }
1315 >>
1316 @end lilypond
1317
1318 Remember the default context name is Voice, so the second
1319 @code{\set} command set the property @code{instrumentName} in the
1320 Voice context to @qq{Alto}, but as LilyPond does not look
1321 for any such property in the @code{Voice} context, no 
1322 further action took place.  This is not an error, and no error 
1323 message is logged in the log file.
1324
1325 Similarly, if the property name is mis-spelt no error message 
1326 is produced, and clearly the expected action cannot be performed.
1327 If fact, you can set any (fictitious) @q{property} using any 
1328 name you like in any context that exists by using the 
1329 @code{\set} command.  But if the name is not
1330 known to LilyPond it will not cause any action to be taken.
1331 This is one of the reasons why it is highly recommended to
1332 use a context-sensitive editor with syntax highlighting for
1333 editing LilyPond files, such as Vim, Jedit, ConTEXT or Emacs,
1334 since unknown property names will be highlighted differently.
1335
1336 The @code{instrumentName} property will take effect only
1337 if it is set in the @code{Staff} context, but
1338 some properties can be set in more than one context.
1339 For example, the property @code{extraNatural} is by
1340 default set to ##t (true) for all staves.  
1341 If it is set to ##f (false) in the @code{Staff} context 
1342 it applies just to the accidentals on that staff.  
1343 If it is set to false in the @code{Score} context
1344 it applies to all staves.
1345
1346 So this turns off extra naturals in one staff:
1347
1348 @lilypond[quote,verbatim,ragged-right]
1349 <<
1350   \new Staff \relative c'' {
1351     ais4 aes
1352  }
1353   \new Staff \relative c'' {
1354     \set Staff.extraNatural = ##f
1355     ais4 aes
1356  }
1357 >>
1358 @end lilypond
1359
1360 @noindent
1361 and this turns them off in all staves:
1362
1363 @lilypond[quote,verbatim,ragged-right]
1364 <<
1365   \new Staff \relative c'' {
1366     ais4 aes
1367  }
1368   \new Staff \relative c'' {
1369     \set Score.extraNatural = ##f
1370     ais4 aes
1371  }
1372 >>
1373 @end lilypond
1374
1375 The value of every property set in this way can be reset
1376 to its original value with the @code{\unset} command.
1377  
1378 The @code{\set} and @code{\unset} commands can appear anywhere
1379 in the input file and will take effect from the time they are
1380 encountered until the end of the score or until the property is 
1381 @code{\set} or @code{\unset} again.  Let's try changing the 
1382 font size, which affects the size of the note heads (among 
1383 other things) several times.
1384
1385 @lilypond[quote,verbatim,ragged-right,relative=1,fragment]
1386 c4 
1387 \set fontSize = #-4   % make noteheads smaller
1388 d e
1389 \set fontSize = #2.5  % make noteheads larger
1390 f g
1391 \unset fontSize       % return to original size
1392 a b
1393 @end lilypond
1394
1395 We have now seen how to set the values of several different
1396 types of property.  Note that integers and numbers are alway 
1397 preceded by a hash sign, @code{#}, while a true or false value 
1398 is specified by ##t and ##f, with two hash signs.  A text 
1399 property should be enclosed in double quotation signs, as above, 
1400 although we shall see later that text can actually be specified
1401 in a much more general way by using the very powerful 
1402 @code{markup} command. 
1403
1404
1405 @funindex \with
1406
1407 Context properties may also be set at the time the context is
1408 created.  Sometimes this is a clearer way of specifying a 
1409 property value if it is to remain fixed for the duration of
1410 the context.  When a context is created with a @code{\new}
1411 command it may be immediately followed by a 
1412 @code{\with @{ .. @}} block in which the property values are
1413 set.  For example, if we wish to suppress the printing of
1414 extra naturals for the duration of a staff we would write:
1415
1416 @lilypond[quote,verbatim,ragged-right]
1417 \new Staff \with {
1418   extraNatural = ##f
1419 }
1420 \relative c' {
1421   gis ges aes ais
1422 }
1423 @end lilypond
1424
1425 In effect this overrides the default value of the property.  It
1426 may still be changed dynamically using @code{\set} and 
1427 @code{\unset}.
1428
1429 @node Adding and removing engravers
1430 @subsection Adding and removing engravers
1431
1432 @cindex Engravers, adding
1433 @cindex Engravers, removing
1434
1435 @funindex \consists
1436 @funindex \remove
1437
1438 We have seen that contexts each contain several engravers, each
1439 of which is responsible for producing a particular part of the
1440 output, like barlines, staves, note heads, stems, etc.  If an
1441 engraver is removed from a context it can no longer produce its
1442 output.  This is a crude way of modifying the output, but it
1443 can sometimes be useful.  
1444
1445 To remove an engraver we can use the @code{\with} command placed
1446 immediately after the context creation command, as in the 
1447 previous section.
1448
1449 As an 
1450 illustration let's repeat an example from the previous 
1451 section with the staff lines removed.  Remember that the 
1452 staff lines are produced by the Staff_symbol_engraver.
1453
1454 @lilypond[quote,verbatim,ragged-right]
1455 \new Staff \with {
1456   \remove Staff_symbol_engraver
1457 }
1458 \relative c' {
1459   c4 
1460   \set fontSize = #-4  % make noteheads smaller
1461   d e
1462   \set fontSize = #2.5  % make noteheads larger
1463   f g
1464   \unset fontSize  % return to original size
1465   a b
1466 }
1467 @end lilypond
1468
1469 @cindex ambitus engraver
1470
1471 Engravers can also be added to contexts.  The command
1472 to do this is 
1473
1474 @code{\consists @emph{Engraver_name}},
1475
1476 placed inside a @code{\with} block.  Some vocal scores
1477 have an @rglos{ambitus} placed at the beginning of a
1478 staff to indicate the range of notes in that staff.
1479 The ambitus is produced by the @code{Ambitus_engraver},
1480 which is not normally included in any context.  If
1481 we add it to the @code{Voice} context it calculates
1482 the range from that voice only:
1483
1484 @lilypond[quote,verbatim,ragged-right]
1485 \new Staff <<
1486   \new Voice \with {
1487     \consists Ambitus_engraver
1488   }
1489   \relative c'' { 
1490     \voiceOne
1491     c a b g 
1492   }
1493   \new Voice
1494   \relative c' {
1495     \voiceTwo
1496     c e d f
1497   }
1498 >>
1499 @end lilypond
1500
1501 @noindent
1502 but if we add the Ambitus engraver to the 
1503 @code{Staff} context it calculates the range from all
1504 the notes in all the voices on that staff:
1505
1506 @lilypond[quote,verbatim,ragged-right]
1507 \new Staff \with {
1508     \consists Ambitus_engraver
1509   }
1510   <<
1511   \new Voice
1512   \relative c'' { 
1513     \voiceOne
1514     c a b g 
1515   }
1516   \new Voice
1517   \relative c' {
1518     \voiceTwo
1519     c e d f
1520   }
1521 >>
1522 @end lilypond
1523
1524
1525 @node Extending the templates
1526 @section Extending the templates
1527
1528 You've read the tutorial, you know how to write music, you 
1529 understand the fundamental concepts.  But how can you
1530 get the staves that you want?  Well, you can find lots of 
1531 templates (see @ref{Templates}) which may give you a start.  
1532 But what
1533 if you want something that isn't covered there?  Read on.
1534
1535 TODO Add links to templates after they have been moved to LSR
1536
1537 @menu
1538 * Soprano and cello::           
1539 * Four-part SATB vocal score::  
1540 * Building a score from scratch::  
1541 @end menu
1542
1543 @node Soprano and cello
1544 @subsection Soprano and cello
1545
1546 Start off with the template that seems closest to what you want to end
1547 up with.  Let's say that you want to write something for soprano and
1548 cello.  In this case, we would start with @q{Notes and lyrics} (for the
1549 soprano part).
1550
1551 @example
1552 \version "2.11.23"
1553 melody = \relative c' @{
1554   \clef treble
1555   \key c \major
1556   \time 4/4
1557
1558   a4 b c d
1559 @}
1560
1561 text = \lyricmode @{
1562   Aaa Bee Cee Dee
1563 @}
1564
1565 \score @{
1566   <<
1567     \new Voice = "one" @{
1568       \autoBeamOff
1569       \melody
1570     @}
1571     \new Lyrics \lyricsto "one" \text
1572   >>
1573   \layout @{ @}
1574   \midi @{ @}
1575 @}
1576 @end example
1577
1578 Now we want to add a cello part.  Let's look at the @q{Notes only} example:
1579
1580 @example
1581 \version "2.11.23"
1582 melody = \relative c' @{
1583   \clef treble
1584   \key c \major
1585   \time 4/4
1586
1587   a4 b c d
1588 @}
1589
1590 \score @{
1591   \new Staff \melody
1592   \layout @{ @}
1593   \midi @{ @}
1594 @}
1595 @end example
1596
1597 We don't need two @code{\version} commands.  We'll need the @code{melody}
1598 section.  We don't want two @code{\score} sections -- if we had two
1599 @code{\score}s, we'd get the two parts separately.  We want them together,
1600 as a duet.  Within the @code{\score} section, we don't need two
1601 @code{\layout} or @code{\midi}.
1602
1603 If we simply cut and paste the @code{melody} section, we would end up with
1604 two @code{melody} sections.  So let's rename them.  We'll call the section
1605 for the soprano @code{sopranoMusic} and the section for the cello
1606 @code{celloMusic}.  While we're doing this, let's rename @code{text}
1607 to be @code{sopranoLyrics}.  Remember to rename both instances of all
1608 these names -- both the initial definition (the
1609 @code{melody = relative c' @{ } part) and the name's use (in the
1610 @code{\score} section).
1611
1612 While we're doing this, let's change the cello part's staff -- celli
1613 normally use bass clef.  We'll also give the cello some different
1614 notes.
1615
1616 @example
1617 \version "2.11.23"
1618 sopranoMusic = \relative c' @{
1619   \clef treble
1620   \key c \major
1621   \time 4/4
1622
1623   a4 b c d
1624 @}
1625
1626 sopranoLyrics = \lyricmode @{
1627   Aaa Bee Cee Dee
1628 @}
1629
1630 celloMusic = \relative c @{
1631   \clef bass
1632   \key c \major
1633   \time 4/4
1634
1635   d4 g fis8 e d4
1636 @}
1637
1638 \score @{
1639   <<
1640     \new Voice = "one" @{
1641       \autoBeamOff
1642       \sopranoMusic
1643     @}
1644     \new Lyrics \lyricsto "one" \sopranoLyrics
1645   >>
1646   \layout @{ @}
1647   \midi @{ @}
1648 @}
1649 @end example
1650
1651 This is looking promising, but the cello part won't appear in the
1652 score -- we haven't used it in the @code{\score} section.  If we
1653 want the cello part to appear under the soprano part, we need to add
1654
1655 @example
1656 \new Staff \celloMusic
1657 @end example
1658
1659 @noindent
1660 underneath the soprano stuff.  We also need to add @code{<<} and
1661 @code{>>} around the music -- that tells LilyPond that there's
1662 more than one thing (in this case, two @code{Staves}) happening 
1663 at once.  The @code{\score} looks like this now
1664
1665 @c Indentation in this example is deliberately poor
1666 @example
1667 \score @{
1668   <<
1669   <<
1670     \new Voice = "one" @{
1671       \autoBeamOff
1672       \sopranoMusic
1673     @}
1674     \new Lyrics \lyricsto "one" \sopranoLyrics
1675   >>
1676   \new Staff \celloMusic
1677   >>
1678   \layout @{ @}
1679   \midi @{ @}
1680 @}
1681 @end example
1682
1683 @noindent
1684 This looks a bit messy; the indentation is messed up now.  That is
1685 easily fixed.  Here's the complete soprano and cello template.
1686
1687 @lilypond[quote,verbatim,ragged-right]
1688 \version "2.11.23"
1689 sopranoMusic = \relative c' {
1690   \clef treble
1691   \key c \major
1692   \time 4/4
1693
1694   a4 b c d
1695 }
1696
1697 sopranoLyrics = \lyricmode {
1698   Aaa Bee Cee Dee
1699 }
1700
1701 celloMusic = \relative c {
1702   \clef bass
1703   \key c \major
1704   \time 4/4
1705
1706   d4 g fis8 e d4
1707 }
1708
1709 \score {
1710   <<
1711     <<
1712       \new Voice = "one" {
1713         \autoBeamOff
1714         \sopranoMusic
1715       }
1716       \new Lyrics \lyricsto "one" \sopranoLyrics
1717     >>
1718     \new Staff \celloMusic
1719   >>
1720   \layout { }
1721   \midi { }
1722 }
1723 @end lilypond
1724
1725
1726 @node Four-part SATB vocal score
1727 @subsection Four-part SATB vocal score
1728
1729 Most vocal scores of music written for four-part mixed choir 
1730 with orchestral accompaniment such as Mendelssohn's Elijah or
1731 Handel's Messiah have the choral music and words on four
1732 staves, one for each of SATB, with a piano reduction of the
1733 orchestral accompaniment underneath.  Here's an example
1734 from Handel's Messiah:
1735
1736 @c The following should appear as music without code
1737 @lilypond[quote,ragged-right]
1738 \version "2.11.23"
1739 global = { \key d \major \time 4/4 }
1740 sopMusic = \relative c'' {
1741   \clef "treble"
1742   r4 d2 a4 | d4. d8 a2 | cis4 d cis2 |
1743 }
1744 sopWords = \lyricmode {
1745   Wor -- thy is the lamb that was slain
1746 }
1747 altoMusic = \relative a' {
1748   \clef "treble"
1749   r4 a2 a4 | fis4. fis8 a2 | g4 fis fis2 |
1750 }
1751 altoWords = \sopWords
1752 tenorMusic = \relative c' {
1753   \clef "G_8"
1754   r4 fis2 e4 | d4. d8 d2 | e4 a, cis2 |
1755 }
1756 tenorWords = \sopWords
1757 bassMusic = \relative c' {
1758   \clef "bass"
1759   r4 d2 cis4 | b4. b8 fis2 | e4 d a'2 |
1760 }
1761 bassWords = \sopWords
1762 upper = \relative a' {
1763   \clef "treble"
1764   \global
1765   r4 <a d fis>2 <a e' a>4 |
1766   <d fis d'>4. <d fis d'>8 <a d a'>2 |
1767   <g cis g'>4 <a d fis> <a cis e>2 |
1768 }
1769 lower = \relative c, {
1770   \clef "bass"
1771   \global
1772   <d d'>4 <d d'>2 <cis cis'>4 |
1773   <b b'>4. <b' b'>8 <fis fis'>2 |
1774   <e e'>4 <d d'> <a' a'>2 |
1775 }
1776
1777 \score {
1778   <<  % combine ChoirStaff and PianoStaff in parallel
1779     \new ChoirStaff <<
1780       \new Staff = "sopranos" <<
1781         \set Staff.instrumentName = "Soprano"
1782         \new Voice = "sopranos" { \global \sopMusic }
1783       >>
1784       \new Lyrics \lyricsto "sopranos" { \sopWords }
1785       \new Staff = "altos" <<
1786         \set Staff.instrumentName = "Alto"
1787         \new Voice = "altos" { \global \altoMusic }
1788       >>
1789       \new Lyrics \lyricsto "altos" { \altoWords }
1790       \new Staff = "tenors" <<
1791         \set Staff.instrumentName = "Tenor"
1792         \new Voice = "tenors" { \global \tenorMusic }
1793       >>
1794       \new Lyrics \lyricsto "tenors" { \tenorWords }
1795       \new Staff = "basses" <<
1796         \set Staff.instrumentName = "Bass"
1797         \new Voice = "basses" { \global \bassMusic }
1798       >>
1799       \new Lyrics \lyricsto "basses" { \bassWords }
1800     >>  % end ChoirStaff
1801
1802     \new PianoStaff <<
1803       \set PianoStaff.instrumentName = "Piano  "
1804       \new Staff = "upper" \upper
1805       \new Staff = "lower" \lower
1806     >>
1807   >>
1808 }
1809 @end lilypond
1810
1811 None of the templates provides this layout exactly.  The
1812 nearest is @q{SATB vocal score and automatic piano reduction},
1813 but we shall need to change the layout and add a piano
1814 accompaniment which is not derived automatically from the
1815 vocal parts.  The variables holding the music and words for
1816 the vocal parts are fine, but we shall need to add variables for
1817 the piano reduction.
1818
1819 The order in which the contexts appear in the ChoirStaff of
1820 the template do not correspond with the order in the vocal 
1821 score shown above.  We need to rearrange them so there are
1822 four staves with the words written directly underneath the
1823 notes for each part.
1824 All the voices should be @code{\voiceOne}, which is
1825 the default, so the @code{\voiceXXX} commands can be removed.
1826 We also need to specify the tenor clef for the tenors.
1827 The way in which lyrics are specified has also been simplified
1828 as we have not yet encountered the method used in the template.
1829 We've also added the names of each staff.
1830
1831 Doing this gives for our ChoirStaff:
1832
1833 @example
1834     \new ChoirStaff <<
1835       \new Staff = "sopranos" <<
1836         \set Staff.instrumentName = "Soprano"
1837         \new Voice = "sopranos" @{ \global \sopMusic @}
1838       >>
1839       \new Lyrics \lyricsto "sopranos" @{ \sopWords @}
1840       \new Staff = "altos" <<
1841         \set Staff.instrumentName = "Alto"
1842         \new Voice = "altos" @{ \global \altoMusic @}
1843       >>
1844       \new Lyrics \lyricsto "altos" @{ \altoWords @}
1845       \new Staff = "tenors" <<
1846         \set Staff.instrumentName = "Tenor"
1847         \new Voice = "tenors" @{ \global \tenorMusic @}
1848       >>
1849       \new Lyrics \lyricsto "tenors" @{ \tenorWords @}
1850       \new Staff = "basses" <<
1851         \set Staff.instrumentName = "Bass"
1852         \new Voice = "basses" @{ \global \bassMusic @}
1853       >>
1854       \new Lyrics \lyricsto "basses" @{ \bassWords @}
1855     >>  % end ChoirStaff
1856 @end example
1857
1858 Next we must work out the piano part.  This is
1859 easy - we just pull out the piano part from the
1860 @q{Solo piano} template:
1861
1862 @example
1863 \new PianoStaff <<
1864   \set PianoStaff.instrumentName = "Piano  "
1865   \new Staff = "upper" \upper
1866   \new Staff = "lower" \lower
1867 >>
1868 @end example
1869
1870 and add the variable definitions for @code{upper}
1871 and @code{lower}.
1872
1873 The ChoirStaff and PianoStaff must be combined
1874 using angle brackets as we want them to be
1875 stacked one above the other:
1876
1877 @example
1878 <<  % combine ChoirStaff and PianoStaff one above the other 
1879   \new ChoirStaff <<
1880     \new Staff = "sopranos" <<
1881       \new Voice = "sopranos" @{ \global \sopMusic @}
1882     >>
1883     \new Lyrics \lyricsto "sopranos" @{ \sopWords @}
1884     \new Staff = "altos" <<
1885       \new Voice = "altos" @{ \global \altoMusic @}
1886     >>
1887     \new Lyrics \lyricsto "altos" @{ \altoWords @}
1888     \new Staff = "tenors" <<
1889       \clef "G_8"  % tenor clef
1890       \new Voice = "tenors" @{ \global \tenorMusic @}
1891     >>
1892     \new Lyrics \lyricsto "tenors" @{ \tenorWords @}
1893     \new Staff = "basses" <<
1894       \clef "bass"
1895       \new Voice = "basses" @{ \global \bassMusic @}
1896     >>
1897     \new Lyrics \lyricsto "basses" @{ bassWords @}   
1898   >>  % end ChoirStaff
1899
1900   \new PianoStaff <<
1901     \set PianoStaff.instrumentName = "Piano  "
1902     \new Staff = "upper" \upper
1903     \new Staff = "lower" \lower
1904   >>
1905 >>
1906 @end example
1907
1908 Combining all these together and adding the music
1909 for the three bars of the example above gives:
1910
1911 @lilypond[quote,verbatim,ragged-right]
1912 \version "2.11.23"
1913 global = { \key d \major \time 4/4 }
1914 sopMusic = \relative c'' {
1915   \clef "treble"
1916   r4 d2 a4 | d4. d8 a2 | cis4 d cis2 |
1917 }
1918 sopWords = \lyricmode {
1919   Wor -- thy is the lamb that was slain
1920 }
1921 altoMusic = \relative a' {
1922   \clef "treble"
1923   r4 a2 a4 | fis4. fis8 a2 | g4 fis fis2 |
1924 }
1925 altoWords = \sopWords
1926 tenorMusic = \relative c' {
1927   \clef "G_8"
1928   r4 fis2 e4 | d4. d8 d2 | e4 a, cis2 |
1929 }
1930 tenorWords = \sopWords
1931 bassMusic = \relative c' {
1932   \clef "bass"
1933   r4 d2 cis4 | b4. b8 fis2 | e4 d a'2 |
1934 }
1935 bassWords = \sopWords
1936 upper = \relative a' {
1937   \clef "treble"
1938   \global
1939   r4 <a d fis>2 <a e' a>4 |
1940   <d fis d'>4. <d fis d'>8 <a d a'>2 |
1941   <g cis g'>4 <a d fis> <a cis e>2 |
1942 }
1943 lower = \relative c, {
1944   \clef "bass"
1945   \global
1946   <d d'>4 <d d'>2 <cis cis'>4 |
1947   <b b'>4. <b' b'>8 <fis fis'>2 |
1948   <e e'>4 <d d'> <a' a'>2 |
1949 }
1950
1951 \score {
1952   <<  % combine ChoirStaff and PianoStaff in parallel
1953     \new ChoirStaff <<
1954       \new Staff = "sopranos" <<
1955         \set Staff.instrumentName = "Soprano"
1956         \new Voice = "sopranos" { \global \sopMusic }
1957       >>
1958       \new Lyrics \lyricsto "sopranos" { \sopWords }
1959       \new Staff = "altos" <<
1960         \set Staff.instrumentName = "Alto"
1961         \new Voice = "altos" { \global \altoMusic }
1962       >>
1963       \new Lyrics \lyricsto "altos" { \altoWords }
1964       \new Staff = "tenors" <<
1965         \set Staff.instrumentName = "Tenor"
1966         \new Voice = "tenors" { \global \tenorMusic }
1967       >>
1968       \new Lyrics \lyricsto "tenors" { \tenorWords }
1969       \new Staff = "basses" <<
1970         \set Staff.instrumentName = "Bass"
1971         \new Voice = "basses" { \global \bassMusic }
1972       >>
1973       \new Lyrics \lyricsto "basses" { \bassWords }
1974     >>  % end ChoirStaff
1975
1976     \new PianoStaff <<
1977       \set PianoStaff.instrumentName = "Piano  "
1978       \new Staff = "upper" \upper
1979       \new Staff = "lower" \lower
1980     >>
1981   >>
1982 }
1983 @end lilypond
1984   
1985
1986 @node Building a score from scratch
1987 @subsection Building a score from scratch
1988
1989 After gaining some facility with writing LilyPond code you
1990 may find that it is easier to build a score from scratch
1991 rather than modifying one of the templates.  You can also
1992 develop your own style this way to suit the sort of music you
1993 like.  Let's see how to put together the score for an organ 
1994 prelude as an example.
1995
1996 We begin with a header section.  Here go the title, name
1997 of composer, etc, then come any variable definitions, and
1998 finally the score block.  Let's start with these in outline
1999 and fill in the details later.
2000
2001 We'll use the first two bars of Bach's prelude
2002 based on @emph{Jesu, meine Freude} which is written for two
2003 manuals and pedal organ.  The top manual part has two voices,
2004 the lower and pedal organ one each.  So we need four
2005 music definitions and one to define the time signature
2006 and key:
2007
2008 @example
2009 \version "2.11.23"
2010 \header @{
2011   title = "Jesu, meine Freude"
2012   composer = "J S Bach"
2013 @}
2014 TimeKey = @{ \time 4/4 \key c \minor @}
2015 ManualOneVoiceOneMusic = @{s1@}
2016 ManualOneVoiceTwoMusic = @{s1@}
2017 ManualTwoMusic = @{s1@}
2018 PedalOrganMusic = @{s1@}
2019
2020 \score @{
2021 @}
2022 @end example
2023
2024 For now we've just used a spacer note, @code{s1},
2025 instead of the real music.  We'll add that later.
2026
2027 Next let's see what should go in the score block.
2028 We simply mirror the staff structure we want.
2029 Organ music is usually written on three staves,
2030 one for each manual and one for the pedals.  The
2031 manual staves should be bracketed together so we
2032 need to use a PianoStaff for them.  The first
2033 manual part needs two voices and the second manual
2034 part just one.
2035
2036 @example
2037   \new PianoStaff <<
2038     \new Staff = "ManualOne" <<
2039       \new Voice @{ \ManualOneVoiceOneMusic @}
2040       \new Voice @{ \ManualOneVoiceTwoMusic @}
2041     >>  % end ManualOne Staff context
2042     \new Staff = "ManualTwo" <<
2043       \new Voice @{ \ManualTwoMusic @}
2044     >>  % end ManualTwo Staff context
2045   >>  % end PianoStaff context
2046 @end example
2047
2048 Next we need to add a staff for the pedal organ.
2049 This goes underneath the PianoStaff, but it must
2050 be simultaneous with it, so we need angle brackets
2051 round the two.  Missing these out would generate
2052 an error in the log file.  It's a common mistake 
2053 which you'll make sooner or later!  Try copying
2054 the final example at the end of this section,
2055 remove these angle brackets, and compile it to
2056 see what errors it generates.
2057
2058 @example
2059 <<  % PianoStaff and Pedal Staff must be simultaneous
2060   \new PianoStaff <<
2061     \new Staff = "ManualOne" <<
2062       \new Voice @{ \ManualOneVoiceOneMusic @}
2063       \new Voice @{ \ManualOneVoiceTwoMusic @}
2064     >>  % end ManualOne Staff context
2065     \new Staff = "ManualTwo" <<
2066       \new Voice @{ \ManualTwoMusic @}
2067     >>  % end ManualTwo Staff context
2068   >>  % end PianoStaff context
2069   \new Staff = "PedalOrgan" <<
2070     \new Voice @{ \PedalOrganMusic @}
2071   >>
2072 >>
2073 @end example
2074
2075 It is not strictly necessary to use the simultaneous construct
2076 @code{<<  >>} for the manual two staff and the pedal organ staff,
2077 since they contain only one music expression, but it does no harm
2078 and always using angle brackets after @code{\new Staff} is a good
2079 habit to cultivate in case there are multiple voices.  
2080
2081 Let's add this structure to the score block, and adjust the
2082 indenting.  We also add the appropriate clefs, ensure the
2083 second voice stems point down with @code{\voiceTwo} and
2084 enter the time signature and key to each staff using our
2085 predefined variable, @code{\TimeKey}.
2086
2087 @example
2088 \score @{
2089   <<  % PianoStaff and Pedal Staff must be simultaneous
2090     \new PianoStaff <<
2091       \new Staff = "ManualOne" <<
2092         \TimeKey  % set time signature and key
2093         \clef "treble"
2094         \new Voice @{ \ManualOneVoiceOneMusic @}
2095         \new Voice @{ \voiceTwo \ManualOneVoiceTwoMusic @}
2096       >>  % end ManualOne Staff context
2097       \new Staff = "ManualTwo" <<
2098         \TimeKey
2099         \clef "bass"
2100         \new Voice @{ \ManualTwoMusic @}
2101       >>  % end ManualTwo Staff context
2102     >>  % end PianoStaff context
2103     \new Staff = "PedalOrgan" <<
2104       \TimeKey
2105       \clef "bass"
2106       \new Voice @{ \PedalOrganMusic @}
2107     >>  % end PedalOrgan Staff
2108   >>
2109 @}  % end Score context
2110 @end example
2111
2112 That completes the structure.  Any three-staff organ music
2113 will have a similar structure, although the number of voices
2114 may vary.  All that remains now 
2115 is to add the music, and combine all the parts together.
2116
2117 @lilypond[quote,verbatim,ragged-right]
2118 \version "2.11.23"
2119 \header {
2120   title = "Jesu, meine Freude"
2121   composer = "J S Bach"
2122 }
2123 TimeKey = { \time 4/4 \key c \minor }
2124 ManualOneVoiceOneMusic = \relative g' {
2125   g4 g f ees | d2 c2 |
2126 }
2127 ManualOneVoiceTwoMusic = \relative c' {
2128   ees16 d ees8~ ees16 f ees s c8 d~ d c~ |
2129   c c4 b8 c8. g16 c b c d |
2130 }
2131 ManualTwoMusic = \relative c' {
2132   c16 b c8~ c16 b c g a8 g~ g16 g aes ees |
2133   f ees f d g aes g f ees d e8~ ees16 f ees d |
2134 }
2135 PedalOrganMusic = \relative c {
2136   r8 c16 d ees d ees8~ ees16 a, b g c b c8 |
2137   r16 g ees f g f g8 c,2 |
2138   }
2139
2140 \score {
2141   <<  % PianoStaff and Pedal Staff must be simultaneous
2142     \new PianoStaff <<
2143       \new Staff = "ManualOne" <<
2144         \TimeKey  % set time signature and key
2145         \clef "treble"
2146         \new Voice { \ManualOneVoiceOneMusic }
2147         \new Voice { \voiceTwo \ManualOneVoiceTwoMusic }
2148       >>  % end ManualOne Staff context
2149       \new Staff = "ManualTwo" <<
2150         \TimeKey
2151         \clef "bass"
2152         \new Voice { \ManualTwoMusic }
2153       >>  % end ManualTwo Staff context
2154     >>  % end PianoStaff context
2155     \new Staff = "PedalOrgan" <<
2156       \TimeKey
2157       \clef "bass"
2158       \new Voice { \PedalOrganMusic }
2159     >>  % end PedalOrgan Staff
2160   >>
2161 }  % end Score context
2162 @end lilypond
2163
2164
2165