]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/fundamental.itely
61b361a0966e60727c289e0d10c8273cd7b8a1d8
[lilypond.git] / Documentation / user / fundamental.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond-learning.tely
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  See TRANSLATION for details.
8 @end ignore
9
10 @c \version "2.12.0"
11
12 @node Fundamental concepts
13 @chapter Fundamental concepts
14
15 You've seen in the Tutorial how to produce beautifully printed
16 music from a simple text file.  This section introduces the
17 concepts and techniques required to produce equally beautiful
18 but more complex scores.
19
20 @menu
21 * How LilyPond input files work::
22 * Voices contain music::
23 * Contexts and engravers::
24 * Extending the templates::
25 @end menu
26
27
28 @node How LilyPond input files work
29 @section How LilyPond input files work
30
31 The LilyPond input format is quite free-form, giving experienced
32 users a lot of flexibility to structure their files however they
33 wish.  But this flexibility can make things confusing for new
34 users.  This section will explain some of this structure, but may
35 gloss over some details in favor of simplicity.  For a complete
36 description of the input format, see @ruser{File structure}.
37
38 @menu
39 * Introduction to the LilyPond file structure::
40 * Score is a (single) compound musical expression::
41 * Nesting music expressions::
42 * On the un-nestedness of brackets and ties::
43 @end menu
44
45 @node Introduction to the LilyPond file structure
46 @subsection Introduction to the LilyPond file structure
47
48 @cindex input format
49 @cindex file structure
50
51 A basic example of a LilyPond input file is
52
53 @example
54 \version @w{"@version{}"}
55 \header @{ @}
56 \score @{
57   @var{...compound music expression...}  % all the music goes here!
58   \layout @{ @}
59   \midi @{ @}
60 @}
61 @end example
62
63 @noindent
64 There are many variations of this basic pattern, but this
65 example serves as a useful starting place.
66
67 @funindex \book
68 @funindex book
69 @funindex \score
70 @funindex score
71 @cindex book
72 @cindex score
73
74 Up to this point none of the examples you have seen has used a
75 @code{\score@{@}} command.  This is because LilyPond automatically
76 adds the extra commands which are needed when you give it simple
77 input.  LilyPond treats input like this:
78
79 @example
80 \relative c'' @{
81   c4 a d c
82 @}
83 @end example
84
85 @noindent
86 as shorthand for this:
87
88 @example
89 \book @{
90   \score @{
91     \new Staff @{
92       \new Voice @{
93         \relative c'' @{
94           c4 a b c
95         @}
96       @}
97     @}
98     \layout @{ @}
99   @}
100 @}
101 @end example
102
103 In other words, if the input contains a single music expression,
104 LilyPond will interpret the file as though the music expression
105 was wrapped up inside the commands shown above.
106
107 @cindex implicit contexts
108 @cindex contexts, implicit
109
110 @strong{A word of warning!}  Many of the examples in the LilyPond
111 documentation will omit the @code{\new Staff} and @code{\new Voice}
112 commands, leaving them to be created implicitly.  For simple
113 examples this works well, but for more complex examples, especially
114 when additional commands are used, the implicit creation of contexts
115 can give surprising results, maybe creating extra unwanted staves.
116 The way to create contexts explicitly is explained in
117 @ref{Contexts and engravers}.
118
119 @warning{When entering more than a few lines of music it is
120 advisable to always create staves and voices explicitly.}
121
122 For now, though, let us return to the first example and examine the
123 @code{\score} command, leaving the others to default.
124
125 A @code{\score} block must always contain just one music expression,
126 and this must appear immediately after the @code{\score} command.
127 Remember that a music expression could be anything from a single
128 note to a huge compound expression like
129
130 @example
131 @{
132   \new StaffGroup <<
133     @var{...insert the whole score of a Wagner opera in here...}
134   >>
135 @}
136 @end example
137
138 @noindent
139 Since everything is inside @code{@{ ... @}}, it counts
140 as one music expression.
141
142 As we saw previously, the @code{\score} block can contain other
143 things, such as
144
145 @example
146 \score @{
147   @{ c'4 a b c' @}
148   \header @{ @}
149   \layout @{ @}
150   \midi @{ @}
151 @}
152 @end example
153
154 @funindex \header
155 @funindex header
156 @funindex \layout
157 @funindex layout
158 @funindex \midi
159 @funindex midi
160 @cindex header
161 @cindex layout
162 @cindex midi
163
164 @noindent
165 Note that these three commands -- @code{\header}, @code{\layout} and
166 @code{\midi} -- are special: unlike many other commands which begin
167 with a backward slash (@code{\}) they are @emph{not} music expressions
168 and are not part of any music expression.  So they may be placed
169 inside a @code{\score} block or outside it.  In fact, these commands
170 are commonly placed outside the @code{\score} block -- for example,
171 @code{\header} is often placed above the @code{\score} command, as the
172 example at the beginning of this section shows.
173
174 Two more commands you have not previously seen are
175 @code{\layout @{ @}} and @code{\midi @{@}}.  If these appear as
176 shown they will cause LilyPond to produce a printed output and a
177 MIDI output respectively.  They are described fully in the
178 Notation Reference -- @ruser{Score layout}, and
179 @ruser{Creating MIDI files}.
180
181 @cindex scores, multiple
182 @cindex book block, implicit
183 @cindex implicit book block
184 @funindex \book
185 @funindex book
186
187 You may code multiple @code{\score} blocks.  Each will be
188 treated as a separate score, but they will be all combined into
189 a single output file.  A @code{\book} command is not necessary
190 -- one will be implicitly created.  However, if you would like
191 separate output files from one @code{.ly} file then the
192 @code{\book} command should be used to separate the different
193 sections: each @code{\book} block will produce a
194 separate output file.
195
196 In summary:
197
198 Every @code{\book} block creates a separate output file (e.g., a
199 PDF file).  If you haven't explicitly added one, LilyPond wraps
200 your entire input code in a @code{\book} block implicitly.
201
202 Every @code{\score} block is a separate chunk of music within a
203 @code{\book} block.
204
205 @cindex layout block, effect of location
206
207 Every @code{\layout} block affects the @code{\score} or
208 @code{\book} block in which it appears -- i.e., a @code{\layout}
209 block inside a @code{\score} block affects only that @code{\score}
210 block, but a @code{\layout} block outside of a @code{\score} block
211 (and thus in a @code{\book} block, either explicitly or
212 implicitly) will affect every @code{\score} in that @code{\book}.
213
214 For details see @ruser{Multiple scores in a book}.
215
216 @cindex variables
217
218 Another great shorthand is the ability to define variables.  All
219 the templates use this
220
221 @example
222 melody = \relative c' @{
223   c4 a b c
224 @}
225
226 \score @{
227   \melody
228 @}
229 @end example
230
231 When LilyPond looks at this file, it takes the value of
232 @code{melody} (everything after the equals sign) and inserts it
233 whenever it sees @code{\melody}.  There's nothing special about
234 the names -- it could be @code{melody}, @code{global},
235 @code{TimeKey},
236 @code{pianorighthand}, or @code{foofoobarbaz}.  For more details,
237 see @ref{Saving typing with variables and functions}.
238 Remember that you can use almost any name you like as long
239 as it contains just alphabetic characters and is distinct from
240 LilyPond command names.  The exact
241 limitations on variable names are detailed in
242 @ruser{File structure}.
243
244
245 @seealso
246 For a complete definition of the input format, see
247 @ruser{File structure}.
248
249
250 @node Score is a (single) compound musical expression
251 @subsection Score is a (single) compound musical expression
252
253 @funindex \score
254 @funindex score
255 @cindex score
256 @cindex contents of a score block
257 @cindex score block, contents of
258 @cindex compound music expression
259 @cindex music expression, compound
260
261 We saw the general organization of LilyPond input files in the
262 previous section, @ref{Introduction to the LilyPond file structure}.
263 But we seemed to skip over the most important part: how do we figure
264 out what to write after @code{\score}?
265
266 We didn't skip over it at all.  The big mystery is simply that
267 there @emph{is} no mystery.  This line explains it all:
268
269 @quotation
270 @emph{A @code{\score} block must begin with a compound music expression.}
271 @end quotation
272
273 @noindent
274 To understand what is meant by a music expression and a compound
275 music expression, you may find it useful to review the tutorial,
276 @ref{Music expressions explained}.  In that section, we saw how to
277 build big music expressions from small pieces -- we started from
278 notes, then chords, etc.  Now we're going to start from a big
279 music expression and work our way down.
280
281 @example
282 \score @{
283   @{ % this brace begins the overall compound music expression
284     \new StaffGroup <<
285       @var{...insert the whole score of a Wagner opera in here...}
286     >>
287   @} % this brace ends the overall compound music expression
288   \layout @{ @}
289 @}
290 @end example
291
292 A whole Wagner opera would easily double the length of this
293 manual, so let's just add a singer and piano.  We don't need a
294 @code{StaffGroup} for this ensemble, which simply groups a number
295 of staves together with a bracket at the left, so we shall remove
296 it.  We @emph{do} need a singer and a piano, though.
297
298 @example
299 \score @{
300   <<
301     \new Staff = "singer" <<
302     >>
303     \new PianoStaff = "piano" <<
304     >>
305   >>
306   \layout @{ @}
307 @}
308 @end example
309
310 Remember that we use @code{<< ... >>} instead of @code{@{ ... @}} to
311 show simultaneous music.  And we definitely want to show the vocal
312 part and piano part at the same time, not one after the other!  Note
313 that the @code{<< ... >>} construct is not really necessary for the
314 Singer staff, as it contains only one sequential music expression;
315 however, using @code{<< ... >>} instead of braces is still necessary
316 if the music in the Staff is made of two simultaneous expressions,
317 e.g. two simultaneous Voices, or a Voice with lyrics.  We'll add some
318 real music later; for now let's just put in some dummy notes and
319 lyrics.
320
321 @lilypond[verbatim,quote,ragged-right]
322 \score {
323   <<
324     \new Staff = "singer" <<
325       \new Voice = "vocal" { c'1 }
326       \addlyrics { And }
327     >>
328     \new PianoStaff = "piano" <<
329       \new Staff = "upper" { c'1 }
330       \new Staff = "lower" { c'1 }
331     >>
332   >>
333   \layout { }
334 }
335 @end lilypond
336
337 Now we have a lot more details.  We have the singer's staff: it
338 contains a @code{Voice} (in LilyPond, this term refers to a set of
339 notes, not necessarily vocal notes -- for example, a violin
340 generally plays one voice) and some lyrics.  We also have a piano
341 staff: it contains an upper staff (right hand) and a lower staff
342 (left hand).
343
344 At this stage, we could start filling in notes.  Inside the curly
345 braces next to @code{\new Voice = "vocal"}, we could start writing
346
347 @example
348 \relative c'' @{
349   r4 d8\noBeam g, c4 r
350 @}
351 @end example
352
353 But if we did that, the @code{\score} section would get pretty
354 long, and it would be harder to understand what was happening.  So
355 let's use variables instead.  These were introduced at the end
356 of the previous section, remember?  So, adding a few notes, we
357 now have a piece of real music:
358
359 @lilypond[verbatim,quote,ragged-right]
360 melody = \relative c'' { r4 d8\noBeam g, c4 r }
361 text   = \lyricmode { And God said, }
362 upper  = \relative c'' { <g d g,>2~ <g d g,> }
363 lower  = \relative c { b2 e2 }
364
365 \score {
366   <<
367     \new Staff = "singer" <<
368       \new Voice = "vocal" { \melody }
369       \addlyrics { \text }
370     >>
371     \new PianoStaff = "piano" <<
372       \new Staff = "upper" { \upper }
373       \new Staff = "lower" {
374         \clef "bass"
375         \lower
376       }
377     >>
378   >>
379   \layout { }
380 }
381 @end lilypond
382
383
384 Be careful about the difference between notes, which are introduced
385 with @code{\relative} or which are directly included in a music
386 expression, and lyrics, which are introduced with
387 @code{\lyricmode}.  These are essential to tell LilyPond
388 to interpret the following content as music and text
389 respectively.
390
391 When writing (or reading) a @code{\score} section, just take it
392 slowly and carefully.  Start with the outer level, then work on
393 each smaller level.  It also really helps to be strict with
394 indentation -- make sure that each item on the same level starts
395 on the same horizontal position in your text editor.
396
397
398 @seealso
399 Notation Reference: @ruser{Structure of a score}.
400
401
402 @node Nesting music expressions
403 @subsection Nesting music expressions
404
405 @cindex staves, temporary
406 @cindex temporary staves
407 @cindex ossias
408
409 It is not essential to declare all staves at the beginning; they may
410 be introduced temporarily at any point.  This is particularly useful
411 for creating ossia sections -- see @rglos{ossia}.  Here is a simple
412 example showing how to introduce a new staff temporarily for the
413 duration of three notes:
414
415 @lilypond[verbatim,quote,ragged-right]
416 \new Staff {
417   \relative g' {
418     r4 g8 g c4 c8 d |
419     e4 r8
420     <<
421       { f c c }
422       \new Staff {
423         f8 f c
424       }
425     >>
426     r4 |
427   }
428 }
429 @end lilypond
430
431 @noindent
432 Note that the size of the clef is the same as a clef printed
433 following a clef change -- slightly smaller than the clef
434 at the beginning of the line.  This is usual for clefs printed
435 in the middle of a line.
436
437 @cindex staff, positioning
438
439 The ossia section may be placed above the staff
440 as follows:
441
442 @lilypond[verbatim,quote,ragged-right]
443 \new Staff = "main" {
444   \relative g' {
445     r4 g8 g c4 c8 d |
446     e4 r8
447     <<
448       { f c c }
449       \new Staff \with {
450         alignAboveContext = #"main" }
451       { f8 f c }
452     >>
453     r4 |
454   }
455 }
456 @end lilypond
457
458 This example uses @code{\with}, which will be explained more
459 fully later.  It is a means of modifying the default behavior
460 of a single Staff.  Here it says that the new staff should be
461 placed above the staff called @qq{main} instead of the default
462 position which is below.
463
464
465 @seealso
466 Ossia are often written without clef and without
467 time signature and are usually in a smaller font.
468 These require further commands which
469 have not yet been introduced.  See @ref{Size of objects},
470 and @ruser{Ossia staves}.
471
472
473 @node On the un-nestedness of brackets and ties
474 @subsection On the un-nestedness of brackets and ties
475
476 @cindex brackets, nesting
477 @cindex bracket types
478 @cindex brackets, enclosing vs. marking
479
480 You have already met a number of different types of bracket in
481 writing the input file to LilyPond.  These obey different rules
482 which can be confusing at first.  Before we explain the rules
483 let's first review the different types of bracket.
484
485 @c attempt to force this onto a new page
486 @need 50
487 @multitable @columnfractions .3 .7
488 @headitem Bracket Type
489   @tab Function
490 @item @code{@{ .. @}}
491   @tab Encloses a sequential segment of music
492 @item @code{< .. >}
493   @tab Encloses the notes of a chord
494 @item @code{<< .. >>}
495   @tab Encloses simultaneous music expressions
496 @item @code{( .. )}
497   @tab Marks the start and end of a slur
498 @item @code{\( .. \)}
499   @tab Marks the start and end of a phrasing slur
500 @item @code{[ .. ]}
501   @tab Marks the start and end of a manual beam
502 @end multitable
503
504 To these we should add other constructs which generate lines
505 between or across notes: ties (marked by a tilde, @code{~}),
506 tuplets written as @code{\times x/y @{..@}}, and grace notes
507 written as @code{\grace@{..@}}.
508
509 Outside LilyPond, the conventional use of brackets requires the
510 different types to be properly nested, like this, @code{<< [ @{ ( .. )
511 @} ] >>}, with the closing brackets being encountered in exactly the
512 opposite order to the opening brackets.  This @strong{is} a
513 requirement for the three types of bracket described by the word
514 @q{Encloses} in the table above -- they must nest properly.  However,
515 the remaining brackets, described with the word @q{Marks} in the table
516 above together with ties and tuplets, do @strong{not} have to nest
517 properly with any of the brackets.  In fact, these are not brackets in
518 the sense that they enclose something -- they are simply markers to
519 indicate where something starts and ends.
520
521 So, for example, a phrasing slur can start before a manually
522 inserted beam and end before the end of the beam -- not very
523 musical, perhaps, but possible:
524
525 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
526  { g8\( a b[ c b\) a] }
527 @end lilypond
528
529 In general, different kinds of brackets, and those implied by
530 tuplets, ties and grace notes, may be mixed freely.
531 This example shows a beam extending into a tuplet (line 1),
532 a slur extending into a tuplet (line 2),
533 a beam and a slur extending into a tuplet, a tie crossing
534 two tuplets, and a phrasing slur extending out of a tuplet
535 (lines 3 and 4).
536
537 @lilypond[quote,verbatim,fragment,ragged-right]
538 {
539   r16[ g16 \times 2/3 {r16 e'8] }
540   g16( a \times 2/3 {b d) e' }
541   g8[( a \times 2/3 {b d') e'~]}
542   \times 4/5 {e'32\( a b d' e'} a'4.\)
543 }
544 @end lilypond
545
546
547 @node Voices contain music
548 @section Voices contain music
549
550 Singers need voices to sing, and so does LilyPond.
551 The actual music for all instruments in a score
552 is contained in Voices -- the most fundamental
553 of all LilyPond's concepts.
554
555 @menu
556 * I'm hearing Voices::
557 * Explicitly instantiating voices::
558 * Voices and vocals::
559 @end menu
560
561 @node I'm hearing Voices
562 @subsection I'm hearing Voices
563
564 @cindex polyphony
565 @cindex layers
566 @cindex multiple voices
567 @cindex voices, multiple
568 @cindex Voice context
569 @cindex context, Voice
570 @cindex simultaneous music
571 @cindex music, simultaneous
572 @cindex concurrent music
573 @cindex music, concurrent
574 @cindex voices vs. chords
575 @cindex chords vs. voices
576
577 The lowest, most fundamental or innermost layers in a LilyPond
578 score are called @q{Voice contexts} or just @q{Voices} for short.
579 Voices are sometimes called @q{layers} in other notation
580 packages.
581
582 In fact, a Voice layer or context is the only one which can contain
583 music.  If a Voice context is not explicitly declared one is created
584 automatically, as we saw at the beginning of this chapter.  Some
585 instruments such as an Oboe can play only one note at a time.  Music
586 written for such instruments is monophonic and requires just a single
587 voice.  Instruments which can play more than one note at a time like
588 the piano will often require multiple voices to encode the different
589 concurrent notes and rhythms they are capable of playing.
590
591 A single voice can contain many notes in a chord, of course,
592 so when exactly are multiple voices needed?  Look first at
593 this example of four chords:
594
595 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
596 \key g \major
597 <d g>4 <d fis> <d a'> <d g>
598 @end lilypond
599
600 This can be expressed using just the single angle bracket chord
601 symbols, @code{< ... >}, and for this just a single voice is
602 needed.  But suppose the F-sharp were actually an eighth-note
603 followed by an eighth-note G, a passing note on the way to the A?
604 Now we have two notes which start at the same time but have
605 different durations: the quarter-note D and the eighth-note
606 F-sharp.  How are these to be coded?  They cannot be written as
607 a chord because all the notes in a chord must have the same
608 duration.  And they cannot be written as two sequential notes
609 as they need to start at the same time.  This is when two
610 voices are required.
611
612 Let us see how this is done in LilyPond input syntax.
613
614 @funindex << \\ >>
615 @funindex \\
616
617 The easiest way to enter fragments with more than one voice on a
618 staff is to enter each voice as a sequence (with @code{@{...@}}),
619 and combine them simultaneously with angle brackets, @code{<<...>>}.
620 The fragments must also be separated with double backward slashes,
621 @code{\\}, to place them in separate voices.  Without these, the
622 notes would be entered into a single voice, which would usually
623 cause errors.  This technique is particularly suited to pieces of
624 music which are largely monophonic with occasional short sections
625 of polyphony.
626
627 Here's how we split the chords above into two voices and add both
628 the passing note and a slur:
629
630 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
631 \key g \major
632 %    Voice "1"                  Voice "2"
633 << { g4 fis8( g) a4 g }    \\ { d4 d d d }  >> |
634 @end lilypond
635
636 Notice how the stems of the second voice now point down.
637
638 Here's another simple example:
639
640 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
641 \key d \minor
642 %    Voice "1"             Voice "2"
643 << { r4 g g4. a8 }    \\ { d,2 d4 g }       >> |
644 << { bes4 bes c bes } \\ { g4 g g8( a) g4 } >> |
645 << { a2. r4 }         \\ { fis2. s4 }       >> |
646 @end lilypond
647
648 It is not necessary to use a separate @code{<< \\ >>} construct
649 for each bar. For music with few notes in each bar this layout
650 can help the legibility of the code, but if there are many
651 notes in each bar it may be better to split out each voice
652 separately, like this:
653
654 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
655 \key d \minor
656 << {
657   % Voice "1"
658   r4 g g4. a8 |
659   bes4 bes c bes |
660   a2. r4 |
661 } \\ {
662   % Voice "2"
663   d,2 d4 g |
664   g4 g g8( a) g4 |
665   fis2. s4 |
666 } >>
667 @end lilypond
668
669
670 @cindex voices, naming
671 @cindex voices crossing brackets
672 @cindex slurs crossing brackets
673 @cindex ties crossing brackest
674
675 This example has just two voices, but the same construct may be
676 used to encode three or more voices by adding more back-slash
677 separators.
678
679 The Voice contexts bear the names @code{"1"}, @code{"2"}, etc.
680 In each of these contexts, the vertical direction of slurs,
681 stems, ties, dynamics etc., is set appropriately.
682
683 @lilypond[quote,verbatim,fragment]
684 \new Staff \relative c' {
685   % Main voice
686   c16 d e f
687   %    Voice "1"     Voice "2"                 Voice "3"
688   << { g4 f e } \\ { r8 e4 d c8 ~ } >> |
689   << { d2 e2 }  \\ { c8 b16 a b8 g ~ g2 } \\ { s4 b4 c2 } >> |
690 }
691 @end lilypond
692
693 These voices are all separate from the main voice that contains
694 the notes just outside the @code{<< .. >>} construct.  Let's call
695 this the @emph{simultaneous construct}.  Slurs and ties may only
696 connect notes within the same voice, so slurs and ties cannot go
697 into or out of a simultaneous construct.  Conversely,
698 parallel voices from separate simultaneous constructs on the same
699 staff are the same voice.  Other voice-related properties also
700 carry across simultaneous constructs.  Here is the same example,
701 with different colors and note heads for each voice.  Note that
702 changes in one voice do not affect other voices, but they do
703 persist in the same voice later.  Note also that tied notes may be
704 split across the same voices in two constructs, shown here in the
705 blue triangle voice.
706
707 @lilypond[quote,verbatim]
708 \new Staff \relative c' {
709   % Main voice
710   c16 d e f
711   << % Bar 1
712     {
713       \voiceOneStyle
714       g4 f e
715     }
716   \\
717     {
718       \voiceTwoStyle
719       r8 e4 d c8 ~
720     }
721   >>
722   << % Bar 2
723      % Voice 1 continues
724     { d2 e2 }
725   \\
726      % Voice 2 continues
727     { c8 b16 a b8 g ~ g2 }
728   \\
729     {
730       \voiceThreeStyle
731       s4 b4 c2
732     }
733   >>
734 }
735 @end lilypond
736
737 @funindex \voiceOneStyle
738 @funindex \voiceTwoStyle
739 @funindex \voiceThreeStyle
740 @funindex \voiceFourStyle
741 @funindex \voiceNeutralStyle
742
743 The commands @code{\voiceXXXStyle} are mainly intended for use in
744 educational documents such as this one.  They modify the color
745 of the note head, the stem and the beams, and the style of the
746 note head, so that the voices may be easily distinguished.
747 Voice one is set to red diamonds, voice two to blue triangles,
748 voice three to green crossed circles, and voice four (not used
749 here) to magenta crosses;  @code{\voiceNeutralStyle} (also not
750 used here) reverts the style back to the default.
751 We shall see later how commands like these may be created by the
752 user.
753 See @ref{Visibility and color of objects} and
754 @ref{Using variables for tweaks}.
755
756 @cindex polyphony and relative note entry
757 @cindex relative note entry and polyphony
758
759 Polyphony does not change the relationship of notes within a
760 @code{\relative @{ @}} block.  Each note is still calculated
761 relative to the note immediately preceding it, or to the first
762 note of the preceding chord.  So in
763
764 @example
765 \relative c' @{ noteA << < noteB noteC > \\ noteD >> noteE @}
766 @end example
767
768 @noindent
769 @code{noteB} is relative to @code{noteA}                      @*
770 @code{noteC} is relative to @code{noteB}, not @code{noteA};   @*
771 @code{noteD} is relative to @code{noteB}, not @code{noteA} or
772 @code{noteC};                                                 @*
773 @code{noteE} is relative to @code{noteD}, not @code{noteA}.
774
775 An alternative way, which may be clearer if the notes in the
776 voices are widely separated, is to place a @code{\relative}
777 command at the start of each voice:
778
779 @example
780 \relative c' @{ noteA ... @}
781 <<
782   \relative c'' @{ < noteB noteC > ... @}
783 \\
784   \relative g' @{ noteD ... @}
785 >>
786 \relative c' @{ noteE ... @}
787 @end example
788
789 Let us finally analyze the voices in a more complex piece of music.
790 Here are the notes from the first two bars of the second of Chopin's
791 Deux Nocturnes, Op 32.  This example will be used at later stages in
792 this and the next chapter to illustrate several techniques for
793 producing notation, so please ignore for now anything in the
794 underlying code which looks mysterious and concentrate just on the
795 music and the voices -- the complications will all be explained in
796 later sections.
797
798 @c The following should appear as music without code
799 @lilypond[quote,ragged-right]
800 \new Staff \relative c'' {
801   \key aes \major
802   << % Voice one
803     { c2 aes4. bes8 }
804   \\ % Voice two
805     { aes2 f4 fes }
806   \\ % No voice three
807   \\ % Voice four
808     {
809       % Ignore these for now - they are explained in Ch 4
810       \once \override NoteColumn #'force-hshift = #0
811       <ees c>2
812       \once \override NoteColumn #'force-hshift = #0.5
813       des2
814     }
815   >> |
816   <c ees aes c>1 |
817 }
818 @end lilypond
819
820 The direction of the stems is often used to indicate the continuity of
821 two simultaneous melodic lines.  Here the stems of the highest notes
822 are all pointing up and the stems of the lower notes are all pointing
823 down.  This is the first indication that more than one voice is
824 required.
825
826 But the real need for multiple voices arises when notes
827 which start at the same time have different durations.
828 Look at the notes which start at beat three in the first
829 bar.  The A-flat is a dotted quarter note, the F is a
830 quarter note and the D-flat is a half note.  These
831 cannot be written as a chord as all the notes in a chord
832 must have the same duration.  Neither can they be written
833 as sequential notes, as they must start at the same time.
834 This section of the bar requires three voices, and the
835 normal practice would be to write the whole bar as three
836 voices, as shown below, where we have used different note heads
837 and colors for the three voices.  Again, the code behind this
838 example will be explained later, so ignore anything you do
839 not understand.
840
841 @c The following should appear as music without code
842 @c The three voice styles should be defined in -init
843 @lilypond[quote,ragged-right]
844 \new Staff \relative c'' {
845   \key aes \major
846   <<
847     { % Voice one
848       \voiceOneStyle
849       c2 aes4. bes8
850     }
851   \\  % Voice two
852     { \voiceTwoStyle
853       aes2 f4 fes
854     }
855   \\  % No Voice three (we want stems down)
856   \\  % Voice four
857     { \voiceThreeStyle
858       % Ignore these for now - they are explained in Ch 4
859       \once \override NoteColumn #'force-hshift = #0
860       <ees c>2
861       \once \override NoteColumn #'force-hshift = #0.5
862       des2
863     }
864   >> |
865   <c ees aes c>1 |
866 }
867 @end lilypond
868
869
870 Let us try to encode this music from scratch.  As we
871 shall see, this encounters some difficulties.  We begin as
872 we have learnt, using the @code{<< \\  >>} construct to
873 enter the music of the first bar in three voices:
874
875 @lilypond[quote,verbatim,fragment,ragged-right]
876 \new Staff \relative c'' {
877   \key aes \major
878   <<
879     { c2 aes4. bes8 } \\ { aes2 f4 fes } \\ { <ees c>2 des2 }
880   >>
881   <c ees aes c>1
882 }
883 @end lilypond
884
885 @cindex stem down
886 @cindex voices and stem directions
887 @cindex stem directions and voices
888 @cindex stem up
889
890 The stem directions are automatically assigned with the
891 odd-numbered voices taking upward stems and the even-numbered
892 voices downward ones.  The stems for voices 1 and 2 are right,
893 but the stems in voice 3 should go down in this particular piece
894 of music.  We can correct this by skipping voice three
895 and placing the music in voice four. This is done by simply
896 adding another pair of @code{\\}.
897
898 @lilypond[quote,verbatim,fragment,ragged-right]
899 \new Staff \relative c'' {
900   \key aes \major
901   << % Voice one
902     { c2 aes4. bes8 }
903   \\ % Voice two
904     { aes2 f4 fes   }
905   \\ % Omit Voice three
906   \\ % Voice four
907     { <ees c>2 des2 }
908   >> |
909   <c ees aes c>1 |
910 }
911 @end lilypond
912
913 @noindent
914 We see that this fixes the stem direction, but exposes a problem
915 sometimes encountered with multiple voices -- the stems of the notes
916 in one voice can collide with the note heads in other voices.  In
917 laying out the notes, LilyPond allows the notes or chords from two
918 voices to occupy the same vertical note column provided the stems are
919 in opposite directions, but the notes from the third and fourth voices
920 are displaced, if necessary, to avoid the note heads colliding.  This
921 usually works well, but in this example the notes of the lowest voice
922 are clearly not well placed by default. LilyPond provides several ways
923 to adjust the horizontal placing of notes.  We are not quite ready yet
924 to see how to correct this, so we shall leave this problem until a
925 later section --- see the @code{force-hshift} property in @ref{Fixing
926 overlapping notation}.
927
928
929 @seealso
930 Notation Reference: @ruser{Multiple voices}.
931
932
933 @node Explicitly instantiating voices
934 @subsection Explicitly instantiating voices
935
936 @funindex \voiceOne
937 @funindex voiceOne
938 @funindex \voiceTwo
939 @funindex voiceTwo
940 @funindex \voiceThree
941 @funindex voiceThree
942 @funindex \voiceFour
943 @funindex voiceFour
944 @funindex \oneVoice
945 @funindex oneVoice
946 @funindex \new Voice
947 @cindex voice contexts, creating
948
949 Voice contexts can also be created manually
950 inside a @code{<< >>} block to create polyphonic music, using
951 @code{\voiceOne} ... @code{\voiceFour} to indicate the required
952 directions of stems, slurs, etc.  In longer scores this method
953 is clearer, as it permits the voices to be separated and to be
954 given more descriptive names.
955
956 Specifically, the construct @code{<< \\ >>} which we used in
957 the previous section:
958
959 @example
960 \new Staff @{
961   \relative c' @{
962     << @{ e4 f g a @} \\ @{ c,4 d e f @} >>
963   @}
964 @}
965 @end example
966
967 @noindent
968 is equivalent to
969
970 @example
971 \new Staff <<
972   \new Voice = "1" @{ \voiceOne \relative c' @{ e4 f g a @} @}
973   \new Voice = "2" @{ \voiceTwo \relative c' @{ c4 d e f @} @}
974 >>
975 @end example
976
977 Both of the above would produce
978
979 @c The following example should not display the code
980 @lilypond[ragged-right,quote]
981 \new Staff <<
982   \new Voice = "1" { \voiceOne \relative c' { e4 f g a } }
983   \new Voice = "2" { \voiceTwo \relative c' { c4 d e f } }
984 >>
985 @end lilypond
986
987 @cindex voices, reverting to single
988 @cindex reverting to a single voice
989
990 The @code{\voiceXXX} commands set the direction of stems, slurs,
991 ties, articulations, text annotations, augmentation dots of dotted
992 notes, and fingerings.  @code{\voiceOne} and @code{\voiceThree}
993 make these objects point upwards, while @code{\voiceTwo} and
994 @code{\voiceFour} make them point downwards.  These commands also
995 generate a horizontal shift for each voice when this is required
996 to avoid clashes of note heads.  The command @code{\oneVoice}
997 reverts the settings back to the normal values for a single voice.
998
999 Let us see in some simple examples exactly what effect
1000 @code{\oneVoice}, @code{\voiceOne} and @code{voiceTwo} have on
1001 markup, ties, slurs, and dynamics:
1002
1003 @lilypond[quote,ragged-right,verbatim]
1004 \relative c'{
1005   % Default behavior or behavior after \oneVoice
1006   c d8 ~ d e4 ( f g a ) b-> c
1007 }
1008 @end lilypond
1009
1010 @lilypond[quote,ragged-right,verbatim]
1011 \relative c'{
1012   \voiceOne
1013   c d8 ~ d e4 ( f g a ) b-> c
1014   \oneVoice
1015   c, d8 ~ d e4 ( f g a ) b-> c
1016 }
1017 @end lilypond
1018
1019 @lilypond[quote,ragged-right,verbatim]
1020 \relative c'{
1021   \voiceTwo
1022   c d8 ~ d e4 ( f g a ) b-> c
1023   \oneVoice
1024   c, d8 ~ d e4 ( f g a ) b-> c
1025 }
1026 @end lilypond
1027
1028 Now let's look at three different ways to notate the same passage
1029 of polyphonic music, each of which is advantageous in different
1030 circumstances, using the example from the previous section.
1031
1032 An expression that appears directly inside a @code{<< >>} belongs
1033 to the main voice (but, note, @strong{not} in a @code{<< \\ >>}
1034 construct).  This is useful when extra voices appear while the
1035 main voice is playing.  Here is a more correct rendition of our
1036 example.  The red diamond-shaped notes
1037 demonstrate that the main melody is now in a single voice context,
1038 permitting a phrasing slur to be drawn over them.
1039
1040 @lilypond[quote,ragged-right,verbatim]
1041 \new Staff \relative c' {
1042   \voiceOneStyle
1043   % The following notes are monophonic
1044   c16^( d e f
1045   % Start simultaneous section of three voices
1046   <<
1047     % Continue the main voice in parallel
1048     { g4 f e | d2 e2) }
1049     % Initiate second voice
1050     \new Voice {
1051       % Set stems, etc, down
1052       \voiceTwo
1053       r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2
1054     }
1055     % Initiate third voice
1056     \new Voice {
1057       % Set stems, etc, up
1058       \voiceThree
1059       s2. | s4 b4 c2
1060     }
1061   >>
1062 }
1063 @end lilypond
1064
1065 @cindex nesting music expressions
1066 @cindex nesting simultaneous constructs
1067 @cindex nesting voices
1068 @cindex voices, temporary
1069 @cindex voices, nesting
1070
1071 More deeply nested polyphony constructs are possible, and if a
1072 voice appears only briefly this might be a more natural way to
1073 typeset the music:
1074
1075 @lilypond[quote,ragged-right,verbatim]
1076 \new Staff \relative c' {
1077   c16^( d e f
1078   <<
1079     { g4 f e | d2 e2) }
1080     \new Voice {
1081       \voiceTwo
1082       r8 e4 d c8 ~ |
1083       <<
1084         {c8 b16 a b8 g ~ g2}
1085         \new Voice {
1086           \voiceThree
1087           s4 b4 c2
1088         }
1089       >>
1090     }
1091   >>
1092 }
1093 @end lilypond
1094
1095 @cindex spacing notes
1096
1097 This method of nesting new voices briefly is useful
1098 when only small sections of the music
1099 are polyphonic, but when the whole staff is largely polyphonic
1100 it can be clearer to use multiple voices throughout, using
1101 spacing notes to step over sections where the voice is silent,
1102 as here:
1103
1104 @lilypond[quote,ragged-right,verbatim]
1105 \new Staff \relative c' <<
1106   % Initiate first voice
1107   \new Voice {
1108     \voiceOne
1109     c16^( d e f g4 f e | d2 e2) |
1110   }
1111   % Initiate second voice
1112   \new Voice {
1113     % Set stems, etc, down
1114     \voiceTwo
1115     s4 r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2 |
1116   }
1117   % Initiate third voice
1118   \new Voice {
1119     % Set stems, etc, up
1120     \voiceThree
1121     s1 | s4 b4 c2 |
1122   }
1123 >>
1124 @end lilypond
1125
1126 @subsubheading Note columns
1127
1128 @cindex note column
1129 @cindex note collisions
1130 @cindex collisions, notes
1131 @cindex shift commands
1132 @funindex \shiftOff
1133 @funindex shiftOff
1134 @funindex \shiftOn
1135 @funindex shiftOn
1136 @funindex \shiftOnn
1137 @funindex shiftOnn
1138 @funindex \shiftOnnn
1139 @funindex shiftOnnn
1140
1141 Closely spaced notes in a chord, or notes occurring at the same
1142 time in different voices, are arranged in two, occasionally more,
1143 columns to prevent the note heads overlapping.  These are called
1144 note columns.  There are separate columns for each voice, and
1145 the currently specified voice-dependent shift is applied to the
1146 note column if there would otherwise be a collision.  This can
1147 be seen in the example above.  In bar 2 the C in voice two is
1148 shifted to the right relative to the D in voice one, and in the
1149 final chord the C in voice three is also shifted to the right
1150 relative to the other notes.
1151
1152 The @code{\shiftOn}, @code{\shiftOnn}, @code{\shiftOnnn}, and
1153 @code{\shiftOff} commands specify the degree to which notes and
1154 chords of the voice should be shifted if a collision
1155 would otherwise occur. By default, the outer voices (normally
1156 voices one and two) have @code{\shiftOff} specified, while the
1157 inner voices (three and four) have @code{\shiftOn} specified.
1158 When a shift is applied, voices one and three are shifted to
1159 the right and voices two and four to the left.
1160
1161 @code{\shiftOnn} and @code{\shiftOnnn} define further shift
1162 levels which may be specified temporarily to resolve collisions
1163 in complex situations -- see @ref{Real music example}.
1164
1165 A note column can contain just one note (or chord) from a voice
1166 with stems up and one note (or chord) from a voice with stems
1167 down.  If notes from two voices which have their stems in the
1168 same direction are placed at the same position and both voices
1169 have no shift or the same shift specified, the error message
1170 @qq{Too many clashing note columns} will be produced.
1171
1172
1173 @seealso
1174 Notation Reference: @ruser{Multiple voices}.
1175
1176
1177 @node Voices and vocals
1178 @subsection Voices and vocals
1179
1180 Vocal music presents a special difficulty: we need to combine two
1181 expressions -- notes and lyrics.
1182
1183 @funindex \new Lyrics
1184 @funindex \lyricsto
1185 @funindex lyricsto
1186 @funindex Lyrics
1187 @cindex Lyrics context, creating
1188 @cindex lyrics, linking to voice
1189
1190 You have already seen the @code{\addlyrics@{@}} command, which
1191 handles simple scores well.  However, this technique is
1192 quite limited.  For more complex music, you must introduce the
1193 lyrics in a @code{Lyrics} context using @code{\new Lyrics} and
1194 explicitly link
1195 the lyrics to the notes with @code{\lyricsto@{@}}, using the
1196 name assigned to the Voice.
1197
1198 @lilypond[quote,verbatim,fragment]
1199 <<
1200   \new Voice = "one" \relative c'' {
1201     \autoBeamOff
1202     \time 2/4
1203     c4 b8. a16 g4. f8 e4 d c2
1204   }
1205   \new Lyrics \lyricsto "one" {
1206     No more let sins and sor -- rows grow.
1207   }
1208 >>
1209 @end lilypond
1210
1211 Note that the lyrics must be linked to a @code{Voice} context,
1212 @emph{not} a @code{Staff} context.  This is a case where it is
1213 necessary to create @code{Staff} and @code{Voice} contexts
1214 explicitly.
1215
1216 @cindex lyrics and beaming
1217 @cindex beaming and lyrics
1218 @funindex \autoBeamOff
1219 @funindex autoBeamOff
1220
1221 The automatic beaming which LilyPond uses by default works well
1222 for instrumental music, but not so well for music with lyrics,
1223 where beaming is either not required at all or is used to indicate
1224 melismata in the lyrics.  In the example above we use the command
1225 @code{\autoBeamOff} to turn off the automatic beaming.
1226
1227 @funindex \new ChoirStaff
1228 @funindex ChoirStaff
1229 @funindex \lyricmode
1230 @funindex lyricmode
1231 @cindex vocal score structure
1232 @cindex choir staff
1233
1234 Let us reuse the earlier example from Judas Maccabæus to
1235 illustrate this more flexible technique.  We first recast
1236 it to use variables so the music and lyrics can be separated
1237 from the staff structure.  We also introduce a ChoirStaff
1238 bracket.  The lyrics themselves must be introduced with
1239 @code{\lyricmode} to ensure they are interpreted as lyrics
1240 rather than music.
1241
1242 @lilypond[quote,verbatim]
1243 global = { \time 6/8 \partial 8 \key f \major}
1244 SopOneMusic = \relative c'' {
1245   c8 | c([ bes)] a a([ g)] f | f'4. b, | c4.~ c4 }
1246 SopTwoMusic = \relative c' {
1247   r8 | r4. r4 c8 | a'([ g)] f f([ e)] d | e([ d)] c bes' }
1248 SopOneLyrics = \lyricmode {
1249   Let | flee -- cy flocks the | hills a -- dorn, __ }
1250 SopTwoLyrics = \lyricmode {
1251   Let | flee -- cy flocks the | hills a -- dorn, }
1252
1253 \score {
1254   \new ChoirStaff <<
1255     \new Staff <<
1256       \new Voice = "SopOne" {
1257         \global
1258         \SopOneMusic
1259       }
1260       \new Lyrics \lyricsto "SopOne" {
1261         \SopOneLyrics
1262       }
1263     >>
1264     \new Staff <<
1265       \new Voice = "SopTwo" {
1266         \global
1267         \SopTwoMusic
1268       }
1269       \new Lyrics \lyricsto "SopTwo" {
1270         \SopTwoLyrics
1271       }
1272     >>
1273   >>
1274 }
1275 @end lilypond
1276
1277 This is the basic structure of all vocal scores.  More staves may be
1278 added as required, more voices may be added to the staves, more verses
1279 may be added to the lyrics, and the variables containing the music can
1280 easily be placed in separate files should they become too long.
1281
1282 @cindex hymn structure
1283 @cindex SATB structure
1284 @cindex vocal scores with multiple verses
1285 @cindex multiple vocal verses
1286 @cindex verses, multiple vocal
1287
1288 Here is an example of the first line of a hymn with four
1289 verses, set for SATB.  In this case the words for all four
1290 parts are the same.  Note how we use variables to separate the
1291 music notation and words from the staff structure.  See too
1292 how a variable, which we have chosen to call @q{TimeKey}, is used
1293 to hold several commands for use within the two staves.  In other
1294 examples this is often called @q{global}.
1295
1296 @lilypond[quote,verbatim]
1297 TimeKey = { \time 4/4 \partial 4 \key c \major}
1298 SopMusic   = \relative c' { c4 | e4. e8 g4  g  | a a g }
1299 AltoMusic  = \relative c' { c4 | c4. c8 e4  e  | f f e }
1300 TenorMusic = \relative c  { e4 | g4. g8 c4. b8 | a8 b c d e4 }
1301 BassMusic  = \relative c  { c4 | c4. c8 c4  c  | f8 g a b c4 }
1302 VerseOne   = \lyricmode {
1303   E -- | ter -- nal fa -- ther, | strong to save, }
1304 VerseTwo   = \lyricmode {
1305   O | Christ, whose voice the | wa -- ters heard, }
1306 VerseThree = \lyricmode {
1307   O | Ho -- ly Spi -- rit, | who didst brood }
1308 VerseFour  = \lyricmode {
1309   O | Tri -- ni -- ty of | love and pow'r }
1310
1311 \score {
1312   \new ChoirStaff <<
1313     \new Staff <<
1314       \clef "treble"
1315       \new Voice = "Sop"  { \voiceOne \TimeKey \SopMusic }
1316       \new Voice = "Alto" { \voiceTwo \AltoMusic }
1317       \new Lyrics \lyricsto "Sop" { \VerseOne   }
1318       \new Lyrics \lyricsto "Sop" { \VerseTwo   }
1319       \new Lyrics \lyricsto "Sop" { \VerseThree }
1320       \new Lyrics \lyricsto "Sop" { \VerseFour  }
1321     >>
1322     \new Staff <<
1323       \clef "bass"
1324       \new Voice = "Tenor" { \voiceOne \TimeKey \TenorMusic }
1325       \new Voice = "Bass"  { \voiceTwo \BassMusic  }
1326     >>
1327   >>
1328 }
1329 @end lilypond
1330
1331 @cindex verse and refrain
1332
1333 We end with an example to show how we might code a solo verse which
1334 continues into a two-part refrain in two staves.  The
1335 positioning of the sequential and simultaneous sections to achieve
1336 this within a single score is quite tricky, so follow the
1337 explanation carefully!
1338
1339 Let's start with a score block containing a @code{ChoirStaff}, as
1340 we would like the brace to appear at the start of the chorus.
1341 Normally you would need angle brackets after @code{\new ChoirStaff}
1342 to bring in all the staves in parallel, but here we want to
1343 defer the parallelism during the solo so we use braces, although
1344 angle brackets here wouldn't hurt.  Inside the @code{ChoirStaff} we
1345 want first the staff which will contain the verse.  This must
1346 contain notes and lyrics in parallel, so here we need angle
1347 brackets around the @code{\new Voice} and @code{\new Lyrics} to
1348 start them at the same time:
1349
1350 @lilypond[quote,verbatim,ragged-right]
1351 versenotes = \relative c'' {
1352   \clef "treble"
1353   \key g \major
1354   \time 3/4 g g g b b b
1355 }
1356 versewords = \lyricmode {
1357   One two three four five six
1358 }
1359 \score {
1360   \new ChoirStaff {
1361     \new Staff <<
1362       \new Voice = "verse" {
1363         \versenotes \break
1364       }
1365       \new Lyrics \lyricsto verse {
1366         \versewords
1367       }
1368     >>
1369   }
1370 }
1371 @end lilypond
1372
1373 That gives the verse line.
1374
1375 Now we want to continue with refrainA on the same staff while a
1376 second staff is introduced in parallel with it for refrainB, so
1377 this is a parallel section which must be positioned immediately
1378 following the @code{\break} in the verse Voice.  Yes, @emph{within}
1379 the verse Voice!  Here's that parallel section.  More staves
1380 could be introduced here in the same way.
1381
1382 @example
1383 <<
1384   \refrainnotesA
1385   \new Lyrics \lyricsto verse @{
1386     \refrainwordsA
1387   @}
1388   \new Staff <<
1389     \new Voice = "refrainB" @{
1390       \refrainnotesB
1391     @}
1392     \new Lyrics \lyricsto "refrainB" @{
1393       \refrainwordsB
1394     @}
1395   >>
1396 >>
1397 @end example
1398
1399 Here's the final result with two staves in the chorus showing
1400 how the parallel section is positioned within the verse Voice:
1401
1402 @lilypond[quote,verbatim, ragged-right]
1403 versenotes = \relative c'' {
1404   \clef "treble"
1405   \key g \major
1406   \time 3/4 g g g b b b
1407 }
1408 refrainnotesA = \relative c'' {
1409   \time 2/4
1410   c c g g \bar "|."
1411 }
1412 refrainnotesB = \relative c {
1413   \clef "bass"
1414   \key g \major
1415   c e d d
1416 }
1417 versewords = \lyricmode {
1418   One two three four five six
1419 }
1420 refrainwordsA = \lyricmode {
1421   la la la la
1422 }
1423 refrainwordsB = \lyricmode {
1424   dum dum dum dum
1425 }
1426 \score {
1427   \new ChoirStaff {
1428     \new Staff <<
1429       \new Voice = "verse" {
1430         \versenotes \break
1431         <<
1432           \refrainnotesA
1433           \new Lyrics \lyricsto "verse" {
1434             \refrainwordsA
1435           }
1436           \new Staff <<
1437             \new Voice = "refrainB" {
1438               \refrainnotesB
1439             }
1440             \new Lyrics \lyricsto "refrainB" {
1441               \refrainwordsB
1442             }
1443           >>
1444         >>
1445       }
1446       \new Lyrics \lyricsto "verse" {
1447         \versewords
1448       }
1449     >>
1450   }
1451 }
1452 @end lilypond
1453
1454 @cindex book, example of using
1455 @funindex \book
1456 @funindex book
1457
1458 However, although this is an interesting and useful exercise to
1459 help you to understand how sequential and simultaneous blocks work,
1460 in practice one would perhaps choose to code this as two
1461 @code{\score} blocks within an implicit @code{\book} block, as
1462 follows:
1463
1464 @lilypond[quote,verbatim,ragged-right]
1465 versenotes = \relative c'' {
1466   \clef "treble"
1467   \key g \major
1468   \time 3/4 g g g b b b
1469 }
1470 refrainnotesA = \relative c'' {
1471   \time 2/4
1472   c c g g \bar "|."
1473 }
1474 refrainnotesB = \relative c {
1475   \clef "bass"
1476   \key g \major
1477   c e d d
1478 }
1479 versewords = \lyricmode {
1480   One two three four five six
1481 }
1482 refrainwordsA = \lyricmode {
1483   la la la la
1484 }
1485 refrainwordsB = \lyricmode {
1486   dum dum dum dum
1487 }
1488 \score {
1489   \new Staff <<
1490     \new Voice = "verse" {
1491       \versenotes
1492     }
1493     \new Lyrics \lyricsto "verse" {
1494       \versewords
1495     }
1496   >>
1497 }
1498
1499 \score {
1500   \new ChoirStaff <<
1501     \new Staff <<
1502       \new Voice = "refrainA" {
1503         \refrainnotesA
1504       }
1505       \new Lyrics \lyricsto "refrainA" {
1506         \refrainwordsA
1507       }
1508     >>
1509     \new Staff <<
1510       \new Voice = "refrainB" {
1511         \refrainnotesB
1512       }
1513       \new Lyrics \lyricsto "refrainB" {
1514         \refrainwordsB
1515       }
1516     >>
1517   >>
1518 }
1519 @end lilypond
1520
1521
1522 @seealso
1523 Notation Reference: @ruser{Vocal music}.
1524
1525
1526 @node Contexts and engravers
1527 @section Contexts and engravers
1528
1529 Contexts and engravers have been mentioned informally
1530 in earlier sections; we now must look at
1531 these concepts in more detail, as they are important
1532 in the fine-tuning of LilyPond output.
1533
1534
1535 @menu
1536 * Contexts explained::
1537 * Creating contexts::
1538 * Engravers explained::
1539 * Modifying context properties::
1540 * Adding and removing engravers::
1541 @end menu
1542
1543 @node Contexts explained
1544 @subsection Contexts explained
1545
1546 @cindex contexts explained
1547
1548 When music is printed, many notational elements which do not
1549 appear explicitly in the input file must be added to the
1550 output.  For example, compare the input and output of the
1551 following example:
1552
1553 @lilypond[quote,verbatim,relative=2,fragment]
1554 cis4 cis2. g4
1555 @end lilypond
1556
1557 The input is rather sparse, but in the output, bar lines,
1558 accidentals, clef, and time signature have been added.  When
1559 LilyPond @emph{interprets} the input the musical information
1560 is parsed from left to right, similar to the way a performer
1561 reads the score.  While reading the input, the program remembers
1562 where measure boundaries are, and which pitches require explicit
1563 accidentals.  This information must be held on several levels.
1564 For example, an accidental affects only a single staff, while
1565 a bar line must be synchronized across the entire score.
1566
1567 Within LilyPond, these rules and bits of information are grouped in
1568 @emph{Contexts}.  We have already introduced the @code{Voice} context.
1569 Others are the @code{Staff} and @code{Score} contexts.  Contexts are
1570 hierarchical to reflect the hierarchical nature of a musical score.
1571 For example: a @code{Staff} context can contain many @code{Voice}
1572 contexts, and a @code{Score} context can contain many @code{Staff}
1573 contexts.
1574
1575 @quotation
1576 @sourceimage{context-example,5cm,,}
1577 @end quotation
1578
1579 Each context has the responsibility for enforcing some notation rules,
1580 creating some notation objects and maintaining the associated
1581 properties.  For example, the @code{Voice} context may introduce an
1582 accidental and then the @code{Staff} context maintains the rule to
1583 show or suppress the accidental for the remainder of the measure.
1584
1585 As another example, the synchronization of bar lines is, by default,
1586 handled in the @code{Score} context.
1587 However, in some music we may not want the bar lines to be
1588 synchronized -- consider a polymetric score in 4/4 and 3/4 time.
1589 In such cases, we must modify the default settings of the
1590 @code{Score} and @code{Staff} contexts.
1591
1592 For very simple scores, contexts are created implicitly, and you need
1593 not be aware of them.  For larger pieces, such as anything with more
1594 than one staff, they must be
1595 created explicitly to make sure that you get as many staves as you
1596 need, and that they are in the correct order.  For typesetting pieces
1597 with specialized notation, it is usual to modify existing, or
1598 even to define totally new, contexts.
1599
1600 In addition to the @code{Score,} @code{Staff} and
1601 @code{Voice} contexts there are contexts which fit between
1602 the score and staff levels to control staff groups, such as the
1603 @code{PianoStaff} and @code{ChoirStaff} contexts.  There
1604 are also alternative staff and voice contexts, and contexts for
1605 lyrics, percussion, fret boards, figured bass, etc.
1606
1607 The names of all context types are formed from one or more
1608 words, each word being capitalized and joined immediately to the
1609 preceding word with no hyphen or underscore, e.g.,
1610 @code{GregorianTranscriptionStaff}.
1611
1612
1613 @seealso
1614 Notation Reference: @ruser{Contexts explained}.
1615
1616
1617 @node Creating contexts
1618 @subsection Creating contexts
1619
1620 @funindex \new
1621 @funindex new
1622 @cindex new contexts
1623 @cindex creating contexts
1624 @cindex contexts, creating
1625
1626 There can be only one top level context: the @code{Score} context.
1627 This is created with the @code{\score} command, or, in simple scores,
1628 it is created automatically.
1629
1630 For scores with only one voice and one staff, the @code{Voice} and
1631 @code{Staff} contexts may be left to be created automatically, but for
1632 more complex scores it is necessary to create them by hand.  The
1633 simplest command that does this is @code{\new}.  It is prepended to a
1634 music expression, for example
1635
1636 @example
1637 \new @var{type} @var{music-expression}
1638 @end example
1639
1640 @noindent
1641 where @var{type} is a context name (like @code{Staff} or
1642 @code{Voice}).  This command creates a new context, and starts
1643 interpreting the @var{music-expression} within that context.
1644
1645 Note that there is no @code{\new Score} command;
1646 the single top-level @code{Score} context is introduced
1647 with @code{\score}.
1648
1649 You have seen many practical examples which created new
1650 @code{Staff} and @code{Voice} contexts in earlier sections, but
1651 to remind you how these commands are used in practice, here's an
1652 annotated real-music example:
1653
1654 @lilypond[quote,verbatim,ragged-right]
1655 \score {  % start of single compound music expression
1656   <<  % start of simultaneous staves section
1657     \time 2/4
1658     \new Staff {  % create RH staff
1659       \key g \minor
1660       \clef "treble"
1661       \new Voice {  % create voice for RH notes
1662         \relative c'' {  % start of RH notes
1663           d4 ees16 c8. |
1664           d4 ees16 c8. |
1665         }  % end of RH notes
1666       }  % end of RH voice
1667     }  % end of RH staff
1668     \new Staff <<  % create LH staff; needs two simultaneous voices
1669       \key g \minor
1670       \clef "bass"
1671       \new Voice {  % create LH voice one
1672         \voiceOne
1673         \relative g {  % start of LH voice one notes
1674           g8 <bes d> ees, <g c> |
1675           g8 <bes d> ees, <g c> |
1676         }  % end of LH voice one notes
1677       }  % end of LH voice one
1678       \new Voice {  % create LH voice two
1679         \voiceTwo
1680         \relative g {  % start of LH voice two notes
1681           g4 ees |
1682           g4 ees |
1683         }  % end of LH voice two notes
1684       }  % end of LH voice two
1685     >>  % end of LH staff
1686   >>  % end of simultaneous staves section
1687 }  % end of single compound music expression
1688 @end lilypond
1689
1690 (Note how all the statements which open a block with either a
1691 curly bracket, @code{@{}, or double angle brackets, @code{<<},
1692 are indented by two further spaces, and the corresponding
1693 closing bracket is indented by exactly the same amount.  While
1694 this is not required, following this practice will greatly
1695 reduce the number of @q{unmatched bracket} errors, and is
1696 strongly recommended.  It enables the structure of the music to
1697 be seen at a glance, and any unmatched brackets will be obvious.
1698 Note too how the LH staff is created using double angle brackets
1699 because it requires two voices for its music, whereas the RH staff
1700 is created with a single music expression surrounded by curly
1701 brackets because it requires only one voice.)
1702
1703 @cindex contexts, naming
1704 @cindex naming contexts
1705
1706 The @code{\new} command may also give a identifying name to the
1707 context to distinguish it from other contexts of the same type,
1708
1709 @example
1710 \new @var{type} = @var{id} @var{music-expression}
1711 @end example
1712
1713 Note the distinction between the name of the context type,
1714 @code{Staff}, @code{Voice}, etc, and the identifying name of a
1715 particular instance of that type, which can be any sequence of letters
1716 invented by the user.  Digits and spaces can also be used in the
1717 identifying name, but then it has to be placed in quotes,
1718 i.e. @code{\new Staff = "MyStaff 1" @var{music-expression}}.
1719 The identifying name is used to
1720 refer back to that particular instance of a context.  We saw this in
1721 use in the section on lyrics, see @ref{Voices and vocals}.
1722
1723
1724 @seealso
1725 Notation Reference: @ruser{Creating contexts}.
1726
1727
1728 @node Engravers explained
1729 @subsection Engravers explained
1730
1731 @cindex engravers
1732
1733 Every mark on the printed output of a score produced by LilyPond
1734 is produced by an @code{Engraver}.  Thus there is an engraver
1735 to print staves, one to print note heads, one for stems, one for
1736 beams, etc, etc.  In total there are over 120 such engravers!
1737 Fortunately, for most scores it is not necessary to know about
1738 more than a few, and for simple scores you do not need to know
1739 about any.
1740
1741 Engravers live and operate in Contexts.  Engravers such as the
1742 @code{Metronome_mark_engraver}, whose action and output apply to the
1743 score as a whole, operate in the highest level context -- the
1744 @code{Score} context.
1745
1746 The @code{Clef_engraver} and @code{Key_engraver} are to be
1747 found in every @code{Staff} Context, as different staves may require
1748 different clefs and keys.
1749
1750 The @code{Note_heads_engraver} and @code{Stem_engraver} live
1751 in every @code{Voice} context, the lowest level context of all.
1752
1753 Each engraver processes the particular objects associated
1754 with its function, and maintains the properties that relate
1755 to that function.  These properties, like the properties
1756 associated with contexts, may be modified to change the
1757 operation of the engraver or the appearance of those elements
1758 in the printed score.
1759
1760 Engravers all have compound names formed from words which
1761 describe their function.  Just the first word is capitalized,
1762 and the remainder are joined to it with underscores.  Thus
1763 the @code{Staff_symbol_engraver} is responsible for creating the
1764 lines of the staff, the @code{Clef_engraver} determines and sets
1765 the pitch reference point on the staff by drawing a clef symbol.
1766
1767 Here are some of the most common engravers together with their
1768 function.  You will see it is usually easy to guess the function
1769 from the name, or vice versa.
1770
1771 @multitable @columnfractions .3 .7
1772 @headitem Engraver
1773   @tab Function
1774 @item Accidental_engraver
1775   @tab Makes accidentals, cautionary and suggested accidentals
1776 @item Beam_engraver
1777   @tab Engraves beams
1778 @item Clef_engraver
1779   @tab Engraves clefs
1780 @item Completion_heads_engraver
1781   @tab Splits notes which cross bar lines
1782 @c The old Dynamic_engraver is deprecated. -jm
1783 @item New_dynamic_engraver
1784   @tab Creates hairpins and dynamic texts
1785 @item Forbid_line_break_engraver
1786   @tab Prevents line breaks if a musical element is still active
1787 @item Key_engraver
1788   @tab Creates the key signature
1789 @item Metronome_mark_engraver
1790   @tab Engraves metronome marking
1791 @item Note_heads_engraver
1792   @tab Engraves note heads
1793 @item Rest_engraver
1794   @tab Engraves rests
1795 @item Staff_symbol_engraver
1796   @tab Engraves the five (by default) lines of the staff
1797 @item Stem_engraver
1798   @tab Creates stems and single-stem tremolos
1799 @item Time_signature_engraver
1800   @tab Creates time signatures
1801 @end multitable
1802
1803 @smallspace
1804
1805 We shall see later how the output of LilyPond can be changed
1806 by modifying the action of Engravers.
1807
1808
1809 @seealso
1810 Internals reference: @rinternals{Engravers and Performers}.
1811
1812
1813 @node Modifying context properties
1814 @subsection Modifying context properties
1815
1816 @cindex context properties
1817 @cindex context properties, modifying
1818 @cindex modifying context properties
1819 @funindex \set
1820 @funindex set
1821 @funindex \unset
1822 @funindex unset
1823
1824 Contexts are responsible for holding the values of a number of
1825 context @emph{properties}.  Many of them can be changed to
1826 influence the interpretation of the input and so change the
1827 appearance of the output.  They are changed by the
1828 @code{\set} command.  This takes the form
1829
1830 @example
1831 \set @emph{ContextName}.@emph{propertyName} = #@emph{value}
1832 @end example
1833
1834 Where the @emph{ContextName} is usually @code{Score},
1835 @code{Staff} or @code{Voice}.  It may be omitted,
1836 in which case @code{Voice} is assumed.
1837
1838 The names of context properties consist of words joined
1839 together with no hyphens or underscores, all except the
1840 first having a capital letter.  Here are a few examples
1841 of some commonly used ones.  There are many more.
1842
1843 @c attempt to force this onto a new page
1844 @need 50
1845 @multitable @columnfractions .25 .15 .45 .15
1846 @headitem propertyName
1847   @tab Type
1848   @tab Function
1849   @tab Example Value
1850 @item extraNatural
1851   @tab Boolean
1852   @tab If true, set extra natural signs before accidentals
1853   @tab @code{#t}, @code{#f}
1854 @item currentBarNumber
1855   @tab Integer
1856   @tab Set the current bar number
1857   @tab @code{50}
1858 @item doubleSlurs
1859   @tab Boolean
1860   @tab If true, print slurs both above and below notes
1861   @tab @code{#t}, @code{#f}
1862 @item instrumentName
1863   @tab Text
1864   @tab Set the name to be placed at the start of the staff
1865   @tab @code{"Cello I"}
1866 @item fontSize
1867   @tab Real
1868   @tab Increase or decrease the font size
1869   @tab @code{2.4}
1870 @item stanza
1871   @tab Text
1872   @tab Set the text to print before the start of a verse
1873   @tab @code{"2"}
1874 @end multitable
1875
1876 @noindent
1877 where a Boolean is either True (@code{#t}) or False (@code{#f}),
1878 an Integer is a positive whole number, a Real is a positive
1879 or negative decimal number, and text is enclosed in double
1880 apostrophes.  Note the occurrence of hash signs,
1881 (@code{#}), in two different places -- as part of the Boolean
1882 value before the @code{t} or @code{f}, and before @emph{value}
1883 in the @code{\set} statement.  So when a Boolean is being
1884 entered you need to code two hash signs, e.g., @code{##t}.
1885
1886 @cindex properties operating in contexts
1887 @cindex setting properties within contexts
1888
1889 Before we can set any of these properties we need to know
1890 in which context they operate.  Sometimes this is obvious,
1891 but occasionally it can be tricky.  If the wrong context
1892 is specified, no error message is produced, but the expected
1893 action will not take place.  For example, the
1894 @code{instrumentName} clearly lives in the @code{Staff} context, since
1895 it is the staff that is to be named.
1896 In this example the first staff is labelled, but not the second,
1897 because we omitted the context name.
1898
1899 @lilypond[quote,verbatim,ragged-right]
1900 <<
1901   \new Staff \relative c'' {
1902     \set Staff.instrumentName = #"Soprano"
1903     c4 c
1904  }
1905   \new Staff \relative c' {
1906   \set instrumentName = #"Alto"  % Wrong!
1907   d4 d
1908  }
1909 >>
1910 @end lilypond
1911
1912 Remember the default context name is @code{Voice}, so the second
1913 @code{\set} command set the property @code{instrumentName} in the
1914 @code{Voice} context to @qq{Alto}, but as LilyPond does not look
1915 for any such property in the @code{Voice} context, no
1916 further action took place.  This is not an error, and no error
1917 message is logged in the log file.
1918
1919 Similarly, if the property name is mis-spelt no error message is
1920 produced, and clearly the expected action cannot be performed.  In
1921 fact, you can set any (fictitious) @q{property} using any name you
1922 like in any context that exists by using the @code{\set} command.  But
1923 if the name is not known to LilyPond it will not cause any action to
1924 be taken.  Some text editors with special support for LilyPond input
1925 files document property names with bullets when you hover them with
1926 the mouse, like JEdit with LilyPondTool, or highlight unknown property
1927 names differently, like ConTEXT.  If you do not use an editor with
1928 such features, it is recommended to check the property name in the
1929 Internals Reference: see @rinternals{Tunable context properties}, or
1930 @rinternals{Contexts}.
1931
1932 The @code{instrumentName} property will take effect only
1933 if it is set in the @code{Staff} context, but
1934 some properties can be set in more than one context.
1935 For example, the property @code{extraNatural} is by
1936 default set to ##t (true) for all staves.
1937 If it is set to ##f (false) in one particular @code{Staff}
1938 context it applies just to the accidentals on that staff.
1939 If it is set to false in the @code{Score} context
1940 it applies to all staves.
1941
1942 So this turns off extra naturals in one staff:
1943
1944 @lilypond[quote,verbatim,ragged-right]
1945 <<
1946   \new Staff \relative c'' {
1947     ais4 aes
1948  }
1949   \new Staff \relative c'' {
1950     \set Staff.extraNatural = ##f
1951     ais4 aes
1952  }
1953 >>
1954 @end lilypond
1955
1956 @noindent
1957 and this turns them off in all staves:
1958
1959 @lilypond[quote,verbatim,ragged-right]
1960 <<
1961   \new Staff \relative c'' {
1962     ais4 aes
1963  }
1964   \new Staff \relative c'' {
1965     \set Score.extraNatural = ##f
1966     ais4 aes
1967  }
1968 >>
1969 @end lilypond
1970
1971 As another example, if @code{clefOctavation} is set in
1972 the @code{Score} context this immediately changes the value
1973 of the octavation in all current staves and sets a new default
1974 value which will be applied to all staves.
1975
1976 The opposite command, @code{\unset}, effectively removes the
1977 property from the context, which causes most properties to
1978 revert to their default value.  Usually @code{\unset} is not
1979 required as a new @code{\set} command will achieve what is
1980 wanted.
1981
1982 The @code{\set} and @code{\unset} commands can appear anywhere
1983 in the input file and will take effect from the time they are
1984 encountered until the end of the score or until the property is
1985 @code{\set} or @code{\unset} again.  Let's try changing the
1986 font size, which affects the size of the note heads (among
1987 other things) several times.  The change is from the default
1988 value, not the most recently set value.
1989
1990 @lilypond[quote,verbatim,ragged-right,relative=1,fragment]
1991 c4
1992 % make note heads smaller
1993 \set fontSize = #-4
1994 d e
1995 % make note heads larger
1996 \set fontSize = #2.5
1997 f g
1998 % return to default size
1999 \unset fontSize
2000 a b
2001 @end lilypond
2002
2003 We have now seen how to set the values of several different types of
2004 property.  Note that integers and numbers are always preceded by a
2005 hash sign, @code{#}, while a true or false value is specified by
2006 @code{##t} and @code{##f}, with two hash signs.  A text property
2007 should be enclosed in double quotation signs, as above, although we
2008 shall see later that text can actually be specified in a much more
2009 general way by using the very powerful @code{markup} command.
2010
2011 @subsubheading Setting context properties with @code{\with}
2012
2013 @funindex \with
2014 @funindex with
2015 @cindex context properties, setting with \with
2016
2017 Context properties may also be set at the time the context is
2018 created.  Sometimes this is a clearer way of specifying a
2019 property value if it is to remain fixed for the duration of
2020 the context.  When a context is created with a @code{\new}
2021 command it may be followed immediately by a
2022 @code{\with @{ .. @}} block in which the property values are
2023 set.  For example, if we wish to suppress the printing of
2024 extra naturals for the duration of a staff we would write:
2025
2026 @example
2027 \new Staff \with @{ extraNatural = ##f @}
2028 @end example
2029
2030 @noindent
2031 like this:
2032
2033 @lilypond[quote,verbatim,ragged-right]
2034 <<
2035   \new Staff
2036   \relative c'' {
2037     gis ges aes ais
2038   }
2039   \new Staff \with { extraNatural = ##f }
2040   \relative c'' {
2041     gis ges aes ais
2042   }
2043 >>
2044 @end lilypond
2045
2046 Properties set in this way may still be changed dynamically using
2047 @code{\set} and returned to their default value with @code{\unset}.
2048
2049 @cindex fontSize, default and setting
2050
2051 The @code{fontSize} property is treated differently.  If this is
2052 set in a @code{\with} clause it effectively resets the default
2053 value of the font size.  If it is later changed with @code{\set},
2054 this new default value may be restored with the
2055 @code{\unset fontSize} command.
2056
2057 @subsubheading Setting context properties with @code{\context}
2058
2059 @cindex context properties, setting with \context
2060 @funindex \context
2061 @funindex context
2062
2063 The values of context properties may be set in @emph{all} contexts
2064 of a particular type, such as all @code{Staff} contexts, with a single
2065 command.  The context type is identified by using its
2066 type name, like @code{Staff}, prefixed by a back-slash: @code{\Staff}.
2067 The statement which sets the property value is the same as that in a
2068 @code{\with} block, introduced above.  It is placed in a
2069 @code{\context} block within a @code{\layout} block.  Each
2070 @code{\context} block will affect all contexts of the type specified
2071 throughout the @code{\score} or @code{\book} block in which the
2072 @code{\layout} block appears.  Here is a example to show the format:
2073
2074 @lilypond[verbatim,quote]
2075 \score {
2076   \new Staff {
2077     \relative c'' {
2078       cis4 e d ces
2079     }
2080   }
2081   \layout {
2082     \context {
2083       \Staff
2084       extraNatural = ##t
2085     }
2086   }
2087 }
2088 @end lilypond
2089
2090 @noindent
2091 Context properties set in this way may be overridden for particular
2092 instances of contexts by statements in a @code{\with} block, and by
2093 @code{\set} commands embedded in music statements.
2094
2095
2096 @seealso
2097 Notation Reference:
2098 @ruser{Changing context default settings}.
2099 @c FIXME
2100 @c uncomment when backslash-node-name issue is resolved -pm
2101 @c @ruser{The set command}.
2102
2103 Internals Reference:
2104 @rinternals{Contexts},
2105 @rinternals{Tunable context properties}.
2106
2107
2108 @node Adding and removing engravers
2109 @subsection Adding and removing engravers
2110
2111 @cindex engravers, adding
2112 @cindex adding engravers
2113 @cindex engravers, removing
2114 @cindex removing engravers
2115
2116 @funindex \consists
2117 @funindex consists
2118 @funindex \remove
2119 @funindex remove
2120
2121 We have seen that contexts each contain several engravers, each
2122 of which is responsible for producing a particular part of the
2123 output, like bar lines, staves, note heads, stems, etc.  If an
2124 engraver is removed from a context, it can no longer produce its
2125 output.  This is a crude way of modifying the output, but it
2126 can sometimes be useful.
2127
2128 @subsubheading Changing a single context
2129
2130 To remove an engraver from a single context we use the
2131 @code{\with} command placed immediately after the context creation
2132 command, as in the previous section.
2133
2134 As an illustration, let's repeat an example from the previous section
2135 with the staff lines removed.  Remember that the staff lines are
2136 produced by the @code{Staff_symbol_engraver}.
2137
2138 @lilypond[quote,verbatim,ragged-right]
2139 \new Staff \with {
2140   \remove Staff_symbol_engraver
2141 }
2142 \relative c' {
2143   c4
2144   \set fontSize = #-4  % make note heads smaller
2145   d e
2146   \set fontSize = #2.5  % make note heads larger
2147   f g
2148   \unset fontSize  % return to default size
2149   a b
2150 }
2151 @end lilypond
2152
2153 @cindex ambitus engraver
2154
2155 Engravers can also be added to individual contexts.
2156 The command to do this is
2157
2158 @code{\consists @var{Engraver_name}},
2159
2160 @noindent
2161 placed inside a @code{\with} block.  Some vocal scores have an ambitus
2162 placed at the beginning of a staff to indicate the range of notes in
2163 that staff -- see @rglos{ambitus}.  The ambitus is produced by the
2164 @code{Ambitus_engraver}, which is not normally included in any
2165 context.  If we add it to the @code{Voice} context, it calculates the
2166 range from that voice only:
2167
2168 @lilypond[quote,verbatim,ragged-right]
2169 \new Staff <<
2170   \new Voice \with {
2171     \consists Ambitus_engraver
2172   }
2173   \relative c'' {
2174     \voiceOne
2175     c a b g
2176   }
2177   \new Voice
2178   \relative c' {
2179     \voiceTwo
2180     c e d f
2181   }
2182 >>
2183 @end lilypond
2184
2185 @noindent
2186 but if we add the ambitus engraver to the
2187 @code{Staff} context, it calculates the range from all
2188 the notes in all the voices on that staff:
2189
2190 @lilypond[quote,verbatim,ragged-right]
2191 \new Staff \with {
2192     \consists Ambitus_engraver
2193   }
2194   <<
2195   \new Voice
2196   \relative c'' {
2197     \voiceOne
2198     c a b g
2199   }
2200   \new Voice
2201   \relative c' {
2202     \voiceTwo
2203     c e d f
2204   }
2205 >>
2206 @end lilypond
2207
2208 @subsubheading Changing all contexts of the same type
2209
2210 @funindex \layout
2211 @funindex layout
2212
2213 The examples above show how to remove or add engravers to
2214 individual contexts.  It is also possible to remove or add
2215 engravers to every context of a specific type by placing the
2216 commands in the appropriate context in a @code{\layout}
2217 block.  For example, if we wanted to show an ambitus for every
2218 staff in a four-staff score, we could write
2219
2220 @lilypond[quote,verbatim,ragged-right]
2221 \score {
2222   <<
2223     \new Staff <<
2224       \relative c'' { c a b g }
2225     >>
2226     \new Staff <<
2227       \relative c' { c a b g }
2228     >>
2229     \new Staff <<
2230       \clef "G_8"
2231       \relative c' { c a b g }
2232     >>
2233     \new Staff <<
2234       \clef "bass"
2235       \relative c { c a b g }
2236     >>
2237   >>
2238   \layout {
2239     \context {
2240       \Staff
2241       \consists Ambitus_engraver
2242     }
2243   }
2244 }
2245 @end lilypond
2246
2247 @noindent
2248 The values of context properties may also be set
2249 for all contexts of a particular type by including the
2250 @code{\set} command in a @code{\context} block in the
2251 same way.
2252
2253
2254 @seealso
2255 Notation Reference: @ruser{Modifying context plug-ins},
2256 @ruser{Changing context default settings}.
2257
2258
2259 @node Extending the templates
2260 @section Extending the templates
2261
2262 You've read the tutorial, you know how to write music, you
2263 understand the fundamental concepts.  But how can you
2264 get the staves that you want?  Well, you can find lots of
2265 templates (see @ref{Templates}) which may give you a start.
2266 But what if you want something that isn't covered there?  Read on.
2267
2268 @menu
2269 * Soprano and cello::
2270 * Four-part SATB vocal score::
2271 * Building a score from scratch::
2272 @end menu
2273
2274 @node Soprano and cello
2275 @subsection Soprano and cello
2276
2277 @cindex template, modifying
2278 @cindex modifying templates
2279
2280 Start off with the template that seems closest to what you want to end
2281 up with.  Let's say that you want to write something for soprano and
2282 cello.  In this case, we would start with @q{Notes and lyrics} (for the
2283 soprano part).
2284
2285 @example
2286 \version @w{"@version{}"}
2287 melody = \relative c' @{
2288   \clef treble
2289   \key c \major
2290   \time 4/4
2291   a4 b c d
2292 @}
2293
2294 text = \lyricmode @{
2295   Aaa Bee Cee Dee
2296 @}
2297
2298 \score @{
2299   <<
2300     \new Voice = "one" @{
2301       \autoBeamOff
2302       \melody
2303     @}
2304     \new Lyrics \lyricsto "one" \text
2305   >>
2306   \layout @{ @}
2307   \midi @{ @}
2308 @}
2309 @end example
2310
2311 Now we want to add a cello part.  Let's look at the @q{Notes only} example:
2312
2313 @example
2314 \version @w{"@version{}"}
2315 melody = \relative c' @{
2316   \clef treble
2317   \key c \major
2318   \time 4/4
2319   a4 b c d
2320 @}
2321
2322 \score @{
2323   \new Staff \melody
2324   \layout @{ @}
2325   \midi @{ @}
2326 @}
2327 @end example
2328
2329 We don't need two @code{\version} commands.  We'll need the
2330 @code{melody} section.  We don't want two @code{\score} sections
2331 -- if we had two @code{\score}s, we'd get the two parts separately.
2332 We want them together, as a duet.  Within the @code{\score}
2333 section, we don't need two @code{\layout} or @code{\midi}.
2334
2335 If we simply cut and paste the @code{melody} section, we would
2336 end up with two @code{melody} definitions.  This would not generate
2337 an error, but the second one would be used for both melodies.
2338 So let's rename them to make them distinct.  We'll call the
2339 section for the soprano @code{sopranoMusic} and the section for
2340 the cello @code{celloMusic}.  While we're doing this, let's rename
2341 @code{text} to be @code{sopranoLyrics}.  Remember to rename both
2342 instances of all these names -- both the initial definition (the
2343 @code{melody = \relative c' @{ } part) and the name's use (in the
2344 @code{\score} section).
2345
2346 While we're doing this, let's change the cello part's staff --
2347 celli normally use bass clef.  We'll also give the cello some
2348 different notes.
2349
2350 @example
2351 \version @w{"@version{}"}
2352 sopranoMusic = \relative c' @{
2353   \clef treble
2354   \key c \major
2355   \time 4/4
2356   a4 b c d
2357 @}
2358
2359 sopranoLyrics = \lyricmode @{
2360   Aaa Bee Cee Dee
2361 @}
2362
2363 celloMusic = \relative c @{
2364   \clef bass
2365   \key c \major
2366   \time 4/4
2367   d4 g fis8 e d4
2368 @}
2369
2370 \score @{
2371   <<
2372     \new Voice = "one" @{
2373       \autoBeamOff
2374       \sopranoMusic
2375     @}
2376     \new Lyrics \lyricsto "one" \sopranoLyrics
2377   >>
2378   \layout @{ @}
2379   \midi @{ @}
2380 @}
2381 @end example
2382
2383 This is looking promising, but the cello part won't appear in the
2384 score -- we haven't used it in the @code{\score} section.  If we
2385 want the cello part to appear under the soprano part, we need to add
2386
2387 @example
2388 \new Staff \celloMusic
2389 @end example
2390
2391 @noindent
2392 underneath the soprano stuff.  We also need to add @code{<<} and
2393 @code{>>} around the music -- that tells LilyPond that there's
2394 more than one thing (in this case, two @code{Staves}) happening
2395 at once.  The @code{\score} looks like this now:
2396
2397 @c Indentation in this example is deliberately poor
2398 @example
2399 \score @{
2400   <<
2401   <<
2402     \new Voice = "one" @{
2403       \autoBeamOff
2404       \sopranoMusic
2405     @}
2406     \new Lyrics \lyricsto "one" \sopranoLyrics
2407   >>
2408   \new Staff \celloMusic
2409   >>
2410   \layout @{ @}
2411   \midi @{ @}
2412 @}
2413 @end example
2414
2415 @noindent
2416 This looks a bit messy; the indentation is messed up now.  That is
2417 easily fixed.  Here's the complete soprano and cello template.
2418
2419 @lilypond[quote,verbatim,ragged-right,addversion]
2420 sopranoMusic = \relative c' {
2421   \clef treble
2422   \key c \major
2423   \time 4/4
2424   a4 b c d
2425 }
2426
2427 sopranoLyrics = \lyricmode {
2428   Aaa Bee Cee Dee
2429 }
2430
2431 celloMusic = \relative c {
2432   \clef bass
2433   \key c \major
2434   \time 4/4
2435   d4 g fis8 e d4
2436 }
2437
2438 \score {
2439   <<
2440     <<
2441       \new Voice = "one" {
2442         \autoBeamOff
2443         \sopranoMusic
2444       }
2445       \new Lyrics \lyricsto "one" \sopranoLyrics
2446     >>
2447     \new Staff \celloMusic
2448   >>
2449   \layout { }
2450   \midi { }
2451 }
2452 @end lilypond
2453
2454
2455 @seealso
2456 The starting templates can be found in the @q{Templates} appendix,
2457 see @ref{Single staff}.
2458
2459
2460 @node Four-part SATB vocal score
2461 @subsection Four-part SATB vocal score
2462
2463 @cindex template, SATB
2464 @cindex SATB template
2465
2466 Most vocal scores of music written for four-part mixed choir
2467 with orchestral accompaniment such as Mendelssohn's Elijah or
2468 Handel's Messiah have the choral music and words on four
2469 staves, one for each of SATB, with a piano reduction of the
2470 orchestral accompaniment underneath.  Here's an example
2471 from Handel's Messiah:
2472
2473 @c The following should appear as music without code
2474 @lilypond[quote,ragged-right]
2475 global = { \key d \major \time 4/4 }
2476 sopranoMusic = \relative c'' {
2477   \clef "treble"
2478   r4 d2 a4 | d4. d8 a2 | cis4 d cis2 |
2479 }
2480 sopranoWords = \lyricmode {
2481   Wor -- thy is the lamb that was slain
2482 }
2483 altoMusic = \relative a' {
2484   \clef "treble"
2485   r4 a2 a4 | fis4. fis8 a2 | g4 fis e2 |
2486 }
2487 altoWords = \sopranoWords
2488 tenorMusic = \relative c' {
2489   \clef "G_8"
2490   r4 fis2 e4 | d4. d8 d2 | e4 a, cis2 |
2491 }
2492 tenorWords = \sopranoWords
2493 bassMusic = \relative c' {
2494   \clef "bass"
2495   r4 d2 cis4 | b4. b8 fis2 | e4 d a'2 |
2496 }
2497 bassWords = \sopranoWords
2498 upper = \relative a' {
2499   \clef "treble"
2500   \global
2501   r4 <a d fis>2 <a e' a>4 |
2502   <d fis d'>4. <d fis d'>8 <a d a'>2 |
2503   <g cis g'>4 <a d fis> <a cis e>2 |
2504 }
2505 lower = \relative c, {
2506   \clef "bass"
2507   \global
2508   <d d'>4 <d d'>2 <cis cis'>4 |
2509   <b b'>4. <b' b'>8 <fis fis'>2 |
2510   <e e'>4 <d d'> <a' a'>2 |
2511 }
2512
2513 \score {
2514   <<  % combine ChoirStaff and PianoStaff in parallel
2515     \new ChoirStaff <<
2516       \new Staff = "sopranos" <<
2517         \set Staff.instrumentName = #"Soprano"
2518         \new Voice = "sopranos" { \global \sopranoMusic }
2519       >>
2520       \new Lyrics \lyricsto "sopranos" { \sopranoWords }
2521       \new Staff = "altos" <<
2522         \set Staff.instrumentName = #"Alto"
2523         \new Voice = "altos" { \global \altoMusic }
2524       >>
2525       \new Lyrics \lyricsto "altos" { \altoWords }
2526       \new Staff = "tenors" <<
2527         \set Staff.instrumentName = #"Tenor"
2528         \new Voice = "tenors" { \global \tenorMusic }
2529       >>
2530       \new Lyrics \lyricsto "tenors" { \tenorWords }
2531       \new Staff = "basses" <<
2532         \set Staff.instrumentName = #"Bass"
2533         \new Voice = "basses" { \global \bassMusic }
2534       >>
2535       \new Lyrics \lyricsto "basses" { \bassWords }
2536     >>  % end ChoirStaff
2537
2538     \new PianoStaff <<
2539       \set PianoStaff.instrumentName = #"Piano"
2540       \new Staff = "upper" \upper
2541       \new Staff = "lower" \lower
2542     >>
2543   >>
2544 }
2545 @end lilypond
2546
2547 None of the templates provides this layout exactly.  The nearest is
2548 @q{SATB vocal score and automatic piano reduction} -- see @ref{Vocal
2549 ensembles} -- but we need to change the layout and add a piano
2550 accompaniment which is not derived automatically from the vocal parts.
2551 The variables holding the music and words for the vocal parts are
2552 fine, but we shall need to add variables for the piano reduction.
2553
2554 The order in which the contexts appear in the ChoirStaff of the
2555 template do not correspond with the order in the vocal score shown
2556 above.  We need to rearrange them so there are four staves with the
2557 words written directly underneath the notes for each part.  All the
2558 voices should be @code{\voiceOne}, which is the default, so the
2559 @code{\voiceXXX} commands should be removed.  We also need to specify
2560 the tenor clef for the tenors.  The way in which lyrics are specified
2561 in the template has not yet been encountered so we need to use the
2562 method with which we are familiar.  We should also add the names of
2563 each staff.
2564
2565 Doing this gives for our ChoirStaff:
2566
2567 @example
2568     \new ChoirStaff <<
2569       \new Staff = "sopranos" <<
2570         \set Staff.instrumentName = #"Soprano"
2571         \new Voice = "sopranos" @{ \global \sopranoMusic @}
2572       >>
2573       \new Lyrics \lyricsto "sopranos" @{ \sopranoWords @}
2574       \new Staff = "altos" <<
2575         \set Staff.instrumentName = #"Alto"
2576         \new Voice = "altos" @{ \global \altoMusic @}
2577       >>
2578       \new Lyrics \lyricsto "altos" @{ \altoWords @}
2579       \new Staff = "tenors" <<
2580         \set Staff.instrumentName = #"Tenor"
2581         \new Voice = "tenors" @{ \global \tenorMusic @}
2582       >>
2583       \new Lyrics \lyricsto "tenors" @{ \tenorWords @}
2584       \new Staff = "basses" <<
2585         \set Staff.instrumentName = #"Bass"
2586         \new Voice = "basses" @{ \global \bassMusic @}
2587       >>
2588       \new Lyrics \lyricsto "basses" @{ \bassWords @}
2589     >>  % end ChoirStaff
2590 @end example
2591
2592 Next we must work out the piano part.  This is
2593 easy - we just pull out the piano part from the
2594 @q{Solo piano} template:
2595
2596 @example
2597 \new PianoStaff <<
2598   \set PianoStaff.instrumentName = #"Piano  "
2599   \new Staff = "upper" \upper
2600   \new Staff = "lower" \lower
2601 >>
2602 @end example
2603
2604 and add the variable definitions for @code{upper}
2605 and @code{lower}.
2606
2607 The ChoirStaff and PianoStaff must be combined
2608 using angle brackets as we want them to be
2609 stacked one above the other:
2610
2611 @example
2612 <<  % combine ChoirStaff and PianoStaff one above the other
2613   \new ChoirStaff <<
2614     \new Staff = "sopranos" <<
2615       \new Voice = "sopranos" @{ \global \sopranoMusic @}
2616     >>
2617     \new Lyrics \lyricsto "sopranos" @{ \sopranoWords @}
2618     \new Staff = "altos" <<
2619       \new Voice = "altos" @{ \global \altoMusic @}
2620     >>
2621     \new Lyrics \lyricsto "altos" @{ \altoWords @}
2622     \new Staff = "tenors" <<
2623       \clef "G_8"  % tenor clef
2624       \new Voice = "tenors" @{ \global \tenorMusic @}
2625     >>
2626     \new Lyrics \lyricsto "tenors" @{ \tenorWords @}
2627     \new Staff = "basses" <<
2628       \clef "bass"
2629       \new Voice = "basses" @{ \global \bassMusic @}
2630     >>
2631     \new Lyrics \lyricsto "basses" @{ \bassWords @}
2632   >>  % end ChoirStaff
2633
2634   \new PianoStaff <<
2635     \set PianoStaff.instrumentName = #"Piano"
2636     \new Staff = "upper" \upper
2637     \new Staff = "lower" \lower
2638   >>
2639 >>
2640 @end example
2641
2642 Combining all these together and adding the music
2643 for the three bars of the example above gives:
2644
2645 @lilypond[quote,verbatim,ragged-right,addversion]
2646 global = { \key d \major \time 4/4 }
2647 sopranoMusic = \relative c'' {
2648   \clef "treble"
2649   r4 d2 a4 | d4. d8 a2 | cis4 d cis2 |
2650 }
2651 sopranoWords = \lyricmode {
2652   Wor -- thy is the lamb that was slain
2653 }
2654 altoMusic = \relative a' {
2655   \clef "treble"
2656   r4 a2 a4 | fis4. fis8 a2 | g4 fis fis2 |
2657 }
2658 altoWords = \sopranoWords
2659 tenorMusic = \relative c' {
2660   \clef "G_8"
2661   r4 fis2 e4 | d4. d8 d2 | e4 a, cis2 |
2662 }
2663 tenorWords = \sopranoWords
2664 bassMusic = \relative c' {
2665   \clef "bass"
2666   r4 d2 cis4 | b4. b8 fis2 | e4 d a'2 |
2667 }
2668 bassWords = \sopranoWords
2669 upper = \relative a' {
2670   \clef "treble"
2671   \global
2672   r4 <a d fis>2 <a e' a>4 |
2673   <d fis d'>4. <d fis d'>8 <a d a'>2 |
2674   <g cis g'>4 <a d fis> <a cis e>2 |
2675 }
2676 lower = \relative c, {
2677   \clef "bass"
2678   \global
2679   <d d'>4 <d d'>2 <cis cis'>4 |
2680   <b b'>4. <b' b'>8 <fis fis'>2 |
2681   <e e'>4 <d d'> <a' a'>2 |
2682 }
2683
2684 \score {
2685   <<  % combine ChoirStaff and PianoStaff in parallel
2686     \new ChoirStaff <<
2687       \new Staff = "sopranos" <<
2688         \set Staff.instrumentName = #"Soprano"
2689         \new Voice = "sopranos" { \global \sopranoMusic }
2690       >>
2691       \new Lyrics \lyricsto "sopranos" { \sopranoWords }
2692       \new Staff = "altos" <<
2693         \set Staff.instrumentName = #"Alto"
2694         \new Voice = "altos" { \global \altoMusic }
2695       >>
2696       \new Lyrics \lyricsto "altos" { \altoWords }
2697       \new Staff = "tenors" <<
2698         \set Staff.instrumentName = #"Tenor"
2699         \new Voice = "tenors" { \global \tenorMusic }
2700       >>
2701       \new Lyrics \lyricsto "tenors" { \tenorWords }
2702       \new Staff = "basses" <<
2703         \set Staff.instrumentName = #"Bass"
2704         \new Voice = "basses" { \global \bassMusic }
2705       >>
2706       \new Lyrics \lyricsto "basses" { \bassWords }
2707     >>  % end ChoirStaff
2708
2709     \new PianoStaff <<
2710       \set PianoStaff.instrumentName = #"Piano  "
2711       \new Staff = "upper" \upper
2712       \new Staff = "lower" \lower
2713     >>
2714   >>
2715 }
2716 @end lilypond
2717
2718
2719 @node Building a score from scratch
2720 @subsection Building a score from scratch
2721
2722 @cindex template, writing your own
2723 @cindex example of writing a score
2724 @cindex writing a score, example
2725 @cindex score, example of writing
2726
2727 After gaining some facility with writing LilyPond code, you
2728 may find that it is easier to build a score from scratch
2729 rather than modifying one of the templates.  You can also
2730 develop your own style this way to suit the sort of music you
2731 like.  Let's see how to put together the score for an organ
2732 prelude as an example.
2733
2734 We begin with a header section.  Here go the title, name
2735 of composer, etc, then come any variable definitions, and
2736 finally the score block.  Let's start with these in outline
2737 and fill in the details later.
2738
2739 We'll use the first two bars of Bach's prelude
2740 based on @emph{Jesu, meine Freude} which is written for two
2741 manuals and pedal organ.  You can see these two bars of music
2742 at the bottom of this section.  The top manual part has two voices,
2743 the lower and pedal organ one each.  So we need four
2744 music definitions and one to define the time signature
2745 and key:
2746
2747 @example
2748 \version @w{"@version{}"}
2749 \header @{
2750   title = "Jesu, meine Freude"
2751   composer = "J S Bach"
2752 @}
2753 TimeKey = @{ \time 4/4 \key c \minor @}
2754 ManualOneVoiceOneMusic = @{s1@}
2755 ManualOneVoiceTwoMusic = @{s1@}
2756 ManualTwoMusic = @{s1@}
2757 PedalOrganMusic = @{s1@}
2758
2759 \score @{
2760 @}
2761 @end example
2762
2763 For now we've just used a spacer note, @code{s1},
2764 instead of the real music.  We'll add that later.
2765
2766 Next let's see what should go in the score block.
2767 We simply mirror the staff structure we want.
2768 Organ music is usually written on three staves,
2769 one for each manual and one for the pedals.  The
2770 manual staves should be bracketed together, so we
2771 need to use a PianoStaff for them.  The first
2772 manual part needs two voices and the second manual
2773 part just one.
2774
2775 @example
2776   \new PianoStaff <<
2777     \new Staff = "ManualOne" <<
2778       \new Voice @{ \ManualOneVoiceOneMusic @}
2779       \new Voice @{ \ManualOneVoiceTwoMusic @}
2780     >>  % end ManualOne Staff context
2781     \new Staff = "ManualTwo" <<
2782       \new Voice @{ \ManualTwoMusic @}
2783     >>  % end ManualTwo Staff context
2784   >>  % end PianoStaff context
2785 @end example
2786
2787 Next we need to add a staff for the pedal organ.
2788 This goes underneath the PianoStaff, but it must
2789 be simultaneous with it, so we need angle brackets
2790 around the two.  Missing these out would generate
2791 an error in the log file.  It's a common mistake
2792 which you'll make sooner or later!  Try copying
2793 the final example at the end of this section,
2794 remove these angle brackets, and compile it to
2795 see what errors it generates.
2796
2797 @example
2798 <<  % PianoStaff and Pedal Staff must be simultaneous
2799   \new PianoStaff <<
2800     \new Staff = "ManualOne" <<
2801       \new Voice @{ \ManualOneVoiceOneMusic @}
2802       \new Voice @{ \ManualOneVoiceTwoMusic @}
2803     >>  % end ManualOne Staff context
2804     \new Staff = "ManualTwo" <<
2805       \new Voice @{ \ManualTwoMusic @}
2806     >>  % end ManualTwo Staff context
2807   >>  % end PianoStaff context
2808   \new Staff = "PedalOrgan" <<
2809     \new Voice @{ \PedalOrganMusic @}
2810   >>
2811 >>
2812 @end example
2813
2814 It is not necessary to use the simultaneous construct
2815 @code{<< .. >>} for the manual two staff and the pedal organ staff,
2816 since they contain only one music expression, but it does no harm,
2817 and always using angle brackets after @code{\new Staff} is a good
2818 habit to cultivate in case there are multiple voices.  The opposite
2819 is true for Voices: these should habitually be followed by braces
2820 @code{@{ .. @}} in case your music is coded in several variables
2821 which need to run consecutively.
2822
2823 Let's add this structure to the score block, and adjust the indenting.
2824 We also add the appropriate clefs, ensure stems, ties and slurs in
2825 each voice on the upper staff point to the right direction with
2826 @code{\voiceOne} and @code{\voiceTwo}, and enter the time signature
2827 and key to each staff using our predefined variable, @code{\TimeKey}.
2828
2829 @example
2830 \score @{
2831   <<  % PianoStaff and Pedal Staff must be simultaneous
2832     \new PianoStaff <<
2833       \new Staff = "ManualOne" <<
2834         \TimeKey  % set time signature and key
2835         \clef "treble"
2836         \new Voice @{ \voiceOne \ManualOneVoiceOneMusic @}
2837         \new Voice @{ \voiceTwo \ManualOneVoiceTwoMusic @}
2838       >>  % end ManualOne Staff context
2839       \new Staff = "ManualTwo" <<
2840         \TimeKey
2841         \clef "bass"
2842         \new Voice @{ \ManualTwoMusic @}
2843       >>  % end ManualTwo Staff context
2844     >>  % end PianoStaff context
2845     \new Staff = "PedalOrgan" <<
2846       \TimeKey
2847       \clef "bass"
2848       \new Voice @{ \PedalOrganMusic @}
2849     >>  % end PedalOrgan Staff
2850   >>
2851 @}  % end Score context
2852 @end example
2853
2854 That completes the structure.  Any three-staff organ music
2855 will have a similar structure, although the number of voices
2856 may vary.  All that remains now
2857 is to add the music, and combine all the parts together.
2858
2859 @lilypond[quote,verbatim,ragged-right,addversion]
2860 \header {
2861   title = "Jesu, meine Freude"
2862   composer = "J S Bach"
2863 }
2864 TimeKey = { \time 4/4 \key c \minor }
2865 ManualOneVoiceOneMusic = \relative g' {
2866   g4 g f ees | d2 c2 |
2867 }
2868 ManualOneVoiceTwoMusic = \relative c' {
2869   ees16 d ees8~ ees16 f ees d c8 d~ d c~ |
2870   c c4 b8 c8. g16 c b c d |
2871 }
2872 ManualTwoMusic = \relative c' {
2873   c16 b c8~ c16 b c g a8 g~ g16 g aes ees |
2874   f ees f d g aes g f ees d e8~ ees16 f ees d |
2875 }
2876 PedalOrganMusic = \relative c {
2877   r8 c16 d ees d ees8~ ees16 a, b g c b c8 |
2878   r16 g ees f g f g8 c,2 |
2879   }
2880
2881 \score {
2882   <<  % PianoStaff and Pedal Staff must be simultaneous
2883     \new PianoStaff <<
2884       \new Staff = "ManualOne" <<
2885         \TimeKey  % set time signature and key
2886         \clef "treble"
2887         \new Voice { \voiceOne \ManualOneVoiceOneMusic }
2888         \new Voice { \voiceTwo \ManualOneVoiceTwoMusic }
2889       >>  % end ManualOne Staff context
2890       \new Staff = "ManualTwo" <<
2891         \TimeKey
2892         \clef "bass"
2893         \new Voice { \ManualTwoMusic }
2894       >>  % end ManualTwo Staff context
2895     >>  % end PianoStaff context
2896     \new Staff = "PedalOrgan" <<
2897       \TimeKey
2898       \clef "bass"
2899       \new Voice { \PedalOrganMusic }
2900     >>  % end PedalOrgan Staff context
2901   >>
2902 }  % end Score context
2903 @end lilypond
2904
2905