]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/fundamental.itely
Update from Trevor.
[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
550 @funindex \\
551
552 The easiest way to enter fragments with more than one voice on a
553 staff is to enter each voice as a sequence (with @code{@{...@}}),
554 and combine them simultaneously with angle brackets, @code{<<...>>}.
555 The fragments must also be separated with double backward slashes, 
556 @code{\\}, to place them in separate voices.  Without these, the 
557 notes would be entered into a single voice, which would usually 
558 cause errors.  This technique is particularly suited to pieces of
559 music which are largely monophonic with occasional short sections
560 of polyphony.  Here's a simple example:
561
562 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
563 \key d \minor
564 %    Voice "1"             Voice "2"
565 << { r4 g g4. a8 }    \\ { d,2 d4 g }       >> |
566 << { bes4 bes c bes } \\ { g4 g g8( a) g4 } >> |
567 << { a2. r4 }         \\ { fis2. s4 }       >>
568 @end lilypond
569
570 It is not necessary to use a separate @code{<< \\ >>} construct
571 for each bar. For music with few notes in each bar this layout
572 can help the legibility of the code, but if there are many
573 notes in each bar it may be better to split out each voice
574 separately, like this:
575
576 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
577 \key d \minor
578 << {
579   % Voice "1"
580   r4 g g4. a8 |
581   bes4 bes c bes |
582   a2. r4 |
583 } \\ {
584   % Voice "2"
585   d,2 d4 g |
586   g4 g g8( a) g4 |
587   fis2. s4 |
588 } >>
589 @end lilypond
590
591
592 This example has just two voices, but the same contruct may be
593 used to encode three or more voices by adding more back-slash
594 separators.
595
596 The Voice contexts bear the names @code{"1"}, @code{"2"}, etc.  
597 In each of these contexts, the vertical direction of slurs, 
598 stems, ties, dynamics etc., is set appropriately.
599
600 @lilypond[quote,verbatim,fragment]
601 \new Staff \relative c' {
602   % Main voice
603   c16 d e f
604   %    Voice "1"     Voice "2"                 Voice "3"
605   << { g4 f e } \\ { r8 e4 d c8 ~ } >> |
606   << { d2 e2 }  \\ { c8 b16 a b8 g ~ g2 } \\ { s4 b4 c2 } >> |
607 }
608 @end lilypond
609
610 These voices are all separate from the main voice that contains
611 the notes just outside the @code{<< .. >>} construct.  Let's call
612 this the @emph{simultaneous construct}.  Slurs and ties may only
613 connect notes within the same voice, so slurs and ties cannot go
614 into or out of a simultaneous construct.  Conversely,
615 parallel voices from separate simultaneous constructs on the same
616 staff are the same voice.  Other voice-related properties also
617 carry across simultaneous constructs.  Here is the same example,
618 with different colors and noteheads for each voice.  Note that
619 changes in one Voice do not affect other voices, but they do
620 persist in the same Voice later.  Note also that tied notes may be
621 split across the same voices in two constructs, shown here in the
622 blue triangle voice.
623
624 @lilypond[quote,verbatim]
625 \new Staff \relative c' {
626   \voiceOneStyle
627   c16 d e f
628   << % Bar 1
629     { g4 f e } \\
630     {
631       \voiceTwoStyle
632       r8 e4 d c8 ~
633     }
634   >> |
635   << % Bar 2
636     { d2 e2 } \\
637     { c8 b16 a b8 g ~ g2 } \\
638     {
639       \voiceThreeStyle
640       s4 b4 c2
641      }
642   >>
643 }
644 @end lilypond
645
646 The commands @code{\voiceXXXStyle} are mainly intended for use in
647 educational documents such as this one.  They modify the color
648 of the notehead, the stem and the beams, and the style of the
649 notehead, so that the voices may be easily distinguished.
650 Voice one is set to red diamonds, voice two to blue triangles,
651 voice three to green crossed circles, and voice four (not used
652 here) to magenta crosses.  We shall see later how commands like 
653 these may be created by the user.  
654 See @ref{Visibility and color of objects}
655 TODO Add link to using variables for tweaks
656
657 Polyphony does not change the relationship of notes within a
658 @code{\relative @{ @}} block.  Each note is still calculated 
659 relative to the note immediately preceding it, or to the first 
660 note of the preceding chord.  So in
661
662 @example
663 \relative c' @{ noteA << < noteB noteC > \\ noteD >> noteE @}
664 @end example
665
666 @noindent
667 @code{noteB} is relative to @code{noteA}                      @*
668 @code{noteC} is relative to @code{noteB}, not @code{noteA};   @*
669 @code{noteD} is relative to @code{noteB}, not @code{noteA} or
670 @code{noteC}.                                                 @*
671 @code{noteE} is relative to @code{noteD}, not @code{noteA}
672
673 We are now in a position to return to the first example from
674 the Chopin Nocturne to see how this might be encoded.  As we
675 shall see, this encounters some difficulties.  We begin as
676 we have learnt, using the @code{<< \\  >>} construct to 
677 enter the music of the first bar in three voices:
678
679 @lilypond[quote,verbatim,fragment,ragged-right]
680 \new Staff \relative c'' {
681   \key aes \major
682   << 
683     { c2 aes4. bes8 } \\ { aes2 f4 fes } \\ { <ees c>2 des2 }
684   >> |
685   <c ees aes c>1 |
686 }
687 @end lilypond
688
689 @cindex stem down
690 @cindex stem up
691 @funindex \voiceOne
692 @funindex \voiceTwo
693 @funindex \voiceThree
694 @funindex \voiceFour
695
696 The stem directions are automatically assigned with the
697 odd-numbered voices taking upward stems and the even-numbered
698 voices downward ones.  The stems for voices 1 and 2 are right,
699 but the stems in voice 3 should go down in this particular piece
700 of music.  We can correct this
701 by telling LilyPond that this third voice is really a fourth
702 voice, with stems going down, using the @code{\voiceFour} 
703 command.  There are also corresponding @code{\voiceOne},
704 @code{\voiceTwo}, and @code{\voiceThree} 
705 commands.  This results in the following:
706
707 @lilypond[quote,verbatim,fragment,ragged-right]
708 \new Staff \relative c'' {
709   \key aes \major
710   << 
711     { c2 aes4. bes8 } \\ 
712     { aes2 f4 fes   } \\ 
713     { \voiceFour <ees c>2 des2 }
714   >> |
715   <c ees aes c>1 |
716 }
717 @end lilypond
718
719 @noindent
720 and exposes a problem commonly encountered with multiple
721 voices: the stems of notes can collide with noteheads
722 in other voices.  In laying out the notes, LilyPond allows the
723 notes or chords from two voices to occupy the same vertical
724 note column provided the stems are in opposite directions, but
725 the notes from a third voice are displaced to avoid the stems
726 colliding.  This often works well, but in this example the
727 notes of the third voice are clearly not well placed by default.
728 LilyPond provides several ways to adjust the horizontal placing
729 of notes.  We are not quite ready yet to see how to correct this,
730 so we shall leave this problem until a later section 
731 (see @ref{Fixing overlapping notation} )
732
733 @node Explicitly instantiating voices
734 @subsection Explicitly instantiating voices
735
736 Voice contexts can also be created manually
737 inside a @code{<< >>} block to create polyphonic music, using
738 @code{\voiceOne} ... @code{\voiceFour} to indicate the required
739 directions of stems, slurs, etc.  In longer scores this method
740 is clearer, as it permits the voices to be separated and to be
741 given more descriptive names.
742
743 Specifically, the construct @code{<< \\ >>} which we used in
744 the previous section:
745
746 @example
747 \new Staff @{
748   \relative c' @{
749     << @{ e4 f g a @} \\ @{ c,4 d e f @} >>
750   @}
751 @}
752 @end example
753
754 @noindent
755 is equivalent to 
756
757 @example
758 \new Staff <<
759   \new Voice = "1" @{ \voiceOne \relative c' @{ e4 f g a @} @}
760   \new Voice = "2" @{ \voiceTwo \relative c' @{ c4 d e f @} @}
761 >>
762 @end example
763
764 Both of the above would produce
765
766 @c The following example should not display the code
767 FIXME: weird compiling bug!  Leave for gp.
768 @c @lilypond{ragged-right,quote]
769 @c \relative c' {
770 @c %  << { e4 f g a } \\ { c,4 d e f } >>
771 @c }
772 @c @end lilypond
773
774 The @code{\voiceXXX} commands set the direction of stems, slurs,
775 ties, articulations, text annotations, augmentation dots of dotted
776 notes, and fingerings.  @code{\voiceOne} and @code{\voiceThree}
777 make these objects point upwards, while @code{\voiceTwo} and
778 @code{\voiceFour} make them point downwards.  These commands also
779 generate a horizontal shift for each voice when this is required 
780 to avoid clashes of note heads.  The command @code{\oneVoice} 
781 reverts the settings back to the normal values for a single voice.
782
783 Let us see in some simple examples exactly what effect 
784 @code{\oneVoice}, @code{\voiceOne} and @code{voiceTwo} have on
785 markup, ties, slurs, and dynamics:
786
787 @lilypond[quote,ragged-right,verbatim]
788 \relative c'{ 
789   c-"default" d8 ~ d e4 ( f g a ) b-> c
790 }
791 @end lilypond
792
793 @lilypond[quote,ragged-right,verbatim]
794 \relative c'{
795   \voiceOne
796   c d8 ~ d e4 ( f g a ) b-> c
797   \oneVoice
798   c, d8 ~ d e4 ( f g a ) b-> c
799 }
800 @end lilypond
801
802 @lilypond[quote,ragged-right,verbatim]
803 \relative c'{
804   \voiceTwo
805   c d8 ~ d e4 ( f g a ) b-> c
806   \oneVoice
807   c, d8 ~ d e4 ( f g a ) b-> c
808 }
809 @end lilypond
810
811 An expression that appears directly inside a @code{<< >>} belongs
812 to the main voice (but, note, @strong{not} in a @code{<< \\ >>}
813 construct).  This is useful when extra voices appear while the
814 main voice is playing.  Here is a more correct rendition of the
815 example from the previous section.  The red diamond-shaped notes
816 demonstrate that the main melody is now in a single voice context,
817 permitting a phrasing slur to be drawn over them.
818
819 @lilypond[quote,ragged-right,verbatim]
820 \new Staff \relative c' {
821   \voiceOneStyle
822   % The following notes are monophonic
823   c16^( d e f
824   % Start simultaneous section of three voices
825   <<
826     % Continue the main voice in parallel
827     { g4 f e | d2 e2) }
828     % Initiate second voice
829     \new Voice {
830       % Set stems, etc, down
831       \voiceTwo
832       r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2
833     }
834     % Initiate third voice
835     \new Voice {
836       % Set stems, etc, up
837       \voiceThree
838       s2. | s4 b4 c2
839     }
840   >>
841 }
842 @end lilypond
843
844 @cindex nesting music expressions
845 @cindex nesting simultaneous constructs
846
847 More deeply nested polyphony constructs are possible, and if a
848 voice appears only briefly this might be a more natural way to
849 typeset the music.
850
851 @lilypond[quote,ragged-right,verbatim]
852 \new Staff \relative c' {
853   c16^( d e f
854   <<
855     { g4 f e | d2 e2) }
856     \new Voice {
857       \voiceTwo
858       r8 e4 d c8 ~ |
859       <<
860         {c8 b16 a b8 g ~ g2}
861         \new Voice {
862           \voiceThree
863           s4 b4 c2
864         }
865       >>
866     }
867   >>
868 }
869 @end lilypond
870
871
872 This method of nesting new voices briefly is useful
873 when only small sections of the music
874 are polyphonic, but when the whole staff is largely polyphonic
875 it can be clearer to use multiple voices throughout, using
876 spacing notes to step over sections where the voice is silent,
877 as here:
878
879 @lilypond[quote,ragged-right,verbatim]
880 \new Staff \relative c' <<
881   % Initiate first voice
882   \new Voice {
883     \voiceOne
884     c16^( d e f g4 f e | d2 e2) |
885   }
886   % Initiate second voice
887   \new Voice {
888     % set stems, etc down
889     \voiceTwo
890     s4 r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2 |
891   }
892   % Initiate third voice
893   \new Voice {
894     % set stems, etc up
895     \voiceThree
896     s1 | s4 b4 c2 |
897   }
898 >>
899 @end lilypond
900
901
902 @node Voices and vocals
903 @subsection Voices and vocals
904
905 Vocal music presents a special difficulty: we need to combine two
906 expressions -- notes and lyrics.
907
908 You have already seen the @code{\addlyrics@{@}} command, which
909 handles simple scores well.  However, this technique is
910 quite limited.  For more complex music, you must introduce the
911 lyrics in a @code{Lyrics} context using @code{\new Lyrics} and
912 explicitly link
913 the lyrics to the notes with @code{\lyricsto@{@}}, using the 
914 name assigned to the Voice.
915
916 @lilypond[quote,verbatim,fragment]
917 <<
918   \new Voice = "one" \relative c'' {
919     \autoBeamOff
920     \time 2/4
921     c4 b8. a16 g4. f8 e4 d c2
922   }
923   \new Lyrics \lyricsto "one" {
924     No more let sins and sor -- rows grow.
925   }
926 >>
927 @end lilypond
928
929 The automatic beaming which LilyPond uses by default works well
930 for instrumental music, but not so well for music with lyrics,
931 where beaming is either not required at all or is used to indicate
932 melismata in the lyrics.  In the example above we use the command
933 @code{\autoBeamOff} to turn off the automatic beaming.
934
935 Let us reuse the earlier example from Judas Maccabæus to 
936 illustrate this more flexible technique.  We first recast
937 it to use variables so the music and lyrics can be separated
938 from the staff structure.  We also introduce a ChoirStaff 
939 bracket.  The lyrics themselves must be introduced with 
940 @code{\lyricmode} to ensure they are interpreted as lyrics
941 rather than music.
942
943 @lilypond[quote,verbatim]
944 global = { \time 6/8 \partial 8 \key f \major}
945 SopOneMusic = \relative c'' {
946   c8 | c([ bes)] a a([ g)] f | f'4. b, | c4.~ c4 }
947 SopTwoMusic = \relative c' {
948   r8 | r4. r4 c8 | a'([ g)] f f([ e)] d | e([ d)] c bes' }
949 SopOneLyrics = \lyricmode {
950   Let | flee -- cy flocks the | hills a -- dorn, __ }
951 SopTwoLyrics = \lyricmode {
952   Let | flee -- cy flocks the | hills a -- dorn, }
953
954 \score {
955   \new ChoirStaff <<
956     \new Staff <<
957       \new Voice = "SopOne" {
958         \global
959         \SopOneMusic
960       }
961       \new Lyrics \lyricsto "SopOne" {
962         \SopOneLyrics
963       }
964     >>
965     \new Staff <<
966       \new Voice = "SopTwo" {
967         \SopTwoMusic
968       }
969       \new Lyrics \lyricsto "SopTwo" {
970         \SopTwoLyrics
971       }
972     >>
973   >>
974 }
975 @end lilypond
976
977 This is the basic structure of all vocal scores.  More staves may
978 be added as required, more voices may be added to the staves,
979 more verses may be added to the lyrics,
980 and the variables containing the music can easily be placed
981 in separate files should they become too long.
982
983 Here is a final example of the first line of a hymn with four
984 verses, set for SATB.  In this case the words for all four
985 parts are the same.
986
987 @lilypond[quote,verbatim]
988 TimeKey = { \time 4/4 \partial 4 \key c \major}
989 SopMusic   = \relative c' { c4 | e4. e8 g4  g  | a a g }
990 AltoMusic  = \relative c' { c4 | c4. c8 e4  e  | f f e }
991 TenorMusic = \relative c  { e4 | g4. g8 c4. b8 | a8 b c d e4 }
992 BassMusic  = \relative c  { c4 | c4. c8 c4  c  | f8 g a b c4 }
993 VerseOne   = \lyricmode { 
994   E -- | ter -- nal fa -- ther, | strong to save, }
995 VerseTwo   = \lyricmode { 
996   O | Christ, whose voice the | wa -- ters heard, }
997 VerseThree = \lyricmode { 
998   O | Ho -- ly Spi -- rit, | who didst brood }
999 VerseFour  = \lyricmode { 
1000   O | Tri -- ni -- ty of | love and pow'r }
1001
1002 \score {
1003   \new ChoirStaff <<
1004     \new Staff <<
1005       \clef "treble"
1006       \new Voice = "Sop"  { \voiceOne \TimeKey \SopMusic }
1007       \new Voice = "Alto" { \voiceTwo \AltoMusic }
1008       \new Lyrics \lyricsto "Sop" { \VerseOne   }
1009       \new Lyrics \lyricsto "Sop" { \VerseTwo   }
1010       \new Lyrics \lyricsto "Sop" { \VerseThree }
1011       \new Lyrics \lyricsto "Sop" { \VerseFour  }
1012     >>
1013     \new Staff <<
1014       \clef "bass"
1015       \new Voice = "Tenor" { \voiceOne \TenorMusic }
1016       \new Voice = "Bass"  { \voiceTwo \BassMusic  }
1017     >>
1018   >>
1019 }
1020 @end lilypond
1021
1022 @node Contexts and engravers
1023 @section Contexts and engravers
1024
1025 Contexts and engravers have been mentioned informally
1026 in earlier sections; we now must look at 
1027 these concepts in more detail, as they are important
1028 in the fine-tuning of LilyPond output.
1029
1030
1031 @menu
1032 * Contexts explained::          
1033 * Creating contexts::           
1034 * Engravers explained::         
1035 * Modifying context properties::  
1036 * Adding and removing engravers::  
1037 @end menu
1038
1039 @node Contexts explained
1040 @subsection Contexts explained
1041
1042 When music is printed, many notational elements which do not 
1043 appear explicitly in the input file must be added to the
1044 output.  For example, compare the input and output of the 
1045 following example:
1046
1047 @lilypond[quote,verbatim,relative=2,fragment]
1048 cis4 cis2. g4
1049 @end lilypond
1050
1051 The input is rather sparse, but in the output, bar lines, 
1052 accidentals, clef, and time signature have been added.  When 
1053 LilyPond @emph{interprets} the input the musical information 
1054 is inspected in time order, similar to reading a score from left 
1055 to right.  While reading the input, the program remembers where 
1056 measure boundaries are, and which pitches require explicit 
1057 accidentals.  This information must be held on several levels.  
1058 For example, the effect of an accidental is limited
1059 to a single staff, while a bar line must be synchronized across 
1060 the entire score.
1061
1062 Within LilyPond, these rules and bits of information are grouped
1063 in @emph{Contexts}.  We have already met the 
1064 @code{Voice} context. 
1065 Others are the @code{Staff} and @code{Score} contexts.  
1066 Contexts are hierarchical to reflect the heirarchical nature of 
1067 a musical score.  
1068 For example: a @code{Staff} context can contain many 
1069 @code{Voice} contexts, and a @code{Score} context can 
1070 contain many @code{Staff} contexts.
1071
1072 @quotation
1073 @image{context-example,5cm,,}
1074 @end quotation
1075
1076 Each context has the responsibility for enforcing some notation rules,
1077 creating some notation objects and maintaining the associated
1078 properties.  For example, the @code{Voice} context may introduce an
1079 accidental and then the @code{Staff} context maintains the rule to
1080 show or suppress the accidental for the remainder of the measure.
1081
1082 As another example, the synchronization of bar lines is, by default, 
1083 handled in the @code{Score} context.
1084 However, in some music we may not want the bar lines to be
1085 synchronized -- consider a polymetric score in 4/4 and 3/4 time.
1086 In such cases, we must modify the default settings of the 
1087 @code{Score} and @code{Staff} contexts.
1088
1089 For very simple scores, contexts are created implicitly, and you need
1090 not be aware of them.  For larger pieces, such as anything with more
1091 than one staff, they must be
1092 created explicitly to make sure that you get as many staves as you
1093 need, and that they are in the correct order.  For typesetting pieces
1094 with specialized notation, it is usual to modify existing, or
1095 even to define totally new, contexts.
1096
1097 In addition to the @code{Score,} @code{Staff} and 
1098 @code{Voice} contexts there are contexts which fit between
1099 the score and staff levels to control staff groups, such as the
1100 @code{PianoStaff} and @code{ChoirStaff} contexts.  There
1101 are also alternative staff and voice contexts, and contexts for
1102 lyrics, percussion, fret boards, figured bass, etc.  A complete
1103 list is shown in the Notation Reference.
1104 TODO: Add link
1105
1106 The names of all context types are formed from one or more 
1107 words, each word being capitalised and joined immediately to the 
1108 preceding word with no hyphen or underscore, e.g., 
1109 @code{GregorianTranscriptionStaff}.
1110
1111 @node Creating contexts
1112 @subsection Creating contexts
1113
1114 There can be only one top level context: the 
1115 @code{Score} 
1116 context.  This is created with the @code{\score} command, 
1117 or, in simple scores, it is created automatically.
1118
1119 For scores with only one voice and one staff, the 
1120 @code{Voice} and @code{Staff} contexts may be left to be 
1121 created automatically, but for more complex scores it is 
1122 necessary to create them by hand.  
1123 The simplest command that does this is @code{\new}.  
1124 It is prepended to a music expression, for example
1125
1126 @funindex \new
1127 @cindex new contexts
1128 @cindex Context, creating
1129
1130 @example
1131 \new @var{type} @var{music-expression}
1132 @end example
1133
1134 @noindent
1135 where @var{type} is a context name (like @code{Staff} or
1136 @code{Voice}).  This command creates a new context, and starts
1137 interpreting the @var{music-expression} within that context.
1138
1139 Note that there is no @code{\new Score} command;
1140 the single top-level @code{Score} context is introduced 
1141 with @code{\score}.  
1142
1143 The @code{\new} command may also give a identifying name to the 
1144 context to distinguish it from other contexts of the same type,
1145
1146 @example
1147 \new @var{type} = @var{id} @var{music-expression}
1148 @end example
1149
1150 Note the distinction between the name of the context type,
1151 @code{Staff}, @code{Voice}, etc, and
1152 the identifying name of a particular instance of that type,
1153 which can be any sequence of letters invented by the user.
1154 The identifying name is used to refer back to that particular
1155 instance of a context.  We saw this in use in the section on 
1156 lyrics in @ref{Voices and vocals}.
1157
1158
1159 @node Engravers explained
1160 @subsection Engravers explained
1161
1162 @cindex engravers
1163
1164 Every mark on the printed output of a score produced by LilyPond
1165 is produced by an @code{Engraver}.  Thus there is an engraver
1166 to print staves, one to print noteheads, one for stems, one for
1167 beams, etc, etc.  In total there are over 120 such engravers!
1168 Fortunately, for most scores it is not necessary to know about 
1169 more than a few, and for simple scores you do not need to know 
1170 about any.  
1171
1172 Engravers live and operate in Contexts.
1173 Engravers such as the @code{Metronome_mark_engraver}, whose
1174 action and output applies to the score as a whole, operate in
1175 the highest level context -- the @code{Score} context.
1176
1177 The @code{Clef_engraver} and @code{Key_engraver} are to be
1178 found in every Staff Context, as different staves may require 
1179 different clefs and keys.
1180
1181 The @code{Note_heads_engraver} and @code{Stem_engraver} live
1182 in each @code{Voice} context, the lowest level context of all.
1183
1184 Each engraver processes the particular objects associated
1185 with its function, and maintains the properties that relate
1186 to that function.  These properties, like the properties
1187 associated with contexts, may be modified to change the
1188 operation of the engraver or the appearance of those elements
1189 in the printed score.
1190    
1191 Engravers all have compound names formed from words which
1192 describe their function.  Just the first word is capitalised, 
1193 and the remainder are joined to it with underscores.  Thus
1194 the @code{Staff_symbol_engraver} is responsible for creating the
1195 lines of the staff, the @code{Clef_engraver} determines and sets
1196 the pitch reference point on the staff by drawing a clef symbol.
1197
1198 Here are some of the most common engravers together with their
1199 function.  You will see it is easy to guess the function from 
1200 the name, or vice versa.
1201
1202 @multitable @columnfractions .3 .7 
1203 @headitem Engraver
1204   @tab Function
1205 @item Accidental_engraver
1206   @tab Makes accidentals, cautionary and suggested accidentals
1207 @item Beam_engraver
1208   @tab Engraves beams
1209 @item Clef_engraver
1210   @tab Engraves clefs
1211 @item Dynamic_engraver
1212   @tab Creates hairpins and dynamic texts
1213 @item Key_engraver
1214   @tab Creates the key signature
1215 @item Metronome_mark_engraver
1216   @tab Engraves metronome marking
1217 @item Note_heads_engraver
1218   @tab Engraves noteheads
1219 @item Rest_engraver
1220   @tab Engraves rests
1221 @item Staff_symbol_engraver
1222   @tab Engraves the five (by default) lines of the staff
1223 @item Stem_engraver
1224   @tab Creates stems and single-stem tremulos
1225 @item Time_signature_engraver
1226   @tab Creates time signatures
1227 @end multitable
1228
1229 @smallspace
1230
1231 We shall see later how the output of LilyPond can be changed
1232 by modifying the action of Engravers.
1233   
1234
1235 @node Modifying context properties
1236 @subsection Modifying context properties
1237
1238 @cindex context properties
1239 @funindex \set
1240 @funindex \unset
1241
1242 Contexts are responsible for holding the values of a number of
1243 context @emph{properties}.  Many of them can be changed to
1244 influence the interpretation of the input and so change the
1245 appearance of the output.  They are changed by the 
1246 @code{\set} command.  This takes the form
1247
1248 @example
1249 \set @emph{ContextName}.@emph{propertyName} = #@emph{value}
1250 @end example
1251
1252 Where the @emph{ContextName} is usually @code{Score},
1253 @code{Staff} or @code{Voice}.  It may be omitted,
1254 in which case @code{Voice} is assumed.
1255
1256 The names of context properties consist of words joined
1257 together with no hyphens or underscores, all except the
1258 first having a capital letter.  Here are a few examples
1259 of some commonly used ones.  There are many more.
1260
1261 @c attempt to force this onto a new page
1262 @need 50
1263 @multitable @columnfractions .25 .2 .4 .15
1264 @headitem propertyName
1265   @tab Value
1266   @tab Function
1267   @tab Example
1268 @item extraNatural
1269   @tab Boolean
1270   @tab If true, set extra natural signs before accidentals
1271   @tab @code{#t}, @code{#f}
1272 @item currentBarNumber
1273   @tab Integer
1274   @tab Set the current bar number
1275   @tab @code{50}
1276 @item doubleSlurs
1277   @tab Boolean
1278   @tab If true, print slurs both above and below notes
1279   @tab @code{#t}, @code{#f}
1280 @item instrumentName
1281   @tab Text
1282   @tab Set the name to be placed at the start of the staff
1283   @tab @code{"Cello I"}
1284 @item fontSize
1285   @tab Real
1286   @tab Increase or decrease the font size
1287   @tab @code{2.4}
1288 @item stanza
1289   @tab Text
1290   @tab Set the text to print before the start of a verse
1291   @tab @code{"2"}
1292 @end multitable
1293 @noindent
1294 where a Boolean is either True (@code{#t}) or False (@code{#f}),
1295 an Integer is a positive whole number, a Real is a positive
1296 or negative decimal number, and text is enclosed in double
1297 apostrophes.  Note the occurrence of hash signs,
1298 (@code{#}), in two different places -- as part of the Boolean 
1299 value before the @code{t} or @code{f}, and before @emph{value}
1300 in the @code{\set} statement.  So when a Boolean is being 
1301 entered you need to code two hash signs, e.g., @code{##t}.  
1302
1303 Before we can set any of these properties we need to know
1304 in which context they operate.  Sometimes this is obvious,
1305 but occasionally it can be tricky.  If the wrong context
1306 is specified, no error message is produced, but the expected
1307 action will not be taken.  For example, the 
1308 @code{instrumentName} clearly lives in the Staff context, since
1309 it is the staff that is to be named.
1310 In this example the first staff is labelled, but not the second,
1311 because we omitted the context name.
1312
1313 @lilypond[quote,verbatim,ragged-right]
1314 <<
1315   \new Staff \relative c'' {
1316     \set Staff.instrumentName = "Soprano"
1317     c4 c
1318  }
1319   \new Staff \relative c' {
1320   \set instrumentName = "Alto"  % Wrong!
1321   d4 d 
1322  }
1323 >>
1324 @end lilypond
1325
1326 Remember the default context name is Voice, so the second
1327 @code{\set} command set the property @code{instrumentName} in the
1328 Voice context to @qq{Alto}, but as LilyPond does not look
1329 for any such property in the @code{Voice} context, no 
1330 further action took place.  This is not an error, and no error 
1331 message is logged in the log file.
1332
1333 Similarly, if the property name is mis-spelt no error message 
1334 is produced, and clearly the expected action cannot be performed.
1335 If fact, you can set any (fictitious) @q{property} using any 
1336 name you like in any context that exists by using the 
1337 @code{\set} command.  But if the name is not
1338 known to LilyPond it will not cause any action to be taken.
1339 This is one of the reasons why it is highly recommended to
1340 use a context-sensitive editor with syntax highlighting for
1341 editing LilyPond files, such as Vim, Jedit, ConTEXT or Emacs,
1342 since unknown property names will be highlighted differently.
1343
1344 The @code{instrumentName} property will take effect only
1345 if it is set in the @code{Staff} context, but
1346 some properties can be set in more than one context.
1347 For example, the property @code{extraNatural} is by
1348 default set to ##t (true) for all staves.  
1349 If it is set to ##f (false) in the @code{Staff} context 
1350 it applies just to the accidentals on that staff.  
1351 If it is set to false in the @code{Score} context
1352 it applies to all staves.
1353
1354 So this turns off extra naturals in one staff:
1355
1356 @lilypond[quote,verbatim,ragged-right]
1357 <<
1358   \new Staff \relative c'' {
1359     ais4 aes
1360  }
1361   \new Staff \relative c'' {
1362     \set Staff.extraNatural = ##f
1363     ais4 aes
1364  }
1365 >>
1366 @end lilypond
1367
1368 @noindent
1369 and this turns them off in all staves:
1370
1371 @lilypond[quote,verbatim,ragged-right]
1372 <<
1373   \new Staff \relative c'' {
1374     ais4 aes
1375  }
1376   \new Staff \relative c'' {
1377     \set Score.extraNatural = ##f
1378     ais4 aes
1379  }
1380 >>
1381 @end lilypond
1382
1383 The value of every property set in this way can be reset
1384 to its original value with the @code{\unset} command.
1385  
1386 The @code{\set} and @code{\unset} commands can appear anywhere
1387 in the input file and will take effect from the time they are
1388 encountered until the end of the score or until the property is 
1389 @code{\set} or @code{\unset} again.  Let's try changing the 
1390 font size, which affects the size of the note heads (among 
1391 other things) several times.
1392
1393 @lilypond[quote,verbatim,ragged-right,relative=1,fragment]
1394 c4 
1395 % make noteheads smaller
1396 \set fontSize = #-4
1397 d e
1398 % make noteheads larger
1399 \set fontSize = #2.5
1400 f g
1401 % return to original size
1402 \unset fontSize
1403 a b
1404 @end lilypond
1405
1406 We have now seen how to set the values of several different
1407 types of property.  Note that integers and numbers are alway 
1408 preceded by a hash sign, @code{#}, while a true or false value 
1409 is specified by ##t and ##f, with two hash signs.  A text 
1410 property should be enclosed in double quotation signs, as above, 
1411 although we shall see later that text can actually be specified
1412 in a much more general way by using the very powerful 
1413 @code{markup} command. 
1414
1415
1416 @funindex \with
1417
1418 Context properties may also be set at the time the context is
1419 created.  Sometimes this is a clearer way of specifying a 
1420 property value if it is to remain fixed for the duration of
1421 the context.  When a context is created with a @code{\new}
1422 command it may be immediately followed by a 
1423 @code{\with @{ .. @}} block in which the property values are
1424 set.  For example, if we wish to suppress the printing of
1425 extra naturals for the duration of a staff we would write:
1426
1427 @lilypond[quote,verbatim,ragged-right]
1428 \new Staff \with {
1429   extraNatural = ##f
1430 }
1431 \relative c' {
1432   gis ges aes ais
1433 }
1434 @end lilypond
1435
1436 In effect this overrides the default value of the property.  It
1437 may still be changed dynamically using @code{\set} and 
1438 @code{\unset}.
1439
1440 @node Adding and removing engravers
1441 @subsection Adding and removing engravers
1442
1443 @cindex Engravers, adding
1444 @cindex Engravers, removing
1445
1446 @funindex \consists
1447 @funindex \remove
1448
1449 We have seen that contexts each contain several engravers, each
1450 of which is responsible for producing a particular part of the
1451 output, like barlines, staves, note heads, stems, etc.  If an
1452 engraver is removed from a context it can no longer produce its
1453 output.  This is a crude way of modifying the output, but it
1454 can sometimes be useful.  
1455
1456 To remove an engraver we can use the @code{\with} command placed
1457 immediately after the context creation command, as in the 
1458 previous section.
1459
1460 As an 
1461 illustration let's repeat an example from the previous 
1462 section with the staff lines removed.  Remember that the 
1463 staff lines are produced by the Staff_symbol_engraver.
1464
1465 @lilypond[quote,verbatim,ragged-right]
1466 \new Staff \with {
1467   \remove Staff_symbol_engraver
1468 }
1469 \relative c' {
1470   c4 
1471   \set fontSize = #-4  % make noteheads smaller
1472   d e
1473   \set fontSize = #2.5  % make noteheads larger
1474   f g
1475   \unset fontSize  % return to original size
1476   a b
1477 }
1478 @end lilypond
1479
1480 @cindex ambitus engraver
1481
1482 Engravers can also be added to contexts.  The command
1483 to do this is 
1484
1485 @code{\consists @emph{Engraver_name}},
1486
1487 placed inside a @code{\with} block.  Some vocal scores
1488 have an @rglos{ambitus} placed at the beginning of a
1489 staff to indicate the range of notes in that staff.
1490 The ambitus is produced by the @code{Ambitus_engraver},
1491 which is not normally included in any context.  If
1492 we add it to the @code{Voice} context it calculates
1493 the range from that voice only:
1494
1495 @lilypond[quote,verbatim,ragged-right]
1496 \new Staff <<
1497   \new Voice \with {
1498     \consists Ambitus_engraver
1499   }
1500   \relative c'' { 
1501     \voiceOne
1502     c a b g 
1503   }
1504   \new Voice
1505   \relative c' {
1506     \voiceTwo
1507     c e d f
1508   }
1509 >>
1510 @end lilypond
1511
1512 @noindent
1513 but if we add the Ambitus engraver to the 
1514 @code{Staff} context it calculates the range from all
1515 the notes in all the voices on that staff:
1516
1517 @lilypond[quote,verbatim,ragged-right]
1518 \new Staff \with {
1519     \consists Ambitus_engraver
1520   }
1521   <<
1522   \new Voice
1523   \relative c'' { 
1524     \voiceOne
1525     c a b g 
1526   }
1527   \new Voice
1528   \relative c' {
1529     \voiceTwo
1530     c e d f
1531   }
1532 >>
1533 @end lilypond
1534
1535
1536 @node Extending the templates
1537 @section Extending the templates
1538
1539 You've read the tutorial, you know how to write music, you 
1540 understand the fundamental concepts.  But how can you
1541 get the staves that you want?  Well, you can find lots of 
1542 templates (see @ref{Templates}) which may give you a start.  
1543 But what
1544 if you want something that isn't covered there?  Read on.
1545
1546 TODO Add links to templates after they have been moved to LSR
1547
1548 @menu
1549 * Soprano and cello::           
1550 * Four-part SATB vocal score::  
1551 * Building a score from scratch::  
1552 @end menu
1553
1554 @node Soprano and cello
1555 @subsection Soprano and cello
1556
1557 Start off with the template that seems closest to what you want to end
1558 up with.  Let's say that you want to write something for soprano and
1559 cello.  In this case, we would start with @q{Notes and lyrics} (for the
1560 soprano part).
1561
1562 @example
1563 \version "2.11.23"
1564 melody = \relative c' @{
1565   \clef treble
1566   \key c \major
1567   \time 4/4
1568
1569   a4 b c d
1570 @}
1571
1572 text = \lyricmode @{
1573   Aaa Bee Cee Dee
1574 @}
1575
1576 \score @{
1577   <<
1578     \new Voice = "one" @{
1579       \autoBeamOff
1580       \melody
1581     @}
1582     \new Lyrics \lyricsto "one" \text
1583   >>
1584   \layout @{ @}
1585   \midi @{ @}
1586 @}
1587 @end example
1588
1589 Now we want to add a cello part.  Let's look at the @q{Notes only} example:
1590
1591 @example
1592 \version "2.11.23"
1593 melody = \relative c' @{
1594   \clef treble
1595   \key c \major
1596   \time 4/4
1597
1598   a4 b c d
1599 @}
1600
1601 \score @{
1602   \new Staff \melody
1603   \layout @{ @}
1604   \midi @{ @}
1605 @}
1606 @end example
1607
1608 We don't need two @code{\version} commands.  We'll need the @code{melody}
1609 section.  We don't want two @code{\score} sections -- if we had two
1610 @code{\score}s, we'd get the two parts separately.  We want them together,
1611 as a duet.  Within the @code{\score} section, we don't need two
1612 @code{\layout} or @code{\midi}.
1613
1614 If we simply cut and paste the @code{melody} section, we would end up with
1615 two @code{melody} sections.  So let's rename them.  We'll call the section
1616 for the soprano @code{sopranoMusic} and the section for the cello
1617 @code{celloMusic}.  While we're doing this, let's rename @code{text}
1618 to be @code{sopranoLyrics}.  Remember to rename both instances of all
1619 these names -- both the initial definition (the
1620 @code{melody = relative c' @{ } part) and the name's use (in the
1621 @code{\score} section).
1622
1623 While we're doing this, let's change the cello part's staff -- celli
1624 normally use bass clef.  We'll also give the cello some different
1625 notes.
1626
1627 @example
1628 \version "2.11.23"
1629 sopranoMusic = \relative c' @{
1630   \clef treble
1631   \key c \major
1632   \time 4/4
1633
1634   a4 b c d
1635 @}
1636
1637 sopranoLyrics = \lyricmode @{
1638   Aaa Bee Cee Dee
1639 @}
1640
1641 celloMusic = \relative c @{
1642   \clef bass
1643   \key c \major
1644   \time 4/4
1645
1646   d4 g fis8 e d4
1647 @}
1648
1649 \score @{
1650   <<
1651     \new Voice = "one" @{
1652       \autoBeamOff
1653       \sopranoMusic
1654     @}
1655     \new Lyrics \lyricsto "one" \sopranoLyrics
1656   >>
1657   \layout @{ @}
1658   \midi @{ @}
1659 @}
1660 @end example
1661
1662 This is looking promising, but the cello part won't appear in the
1663 score -- we haven't used it in the @code{\score} section.  If we
1664 want the cello part to appear under the soprano part, we need to add
1665
1666 @example
1667 \new Staff \celloMusic
1668 @end example
1669
1670 @noindent
1671 underneath the soprano stuff.  We also need to add @code{<<} and
1672 @code{>>} around the music -- that tells LilyPond that there's
1673 more than one thing (in this case, two @code{Staves}) happening 
1674 at once.  The @code{\score} looks like this now
1675
1676 @c Indentation in this example is deliberately poor
1677 @example
1678 \score @{
1679   <<
1680   <<
1681     \new Voice = "one" @{
1682       \autoBeamOff
1683       \sopranoMusic
1684     @}
1685     \new Lyrics \lyricsto "one" \sopranoLyrics
1686   >>
1687   \new Staff \celloMusic
1688   >>
1689   \layout @{ @}
1690   \midi @{ @}
1691 @}
1692 @end example
1693
1694 @noindent
1695 This looks a bit messy; the indentation is messed up now.  That is
1696 easily fixed.  Here's the complete soprano and cello template.
1697
1698 @lilypond[quote,verbatim,ragged-right]
1699 \version "2.11.23"
1700 sopranoMusic = \relative c' {
1701   \clef treble
1702   \key c \major
1703   \time 4/4
1704
1705   a4 b c d
1706 }
1707
1708 sopranoLyrics = \lyricmode {
1709   Aaa Bee Cee Dee
1710 }
1711
1712 celloMusic = \relative c {
1713   \clef bass
1714   \key c \major
1715   \time 4/4
1716
1717   d4 g fis8 e d4
1718 }
1719
1720 \score {
1721   <<
1722     <<
1723       \new Voice = "one" {
1724         \autoBeamOff
1725         \sopranoMusic
1726       }
1727       \new Lyrics \lyricsto "one" \sopranoLyrics
1728     >>
1729     \new Staff \celloMusic
1730   >>
1731   \layout { }
1732   \midi { }
1733 }
1734 @end lilypond
1735
1736
1737 @node Four-part SATB vocal score
1738 @subsection Four-part SATB vocal score
1739
1740 Most vocal scores of music written for four-part mixed choir 
1741 with orchestral accompaniment such as Mendelssohn's Elijah or
1742 Handel's Messiah have the choral music and words on four
1743 staves, one for each of SATB, with a piano reduction of the
1744 orchestral accompaniment underneath.  Here's an example
1745 from Handel's Messiah:
1746
1747 @c The following should appear as music without code
1748 @lilypond[quote,ragged-right]
1749 \version "2.11.23"
1750 global = { \key d \major \time 4/4 }
1751 sopMusic = \relative c'' {
1752   \clef "treble"
1753   r4 d2 a4 | d4. d8 a2 | cis4 d cis2 |
1754 }
1755 sopWords = \lyricmode {
1756   Wor -- thy is the lamb that was slain
1757 }
1758 altoMusic = \relative a' {
1759   \clef "treble"
1760   r4 a2 a4 | fis4. fis8 a2 | g4 fis fis2 |
1761 }
1762 altoWords = \sopWords
1763 tenorMusic = \relative c' {
1764   \clef "G_8"
1765   r4 fis2 e4 | d4. d8 d2 | e4 a, cis2 |
1766 }
1767 tenorWords = \sopWords
1768 bassMusic = \relative c' {
1769   \clef "bass"
1770   r4 d2 cis4 | b4. b8 fis2 | e4 d a'2 |
1771 }
1772 bassWords = \sopWords
1773 upper = \relative a' {
1774   \clef "treble"
1775   \global
1776   r4 <a d fis>2 <a e' a>4 |
1777   <d fis d'>4. <d fis d'>8 <a d a'>2 |
1778   <g cis g'>4 <a d fis> <a cis e>2 |
1779 }
1780 lower = \relative c, {
1781   \clef "bass"
1782   \global
1783   <d d'>4 <d d'>2 <cis cis'>4 |
1784   <b b'>4. <b' b'>8 <fis fis'>2 |
1785   <e e'>4 <d d'> <a' a'>2 |
1786 }
1787
1788 \score {
1789   <<  % combine ChoirStaff and PianoStaff in parallel
1790     \new ChoirStaff <<
1791       \new Staff = "sopranos" <<
1792         \set Staff.instrumentName = "Soprano"
1793         \new Voice = "sopranos" { \global \sopMusic }
1794       >>
1795       \new Lyrics \lyricsto "sopranos" { \sopWords }
1796       \new Staff = "altos" <<
1797         \set Staff.instrumentName = "Alto"
1798         \new Voice = "altos" { \global \altoMusic }
1799       >>
1800       \new Lyrics \lyricsto "altos" { \altoWords }
1801       \new Staff = "tenors" <<
1802         \set Staff.instrumentName = "Tenor"
1803         \new Voice = "tenors" { \global \tenorMusic }
1804       >>
1805       \new Lyrics \lyricsto "tenors" { \tenorWords }
1806       \new Staff = "basses" <<
1807         \set Staff.instrumentName = "Bass"
1808         \new Voice = "basses" { \global \bassMusic }
1809       >>
1810       \new Lyrics \lyricsto "basses" { \bassWords }
1811     >>  % end ChoirStaff
1812
1813     \new PianoStaff <<
1814       \set PianoStaff.instrumentName = "Piano  "
1815       \new Staff = "upper" \upper
1816       \new Staff = "lower" \lower
1817     >>
1818   >>
1819 }
1820 @end lilypond
1821
1822 None of the templates provides this layout exactly.  The
1823 nearest is @q{SATB vocal score and automatic piano reduction},
1824 but we shall need to change the layout and add a piano
1825 accompaniment which is not derived automatically from the
1826 vocal parts.  The variables holding the music and words for
1827 the vocal parts are fine, but we shall need to add variables for
1828 the piano reduction.
1829
1830 The order in which the contexts appear in the ChoirStaff of
1831 the template do not correspond with the order in the vocal 
1832 score shown above.  We need to rearrange them so there are
1833 four staves with the words written directly underneath the
1834 notes for each part.
1835 All the voices should be @code{\voiceOne}, which is
1836 the default, so the @code{\voiceXXX} commands can be removed.
1837 We also need to specify the tenor clef for the tenors.
1838 The way in which lyrics are specified has also been simplified
1839 as we have not yet encountered the method used in the template.
1840 We've also added the names of each staff.
1841
1842 Doing this gives for our ChoirStaff:
1843
1844 @example
1845     \new ChoirStaff <<
1846       \new Staff = "sopranos" <<
1847         \set Staff.instrumentName = "Soprano"
1848         \new Voice = "sopranos" @{ \global \sopMusic @}
1849       >>
1850       \new Lyrics \lyricsto "sopranos" @{ \sopWords @}
1851       \new Staff = "altos" <<
1852         \set Staff.instrumentName = "Alto"
1853         \new Voice = "altos" @{ \global \altoMusic @}
1854       >>
1855       \new Lyrics \lyricsto "altos" @{ \altoWords @}
1856       \new Staff = "tenors" <<
1857         \set Staff.instrumentName = "Tenor"
1858         \new Voice = "tenors" @{ \global \tenorMusic @}
1859       >>
1860       \new Lyrics \lyricsto "tenors" @{ \tenorWords @}
1861       \new Staff = "basses" <<
1862         \set Staff.instrumentName = "Bass"
1863         \new Voice = "basses" @{ \global \bassMusic @}
1864       >>
1865       \new Lyrics \lyricsto "basses" @{ \bassWords @}
1866     >>  % end ChoirStaff
1867 @end example
1868
1869 Next we must work out the piano part.  This is
1870 easy - we just pull out the piano part from the
1871 @q{Solo piano} template:
1872
1873 @example
1874 \new PianoStaff <<
1875   \set PianoStaff.instrumentName = "Piano  "
1876   \new Staff = "upper" \upper
1877   \new Staff = "lower" \lower
1878 >>
1879 @end example
1880
1881 and add the variable definitions for @code{upper}
1882 and @code{lower}.
1883
1884 The ChoirStaff and PianoStaff must be combined
1885 using angle brackets as we want them to be
1886 stacked one above the other:
1887
1888 @example
1889 <<  % combine ChoirStaff and PianoStaff one above the other 
1890   \new ChoirStaff <<
1891     \new Staff = "sopranos" <<
1892       \new Voice = "sopranos" @{ \global \sopMusic @}
1893     >>
1894     \new Lyrics \lyricsto "sopranos" @{ \sopWords @}
1895     \new Staff = "altos" <<
1896       \new Voice = "altos" @{ \global \altoMusic @}
1897     >>
1898     \new Lyrics \lyricsto "altos" @{ \altoWords @}
1899     \new Staff = "tenors" <<
1900       \clef "G_8"  % tenor clef
1901       \new Voice = "tenors" @{ \global \tenorMusic @}
1902     >>
1903     \new Lyrics \lyricsto "tenors" @{ \tenorWords @}
1904     \new Staff = "basses" <<
1905       \clef "bass"
1906       \new Voice = "basses" @{ \global \bassMusic @}
1907     >>
1908     \new Lyrics \lyricsto "basses" @{ bassWords @}   
1909   >>  % end ChoirStaff
1910
1911   \new PianoStaff <<
1912     \set PianoStaff.instrumentName = "Piano  "
1913     \new Staff = "upper" \upper
1914     \new Staff = "lower" \lower
1915   >>
1916 >>
1917 @end example
1918
1919 Combining all these together and adding the music
1920 for the three bars of the example above gives:
1921
1922 @lilypond[quote,verbatim,ragged-right]
1923 \version "2.11.23"
1924 global = { \key d \major \time 4/4 }
1925 sopMusic = \relative c'' {
1926   \clef "treble"
1927   r4 d2 a4 | d4. d8 a2 | cis4 d cis2 |
1928 }
1929 sopWords = \lyricmode {
1930   Wor -- thy is the lamb that was slain
1931 }
1932 altoMusic = \relative a' {
1933   \clef "treble"
1934   r4 a2 a4 | fis4. fis8 a2 | g4 fis fis2 |
1935 }
1936 altoWords = \sopWords
1937 tenorMusic = \relative c' {
1938   \clef "G_8"
1939   r4 fis2 e4 | d4. d8 d2 | e4 a, cis2 |
1940 }
1941 tenorWords = \sopWords
1942 bassMusic = \relative c' {
1943   \clef "bass"
1944   r4 d2 cis4 | b4. b8 fis2 | e4 d a'2 |
1945 }
1946 bassWords = \sopWords
1947 upper = \relative a' {
1948   \clef "treble"
1949   \global
1950   r4 <a d fis>2 <a e' a>4 |
1951   <d fis d'>4. <d fis d'>8 <a d a'>2 |
1952   <g cis g'>4 <a d fis> <a cis e>2 |
1953 }
1954 lower = \relative c, {
1955   \clef "bass"
1956   \global
1957   <d d'>4 <d d'>2 <cis cis'>4 |
1958   <b b'>4. <b' b'>8 <fis fis'>2 |
1959   <e e'>4 <d d'> <a' a'>2 |
1960 }
1961
1962 \score {
1963   <<  % combine ChoirStaff and PianoStaff in parallel
1964     \new ChoirStaff <<
1965       \new Staff = "sopranos" <<
1966         \set Staff.instrumentName = "Soprano"
1967         \new Voice = "sopranos" { \global \sopMusic }
1968       >>
1969       \new Lyrics \lyricsto "sopranos" { \sopWords }
1970       \new Staff = "altos" <<
1971         \set Staff.instrumentName = "Alto"
1972         \new Voice = "altos" { \global \altoMusic }
1973       >>
1974       \new Lyrics \lyricsto "altos" { \altoWords }
1975       \new Staff = "tenors" <<
1976         \set Staff.instrumentName = "Tenor"
1977         \new Voice = "tenors" { \global \tenorMusic }
1978       >>
1979       \new Lyrics \lyricsto "tenors" { \tenorWords }
1980       \new Staff = "basses" <<
1981         \set Staff.instrumentName = "Bass"
1982         \new Voice = "basses" { \global \bassMusic }
1983       >>
1984       \new Lyrics \lyricsto "basses" { \bassWords }
1985     >>  % end ChoirStaff
1986
1987     \new PianoStaff <<
1988       \set PianoStaff.instrumentName = "Piano  "
1989       \new Staff = "upper" \upper
1990       \new Staff = "lower" \lower
1991     >>
1992   >>
1993 }
1994 @end lilypond
1995   
1996
1997 @node Building a score from scratch
1998 @subsection Building a score from scratch
1999
2000 After gaining some facility with writing LilyPond code you
2001 may find that it is easier to build a score from scratch
2002 rather than modifying one of the templates.  You can also
2003 develop your own style this way to suit the sort of music you
2004 like.  Let's see how to put together the score for an organ 
2005 prelude as an example.
2006
2007 We begin with a header section.  Here go the title, name
2008 of composer, etc, then come any variable definitions, and
2009 finally the score block.  Let's start with these in outline
2010 and fill in the details later.
2011
2012 We'll use the first two bars of Bach's prelude
2013 based on @emph{Jesu, meine Freude} which is written for two
2014 manuals and pedal organ.  The top manual part has two voices,
2015 the lower and pedal organ one each.  So we need four
2016 music definitions and one to define the time signature
2017 and key:
2018
2019 @example
2020 \version "2.11.23"
2021 \header @{
2022   title = "Jesu, meine Freude"
2023   composer = "J S Bach"
2024 @}
2025 TimeKey = @{ \time 4/4 \key c \minor @}
2026 ManualOneVoiceOneMusic = @{s1@}
2027 ManualOneVoiceTwoMusic = @{s1@}
2028 ManualTwoMusic = @{s1@}
2029 PedalOrganMusic = @{s1@}
2030
2031 \score @{
2032 @}
2033 @end example
2034
2035 For now we've just used a spacer note, @code{s1},
2036 instead of the real music.  We'll add that later.
2037
2038 Next let's see what should go in the score block.
2039 We simply mirror the staff structure we want.
2040 Organ music is usually written on three staves,
2041 one for each manual and one for the pedals.  The
2042 manual staves should be bracketed together so we
2043 need to use a PianoStaff for them.  The first
2044 manual part needs two voices and the second manual
2045 part just one.
2046
2047 @example
2048   \new PianoStaff <<
2049     \new Staff = "ManualOne" <<
2050       \new Voice @{ \ManualOneVoiceOneMusic @}
2051       \new Voice @{ \ManualOneVoiceTwoMusic @}
2052     >>  % end ManualOne Staff context
2053     \new Staff = "ManualTwo" <<
2054       \new Voice @{ \ManualTwoMusic @}
2055     >>  % end ManualTwo Staff context
2056   >>  % end PianoStaff context
2057 @end example
2058
2059 Next we need to add a staff for the pedal organ.
2060 This goes underneath the PianoStaff, but it must
2061 be simultaneous with it, so we need angle brackets
2062 round the two.  Missing these out would generate
2063 an error in the log file.  It's a common mistake 
2064 which you'll make sooner or later!  Try copying
2065 the final example at the end of this section,
2066 remove these angle brackets, and compile it to
2067 see what errors it generates.
2068
2069 @example
2070 <<  % PianoStaff and Pedal Staff must be simultaneous
2071   \new PianoStaff <<
2072     \new Staff = "ManualOne" <<
2073       \new Voice @{ \ManualOneVoiceOneMusic @}
2074       \new Voice @{ \ManualOneVoiceTwoMusic @}
2075     >>  % end ManualOne Staff context
2076     \new Staff = "ManualTwo" <<
2077       \new Voice @{ \ManualTwoMusic @}
2078     >>  % end ManualTwo Staff context
2079   >>  % end PianoStaff context
2080   \new Staff = "PedalOrgan" <<
2081     \new Voice @{ \PedalOrganMusic @}
2082   >>
2083 >>
2084 @end example
2085
2086 It is not strictly necessary to use the simultaneous construct
2087 @code{<<  >>} for the manual two staff and the pedal organ staff,
2088 since they contain only one music expression, but it does no harm
2089 and always using angle brackets after @code{\new Staff} is a good
2090 habit to cultivate in case there are multiple voices.  
2091
2092 Let's add this structure to the score block, and adjust the
2093 indenting.  We also add the appropriate clefs, ensure the
2094 second voice stems point down with @code{\voiceTwo} and
2095 enter the time signature and key to each staff using our
2096 predefined variable, @code{\TimeKey}.
2097
2098 @example
2099 \score @{
2100   <<  % PianoStaff and Pedal Staff must be simultaneous
2101     \new PianoStaff <<
2102       \new Staff = "ManualOne" <<
2103         \TimeKey  % set time signature and key
2104         \clef "treble"
2105         \new Voice @{ \ManualOneVoiceOneMusic @}
2106         \new Voice @{ \voiceTwo \ManualOneVoiceTwoMusic @}
2107       >>  % end ManualOne Staff context
2108       \new Staff = "ManualTwo" <<
2109         \TimeKey
2110         \clef "bass"
2111         \new Voice @{ \ManualTwoMusic @}
2112       >>  % end ManualTwo Staff context
2113     >>  % end PianoStaff context
2114     \new Staff = "PedalOrgan" <<
2115       \TimeKey
2116       \clef "bass"
2117       \new Voice @{ \PedalOrganMusic @}
2118     >>  % end PedalOrgan Staff
2119   >>
2120 @}  % end Score context
2121 @end example
2122
2123 That completes the structure.  Any three-staff organ music
2124 will have a similar structure, although the number of voices
2125 may vary.  All that remains now 
2126 is to add the music, and combine all the parts together.
2127
2128 @lilypond[quote,verbatim,ragged-right]
2129 \version "2.11.23"
2130 \header {
2131   title = "Jesu, meine Freude"
2132   composer = "J S Bach"
2133 }
2134 TimeKey = { \time 4/4 \key c \minor }
2135 ManualOneVoiceOneMusic = \relative g' {
2136   g4 g f ees | d2 c2 |
2137 }
2138 ManualOneVoiceTwoMusic = \relative c' {
2139   ees16 d ees8~ ees16 f ees s c8 d~ d c~ |
2140   c c4 b8 c8. g16 c b c d |
2141 }
2142 ManualTwoMusic = \relative c' {
2143   c16 b c8~ c16 b c g a8 g~ g16 g aes ees |
2144   f ees f d g aes g f ees d e8~ ees16 f ees d |
2145 }
2146 PedalOrganMusic = \relative c {
2147   r8 c16 d ees d ees8~ ees16 a, b g c b c8 |
2148   r16 g ees f g f g8 c,2 |
2149   }
2150
2151 \score {
2152   <<  % PianoStaff and Pedal Staff must be simultaneous
2153     \new PianoStaff <<
2154       \new Staff = "ManualOne" <<
2155         \TimeKey  % set time signature and key
2156         \clef "treble"
2157         \new Voice { \ManualOneVoiceOneMusic }
2158         \new Voice { \voiceTwo \ManualOneVoiceTwoMusic }
2159       >>  % end ManualOne Staff context
2160       \new Staff = "ManualTwo" <<
2161         \TimeKey
2162         \clef "bass"
2163         \new Voice { \ManualTwoMusic }
2164       >>  % end ManualTwo Staff context
2165     >>  % end PianoStaff context
2166     \new Staff = "PedalOrgan" <<
2167       \TimeKey
2168       \clef "bass"
2169       \new Voice { \PedalOrganMusic }
2170     >>  % end PedalOrgan Staff
2171   >>
2172 }  % end Score context
2173 @end lilypond
2174
2175
2176