1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond-learning.tely
4 Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
6 When revising a translation, copy the HEAD committish of the
7 version that you are working on. See TRANSLATION for details.
12 @node Fundamental concepts
13 @chapter Fundamental concepts
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.
21 * How LilyPond input files work::
22 * Voices contain music::
23 * Contexts and engravers::
24 * Extending the templates::
28 @node How LilyPond input files work
29 @section How LilyPond input files work
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}.
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::
45 @node Introduction to the LilyPond file structure
46 @subsection Introduction to the LilyPond file structure
49 @cindex file structure
51 A basic example of a LilyPond input file is
54 \version @w{"@version{}"}
57 @var{...compound music expression...} % all the music goes here!
64 There are many variations of this basic pattern, but this
65 example serves as a useful starting place.
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:
86 as shorthand for this:
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.
107 @cindex implicit contexts
108 @cindex contexts, implicit
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}.
119 @warning{When entering more than a few lines of music it is
120 advisable to always create staves and voices explicitly.}
122 For now, though, let us return to the first example and examine the
123 @code{\score} command, leaving the others to default.
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
133 @var{...insert the whole score of a Wagner opera in here...}
139 Since everything is inside @code{@{ ... @}}, it counts
140 as one music expression.
142 As we saw previously, the @code{\score} block can contain other
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.
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}.
181 @cindex scores, multiple
182 @cindex book block, implicit
183 @cindex implicit book block
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.
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.
202 Every @code{\score} block is a separate chunk of music within a
205 @cindex layout block, effect of location
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}.
214 For details see @ruser{Multiple scores in a book}.
218 Another great shorthand is the ability to define variables. All
219 the templates use this
222 melody = \relative c' @{
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},
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}.
248 For a complete definition of the input format, see
249 @ruser{File structure}.
251 @node Score is a (single) compound musical expression
252 @subsection Score is a (single) compound musical expression
257 @cindex contents of a score block
258 @cindex score block, contents of
259 @cindex compound music expression
260 @cindex music expression, compound
262 We saw the general organization of LilyPond input files in the
263 previous section, @ref{Introduction to the LilyPond file structure}.
264 But we seemed to skip over the most important part: how do we figure
265 out what to write after @code{\score}?
267 We didn't skip over it at all. The big mystery is simply that
268 there @emph{is} no mystery. This line explains it all:
271 @emph{A @code{\score} block must begin with a compound music expression.}
275 To understand what is meant by a music expression and a compound
276 music expression, you may find it useful to review the tutorial,
277 @ref{Music expressions explained}. In that section, we saw how to
278 build big music expressions from small pieces -- we started from
279 notes, then chords, etc. Now we're going to start from a big
280 music expression and work our way down.
284 @{ % this brace begins the overall compound music expression
286 @var{...insert the whole score of a Wagner opera in here...}
288 @} % this brace ends the overall compound music expression
293 A whole Wagner opera would easily double the length of this
294 manual, so let's just add a singer and piano. We don't need a
295 @code{GrandStaff} for this ensemble, which simply groups a number
296 of staves together with a brace at the left, so we shall remove
297 it. We @emph{do} need a singer and a piano, though.
302 \new Staff = "singer" <<
304 \new PianoStaff = "piano" <<
311 Remember that we use @code{<< ... >>} instead of @code{@{ ... @}} to
312 show simultaneous music. And we definitely want to show the vocal
313 part and piano part at the same time, not one after the other! Note
314 that the @code{<< ... >>} construct is not really necessary for the
315 Singer staff, as it contains only one sequential music expression;
316 however, using @code{<< ... >>} instead of braces is still necessary
317 if the music in the Staff is made of two simultaneous expressions,
318 e.g. two simultaneous Voices, or a Voice with lyrics. We'll add some
319 real music later; for now let's just put in some dummy notes and
322 @lilypond[verbatim,quote,ragged-right]
325 \new Staff = "singer" <<
326 \new Voice = "vocal" { c'1 }
329 \new PianoStaff = "piano" <<
330 \new Staff = "upper" { c'1 }
331 \new Staff = "lower" { c'1 }
338 Now we have a lot more details. We have the singer's staff: it
339 contains a @code{Voice} (in LilyPond, this term refers to a set of
340 notes, not necessarily vocal notes -- for example, a violin
341 generally plays one voice) and some lyrics. We also have a piano
342 staff: it contains an upper staff (right hand) and a lower staff
345 At this stage, we could start filling in notes. Inside the curly
346 braces next to @code{\new Voice = "vocal"}, we could start writing
354 But if we did that, the @code{\score} section would get pretty
355 long, and it would be harder to understand what was happening. So
356 let's use variables instead. These were introduced at the end
357 of the previous section, remember? So, adding a few notes, we
358 now have a piece of real music:
360 @lilypond[verbatim,quote,ragged-right]
361 melody = \relative c'' { r4 d8\noBeam g, c4 r }
362 text = \lyricmode { And God said, }
363 upper = \relative c'' { <g d g,>2~ <g d g,> }
364 lower = \relative c { b2 e2 }
368 \new Staff = "singer" <<
369 \new Voice = "vocal" { \melody }
372 \new PianoStaff = "piano" <<
373 \new Staff = "upper" { \upper }
374 \new Staff = "lower" {
385 Be careful about the difference between notes, which are introduced
386 with @code{\relative} or which are directly included in a music
387 expression, and lyrics, which are introduced with
388 @code{\lyricmode}. These are essential to tell LilyPond
389 to interpret the following content as music and text
392 When writing (or reading) a @code{\score} section, just take it
393 slowly and carefully. Start with the outer level, then work on
394 each smaller level. It also really helps to be strict with
395 indentation -- make sure that each item on the same level starts
396 on the same horizontal position in your text editor.
400 Notation Reference: @ruser{Structure of a score}.
402 @node Nesting music expressions
403 @subsection Nesting music expressions
405 @cindex staves, temporary
406 @cindex temporary staves
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:
415 @lilypond[verbatim,quote,ragged-right]
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.
437 @cindex staff, positioning
439 The ossia section may be placed above the staff
442 @lilypond[verbatim,quote,ragged-right]
443 \new Staff = "main" {
450 alignAboveContext = "main" }
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.
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}.
473 @node On the un-nestedness of brackets and ties
474 @subsection On the un-nestedness of brackets and ties
476 @cindex brackets, nesting
477 @cindex bracket types
478 @cindex brackets, enclosing vs. marking
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.
485 @c attempt to force this onto a new page
487 @multitable @columnfractions .3 .7
488 @headitem Bracket Type
490 @item @code{@{ .. @}}
491 @tab Encloses a sequential segment of music
493 @tab Encloses the notes of a chord
494 @item @code{<< .. >>}
495 @tab Encloses simultaneous music expressions
497 @tab Marks the start and end of a slur
498 @item @code{\( .. \)}
499 @tab Marks the start and end of a phrasing slur
501 @tab Marks the start and end of a manual beam
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@{..@}}.
509 Outside LilyPond, the conventional use of brackets requires
510 the different types to be properly nested, like this,
511 @code{<< [ @{ ( .. ) @} ] >>}, with the closing brackets being
512 encountered in exactly the opposite order to the opening
513 brackets. This @strong{is} a requirement for the three types of
514 bracket described by the word @q{Encloses} in the table above --
515 they must nest properly. However, the remaining brackets,
516 described with the word @q{Marks} in the table above together
517 with ties and tuplets, do @strong{not} have to nest properly
518 with any of the brackets. In fact, these are not brackets in
519 the sense that they enclose something -- they are simply
520 markers to indicate where something starts and ends.
522 So, for example, a phrasing slur can start before a manually
523 inserted beam and end before the end of the beam -- not very
524 musical, perhaps, but possible:
526 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
527 { g8\( a b[ c b\) a] }
530 In general, different kinds of brackets, and those implied by
531 tuplets, ties and grace notes, may be mixed freely.
532 This example shows a beam extending into a tuplet (line 1),
533 a slur extending into a tuplet (line 2),
534 a beam and a slur extending into a tuplet, a tie crossing
535 two tuplets, and a phrasing slur extending out of a tuplet
538 @lilypond[quote,verbatim,fragment,ragged-right]
540 r16[ g16 \times 2/3 {r16 e'8] }
541 g16( a \times 2/3 {b d) e' }
542 g8[( a \times 2/3 {b d') e'~]}
543 \times 4/5 {e'32\( a b d' e'} a'4.\)
548 @node Voices contain music
549 @section Voices contain music
551 Singers need voices to sing, and so does LilyPond.
552 The actual music for all instruments in a score
553 is contained in Voices -- the most fundamental
554 of all LilyPond's concepts.
557 * I'm hearing Voices::
558 * Explicitly instantiating voices::
559 * Voices and vocals::
562 @node I'm hearing Voices
563 @subsection I'm hearing Voices
567 @cindex multiple voices
568 @cindex voices, multiple
569 @cindex Voice context
570 @cindex context, Voice
571 @cindex simultaneous music
572 @cindex music, simultaneous
573 @cindex concurrent music
574 @cindex music, concurrent
575 @cindex voices vs. chords
576 @cindex chords vs. voices
578 The lowest, most fundamental or innermost layers in a LilyPond
579 score are called @q{Voice contexts} or just @q{Voices} for short.
580 Voices are sometimes called @q{layers} in other notation
583 In fact, a Voice layer or context is the only one which can
584 contain music. If a Voice context is not explicitly declared
585 one is created automatically, as we saw at the beginning of
586 this chapter. Some instruments such as an
587 Oboe can play only one note at a time. Music written for
588 such instruments is monophonic and requires just a single
589 voice. Instruments which can play more than one note at a
590 time like the piano will often require multiple voices to
591 encode the different concurrent notes and rhythms they are
594 A single voice can contain many notes in a chord, of course,
595 so when exactly are multiple voices needed? Look first at
596 this example of four chords:
598 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
600 <d g>4 <d fis> <d a'> <d g>
603 This can be expressed using just the single angle bracket chord
604 symbols, @code{< ... >}, and for this just a single voice is
605 needed. But suppose the F-sharp were actually an eighth-note
606 followed by an eighth-note G, a passing note on the way to the A?
607 Now we have two notes which start at the same time but have
608 different durations: the quarter-note D and the eighth-note
609 F-sharp. How are these to be coded? They cannot be written as
610 a chord because all the notes in a chord must have the same
611 duration. And they cannot be written as two sequential notes
612 as they need to start at the same time. This is when two
615 Let us see how this is done in LilyPond input syntax.
620 The easiest way to enter fragments with more than one voice on a
621 staff is to enter each voice as a sequence (with @code{@{...@}}),
622 and combine them simultaneously with angle brackets, @code{<<...>>}.
623 The fragments must also be separated with double backward slashes,
624 @code{\\}, to place them in separate voices. Without these, the
625 notes would be entered into a single voice, which would usually
626 cause errors. This technique is particularly suited to pieces of
627 music which are largely monophonic with occasional short sections
630 Here's how we split the chords above into two voices and add both
631 the passing note and a slur:
633 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
635 % Voice "1" Voice "2"
636 << { g4 fis8( g) a4 g } \\ { d4 d d d } >> |
639 Notice how the stems of the second voice now point down.
641 Here's another simple example:
643 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
645 % Voice "1" Voice "2"
646 << { r4 g g4. a8 } \\ { d,2 d4 g } >> |
647 << { bes4 bes c bes } \\ { g4 g g8( a) g4 } >> |
648 << { a2. r4 } \\ { fis2. s4 } >> |
651 It is not necessary to use a separate @code{<< \\ >>} construct
652 for each bar. For music with few notes in each bar this layout
653 can help the legibility of the code, but if there are many
654 notes in each bar it may be better to split out each voice
655 separately, like this:
657 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
673 @cindex voices, naming
674 @cindex voices crossing brackets
675 @cindex slurs crossing brackets
676 @cindex ties crossing brackest
678 This example has just two voices, but the same construct may be
679 used to encode three or more voices by adding more back-slash
682 The Voice contexts bear the names @code{"1"}, @code{"2"}, etc.
683 In each of these contexts, the vertical direction of slurs,
684 stems, ties, dynamics etc., is set appropriately.
686 @lilypond[quote,verbatim,fragment]
687 \new Staff \relative c' {
690 % Voice "1" Voice "2" Voice "3"
691 << { g4 f e } \\ { r8 e4 d c8 ~ } >> |
692 << { d2 e2 } \\ { c8 b16 a b8 g ~ g2 } \\ { s4 b4 c2 } >> |
696 These voices are all separate from the main voice that contains
697 the notes just outside the @code{<< .. >>} construct. Let's call
698 this the @emph{simultaneous construct}. Slurs and ties may only
699 connect notes within the same voice, so slurs and ties cannot go
700 into or out of a simultaneous construct. Conversely,
701 parallel voices from separate simultaneous constructs on the same
702 staff are the same voice. Other voice-related properties also
703 carry across simultaneous constructs. Here is the same example,
704 with different colors and note heads for each voice. Note that
705 changes in one voice do not affect other voices, but they do
706 persist in the same voice later. Note also that tied notes may be
707 split across the same voices in two constructs, shown here in the
710 @lilypond[quote,verbatim]
711 \new Staff \relative c' {
730 { c8 b16 a b8 g ~ g2 }
740 @funindex \voiceOneStyle
741 @funindex \voiceTwoStyle
742 @funindex \voiceThreeStyle
743 @funindex \voiceFourStyle
744 @funindex \voiceNeutralStyle
746 The commands @code{\voiceXXXStyle} are mainly intended for use in
747 educational documents such as this one. They modify the color
748 of the note head, the stem and the beams, and the style of the
749 note head, so that the voices may be easily distinguished.
750 Voice one is set to red diamonds, voice two to blue triangles,
751 voice three to green crossed circles, and voice four (not used
752 here) to magenta crosses; @code{\voiceNeutralStyle} (also not
753 used here) reverts the style back to the default.
754 We shall see later how commands like these may be created by the
756 See @ref{Visibility and color of objects} and
757 @ref{Using variables for tweaks}.
759 @cindex polyphony and relative note entry
760 @cindex relative note entry and polyphony
762 Polyphony does not change the relationship of notes within a
763 @code{\relative @{ @}} block. Each note is still calculated
764 relative to the note immediately preceding it, or to the first
765 note of the preceding chord. So in
768 \relative c' @{ noteA << < noteB noteC > \\ noteD >> noteE @}
772 @code{noteB} is relative to @code{noteA} @*
773 @code{noteC} is relative to @code{noteB}, not @code{noteA}; @*
774 @code{noteD} is relative to @code{noteB}, not @code{noteA} or
776 @code{noteE} is relative to @code{noteD}, not @code{noteA}.
778 An alternative way, which may be clearer if the notes in the
779 voices are widely separated, is to place a @code{\relative}
780 command at the start of each voice:
783 \relative c' @{ noteA ... @}
785 \relative c'' @{ < noteB noteC > ... @}
787 \relative g' @{ noteD ... @}
789 \relative c' @{ noteE ... @}
792 Let us finally analyze the voices in a more complex piece of music.
793 Here are the notes from the first two bars of the second of Chopin's
794 Deux Nocturnes, Op 32. This example will be used at later stages in
795 this and the next chapter to illustrate several techniques for
796 producing notation, so please ignore for now anything in the
797 underlying code which looks mysterious and concentrate just on the
798 music and the voices -- the complications will all be explained in
801 @c The following should appear as music without code
802 @lilypond[quote,ragged-right]
803 \new Staff \relative c'' {
812 % Ignore these for now - they are explained in Ch 4
813 \once \override NoteColumn #'force-hshift = #0
815 \once \override NoteColumn #'force-hshift = #0.5
823 The direction of the stems is often used to indicate the continuity of
824 two simultaneous melodic lines. Here the stems of the highest notes
825 are all pointing up and the stems of the lower notes are all pointing
826 down. This is the first indication that more than one voice is
829 But the real need for multiple voices arises when notes
830 which start at the same time have different durations.
831 Look at the notes which start at beat three in the first
832 bar. The A-flat is a dotted quarter note, the F is a
833 quarter note and the D-flat is a half note. These
834 cannot be written as a chord as all the notes in a chord
835 must have the same duration. Neither can they be written
836 as sequential notes, as they must start at the same time.
837 This section of the bar requires three voices, and the
838 normal practice would be to write the whole bar as three
839 voices, as shown below, where we have used different note heads
840 and colors for the three voices. Again, the code behind this
841 example will be explained later, so ignore anything you do
844 @c The following should appear as music without code
845 @c The three voice styles should be defined in -init
846 @lilypond[quote,ragged-right]
847 \new Staff \relative c'' {
858 \\ % No Voice three (we want stems down)
861 % Ignore these for now - they are explained in Ch 4
862 \once \override NoteColumn #'force-hshift = #0
864 \once \override NoteColumn #'force-hshift = #0.5
873 Let us try to encode this music from scratch. As we
874 shall see, this encounters some difficulties. We begin as
875 we have learnt, using the @code{<< \\ >>} construct to
876 enter the music of the first bar in three voices:
878 @lilypond[quote,verbatim,fragment,ragged-right]
879 \new Staff \relative c'' {
882 { c2 aes4. bes8 } \\ { aes2 f4 fes } \\ { <ees c>2 des2 }
889 @cindex voices and stem directions
890 @cindex stem directions and voices
893 The stem directions are automatically assigned with the
894 odd-numbered voices taking upward stems and the even-numbered
895 voices downward ones. The stems for voices 1 and 2 are right,
896 but the stems in voice 3 should go down in this particular piece
897 of music. We can correct this simply by missing out voice three
898 and placing the music in voice four:
900 @lilypond[quote,verbatim,fragment,ragged-right]
901 \new Staff \relative c'' {
907 \\ % Omit Voice three
916 We see that this fixes the stem direction, but exposes a problem
917 sometimes encountered with multiple voices -- the stems of the notes
918 in one voice can collide with the note heads in other voices. In
919 laying out the notes, LilyPond allows the notes or chords from two
920 voices to occupy the same vertical note column provided the stems are
921 in opposite directions, but the notes from the third and fourth voices
922 are displaced, if necessary, to avoid the note heads colliding. This
923 usually works well, but in this example the notes of the lowest voice
924 are clearly not well placed by default. LilyPond provides several ways
925 to adjust the horizontal placing of notes. We are not quite ready yet
926 to see how to correct this, so we shall leave this problem until a
927 later section --- see the @code{force-hshift} property in @ref{Fixing
928 overlapping notation}.
932 Notation Reference: @ruser{Multiple voices}.
935 @node Explicitly instantiating voices
936 @subsection Explicitly instantiating voices
942 @funindex \voiceThree
949 @cindex voice contexts, creating
951 Voice contexts can also be created manually
952 inside a @code{<< >>} block to create polyphonic music, using
953 @code{\voiceOne} ... @code{\voiceFour} to indicate the required
954 directions of stems, slurs, etc. In longer scores this method
955 is clearer, as it permits the voices to be separated and to be
956 given more descriptive names.
958 Specifically, the construct @code{<< \\ >>} which we used in
959 the previous section:
964 << @{ e4 f g a @} \\ @{ c,4 d e f @} >>
974 \new Voice = "1" @{ \voiceOne \relative c' @{ e4 f g a @} @}
975 \new Voice = "2" @{ \voiceTwo \relative c' @{ c4 d e f @} @}
979 Both of the above would produce
981 @c The following example should not display the code
982 @lilypond[ragged-right,quote]
984 \new Voice = "1" { \voiceOne \relative c' { e4 f g a } }
985 \new Voice = "2" { \voiceTwo \relative c' { c4 d e f } }
989 @cindex voices, reverting to single
990 @cindex reverting to a single voice
992 The @code{\voiceXXX} commands set the direction of stems, slurs,
993 ties, articulations, text annotations, augmentation dots of dotted
994 notes, and fingerings. @code{\voiceOne} and @code{\voiceThree}
995 make these objects point upwards, while @code{\voiceTwo} and
996 @code{\voiceFour} make them point downwards. These commands also
997 generate a horizontal shift for each voice when this is required
998 to avoid clashes of note heads. The command @code{\oneVoice}
999 reverts the settings back to the normal values for a single voice.
1001 Let us see in some simple examples exactly what effect
1002 @code{\oneVoice}, @code{\voiceOne} and @code{voiceTwo} have on
1003 markup, ties, slurs, and dynamics:
1005 @lilypond[quote,ragged-right,verbatim]
1007 % Default behavior or behavior after \oneVoice
1008 c d8 ~ d e4 ( f g a ) b-> c
1012 @lilypond[quote,ragged-right,verbatim]
1015 c d8 ~ d e4 ( f g a ) b-> c
1017 c, d8 ~ d e4 ( f g a ) b-> c
1021 @lilypond[quote,ragged-right,verbatim]
1024 c d8 ~ d e4 ( f g a ) b-> c
1026 c, d8 ~ d e4 ( f g a ) b-> c
1030 Now let's look at three different ways to notate the same passage
1031 of polyphonic music, each of which is advantageous in different
1032 circumstances, using the example from the previous section.
1034 An expression that appears directly inside a @code{<< >>} belongs
1035 to the main voice (but, note, @strong{not} in a @code{<< \\ >>}
1036 construct). This is useful when extra voices appear while the
1037 main voice is playing. Here is a more correct rendition of our
1038 example. The red diamond-shaped notes
1039 demonstrate that the main melody is now in a single voice context,
1040 permitting a phrasing slur to be drawn over them.
1042 @lilypond[quote,ragged-right,verbatim]
1043 \new Staff \relative c' {
1045 % The following notes are monophonic
1047 % Start simultaneous section of three voices
1049 % Continue the main voice in parallel
1051 % Initiate second voice
1053 % Set stems, etc, down
1055 r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2
1057 % Initiate third voice
1059 % Set stems, etc, up
1067 @cindex nesting music expressions
1068 @cindex nesting simultaneous constructs
1069 @cindex nesting voices
1070 @cindex voices, temporary
1071 @cindex voices, nesting
1073 More deeply nested polyphony constructs are possible, and if a
1074 voice appears only briefly this might be a more natural way to
1077 @lilypond[quote,ragged-right,verbatim]
1078 \new Staff \relative c' {
1086 {c8 b16 a b8 g ~ g2}
1097 @cindex spacing notes
1099 This method of nesting new voices briefly is useful
1100 when only small sections of the music
1101 are polyphonic, but when the whole staff is largely polyphonic
1102 it can be clearer to use multiple voices throughout, using
1103 spacing notes to step over sections where the voice is silent,
1106 @lilypond[quote,ragged-right,verbatim]
1107 \new Staff \relative c' <<
1108 % Initiate first voice
1111 c16^( d e f g4 f e | d2 e2) |
1113 % Initiate second voice
1115 % Set stems, etc, down
1117 s4 r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2 |
1119 % Initiate third voice
1121 % Set stems, etc, up
1128 @subsubheading Note columns
1131 @cindex note collisions
1132 @cindex collisions, notes
1133 @cindex shift commands
1140 @funindex \shiftOnnn
1143 Closely spaced notes in a chord, or notes occurring at the same
1144 time in different voices, are arranged in two, occasionally more,
1145 columns to prevent the note heads overlapping. These are called
1146 note columns. There are separate columns for each voice, and
1147 the currently specified voice-dependent shift is applied to the
1148 note column if there would otherwise be a collision. This can
1149 be seen in the example above. In bar 2 the C in voice two is
1150 shifted to the right relative to the D in voice one, and in the
1151 final chord the C in voice three is also shifted to the right
1152 relative to the other notes.
1154 The @code{\shiftOn}, @code{\shiftOnn}, @code{\shiftOnnn}, and
1155 @code{\shiftOff} commands specify the degree to which notes and
1156 chords of the voice should be shifted if a collision
1157 would otherwise occur. By default, the outer voices (normally
1158 voices one and two) have @code{\shiftOff} specified, while the
1159 inner voices (three and four) have @code{\shiftOn} specified.
1160 When a shift is applied, voices one and three are shifted to
1161 the right and voices two and four to the left.
1163 @code{\shiftOnn} and @code{\shiftOnnn} define further shift
1164 levels which may be specified temporarily to resolve collisions
1165 in complex situations -- see @ref{Real music example}.
1167 A note column can contain just one note (or chord) from a voice
1168 with stems up and one note (or chord) from a voice with stems
1169 down. If notes from two voices which have their stems in the
1170 same direction are placed at the same position and both voices
1171 have no shift or the same shift specified, the error message
1172 @qq{Too many clashing note columns} will be produced.
1176 Notation Reference: @ruser{Multiple voices}.
1179 @node Voices and vocals
1180 @subsection Voices and vocals
1182 Vocal music presents a special difficulty: we need to combine two
1183 expressions -- notes and lyrics.
1185 @funindex \new Lyrics
1189 @cindex Lyrics context, creating
1190 @cindex lyrics, linking to voice
1192 You have already seen the @code{\addlyrics@{@}} command, which
1193 handles simple scores well. However, this technique is
1194 quite limited. For more complex music, you must introduce the
1195 lyrics in a @code{Lyrics} context using @code{\new Lyrics} and
1197 the lyrics to the notes with @code{\lyricsto@{@}}, using the
1198 name assigned to the Voice.
1200 @lilypond[quote,verbatim,fragment]
1202 \new Voice = "one" \relative c'' {
1205 c4 b8. a16 g4. f8 e4 d c2
1207 \new Lyrics \lyricsto "one" {
1208 No more let sins and sor -- rows grow.
1213 Note that the lyrics must be linked to a @code{Voice} context,
1214 @emph{not} a @code{Staff} context. This is a case where it is
1215 necessary to create @code{Staff} and @code{Voice} contexts
1218 @cindex lyrics and beaming
1219 @cindex beaming and lyrics
1220 @funindex \autoBeamOff
1221 @funindex autoBeamOff
1223 The automatic beaming which LilyPond uses by default works well
1224 for instrumental music, but not so well for music with lyrics,
1225 where beaming is either not required at all or is used to indicate
1226 melismata in the lyrics. In the example above we use the command
1227 @code{\autoBeamOff} to turn off the automatic beaming.
1229 @funindex \new ChoirStaff
1230 @funindex ChoirStaff
1231 @funindex \lyricmode
1233 @cindex vocal score structure
1236 Let us reuse the earlier example from Judas Maccabæus to
1237 illustrate this more flexible technique. We first recast
1238 it to use variables so the music and lyrics can be separated
1239 from the staff structure. We also introduce a ChoirStaff
1240 bracket. The lyrics themselves must be introduced with
1241 @code{\lyricmode} to ensure they are interpreted as lyrics
1244 @lilypond[quote,verbatim]
1245 global = { \time 6/8 \partial 8 \key f \major}
1246 SopOneMusic = \relative c'' {
1247 c8 | c([ bes)] a a([ g)] f | f'4. b, | c4.~ c4 }
1248 SopTwoMusic = \relative c' {
1249 r8 | r4. r4 c8 | a'([ g)] f f([ e)] d | e([ d)] c bes' }
1250 SopOneLyrics = \lyricmode {
1251 Let | flee -- cy flocks the | hills a -- dorn, __ }
1252 SopTwoLyrics = \lyricmode {
1253 Let | flee -- cy flocks the | hills a -- dorn, }
1258 \new Voice = "SopOne" {
1262 \new Lyrics \lyricsto "SopOne" {
1267 \new Voice = "SopTwo" {
1271 \new Lyrics \lyricsto "SopTwo" {
1279 This is the basic structure of all vocal scores. More staves may be
1280 added as required, more voices may be added to the staves, more verses
1281 may be added to the lyrics, and the variables containing the music can
1282 easily be placed in separate files should they become too long.
1284 @cindex hymn structure
1285 @cindex SATB structure
1286 @cindex vocal scores with multiple verses
1287 @cindex multiple vocal verses
1288 @cindex verses, multiple vocal
1290 Here is an example of the first line of a hymn with four
1291 verses, set for SATB. In this case the words for all four
1292 parts are the same. Note how we use variables to separate the
1293 music notation and words from the staff structure. See too
1294 how a variable, which we have chosen to call @q{TimeKey}, is used
1295 to hold several commands for use within the two staves. In other
1296 examples this is often called @q{global}.
1298 @lilypond[quote,verbatim]
1299 TimeKey = { \time 4/4 \partial 4 \key c \major}
1300 SopMusic = \relative c' { c4 | e4. e8 g4 g | a a g }
1301 AltoMusic = \relative c' { c4 | c4. c8 e4 e | f f e }
1302 TenorMusic = \relative c { e4 | g4. g8 c4. b8 | a8 b c d e4 }
1303 BassMusic = \relative c { c4 | c4. c8 c4 c | f8 g a b c4 }
1304 VerseOne = \lyricmode {
1305 E -- | ter -- nal fa -- ther, | strong to save, }
1306 VerseTwo = \lyricmode {
1307 O | Christ, whose voice the | wa -- ters heard, }
1308 VerseThree = \lyricmode {
1309 O | Ho -- ly Spi -- rit, | who didst brood }
1310 VerseFour = \lyricmode {
1311 O | Tri -- ni -- ty of | love and pow'r }
1317 \new Voice = "Sop" { \voiceOne \TimeKey \SopMusic }
1318 \new Voice = "Alto" { \voiceTwo \AltoMusic }
1319 \new Lyrics \lyricsto "Sop" { \VerseOne }
1320 \new Lyrics \lyricsto "Sop" { \VerseTwo }
1321 \new Lyrics \lyricsto "Sop" { \VerseThree }
1322 \new Lyrics \lyricsto "Sop" { \VerseFour }
1326 \new Voice = "Tenor" { \voiceOne \TimeKey \TenorMusic }
1327 \new Voice = "Bass" { \voiceTwo \BassMusic }
1333 @cindex verse and refrain
1335 We end with an example to show how we might code a solo verse which
1336 continues into a two-part refrain in two staves. The
1337 positioning of the sequential and simultaneous sections to achieve
1338 this within a single score is quite tricky, so follow the
1339 explanation carefully!
1341 Let's start with a score block containing a @code{ChoirStaff}, as
1342 we would like the brace to appear at the start of the chorus.
1343 Normally you would need angle brackets after @code{\new ChoirStaff}
1344 to bring in all the staves in parallel, but here we want to
1345 defer the parallelism during the solo so we use braces, although
1346 angle brackets here wouldn't hurt. Inside the @code{ChoirStaff} we
1347 want first the staff which will contain the verse. This must
1348 contain notes and lyrics in parallel, so here we need angle
1349 brackets around the @code{\new Voice} and @code{\new Lyrics} to
1350 start them at the same time:
1352 @lilypond[quote,verbatim,ragged-right]
1353 versenotes = \relative c'' {
1356 \time 3/4 g g g b b b
1358 versewords = \lyricmode {
1359 One two three four five six
1364 \new Voice = "verse" {
1367 \new Lyrics \lyricsto verse {
1375 That gives the verse line.
1377 Now we want to continue with refrainA on the same staff while a
1378 second staff is introduced in parallel with it for refrainB, so
1379 this is a parallel section which must be positioned immediately
1380 following the @code{\break} in the verse Voice. Yes, @emph{within}
1381 the verse Voice! Here's that parallel section. More staves
1382 could be introduced here in the same way.
1387 \new Lyrics \lyricsto verse @{
1391 \new Voice = "refrainB" @{
1394 \new Lyrics \lyricsto "refrainB" @{
1401 Here's the final result with two staves in the chorus showing
1402 how the parallel section is positioned within the verse Voice:
1404 @lilypond[quote,verbatim, ragged-right]
1405 versenotes = \relative c'' {
1408 \time 3/4 g g g b b b
1410 refrainnotesA = \relative c'' {
1414 refrainnotesB = \relative c {
1419 versewords = \lyricmode {
1420 One two three four five six
1422 refrainwordsA = \lyricmode {
1425 refrainwordsB = \lyricmode {
1431 \new Voice = "verse" {
1435 \new Lyrics \lyricsto "verse" {
1439 \new Voice = "refrainB" {
1442 \new Lyrics \lyricsto "refrainB" {
1448 \new Lyrics \lyricsto "verse" {
1456 @cindex book, example of using
1460 However, although this is an interesting and useful exercise to
1461 help you to understand how sequential and simultaneous blocks work,
1462 in practice one would perhaps choose to code this as two
1463 @code{\score} blocks within an implicit @code{\book} block, as
1466 @lilypond[quote,verbatim,ragged-right]
1467 versenotes = \relative c'' {
1470 \time 3/4 g g g b b b
1472 refrainnotesA = \relative c'' {
1476 refrainnotesB = \relative c {
1481 versewords = \lyricmode {
1482 One two three four five six
1484 refrainwordsA = \lyricmode {
1487 refrainwordsB = \lyricmode {
1492 \new Voice = "verse" {
1495 \new Lyrics \lyricsto "verse" {
1504 \new Voice = "refrainA" {
1507 \new Lyrics \lyricsto "refrainA" {
1512 \new Voice = "refrainB" {
1515 \new Lyrics \lyricsto "refrainB" {
1525 Notation Reference: @ruser{Vocal music}.
1528 @node Contexts and engravers
1529 @section Contexts and engravers
1531 Contexts and engravers have been mentioned informally
1532 in earlier sections; we now must look at
1533 these concepts in more detail, as they are important
1534 in the fine-tuning of LilyPond output.
1538 * Contexts explained::
1539 * Creating contexts::
1540 * Engravers explained::
1541 * Modifying context properties::
1542 * Adding and removing engravers::
1545 @node Contexts explained
1546 @subsection Contexts explained
1548 @cindex contexts explained
1550 When music is printed, many notational elements which do not
1551 appear explicitly in the input file must be added to the
1552 output. For example, compare the input and output of the
1555 @lilypond[quote,verbatim,relative=2,fragment]
1559 The input is rather sparse, but in the output, bar lines,
1560 accidentals, clef, and time signature have been added. When
1561 LilyPond @emph{interprets} the input the musical information
1562 is inspected in time order, similar to reading a score from left
1563 to right. While reading the input, the program remembers where
1564 measure boundaries are, and which pitches require explicit
1565 accidentals. This information must be held on several levels.
1566 For example, the effect of an accidental is limited
1567 to a single staff, while a bar line must be synchronized across
1570 Within LilyPond, these rules and bits of information are grouped
1571 in @emph{Contexts}. We have already met the
1572 @code{Voice} context.
1573 Others are the @code{Staff} and @code{Score} contexts.
1574 Contexts are hierarchical to reflect the hierarchical nature of
1576 For example: a @code{Staff} context can contain many
1577 @code{Voice} contexts, and a @code{Score} context can
1578 contain many @code{Staff} contexts.
1581 @sourceimage{context-example,5cm,,}
1584 Each context has the responsibility for enforcing some notation rules,
1585 creating some notation objects and maintaining the associated
1586 properties. For example, the @code{Voice} context may introduce an
1587 accidental and then the @code{Staff} context maintains the rule to
1588 show or suppress the accidental for the remainder of the measure.
1590 As another example, the synchronization of bar lines is, by default,
1591 handled in the @code{Score} context.
1592 However, in some music we may not want the bar lines to be
1593 synchronized -- consider a polymetric score in 4/4 and 3/4 time.
1594 In such cases, we must modify the default settings of the
1595 @code{Score} and @code{Staff} contexts.
1597 For very simple scores, contexts are created implicitly, and you need
1598 not be aware of them. For larger pieces, such as anything with more
1599 than one staff, they must be
1600 created explicitly to make sure that you get as many staves as you
1601 need, and that they are in the correct order. For typesetting pieces
1602 with specialized notation, it is usual to modify existing, or
1603 even to define totally new, contexts.
1605 In addition to the @code{Score,} @code{Staff} and
1606 @code{Voice} contexts there are contexts which fit between
1607 the score and staff levels to control staff groups, such as the
1608 @code{PianoStaff} and @code{ChoirStaff} contexts. There
1609 are also alternative staff and voice contexts, and contexts for
1610 lyrics, percussion, fret boards, figured bass, etc.
1612 The names of all context types are formed from one or more
1613 words, each word being capitalized and joined immediately to the
1614 preceding word with no hyphen or underscore, e.g.,
1615 @code{GregorianTranscriptionStaff}.
1619 Notation Reference: @ruser{Contexts explained}.
1622 @node Creating contexts
1623 @subsection Creating contexts
1626 @cindex new contexts
1627 @cindex creating contexts
1628 @cindex contexts, creating
1630 There can be only one top level context: the
1632 context. This is created with the @code{\score} command,
1633 or, in simple scores, it is created automatically.
1635 For scores with only one voice and one staff, the
1636 @code{Voice} and @code{Staff} contexts may be left to be
1637 created automatically, but for more complex scores it is
1638 necessary to create them by hand.
1639 The simplest command that does this is @code{\new}.
1640 It is prepended to a music expression, for example
1643 \new @var{type} @var{music-expression}
1647 where @var{type} is a context name (like @code{Staff} or
1648 @code{Voice}). This command creates a new context, and starts
1649 interpreting the @var{music-expression} within that context.
1651 Note that there is no @code{\new Score} command;
1652 the single top-level @code{Score} context is introduced
1655 You have seen many practical examples which created new
1656 @code{Staff} and @code{Voice} contexts in earlier sections, but
1657 to remind you how these commands are used in practice, here's an
1658 annotated real-music example:
1660 @lilypond[quote,verbatim,ragged-right]
1661 \score { % start of single compound music expression
1662 << % start of simultaneous staves section
1664 \new Staff { % create RH staff
1667 \new Voice { % create voice for RH notes
1668 \relative c'' { % start of RH notes
1674 \new Staff << % create LH staff; needs two simultaneous voices
1677 \new Voice { % create LH voice one
1679 \relative g { % start of LH voice one notes
1680 g8 <bes d> ees, <g c> |
1681 g8 <bes d> ees, <g c> |
1682 } % end of LH voice one notes
1683 } % end of LH voice one
1684 \new Voice { % create LH voice two
1686 \relative g { % start of LH voice two notes
1689 } % end of LH voice two notes
1690 } % end of LH voice two
1691 >> % end of LH staff
1692 >> % end of simultaneous staves section
1693 } % end of single compound music expression
1696 (Note how all the statements which open a block with either a
1697 curly bracket, @code{@{}, or double angle brackets, @code{<<},
1698 are indented by two further spaces, and the corresponding
1699 closing bracket is indented by exactly the same amount. While
1700 this is not required, following this practice will greatly
1701 reduce the number of @q{unmatched bracket} errors, and is
1702 strongly recommended. It enables the structure of the music to
1703 be seen at a glance, and any unmatched brackets will be obvious.
1704 Note too how the LH staff is created using double angle brackets
1705 because it requires two voices for its music, whereas the RH staff
1706 is created with a single music expression surrounded by curly
1707 brackets because it requires only one voice.)
1709 @cindex contexts, naming
1710 @cindex naming contexts
1712 The @code{\new} command may also give a identifying name to the
1713 context to distinguish it from other contexts of the same type,
1716 \new @var{type} = @var{id} @var{music-expression}
1719 Note the distinction between the name of the context type,
1720 @code{Staff}, @code{Voice}, etc, and the identifying name of a
1721 particular instance of that type, which can be any sequence of letters
1722 invented by the user. Digits and spaces can also be used in the
1723 identifying name, but then it has to be placed in quotes,
1724 i.e. @code{\new Staff = "MyStaff 1" @var{music-expression}}.
1725 The identifying name is used to
1726 refer back to that particular instance of a context. We saw this in
1727 use in the section on lyrics, see @ref{Voices and vocals}.
1731 Notation Reference: @ruser{Creating contexts}.
1734 @node Engravers explained
1735 @subsection Engravers explained
1739 Every mark on the printed output of a score produced by LilyPond
1740 is produced by an @code{Engraver}. Thus there is an engraver
1741 to print staves, one to print note heads, one for stems, one for
1742 beams, etc, etc. In total there are over 120 such engravers!
1743 Fortunately, for most scores it is not necessary to know about
1744 more than a few, and for simple scores you do not need to know
1747 Engravers live and operate in Contexts.
1748 Engravers such as the @code{Metronome_mark_engraver}, whose
1749 action and output apply to the score as a whole, operate in
1750 the highest level context -- the @code{Score} context.
1752 The @code{Clef_engraver} and @code{Key_engraver} are to be
1753 found in every @code{Staff} Context, as different staves may require
1754 different clefs and keys.
1756 The @code{Note_heads_engraver} and @code{Stem_engraver} live
1757 in every @code{Voice} context, the lowest level context of all.
1759 Each engraver processes the particular objects associated
1760 with its function, and maintains the properties that relate
1761 to that function. These properties, like the properties
1762 associated with contexts, may be modified to change the
1763 operation of the engraver or the appearance of those elements
1764 in the printed score.
1766 Engravers all have compound names formed from words which
1767 describe their function. Just the first word is capitalized,
1768 and the remainder are joined to it with underscores. Thus
1769 the @code{Staff_symbol_engraver} is responsible for creating the
1770 lines of the staff, the @code{Clef_engraver} determines and sets
1771 the pitch reference point on the staff by drawing a clef symbol.
1773 Here are some of the most common engravers together with their
1774 function. You will see it is usually easy to guess the function
1775 from the name, or vice versa.
1777 @multitable @columnfractions .3 .7
1780 @item Accidental_engraver
1781 @tab Makes accidentals, cautionary and suggested accidentals
1786 @item Completion_heads_engraver
1787 @tab Splits notes which cross bar lines
1788 @c The old Dynamic_engraver is deprecated. -jm
1789 @item New_dynamic_engraver
1790 @tab Creates hairpins and dynamic texts
1791 @item Forbid_line_break_engraver
1792 @tab Prevents line breaks if a musical element is still active
1794 @tab Creates the key signature
1795 @item Metronome_mark_engraver
1796 @tab Engraves metronome marking
1797 @item Note_heads_engraver
1798 @tab Engraves note heads
1801 @item Staff_symbol_engraver
1802 @tab Engraves the five (by default) lines of the staff
1804 @tab Creates stems and single-stem tremolos
1805 @item Time_signature_engraver
1806 @tab Creates time signatures
1811 We shall see later how the output of LilyPond can be changed
1812 by modifying the action of Engravers.
1816 Internals reference: @rinternals{Engravers and Performers}.
1819 @node Modifying context properties
1820 @subsection Modifying context properties
1822 @cindex context properties
1823 @cindex context properties, modifying
1824 @cindex modifying context properties
1828 Contexts are responsible for holding the values of a number of
1829 context @emph{properties}. Many of them can be changed to
1830 influence the interpretation of the input and so change the
1831 appearance of the output. They are changed by the
1832 @code{\set} command. This takes the form
1835 \set @emph{ContextName}.@emph{propertyName} = #@emph{value}
1838 Where the @emph{ContextName} is usually @code{Score},
1839 @code{Staff} or @code{Voice}. It may be omitted,
1840 in which case @code{Voice} is assumed.
1842 The names of context properties consist of words joined
1843 together with no hyphens or underscores, all except the
1844 first having a capital letter. Here are a few examples
1845 of some commonly used ones. There are many more.
1847 @c attempt to force this onto a new page
1849 @multitable @columnfractions .25 .15 .45 .15
1850 @headitem propertyName
1856 @tab If true, set extra natural signs before accidentals
1857 @tab @code{#t}, @code{#f}
1858 @item currentBarNumber
1860 @tab Set the current bar number
1864 @tab If true, print slurs both above and below notes
1865 @tab @code{#t}, @code{#f}
1866 @item instrumentName
1868 @tab Set the name to be placed at the start of the staff
1869 @tab @code{"Cello I"}
1872 @tab Increase or decrease the font size
1876 @tab Set the text to print before the start of a verse
1881 where a Boolean is either True (@code{#t}) or False (@code{#f}),
1882 an Integer is a positive whole number, a Real is a positive
1883 or negative decimal number, and text is enclosed in double
1884 apostrophes. Note the occurrence of hash signs,
1885 (@code{#}), in two different places -- as part of the Boolean
1886 value before the @code{t} or @code{f}, and before @emph{value}
1887 in the @code{\set} statement. So when a Boolean is being
1888 entered you need to code two hash signs, e.g., @code{##t}.
1890 Before we can set any of these properties we need to know
1891 in which context they operate. Sometimes this is obvious,
1892 but occasionally it can be tricky. If the wrong context
1893 is specified, no error message is produced, but the expected
1894 action will not take place. For example, the
1895 @code{instrumentName} clearly lives in the @code{Staff} context, since
1896 it is the staff that is to be named.
1897 In this example the first staff is labelled, but not the second,
1898 because we omitted the context name.
1900 @lilypond[quote,verbatim,ragged-right]
1902 \new Staff \relative c'' {
1903 \set Staff.instrumentName = #"Soprano"
1906 \new Staff \relative c' {
1907 \set instrumentName = #"Alto" % Wrong!
1913 Remember the default context name is @code{Voice}, so the second
1914 @code{\set} command set the property @code{instrumentName} in the
1915 @code{Voice} context to @qq{Alto}, but as LilyPond does not look
1916 for any such property in the @code{Voice} context, no
1917 further action took place. This is not an error, and no error
1918 message is logged in the log file.
1920 Similarly, if the property name is mis-spelt no error message is
1921 produced, and clearly the expected action cannot be performed. In
1922 fact, you can set any (fictitious) @q{property} using any name you
1923 like in any context that exists by using the @code{\set} command. But
1924 if the name is not known to LilyPond it will not cause any action to
1925 be taken. Some text editors with special support for LilyPond input
1926 files document property names with bullets when you hover them with
1927 the mouse, like JEdit with LilyPondTool, or highlight unknown property
1928 names differently, like ConTEXT. If you do not use an editor with
1929 such features, it is recommended to check the property name in the
1930 Internals Reference: see @rinternals{Tunable context properties}, or
1931 @rinternals{Contexts}.
1933 The @code{instrumentName} property will take effect only
1934 if it is set in the @code{Staff} context, but
1935 some properties can be set in more than one context.
1936 For example, the property @code{extraNatural} is by
1937 default set to ##t (true) for all staves.
1938 If it is set to ##f (false) in one particular @code{Staff}
1939 context it applies just to the accidentals on that staff.
1940 If it is set to false in the @code{Score} context
1941 it applies to all staves.
1943 So this turns off extra naturals in one staff:
1945 @lilypond[quote,verbatim,ragged-right]
1947 \new Staff \relative c'' {
1950 \new Staff \relative c'' {
1951 \set Staff.extraNatural = ##f
1958 and this turns them off in all staves:
1960 @lilypond[quote,verbatim,ragged-right]
1962 \new Staff \relative c'' {
1965 \new Staff \relative c'' {
1966 \set Score.extraNatural = ##f
1972 As another example, if @code{clefOctavation} is set in
1973 the @code{Score} context this immediately changes the value
1974 of the octavation in all current staves and sets a new default
1975 value which will be applied to all staves.
1977 The opposite command, @code{\unset}, effectively removes the
1978 property from the context, which causes most properties to
1979 revert to their default value. Usually @code{\unset} is not
1980 required as a new @code{\set} command will achieve what is
1983 The @code{\set} and @code{\unset} commands can appear anywhere
1984 in the input file and will take effect from the time they are
1985 encountered until the end of the score or until the property is
1986 @code{\set} or @code{\unset} again. Let's try changing the
1987 font size, which affects the size of the note heads (among
1988 other things) several times. The change is from the default
1989 value, not the most recently set value.
1991 @lilypond[quote,verbatim,ragged-right,relative=1,fragment]
1993 % make note heads smaller
1996 % make note heads larger
1997 \set fontSize = #2.5
1999 % return to default size
2004 We have now seen how to set the values of several different types of
2005 property. Note that integers and numbers are always preceded by a
2006 hash sign, @code{#}, while a true or false value is specified by
2007 @code{##t} and @code{##f}, with two hash signs. A text property
2008 should be enclosed in double quotation signs, as above, although we
2009 shall see later that text can actually be specified in a much more
2010 general way by using the very powerful @code{markup} command.
2012 @unnumberedsubsubsec Setting context properties with @code{\with}
2015 @cindex context properties, setting with \with
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:
2027 \new Staff \with @{ extraNatural = ##f @}
2033 @lilypond[quote,verbatim,ragged-right]
2039 \new Staff \with { extraNatural = ##f }
2046 Properties set in this way may still be changed dynamically using
2047 @code{\set} and returned to their default value with @code{\unset}.
2049 The @code{fontSize} property is treated differently. If this is
2050 set in a @code{\with} clause it effectively resets the default
2051 value of the font size. If it is later changed with @code{\set},
2052 this new default value may be restored with the
2053 @code{\unset fontSize} command.
2055 @unnumberedsubsubsec Setting context properties with @code{\context}
2057 The values of context properties may be set in @emph{all} contexts
2058 of a particular type, such as all @code{Staff} contexts, with a single
2059 command. The context type is identified by using its
2060 type name, like @code{Staff}, prefixed by a back-slash: @code{\Staff}.
2061 The statement which sets the property value is the same as that in a
2062 @code{\with} block, introduced above. It is placed in a
2063 @code{\context} block within a @code{\layout} block. Each
2064 @code{\context} block will affect all contexts of the type specified
2065 throughout the @code{\score} or @code{\book} block in which the
2066 @code{\layout} block appears. Here is a example to show the format:
2068 @lilypond[verbatim,quote]
2085 Context properties set in this way may be overridden for particular
2086 instances of contexts by statements in a @code{\with} block, and by
2087 @code{\set} commands embedded in music statements.
2092 @ruser{Changing context default settings}.
2094 @c uncomment when backslash-node-name issue is resolved -pm
2095 @c @ruser{The set command}.
2097 Internals Reference:
2098 @rinternals{Contexts},
2099 @rinternals{Tunable context properties}.
2102 @node Adding and removing engravers
2103 @subsection Adding and removing engravers
2105 @cindex engravers, adding
2106 @cindex engravers, removing
2111 We have seen that contexts each contain several engravers, each
2112 of which is responsible for producing a particular part of the
2113 output, like bar lines, staves, note heads, stems, etc. If an
2114 engraver is removed from a context, it can no longer produce its
2115 output. This is a crude way of modifying the output, but it
2116 can sometimes be useful.
2118 @subsubheading Changing a single context
2120 To remove an engraver from a single context we use the
2121 @code{\with} command placed immediately after the context creation
2122 command, as in the previous section.
2124 As an illustration, let's repeat an example from the previous section
2125 with the staff lines removed. Remember that the staff lines are
2126 produced by the @code{Staff_symbol_engraver}.
2128 @lilypond[quote,verbatim,ragged-right]
2130 \remove Staff_symbol_engraver
2134 \set fontSize = #-4 % make note heads smaller
2136 \set fontSize = #2.5 % make note heads larger
2138 \unset fontSize % return to default size
2143 @cindex ambitus engraver
2145 Engravers can also be added to individual contexts.
2146 The command to do this is
2148 @code{\consists @var{Engraver_name}},
2151 placed inside a @code{\with} block. Some vocal scores have an ambitus
2152 placed at the beginning of a staff to indicate the range of notes in
2153 that staff -- see @rglos{ambitus}. The ambitus is produced by the
2154 @code{Ambitus_engraver}, which is not normally included in any
2155 context. If we add it to the @code{Voice} context, it calculates the
2156 range from that voice only:
2158 @lilypond[quote,verbatim,ragged-right]
2161 \consists Ambitus_engraver
2176 but if we add the ambitus engraver to the
2177 @code{Staff} context, it calculates the range from all
2178 the notes in all the voices on that staff:
2180 @lilypond[quote,verbatim,ragged-right]
2182 \consists Ambitus_engraver
2198 @subsubheading Changing all contexts of the same type
2202 The examples above show how to remove or add engravers to
2203 individual contexts. It is also possible to remove or add
2204 engravers to every context of a specific type by placing the
2205 commands in the appropriate context in a @code{\layout}
2206 block. For example, if we wanted to show an ambitus for every
2207 staff in a four-staff score, we could write
2209 @lilypond[quote,verbatim,ragged-right]
2213 \relative c'' { c a b g }
2216 \relative c' { c a b g }
2220 \relative c' { c a b g }
2224 \relative c { c a b g }
2230 \consists Ambitus_engraver
2237 The values of context properties may also be set
2238 for all contexts of a particular type by including the
2239 @code{\set} command in a @code{\context} block in the
2244 Notation Reference: @ruser{Modifying context plug-ins},
2245 @ruser{Changing context default settings}.
2248 @node Extending the templates
2249 @section Extending the templates
2251 You've read the tutorial, you know how to write music, you
2252 understand the fundamental concepts. But how can you
2253 get the staves that you want? Well, you can find lots of
2254 templates (see @ref{Templates}) which may give you a start.
2255 But what if you want something that isn't covered there? Read on.
2258 * Soprano and cello::
2259 * Four-part SATB vocal score::
2260 * Building a score from scratch::
2263 @node Soprano and cello
2264 @subsection Soprano and cello
2266 @cindex template, modifying
2268 Start off with the template that seems closest to what you want to end
2269 up with. Let's say that you want to write something for soprano and
2270 cello. In this case, we would start with @q{Notes and lyrics} (for the
2274 \version @w{"@version{}"}
2275 melody = \relative c' @{
2282 text = \lyricmode @{
2288 \new Voice = "one" @{
2292 \new Lyrics \lyricsto "one" \text
2299 Now we want to add a cello part. Let's look at the @q{Notes only} example:
2302 \version @w{"@version{}"}
2303 melody = \relative c' @{
2317 We don't need two @code{\version} commands. We'll need the
2318 @code{melody} section. We don't want two @code{\score} sections
2319 -- if we had two @code{\score}s, we'd get the two parts separately.
2320 We want them together, as a duet. Within the @code{\score}
2321 section, we don't need two @code{\layout} or @code{\midi}.
2323 If we simply cut and paste the @code{melody} section, we would
2324 end up with two @code{melody} definitions. This would not generate
2325 an error, but the second one would be used for both melodies.
2326 So let's rename them to make them distinct. We'll call the
2327 section for the soprano @code{sopranoMusic} and the section for
2328 the cello @code{celloMusic}. While we're doing this, let's rename
2329 @code{text} to be @code{sopranoLyrics}. Remember to rename both
2330 instances of all these names -- both the initial definition (the
2331 @code{melody = \relative c' @{ } part) and the name's use (in the
2332 @code{\score} section).
2334 While we're doing this, let's change the cello part's staff --
2335 celli normally use bass clef. We'll also give the cello some
2339 \version @w{"@version{}"}
2340 sopranoMusic = \relative c' @{
2347 sopranoLyrics = \lyricmode @{
2351 celloMusic = \relative c @{
2360 \new Voice = "one" @{
2364 \new Lyrics \lyricsto "one" \sopranoLyrics
2371 This is looking promising, but the cello part won't appear in the
2372 score -- we haven't used it in the @code{\score} section. If we
2373 want the cello part to appear under the soprano part, we need to add
2376 \new Staff \celloMusic
2380 underneath the soprano stuff. We also need to add @code{<<} and
2381 @code{>>} around the music -- that tells LilyPond that there's
2382 more than one thing (in this case, two @code{Staves}) happening
2383 at once. The @code{\score} looks like this now:
2385 @c Indentation in this example is deliberately poor
2390 \new Voice = "one" @{
2394 \new Lyrics \lyricsto "one" \sopranoLyrics
2396 \new Staff \celloMusic
2404 This looks a bit messy; the indentation is messed up now. That is
2405 easily fixed. Here's the complete soprano and cello template.
2407 @lilypond[quote,verbatim,ragged-right,addversion]
2408 sopranoMusic = \relative c' {
2415 sopranoLyrics = \lyricmode {
2419 celloMusic = \relative c {
2429 \new Voice = "one" {
2433 \new Lyrics \lyricsto "one" \sopranoLyrics
2435 \new Staff \celloMusic
2444 The starting templates can be found in the @q{Templates} appendix,
2445 see @ref{Single staff}.
2448 @node Four-part SATB vocal score
2449 @subsection Four-part SATB vocal score
2451 @cindex template, SATB
2452 @cindex SATB template
2454 Most vocal scores of music written for four-part mixed choir
2455 with orchestral accompaniment such as Mendelssohn's Elijah or
2456 Handel's Messiah have the choral music and words on four
2457 staves, one for each of SATB, with a piano reduction of the
2458 orchestral accompaniment underneath. Here's an example
2459 from Handel's Messiah:
2461 @c The following should appear as music without code
2462 @lilypond[quote,ragged-right]
2463 global = { \key d \major \time 4/4 }
2464 sopranoMusic = \relative c'' {
2466 r4 d2 a4 | d4. d8 a2 | cis4 d cis2 |
2468 sopranoWords = \lyricmode {
2469 Wor -- thy is the lamb that was slain
2471 altoMusic = \relative a' {
2473 r4 a2 a4 | fis4. fis8 a2 | g4 fis e2 |
2475 altoWords = \sopranoWords
2476 tenorMusic = \relative c' {
2478 r4 fis2 e4 | d4. d8 d2 | e4 a, cis2 |
2480 tenorWords = \sopranoWords
2481 bassMusic = \relative c' {
2483 r4 d2 cis4 | b4. b8 fis2 | e4 d a'2 |
2485 bassWords = \sopranoWords
2486 upper = \relative a' {
2489 r4 <a d fis>2 <a e' a>4 |
2490 <d fis d'>4. <d fis d'>8 <a d a'>2 |
2491 <g cis g'>4 <a d fis> <a cis e>2 |
2493 lower = \relative c, {
2496 <d d'>4 <d d'>2 <cis cis'>4 |
2497 <b b'>4. <b' b'>8 <fis fis'>2 |
2498 <e e'>4 <d d'> <a' a'>2 |
2502 << % combine ChoirStaff and PianoStaff in parallel
2504 \new Staff = "sopranos" <<
2505 \set Staff.instrumentName = "Soprano"
2506 \new Voice = "sopranos" { \global \sopranoMusic }
2508 \new Lyrics \lyricsto "sopranos" { \sopranoWords }
2509 \new Staff = "altos" <<
2510 \set Staff.instrumentName = "Alto"
2511 \new Voice = "altos" { \global \altoMusic }
2513 \new Lyrics \lyricsto "altos" { \altoWords }
2514 \new Staff = "tenors" <<
2515 \set Staff.instrumentName = "Tenor"
2516 \new Voice = "tenors" { \global \tenorMusic }
2518 \new Lyrics \lyricsto "tenors" { \tenorWords }
2519 \new Staff = "basses" <<
2520 \set Staff.instrumentName = "Bass"
2521 \new Voice = "basses" { \global \bassMusic }
2523 \new Lyrics \lyricsto "basses" { \bassWords }
2527 \set PianoStaff.instrumentName = "Piano"
2528 \new Staff = "upper" \upper
2529 \new Staff = "lower" \lower
2535 None of the templates provides this layout exactly. The nearest is
2536 @q{SATB vocal score and automatic piano reduction} -- see @ref{Vocal
2537 ensembles} -- but we need to change the layout and add a piano
2538 accompaniment which is not derived automatically from the vocal parts.
2539 The variables holding the music and words for the vocal parts are
2540 fine, but we shall need to add variables for the piano reduction.
2542 The order in which the contexts appear in the ChoirStaff of
2543 the template do not correspond with the order in the vocal
2544 score shown above. We need to rearrange them so there are
2545 four staves with the words written directly underneath the
2546 notes for each part.
2547 All the voices should be @code{\voiceOne}, which is
2548 the default, so the @code{\voiceXXX} commands should be removed.
2549 We also need to specify the tenor clef for the tenors.
2550 The way in which lyrics are specified in the template has not yet
2551 been encountered so we need to use the method with which we are
2552 familiar. We should also add the names of each staff.
2554 Doing this gives for our ChoirStaff:
2558 \new Staff = "sopranos" <<
2559 \set Staff.instrumentName = "Soprano"
2560 \new Voice = "sopranos" @{ \global \sopranoMusic @}
2562 \new Lyrics \lyricsto "sopranos" @{ \sopranoWords @}
2563 \new Staff = "altos" <<
2564 \set Staff.instrumentName = "Alto"
2565 \new Voice = "altos" @{ \global \altoMusic @}
2567 \new Lyrics \lyricsto "altos" @{ \altoWords @}
2568 \new Staff = "tenors" <<
2569 \set Staff.instrumentName = "Tenor"
2570 \new Voice = "tenors" @{ \global \tenorMusic @}
2572 \new Lyrics \lyricsto "tenors" @{ \tenorWords @}
2573 \new Staff = "basses" <<
2574 \set Staff.instrumentName = "Bass"
2575 \new Voice = "basses" @{ \global \bassMusic @}
2577 \new Lyrics \lyricsto "basses" @{ \bassWords @}
2581 Next we must work out the piano part. This is
2582 easy - we just pull out the piano part from the
2583 @q{Solo piano} template:
2587 \set PianoStaff.instrumentName = "Piano "
2588 \new Staff = "upper" \upper
2589 \new Staff = "lower" \lower
2593 and add the variable definitions for @code{upper}
2596 The ChoirStaff and PianoStaff must be combined
2597 using angle brackets as we want them to be
2598 stacked one above the other:
2601 << % combine ChoirStaff and PianoStaff one above the other
2603 \new Staff = "sopranos" <<
2604 \new Voice = "sopranos" @{ \global \sopranoMusic @}
2606 \new Lyrics \lyricsto "sopranos" @{ \sopranoWords @}
2607 \new Staff = "altos" <<
2608 \new Voice = "altos" @{ \global \altoMusic @}
2610 \new Lyrics \lyricsto "altos" @{ \altoWords @}
2611 \new Staff = "tenors" <<
2612 \clef "G_8" % tenor clef
2613 \new Voice = "tenors" @{ \global \tenorMusic @}
2615 \new Lyrics \lyricsto "tenors" @{ \tenorWords @}
2616 \new Staff = "basses" <<
2618 \new Voice = "basses" @{ \global \bassMusic @}
2620 \new Lyrics \lyricsto "basses" @{ \bassWords @}
2624 \set PianoStaff.instrumentName = "Piano"
2625 \new Staff = "upper" \upper
2626 \new Staff = "lower" \lower
2631 Combining all these together and adding the music
2632 for the three bars of the example above gives:
2634 @lilypond[quote,verbatim,ragged-right,addversion]
2635 global = { \key d \major \time 4/4 }
2636 sopranoMusic = \relative c'' {
2638 r4 d2 a4 | d4. d8 a2 | cis4 d cis2 |
2640 sopranoWords = \lyricmode {
2641 Wor -- thy is the lamb that was slain
2643 altoMusic = \relative a' {
2645 r4 a2 a4 | fis4. fis8 a2 | g4 fis fis2 |
2647 altoWords = \sopranoWords
2648 tenorMusic = \relative c' {
2650 r4 fis2 e4 | d4. d8 d2 | e4 a, cis2 |
2652 tenorWords = \sopranoWords
2653 bassMusic = \relative c' {
2655 r4 d2 cis4 | b4. b8 fis2 | e4 d a'2 |
2657 bassWords = \sopranoWords
2658 upper = \relative a' {
2661 r4 <a d fis>2 <a e' a>4 |
2662 <d fis d'>4. <d fis d'>8 <a d a'>2 |
2663 <g cis g'>4 <a d fis> <a cis e>2 |
2665 lower = \relative c, {
2668 <d d'>4 <d d'>2 <cis cis'>4 |
2669 <b b'>4. <b' b'>8 <fis fis'>2 |
2670 <e e'>4 <d d'> <a' a'>2 |
2674 << % combine ChoirStaff and PianoStaff in parallel
2676 \new Staff = "sopranos" <<
2677 \set Staff.instrumentName = "Soprano"
2678 \new Voice = "sopranos" { \global \sopranoMusic }
2680 \new Lyrics \lyricsto "sopranos" { \sopranoWords }
2681 \new Staff = "altos" <<
2682 \set Staff.instrumentName = "Alto"
2683 \new Voice = "altos" { \global \altoMusic }
2685 \new Lyrics \lyricsto "altos" { \altoWords }
2686 \new Staff = "tenors" <<
2687 \set Staff.instrumentName = "Tenor"
2688 \new Voice = "tenors" { \global \tenorMusic }
2690 \new Lyrics \lyricsto "tenors" { \tenorWords }
2691 \new Staff = "basses" <<
2692 \set Staff.instrumentName = "Bass"
2693 \new Voice = "basses" { \global \bassMusic }
2695 \new Lyrics \lyricsto "basses" { \bassWords }
2699 \set PianoStaff.instrumentName = "Piano "
2700 \new Staff = "upper" \upper
2701 \new Staff = "lower" \lower
2708 @node Building a score from scratch
2709 @subsection Building a score from scratch
2711 @cindex template, writing your own
2713 After gaining some facility with writing LilyPond code, you
2714 may find that it is easier to build a score from scratch
2715 rather than modifying one of the templates. You can also
2716 develop your own style this way to suit the sort of music you
2717 like. Let's see how to put together the score for an organ
2718 prelude as an example.
2720 We begin with a header section. Here go the title, name
2721 of composer, etc, then come any variable definitions, and
2722 finally the score block. Let's start with these in outline
2723 and fill in the details later.
2725 We'll use the first two bars of Bach's prelude
2726 based on @emph{Jesu, meine Freude} which is written for two
2727 manuals and pedal organ. You can see these two bars of music
2728 at the bottom of this section. The top manual part has two voices,
2729 the lower and pedal organ one each. So we need four
2730 music definitions and one to define the time signature
2734 \version @w{"@version{}"}
2736 title = "Jesu, meine Freude"
2737 composer = "J S Bach"
2739 TimeKey = @{ \time 4/4 \key c \minor @}
2740 ManualOneVoiceOneMusic = @{s1@}
2741 ManualOneVoiceTwoMusic = @{s1@}
2742 ManualTwoMusic = @{s1@}
2743 PedalOrganMusic = @{s1@}
2749 For now we've just used a spacer note, @code{s1},
2750 instead of the real music. We'll add that later.
2752 Next let's see what should go in the score block.
2753 We simply mirror the staff structure we want.
2754 Organ music is usually written on three staves,
2755 one for each manual and one for the pedals. The
2756 manual staves should be bracketed together, so we
2757 need to use a PianoStaff for them. The first
2758 manual part needs two voices and the second manual
2763 \new Staff = "ManualOne" <<
2764 \new Voice @{ \ManualOneVoiceOneMusic @}
2765 \new Voice @{ \ManualOneVoiceTwoMusic @}
2766 >> % end ManualOne Staff context
2767 \new Staff = "ManualTwo" <<
2768 \new Voice @{ \ManualTwoMusic @}
2769 >> % end ManualTwo Staff context
2770 >> % end PianoStaff context
2773 Next we need to add a staff for the pedal organ.
2774 This goes underneath the PianoStaff, but it must
2775 be simultaneous with it, so we need angle brackets
2776 around the two. Missing these out would generate
2777 an error in the log file. It's a common mistake
2778 which you'll make sooner or later! Try copying
2779 the final example at the end of this section,
2780 remove these angle brackets, and compile it to
2781 see what errors it generates.
2784 << % PianoStaff and Pedal Staff must be simultaneous
2786 \new Staff = "ManualOne" <<
2787 \new Voice @{ \ManualOneVoiceOneMusic @}
2788 \new Voice @{ \ManualOneVoiceTwoMusic @}
2789 >> % end ManualOne Staff context
2790 \new Staff = "ManualTwo" <<
2791 \new Voice @{ \ManualTwoMusic @}
2792 >> % end ManualTwo Staff context
2793 >> % end PianoStaff context
2794 \new Staff = "PedalOrgan" <<
2795 \new Voice @{ \PedalOrganMusic @}
2800 It is not necessary to use the simultaneous construct
2801 @code{<< .. >>} for the manual two staff and the pedal organ staff,
2802 since they contain only one music expression, but it does no harm,
2803 and always using angle brackets after @code{\new Staff} is a good
2804 habit to cultivate in case there are multiple voices. The opposite
2805 is true for Voices: these should habitually be followed by braces
2806 @code{@{ .. @}} in case your music is coded in several variables
2807 which need to run consecutively.
2809 Let's add this structure to the score block, and adjust the indenting.
2810 We also add the appropriate clefs, ensure stems, ties and slurs in
2811 each voice on the upper staff point to the right direction with
2812 @code{\voiceOne} and @code{\voiceTwo}, and enter the time signature
2813 and key to each staff using our predefined variable, @code{\TimeKey}.
2817 << % PianoStaff and Pedal Staff must be simultaneous
2819 \new Staff = "ManualOne" <<
2820 \TimeKey % set time signature and key
2822 \new Voice @{ \voiceOne \ManualOneVoiceOneMusic @}
2823 \new Voice @{ \voiceTwo \ManualOneVoiceTwoMusic @}
2824 >> % end ManualOne Staff context
2825 \new Staff = "ManualTwo" <<
2828 \new Voice @{ \ManualTwoMusic @}
2829 >> % end ManualTwo Staff context
2830 >> % end PianoStaff context
2831 \new Staff = "PedalOrgan" <<
2834 \new Voice @{ \PedalOrganMusic @}
2835 >> % end PedalOrgan Staff
2837 @} % end Score context
2840 That completes the structure. Any three-staff organ music
2841 will have a similar structure, although the number of voices
2842 may vary. All that remains now
2843 is to add the music, and combine all the parts together.
2845 @lilypond[quote,verbatim,ragged-right,addversion]
2847 title = "Jesu, meine Freude"
2848 composer = "J S Bach"
2850 TimeKey = { \time 4/4 \key c \minor }
2851 ManualOneVoiceOneMusic = \relative g' {
2852 g4 g f ees | d2 c2 |
2854 ManualOneVoiceTwoMusic = \relative c' {
2855 ees16 d ees8~ ees16 f ees d c8 d~ d c~ |
2856 c c4 b8 c8. g16 c b c d |
2858 ManualTwoMusic = \relative c' {
2859 c16 b c8~ c16 b c g a8 g~ g16 g aes ees |
2860 f ees f d g aes g f ees d e8~ ees16 f ees d |
2862 PedalOrganMusic = \relative c {
2863 r8 c16 d ees d ees8~ ees16 a, b g c b c8 |
2864 r16 g ees f g f g8 c,2 |
2868 << % PianoStaff and Pedal Staff must be simultaneous
2870 \new Staff = "ManualOne" <<
2871 \TimeKey % set time signature and key
2873 \new Voice { \voiceOne \ManualOneVoiceOneMusic }
2874 \new Voice { \voiceTwo \ManualOneVoiceTwoMusic }
2875 >> % end ManualOne Staff context
2876 \new Staff = "ManualTwo" <<
2879 \new Voice { \ManualTwoMusic }
2880 >> % end ManualTwo Staff context
2881 >> % end PianoStaff context
2882 \new Staff = "PedalOrgan" <<
2885 \new Voice { \PedalOrganMusic }
2886 >> % end PedalOrgan Staff context
2888 } % end Score context