1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond-learning.tely
4 @node Fundamental concepts
5 @chapter Fundamental concepts
9 * How LilyPond files work::
10 * Voices contain music::
11 * Contexts and engravers::
12 * Extending the templates::
17 @node How LilyPond files work
18 @section How LilyPond files work
20 The LilyPond input format is quite free-form, giving experienced
21 users a lot of flexibility to structure their files however they
22 wish. However, this flexibility can make things confusing for new
23 users. This section will explain some of this structure, but may
24 gloss over some details in favor of simplicity. For a complete
25 description of the input format, see @ruser{File structure}.
28 * Introduction to the LilyPond file structure::
29 * Score is a (single) compound musical expression::
30 * Nesting Music Expressions::
33 @node Introduction to the LilyPond file structure
34 @subsection Introduction to the LilyPond file structure
36 A basic example of a lilypond input file is
41 @var{...compound music expression...} % all the music goes here!
49 There are many variations of this basic pattern, but this
50 example serves as a useful starting place.
52 At this point, you may be confused, since you have never seen a
53 @code{\score@{@}} before. This is because LilyPond automatically
54 adds the extra commands when you give it simple input. LilyPond
55 treats input like this:
64 as shorthand for this:
75 In other words, if the input contains a single music expression,
76 LilyPond will interpret the file as though the music expression
77 was wrapped up inside a @code{\score@{@}}.
81 A @code{\score} must begin with a compound music expression.
82 Remember that a music expression could be anything from a single
88 @var{...insert the whole score of a Wagner opera in here...}
94 Since everything is inside @code{@{ ... @}}, it counts
95 as one music expression.
97 As we saw previously, the @code{\score} can contain other things,
110 Some people put some of those commands outside the @code{\score}
111 block -- for example, @code{\header} is often placed above the
112 @code{\score}. That's just another shorthand that LilyPond
119 Another great shorthand is the ability to define variables. All
120 the templates use this
123 melody = \relative c' @{
132 When LilyPond looks at this file, it takes the value of
133 @code{melody} (everything after the equals sign) and inserts it
134 whenever it sees @code{\melody}. There's nothing special about
135 the names -- it could be @code{melody}, @code{global},
136 @code{pianorighthand}, or @code{foofoobarbaz}. You can use
137 whatever variable names you want as along as they contain just
138 alphabetic characters. For more details, see
139 @ruser{Saving typing with variables and functions}.
144 For a complete definition of the input format, see
145 @ruser{File structure}.
147 @node Score is a (single) compound musical expression
148 @subsection Score is a (single) compound musical expression
150 @cindex Compound music expression
151 @cindex Music expression, compound
153 We saw the general organization of LilyPond input files in the
154 previous section, @ref{How LilyPond files work}. But we seemed to
155 skip over the most important part: how do we figure out what to
156 write after @code{\score}?
158 We didn't skip over it at all. The big mystery is simply that
159 there @emph{is} no mystery. This line explains it all:
162 @emph{A @code{\score} must begin with a compound music expression.}
166 You may find it useful to review
167 @ref{Music expressions explained}. In that section, we saw how to
168 build big music expressions from small pieces -- we started from
169 notes, then chords, etc. Now we're going to start from a big
170 music expression and work our way down.
174 @{ % this brace begins the overall compound music expression
176 @var{...insert the whole score of a Wagner opera in here...}
178 @} % this brace ends the overall compound music expression
183 A whole Wagner opera would easily double the length of this
184 manual, so let's just add a singer and piano. We don't need a
185 @code{GrandStaff} for this ensemble, so we shall remove it. We
186 @emph{do} need a singer and a piano, though.
192 \new Staff = "singer" <<
194 \new PianoStaff = piano <<
202 Remember that we use @code{<<} and @code{>>} to show simultaneous
203 music. And we definitely want to show the vocal part and piano
204 part at the same time, not one after the other! However, the
205 @code{<< .. >>} construct is not really necessary for the Singer
206 staff, as it contains only one music expression, but Staves often
207 do require simultaneous Voices within them, so using @code{<< .. >>}
208 rather than braces is a good habit to adopt.
214 \new Staff = "singer" <<
215 \new Voice = "vocal" @{ @}
217 \new Lyrics \lyricsto vocal \new Lyrics @{ @}
218 \new PianoStaff = "piano" <<
219 \new Staff = "upper" @{ @}
220 \new Staff = "lower" @{ @}
228 Now we have a lot more details. We have the singer's staff: it
229 contains a @code{Voice} (in LilyPond, this term refers to a set of
230 notes, not necessarily vocal notes -- for example, a violin
231 generally plays one voice) and some lyrics. We also have a piano
232 staff: it contains an upper staff (right hand) and a lower staff
235 At this stage, we could start filling in notes. Inside the curly
236 braces next to @code{\new Voice = vocal}, we could start writing
244 But if we did that, the @code{\score} section would get pretty
245 long, and it would be harder to understand what was happening. So
246 let's use variables instead.
256 \new Staff = "singer" <<
257 \new Voice = "vocal" @{ \melody @}
259 \new Lyrics \lyricsto vocal \new Lyrics @{ \text @}
260 \new PianoStaff = "piano" <<
261 \new Staff = "upper" @{ \upper @}
262 \new Staff = "lower" @{ \lower @}
271 Remember that you can use almost any name you like as long
272 as it contains just alphabetic characters. The exact
273 limitations on variable names are detailed in
274 @ruser{File structure}.
276 When writing (or reading) a @code{\score} section, just take it
277 slowly and carefully. Start with the outer layer, then work on
278 each smaller layer. It also really helps to be strict with
279 indentation -- make sure that each item on the same layer starts
280 on the same horizontal position in your text editor.
283 @node Nesting Music Expressions
284 @subsection Nesting Music Expressions
286 New staves do not have to all be declared at the beginning;
287 they may be introduced temporarily at any point. This is
288 particularly useful for creating ossia sections
289 (see @rglos{ossia}). Here's a simple example showing how
290 to introduce a new staff temporarily for the duration of
293 @lilypond[verbatim,quote,ragged-right]
309 The ossia section may be placed above the staff
312 @lilypond[verbatim,quote,ragged-right]
320 alignAboveContext = "main" }
328 This example uses @code{\with}, which will be explained more
329 fully later. It is a means of modifying the default behaviour
330 of a Staff. Here it says that the new staff should be placed
331 above the staff called @qq{main} instead of the default position
334 Ossia are often written without clef and without
335 time signature and are usually in a smaller font.
336 These require further commands which
337 have not yet been introduced. See ...
338 TODO Add ref to tweaks section where this example should
339 be placed and explained.
341 @lilypond[verbatim,quote,ragged-right]
342 \new Staff = "main" {
346 << % Start main and ossia in parallel
347 { r8 f c c } % Main music
348 \new Staff \with { % Start ossia staff
349 \remove "Clef_engraver"
350 \remove "Time_signature_engraver"
351 % Reduce size of notes and staff
353 \override StaffSymbol #'staff-space = #(magstep -2)
354 alignAboveContext = "main" % Place above main staff
356 { s8 f f c } % Ossia music
357 >> % End parallel music
364 You have already met a number of different types of bracket in
365 writing the input file to LilyPond. These obey different rules
366 which can be confusing at first. Before we explain the rules
367 let's first review the different types of bracket.
369 @multitable @columnfractions .3 .7
370 @headitem Bracket Type
372 @item @code{@{ .. @}}
373 @tab Encloses a sequential segment of music
375 @tab Encloses the notes of a chord
376 @item @code{<< .. >>}
377 @tab Encloses concurrent or simultaneous sections
379 @tab Marks the start and end of a slur
380 @item @code{\( .. \)}
381 @tab Marks the start and end of a phrase mark
383 @tab Marks the start and end of a manual beam
386 To these we should add other constructs which generate lines
387 between or across notes: ties (marked by a tilde, @code{~}),
388 tuplets written as @code{\times x/y @{ .. @}}, and grace notes
389 written as @code{\grace@{ .. @}}.
391 Outside LilyPond, the conventional use of brackets requires
392 the different types to be properly nested, like this,
393 @code{<< @{ ( .. ) @} >>}, with the closing brackets being
394 encountered in exactly the opposite order to the opening
395 brackets. This @strong{is} a requirement for the three types of
396 bracket described by the word @q{Encloses} in the table above -
397 they must nest properly.
398 However, the remaining brackets, described with the word
399 @q{Marks} in the table above together with ties and tuplets,
400 do @strong{not} have to nest
401 properly with any of the brackets. In fact, these are not
402 brackets in the sense that
403 they enclose something - they are simply markers to indicate
404 where something starts and ends.
406 So, for example, a phrasing slur can start before a manually
407 inserted beam and end before the end of the beam - not very
408 musical, perhaps, but possible:
410 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
411 { g8\( a b[ c b\) a] }
414 In general, different kinds of brackets, and those implied by
415 tuplets, ties and grace notes, may be mixed freely.
416 This example shows a beam extending into a tuplet (line 1),
417 a slur extending into a tuplet (line 2),
418 a beam and a slur extending into a tuplet, a tie crossing
419 two tuplets, and a phrasing slur extending out of a tuplet
422 @lilypond[quote,verbatim,fragment,ragged-right]
424 r16[ g16 \times 2/3 {r16 e'8] }
425 g16( a \times 2/3 {b d) e' }
426 g8[( a \times 2/3 {b d') e'~]}
427 \times 4/5 {e'32\( a b d' e'} a'4.\)
432 @node Voices contain music
433 @section Voices contain music
435 Singers need voices to sing, and so does LilyPond.
436 The actual music for all instruments in a score
437 is contained in Voices - the most fundamental
438 of all LilyPond's concepts.
441 * I'm hearing Voices::
442 * Explicitly instantiating voices::
443 * Voices and vocals::
446 @node I'm hearing Voices
447 @subsection I'm hearing Voices
451 @cindex Voice context
453 The lowest, most fundamental or innermost layers in a LilyPond
454 score are called @q{Voice contexts} or just @q{Voices} for short.
455 Voices are sometimes called @q{layers} in other notation
458 In fact, a Voice layer or context is the only one which can
459 contain music. If a Voice context is not explicitly declared
460 one is created automatically. Some instruments such as an
461 Oboe can play only one note at a time. Music written for
462 such instruments is monophonic and requires just a single
463 voice. Instruments which can play more than one note at a
464 time like the piano will often require multiple voices to
465 encode the different concurrent notes and rhythms they are
468 A single voice can contain many notes in a chord, of course,
469 so when exactly are multiple voices needed?
470 Let us analyse a short piece of music to see how many voices
471 are required. Here are the notes from the first two bars
472 of the second of Chopin's Deux Nocturnes, Op 32.
474 @c The following should appear as music without code
475 @lilypond[quote,ragged-right]
476 \new Staff \relative c'' {
484 \once \override NoteColumn #'force-hshift = #0 <ees c>2
485 \once \override NoteColumn #'force-hshift = #0.5 des2 }
491 The direction of the stems is often used to indicate the
492 continuity of two simultaneous melodic lines. Here the
493 stems of the highest notes are all pointing up and the
494 stems of the lower notes are all pointing down.
495 This is the first indication that more than one voice
498 But the real need for multiple voices arises when notes
499 which start at the same time have different durations.
500 Look at the notes which start at beat three in the first
501 bar. The a-flat is a dotted quarter note, the f is a
502 quarter note and the d-flat is a half note. These
503 cannot be written as a chord as all the notes in a chord
504 must have the same duration. Neither can they be written
505 as sequential notes, as they must start at the same time.
506 This section of the bar requires three voices, and the
507 normal practice would be to write the whole bar as three
508 voices, as shown here, where we have used different noteheads
509 and colors for the three voices.
511 @c The following should appear as music without code
512 @c The three voice styles should be defined in -init
513 @lilypond[quote,ragged-right]
514 \new Staff \relative c'' {
525 \once \override NoteColumn #'force-hshift = #0 <ees c>2
526 \once \override NoteColumn #'force-hshift = #0.5 des2 }
532 Let us see how this is done.
536 The easiest way to enter fragments with more than one voice on a
537 staff is to enter each voice as a sequence (with @code{@{...@}}),
538 and combine them simultaneously with angle brackets, @code{<<...>>}.
539 The fragments must also be separated with double backward slashes,
540 @code{\\}, to place them in separate voices. Without these, the
541 notes would be entered into a single voice, which would usually
542 cause errors. This technique is particularly suited to pieces of
543 music which are largely monophonic with occasional short sections
544 of polyphony. Here's a simple example:
546 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
548 % Voice "1" Voice "2"
549 << { r4 g g4. a8 } \\ { d,2 d4 g } >> |
550 << { bes4 bes c bes } \\ { g4 g g8( a) g4 } >> |
551 << { a2. r4 } \\ { fis2. s4 } >>
554 This example has just two voices, but the same contruct may be
555 used to encode three or more voices by adding more back-slash
558 The Voice contexts bear the names @code{"1"}, @code{"2"}, etc.
559 In each of these contexts, vertical direction of slurs, stems, ties,
560 dynamics etc., is set appropriately.
562 @lilypond[quote,verbatim,fragment]
563 \new Staff \relative c' {
566 % Voice "1" Voice "2" Voice "3"
567 << { g4 f e } \\ { r8 e4 d c8 ~ } >> |
568 << { d2 e2 } \\ { c8 b16 a b8 g ~ g2 } \\ { s4 b4 c2 } >> |
572 These voices are all separate from the main voice that contains
573 the notes just outside the @code{<< .. >>} construct. Let's call
574 this the @emph{simultaneous construct}. Slurs and ties may only
575 connect notes within the same voice, so slurs and ties cannot go
576 into or out of a simultaneous construct. Conversely,
577 parallel voices from separate simultaneous constructs on the same
578 staff are the same voice. Other voice-related properties also
579 carry across simultaneous constructs. Here is the same example,
580 with different colors and noteheads for each voice. Note that
581 changes in one Voice do not affect other voices, but they do
582 persist in the same Voice later. Note also that tied notes may be
583 split across the same voices in two constructs, shown here in the
586 @lilypond[quote,verbatim]
587 \new Staff \relative c' {
597 { c8 b16 a b8 g ~ g2 } \\
604 Polyphony does not change the relationship of notes within a
605 @code{\relative @{ @}} block. Each note is calculated relative to
606 the note immediately preceding it, or to the first note of the
610 \relative c' @{ noteA << <noteB noteC> \\ noteD >> noteE @}
613 @code{noteB} is relative to @code{noteA}
615 @code{noteC} is relative to @code{noteB}, not @code{noteA};
617 @code{noteD} is relative to @code{noteB}, not @code{noteA} or
620 @code{noteE} is relative to @code{noteD}, not @code{noteA}
622 We are now in a position to return to the first example from
623 the Chopin Nocturne to see how this might be encoded. As we
624 shall see, this encounters some difficulties. We begin as
625 we have learnt, using the @code{<< \\ >>} construct to
626 enter the music of the first bar in three voices:
628 @lilypond[quote,verbatim,fragment,ragged-right]
629 \new Staff \relative c'' {
632 { c2 aes4. bes8 } \\ { aes2 f4 fes } \\ { <ees c>2 des2 }
642 @funindex \voiceThree
645 The stem directions are automatically assigned with the
646 odd-numbered voices taking upward stems and the even-numbered
647 voices downward ones. The stems for voices 1 and 2 are right,
648 but the stems in voice 3 should go down in this particular piece
649 of music. We can correct this
650 by telling LilyPond that this third voice is really a fourth
651 voice, with stems going down, using the @code{\voiceFour}
652 command. There are also corresponding @code{\voiceOne},
653 @code{\voiceTwo}, @code{voiceThree} and @code{voiceFour}
654 commands. This results in the following:
656 @lilypond[quote,verbatim,fragment,ragged-right]
657 \new Staff \relative c'' {
662 { \voiceFour <ees c>2 des2 }
669 and exposes a problem commonly encountered with multiple
670 voices: the stems of notes can collide with noteheads
671 in other voices. In laying out the notes, LilyPond allows the
672 notes or chords from two voices to occupy the same vertical
673 note column provided the stems are in opposite directions, but
674 the notes from a third voice are displaced to avoid the stems
675 colliding. This often works well, but in this example the
676 notes of the third voice are clearly not well placed by default.
677 LilyPond provides several ways to adjust the horizontal placing
678 of notes. We are not quite ready yet to see how to correct this,
679 so we shall leave this problem until a later section (see ... )
681 FIXME: Move the following words and example into Tweaks or
682 somewhere more suitable, leaving just a ref here. -td
684 Ways of correcting horizontal placings are described fully
685 in the Notation Reference.
686 We introduce just one here, the @code{force-hshift} property of
687 @code{NoteColumn}. The lower two notes of the first chord (i.e,
688 those in the third voice) should not be shifted away from the
689 note column of the higher two notes. To correct this we set
690 @code{force-hshift} of these notes to zero.
691 The lower note of the second chord is best placed just to the
692 right of the higher notes. We achieve this by setting
693 @code{force-hshift} of this note to 0.5, ie half a notehead's
694 width to the right of the note column of the higher notes.
696 Here's the final result:
698 @lilypond[quote,verbatim,fragment,ragged-right]
699 \new Staff \relative c'' {
705 \once \override NoteColumn #'force-hshift = #0 <ees c>2
706 \once \override NoteColumn #'force-hshift = #0.5 des2
713 @node Explicitly instantiating voices
714 @subsection Explicitly instantiating voices
716 Voice contexts can also be created manually
717 inside a @code{<< >>} block to create polyphonic music, using
718 @code{\voiceOne} ... @code{\voiceFour} to indicate the required
719 directions of stems, slurs, etc.
721 Specifically, the construct @code{<< \\ >>} which we used in
722 the previous section:
725 << \upper \\ \lower >>
729 where @code{upper} and @code{lower} are user-defined variables
730 containing the music for the two voices, is equivalent to
734 \new Voice = "1" @{ \voiceOne \upper @}
735 \new Voice = "2" @{ \voiceTwo \lower @}
739 The @code{\voiceXXX} commands set the direction of stems, slurs,
740 ties, articulations, text annotations, augmentation dots of dotted
741 notes, and fingerings. @code{\voiceOne} and @code{\voiceThree}
742 make these objects point upwards, while @code{\voiceTwo} and
743 @code{\voiceFour} make them point downwards. These commands also
744 generate a horizontal shift for each voice when this is required
745 to avoid clashes of note heads. The command @code{\oneVoice}
746 reverts the settings back to the normal values for a single voice.
748 Let us see in a simple example exactly what effect
749 @code{\oneVoice}, @code{\voiceOne} and @code{voiceTwo} have on
750 markup, ties, slurs, and dynamics:
752 @lilypond[quote,ragged-right,verbatim]
754 c-"default" d8 ~ d e4 ( f g a ) b-> c \break
756 c,-"\\voiceOne" d8 ~ d e4 ( f g a ) b-> c \break
758 c,-"\\oneVoice" d8 ~ d e4 ( f g a ) b-> c \break
760 c,-"\\voiceTwo" d8 ~ d e4 ( f g a ) b-> c \break
764 An expression that appears directly inside a @code{<< >>} belongs
765 to the main voice. This is useful when extra voices appear while
766 the main voice is playing. Here is a more correct rendition of
767 the example from the previous section. The red diamond-shaped
768 notes demonstrate that the main melody is now in a single
769 voice context, permitting a phrasing slur to be drawn over them.
771 @lilypond[quote,ragged-right,verbatim]
772 \new Staff \relative c' {
774 c16^( d e f % These notes are monophonic
775 << % Start simultaneous section of three voices
776 { g4 f e | d2 e2) } % Continue the main voice in parallel
777 \new Voice { % Initiate second voice
778 \voiceTwo % Set stems, etc, down
779 r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2
781 \new Voice { % Initiate third voice
782 \voiceThree % Set stems, etc, up
789 @cindex nesting music expressions
790 @cindex nesting simultaneous constructs
792 More deeply nested polyphony constructs are possible, and if a
793 voice appears only briefly this might be a more natural way to
796 @lilypond[quote,ragged-right,verbatim]
797 \new Staff \relative c' {
817 This method of nesting new voices briefly is useful
818 when only small sections of the music
819 are polyphonic, but when the whole staff is largely polyphonic
820 it can be clearer to use multiple voices throughout, using
821 spacing notes to step over sections where the voice is silent,
824 @lilypond[quote,ragged-right,verbatim]
825 \new Staff \relative c' <<
826 \new Voice { % Initiate first voice
828 c16^( d e f g4 f e | d2 e2) |
830 \new Voice { % Initiate second voice
831 \voiceTwo % set stems, etc down
832 s4 r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2 |
834 \new Voice { % Initiate third voice
835 \voiceThree % set stems, etc up
842 @node Voices and vocals
843 @subsection Voices and vocals
845 Vocal music presents a special difficulty: we need to combine two
846 expressions -- notes and lyrics.
848 You have already seen the @code{\lyricsAdd@{@}} command, which
849 handles simple cases for you. However, this technique is
850 very limited. For most music, you must explicitly link the lyrics
851 to the notes with @code{\lyricsto@{@}}, using the name assigned
854 @lilypond[quote,verbatim,fragment]
856 \new Voice = "one" \relative c'' {
859 c4 b8. a16 g4. f8 e4 d c2
861 \new Lyrics \lyricsto "one" {
862 No more let sins and sor -- rows grow.
867 The automatic beaming which LilyPond uses by default works well
868 for instrumental music, but not so well for music with lyrics,
869 where beaming is either not required at all or is used to indicate
870 melismata in the lyrics. In the example above we use the command
871 @code{\autoBeamOff} to turn off the automatic beaming.
873 Let us reuse the earlier example from Judas Maccabæus to
874 illustrate this more flexible technique. We first recast
875 it to use variables so the music and lyrics can be separated
876 from the staff structure. We also introduce a choirstaff
877 bracket. The lyrics themselves must be introduced with
878 @code{\lyricmode} to ensure they are interpreted as lyrics
881 @lilypond[quote,verbatim]
882 global = { \time 6/8 \partial 8 \key f \major}
883 SopOneMusic = \relative c'' {
884 c8 | c([ bes)] a a([ g)] f | f'4. b, | c4.~ c4 }
885 SopTwoMusic = \relative c' {
886 r8 | r4. r4 c8 | a'([ g)] f f([ e)] d | e([ d)] c bes' }
887 SopOneLyrics = \lyricmode {
888 Let | flee -- cy flocks the | hills a -- dorn, __ }
889 SopTwoLyrics = \lyricmode {
890 Let | flee -- cy flocks the | hills a -- dorn, }
895 \new Voice = "SopOne" {
899 \new Lyrics \lyricsto "SopOne" {
904 \new Voice = "SopTwo" {
907 \new Lyrics \lyricsto "SopTwo" {
915 This is the basic structure of all vocal scores. More staves may
916 be added as required, more voices may be added to the staves,
917 more verses may be added to the lyrics,
918 and the variables containing the music can easily be placed
919 in separate files should they become too long.
921 Here is a final example of the first line of a hymn with four
922 verses, set for SATB. In this case the words for all four
925 @lilypond[quote,verbatim]
926 global = { \time 4/4 \partial 4 \key c \major}
927 SopMusic = \relative c' { c4 | e4. e8 g4 g | a a g }
928 AltoMusic = \relative c' { c4 | c4. c8 e4 e | f f e }
929 TenorMusic = \relative c { e4 | g4. g8 c4. b8 | a8 b c d e4 }
930 BassMusic = \relative c { c4 | c4. c8 c4 c | f8 g a b c4 }
931 VerseOne = \lyricmode {
932 E -- | ter -- nal fa -- ther, | strong to save, }
933 VerseTwo = \lyricmode {
934 O | Christ, whose voice the | wa -- ters heard, }
935 VerseThree = \lyricmode {
936 O | Ho -- ly Spi -- rit, | who didst brood }
937 VerseFour = \lyricmode {
938 O | Tri -- ni -- ty of | love and pow'r }
944 \new Voice = "Sop" { \voiceOne \global \SopMusic }
945 \new Voice = "Alto" { \voiceTwo \AltoMusic }
946 \new Lyrics \lyricsto "Sop" { \VerseOne }
947 \new Lyrics \lyricsto "Sop" { \VerseTwo }
948 \new Lyrics \lyricsto "Sop" { \VerseThree }
949 \new Lyrics \lyricsto "Sop" { \VerseFour }
953 \new Voice = "Tenor" { \voiceOne \TenorMusic }
954 \new Voice = "Bass" { \voiceTwo \BassMusic }
960 @node Contexts and engravers
961 @section Contexts and engravers
963 Contexts and engravers have been mentioned informally
964 in earlier sections; we now must look at
965 these concepts in more detail, as they are important
966 in the fine-tuning of LilyPond output.
970 * Contexts explained::
971 * Creating contexts::
973 * Modifying Contexts::
974 * On the un-nestedness of brackets and ties::
977 @node Contexts explained
978 @subsection Contexts explained
980 When music is printed, many notational elements which do not
981 appear explicitly in the input file must be added to the
982 output. For example, compare the input and output of the
985 @lilypond[quote,verbatim,relative=2,fragment]
989 The input is rather sparse, but in the output, bar lines,
990 accidentals, clef, and time signature have been added. When
991 LilyPond @emph{interprets} the input the musical information
992 is inspected in time order, similar to reading a score from left
993 to right. While reading the input, the program remembers where
994 measure boundaries are, and which pitches require explicit
995 accidentals. This information must be held on several levels.
996 For example, the effect of an accidental is limited
997 to a single staff, while a bar line must be synchronized across
1000 Within LilyPond, these rules and bits of information are grouped
1001 in @emph{Contexts}. We have already met the @context{Voice}
1003 Others are the @context{Staff} and @context{Score} contexts.
1004 Contexts are hierarchical to reflect the heirarchical nature of
1006 For example: a @context{Staff} context can contain many
1007 @context{Voice} contexts, and a @context{Score} context can
1008 contain many @context{Staff} contexts.
1011 @image{context-example,5cm,,}
1014 Each context has the responsibility for enforcing some notation rules,
1015 creating some notation objects and maintaining the associated
1016 properties. For example, the @context{Voice} context may introduce an
1017 accidental and then the @context{Staff} context maintains the rule to
1018 show or suppress the accidental for the remainder of the measure.
1020 As another example, the synchronization of bar lines is by default
1021 handled in the @context{Score} context.
1022 However, in some music we may not want the bar lines to be
1023 synchronized -- consider a polymetric score in 4/4 and 3/4 time.
1024 In such cases, we must modify the default settings of the
1025 @context{Score} and @context{Staff} contexts.
1027 For very simple scores, contexts are created implicitly, and you need
1028 not be aware of them. For larger pieces, such as anything with more
1029 than one staff, they must be
1030 created explicitly to make sure that you get as many staves as you
1031 need, and that they are in the correct order. For typesetting pieces
1032 with specialized notation, it is usual to modify existing or
1033 even to define totally new contexts.
1035 In addition to the @context{Score,} @context{Staff} and
1036 @context{Voice} contexts there are contexts which fit between
1037 the score and staff levels to control staff groups, such as the
1038 @context{PianoStaff} and @context{ChoirStaff} contexts. There
1039 are also alternative staff and voice contexts, and contexts for
1040 lyrics, percussion, fret boards, figured bass, etc. A complete
1041 list is shown in the Notation Reference.
1044 The names of all context types are formed from one or more
1045 words, each word being capitalised and joined immediately to the
1046 preceding word with no hyphen or underscore, e.g.,
1047 @context{GregorianTranscriptionStaff}.
1049 @node Creating contexts
1050 @subsection Creating contexts
1052 There can be only one top level context, the @context{Score}
1053 context. This is created with the @code{\score} command,
1054 or, in simple scores, it is created automatically.
1056 For scores with only one voice and one staff, the
1057 @context{Voice} and @context{Staff} contexts may be left to be
1058 created automatically, but for more complex scores it is
1059 necessary to create them by hand.
1060 The simplest command that does this is @code{\new}.
1061 It is prepended to a music expression, for example
1064 @cindex new contexts
1065 @cindex Context, creating
1068 \new @var{type} @var{music expression}
1072 where @var{type} is a context name (like @code{Staff} or
1073 @code{Voice}). This command creates a new context, and starts
1074 interpreting the @var{music expression} within that context.
1076 Note that there is no @code{\new Score % Invalid!} command;
1077 the single top-level @context{Score} context is introduced
1078 with @code{\score}. This is because there can be only one
1079 @context{Score} context, whereas there may be multiple
1080 @context{Staff} and @context{Voice} contexts - each created
1083 So a practical application of @code{\new} is a score with many
1084 staves. Each part that should be on its own staff is preceded
1085 with @code{\new Staff}.
1087 @lilypond[quote,verbatim,relative=2,ragged-right,fragment]
1094 The @code{\new} command may also give a identifying name to the
1095 context to distinguish it from other contexts of the same type,
1098 \new @var{type} = @var{id} @var{music}
1101 Note the distinction between the name of the context type,
1102 @context{Staff}, @context{Voice}, etc, and
1103 the identifying name of a particular instance of that type,
1104 which can be any sequence of letters invented by the user.
1105 The identifying name is used to refer back to that particular
1106 instance of a context. We saw this in use in the section on
1107 lyrics in @ref{Voices and vocals}.
1111 @subsection Engravers
1113 Every mark on the printed output of a score produced by LilyPond
1114 is produced by an @code{Engraver}. Thus there is an engraver
1115 to print staves, one to print noteheads, one for stems, one for
1116 beams, etc, etc. In total there are over 120 such engravers!
1117 Fortunately, for most scores it is not necessary to know about
1118 more than a few, and for simple scores you do not need to know
1121 A musical score can be viewed heirarchically. At the top level
1122 is the whole score. This consists of one or more staves.
1123 Each staff contains one or more voices. As we have seen, there
1124 are contexts which correspond to each of these levels and it
1125 is in these contexts that the Engravers operate.
1127 Engravers such as the @code{Metronome_mark_engraver}, whose
1128 action and output applies to the score as a whole, live in
1129 the highest level context - the @context{Score} context. There
1130 can be only one of these engravers as there can be only one tempo
1131 at any particular point in the score.
1133 The @code{Clef_engraver} and @code{Key_engraver} are to be
1134 found in the Staff Context, as different staves may require
1135 different clefs and keys.
1137 The @code{Note_heads_engraver} and @code{Stem_engraver} live
1138 in a @context{Voice} context, the lowest level context of all.
1140 Each engraver processes the particular objects associated
1141 with its function, and contains the properties that relate
1142 to that function. These properties, like the properties
1143 associated with contexts, may be modified to change the
1144 operation of the engraver or the appearance of those elements
1145 in the printed score.
1147 Engravers all have compound names formed from words which
1148 describe their function. Just the first word is capitalised,
1149 and the remainder are joined to it with underscores. Thus
1150 the @code{Staff_symbol_engraver} is responsible for creating the
1151 lines of the staff, the @code{Clef_engraver} determines and sets
1152 the pitch reference point on the staff by drawing a clef symbol.
1154 Here are some of the most common engravers together with their
1155 function. You will see it is easy to guess the function from
1156 the name, or vice versa.
1158 @multitable @columnfractions .3 .7
1161 @item Accidental_engraver
1162 @tab Makes accidentals, cautionary and suggested accidentals
1167 @item Dynamic_engraver
1168 @tab Creates hairpins and dynamic texts
1170 @tab Creates the key signature
1171 @item Metronome_mark_engraver
1172 @tab Engraves metronome marking
1173 @item Note_heads_engraver
1174 @tab Engraves noteheads
1177 @item Staff_symbol_engraver
1178 @tab Engraves the five (by default) lines of the staff
1180 @tab Creates stems and single-stem tremulos
1183 We shall see later how the output of LilyPond can be changed
1184 by modifying the action of Engravers.
1187 @node Modifying Contexts
1188 @subsection Modifying Contexts
1190 TODO: write section, including \with, \remove, \consists
1195 @c my name start sucking the more docs I write. -gp
1196 @node On the un-nestedness of brackets and ties
1197 @subsection On the un-nestedness of brackets and ties
1199 Different kinds of brackets and ties may be mixed freely,
1201 TODO: improve this example
1203 @lilypond[quote,verbatim,fragment,ragged-right]
1205 r16[ g16 \times 2/3 {r16 e'8] }
1206 g16( a \times 2/3 {b d e') }
1207 g8[( a \times 2/3 {b d') e'~]}
1208 \times 4/5 {e'32\( a b d' e'} a'4.\)
1212 TODO... add more info? Fluff up the first sentence?
1215 @node Extending the templates
1216 @section Extending the templates
1218 You've read the tutorial, you know how to write music. But how can you
1219 get the staves that you want? The templates are ok, but what if you
1220 want something that isn't covered?
1223 * Soprano and cello::
1224 * Four-part SATB vocal score::
1225 * Building a score from scratch::
1228 @node Soprano and cello
1229 @subsection Soprano and cello
1231 Start off with the template that seems closest to what you want to end
1232 up with. Let's say that you want to write something for soprano and
1233 cello. In this case, we would start with @q{Notes and lyrics} (for the
1238 melody = \relative c' @{
1246 text = \lyricmode @{
1252 \new Voice = "one" @{
1256 \new Lyrics \lyricsto "one" \text
1263 Now we want to add a cello part. Let's look at the @q{Notes only} example:
1267 melody = \relative c' @{
1282 We don't need two @code{\version} commands. We'll need the @code{melody}
1283 section. We don't want two @code{\score} sections -- if we had two
1284 @code{\score}s, we'd get the two parts separately. We want them together,
1285 as a duet. Within the @code{\score} section, we don't need two
1286 @code{\layout} or @code{\midi}.
1288 If we simply cut and paste the @code{melody} section, we would end up with
1289 two @code{melody} sections. So let's rename them. We'll call the section
1290 for the soprano @code{sopranoMusic} and the section for the cello
1291 @code{celloMusic}. While we're doing this, let's rename @code{text}
1292 to be @code{sopranoLyrics}. Remember to rename both instances of all
1293 these names -- both the initial definition (the
1294 @code{melody = relative c' @{ } part) and the name's use (in the
1295 @code{\score} section).
1297 While we're doing this, let's change the cello part's staff -- celli
1298 normally use bass clef. We'll also give the cello some different
1303 sopranoMusic = \relative c' @{
1311 sopranoLyrics = \lyricmode @{
1315 celloMusic = \relative c @{
1325 \new Voice = "one" @{
1329 \new Lyrics \lyricsto "one" \sopranoLyrics
1336 This is looking promising, but the cello part won't appear in the
1337 score -- we haven't used it in the @code{\score} section. If we
1338 want the cello part to appear under the soprano part, we need to add
1341 \new Staff \celloMusic
1345 underneath the soprano stuff. We also need to add @code{<<} and
1346 @code{>>} around the music -- that tells LilyPond that there's
1347 more than one thing (in this case, @code{Staff}) happening at once. The
1348 @code{\score} looks like this now
1350 @c Indentation in this example is deliberately poor
1355 \new Voice = "one" @{
1359 \new Lyrics \lyricsto "one" \sopranoLyrics
1361 \new Staff \celloMusic
1369 This looks a bit messy; the indentation is messed up now. That is
1370 easily fixed. Here's the complete soprano and cello template.
1372 @lilypond[quote,verbatim,ragged-right]
1374 sopranoMusic = \relative c' {
1382 sopranoLyrics = \lyricmode {
1386 celloMusic = \relative c {
1397 \new Voice = "one" {
1401 \new Lyrics \lyricsto "one" \sopranoLyrics
1403 \new Staff \celloMusic
1411 @node Four-part SATB vocal score
1412 @subsection Four-part SATB vocal score
1414 Most vocal scores of music written for four-part mixed choir
1415 with orchestral accompaniment such as Mendelssohn's Elijah or
1416 Handel's Messiah have the choral music and words on four
1417 staves, one for each of SATB, with a piano reduction of the
1418 orchestral accompaniment underneath. Here's an example
1419 from Handel's Messiah:
1421 @c The following should appear as music without code
1422 @lilypond[quote,ragged-right]
1424 global = { \key d \major \time 4/4 }
1425 sopMusic = \relative c'' {
1427 r4 d2 a4 | d4. d8 a2 | cis4 d cis2 |
1429 sopWords = \lyricmode {
1430 Wor -- thy is the lamb that was slain
1432 altoMusic = \relative a' {
1434 r4 a2 a4 | fis4. fis8 a2 | g4 fis fis2 |
1436 altoWords = \sopWords
1437 tenorMusic = \relative c' {
1439 r4 fis2 e4 | d4. d8 d2 | e4 a, cis2 |
1441 tenorWords = \sopWords
1442 bassMusic = \relative c' {
1444 r4 d2 cis4 | b4. b8 fis2 | e4 d a'2 |
1446 bassWords = \sopWords
1447 upper = \relative a' {
1450 r4 <a d fis>2 <a e' a>4 |
1451 <d fis d'>4. <d fis d'>8 <a d a'>2 |
1452 <g cis g'>4 <a d fis> <a cis e>2 |
1454 lower = \relative c, {
1457 <d d'>4 <d d'>2 <cis cis'>4 |
1458 <b b'>4. <b' b'>8 <fis fis'>2 |
1459 <e e'>4 <d d'> <a' a'>2 |
1463 << % combine ChoirStaff and PianoStaff in parallel
1465 \new Staff = "sopranos" <<
1466 \set Staff.instrumentName = "Soprano"
1467 \new Voice = "sopranos" { \global \sopMusic }
1469 \new Lyrics \lyricsto "sopranos" { \sopWords }
1470 \new Staff = "altos" <<
1471 \set Staff.instrumentName = "Alto"
1472 \new Voice = "altos" { \global \altoMusic }
1474 \new Lyrics \lyricsto "altos" { \altoWords }
1475 \new Staff = "tenors" <<
1476 \set Staff.instrumentName = "Tenor"
1477 \new Voice = "tenors" { \global \tenorMusic }
1479 \new Lyrics \lyricsto "tenors" { \tenorWords }
1480 \new Staff = "basses" <<
1481 \set Staff.instrumentName = "Bass"
1482 \new Voice = "basses" { \global \bassMusic }
1484 \new Lyrics \lyricsto "basses" { \bassWords }
1488 \set PianoStaff.instrumentName = "Piano "
1489 \new Staff = "upper" \upper
1490 \new Staff = "lower" \lower
1496 None of the templates provides this layout exactly. The
1497 nearest is @q{SATB vocal score and automatic piano reduction},
1498 but we shall need to change the layout and add a piano
1499 accompaniment which is not derived automatically from the
1500 vocal parts. The variables holding the music and words for
1501 the vocal parts are fine, but we shall need to add variables for
1502 the piano reduction.
1504 The order in which the contexts appear in the ChoirStaff of
1505 the template do not correspond with the order in the vocal
1506 score shown above. We need to rearrange them so there are
1507 four staves with the words written directly underneath the
1508 notes for each part.
1509 All the voices should be @code{voiceOne}, which is
1510 the default, so the @code{\voiceXXX} commands can be removed.
1511 We also need to specify the tenor clef for the tenors.
1512 The way in which lyrics are specified has also been simplified
1513 as we have not yet encountered the method used in the template.
1514 We've also added the names of each staff.
1516 Doing this gives for our ChoirStaff:
1520 \new Staff = "sopranos" <<
1521 \set Staff.instrumentName = "Soprano"
1522 \new Voice = "sopranos" @{ \global \sopMusic @}
1524 \new Lyrics \lyricsto "sopranos" @{ \sopWords @}
1525 \new Staff = "altos" <<
1526 \set Staff.instrumentName = "Alto"
1527 \new Voice = "altos" @{ \global \altoMusic @}
1529 \new Lyrics \lyricsto "altos" @{ \altoWords @}
1530 \new Staff = "tenors" <<
1531 \set Staff.instrumentName = "Tenor"
1532 \new Voice = "tenors" @{ \global \tenorMusic @}
1534 \new Lyrics \lyricsto "tenors" @{ \tenorWords @}
1535 \new Staff = "basses" <<
1536 \set Staff.instrumentName = "Bass"
1537 \new Voice = "basses" @{ \global \bassMusic @}
1539 \new Lyrics \lyricsto "basses" @{ \bassWords @}
1543 Next we must work out the piano part. This is
1544 easy - we just pull out the piano part from the
1545 @q{Solo piano} template:
1549 \set PianoStaff.instrumentName = "Piano "
1550 \new Staff = "upper" \upper
1551 \new Staff = "lower" \lower
1555 and add the variable definitions for @code{upper}
1558 The ChoirStaff and PianoStaff must be combined
1559 using angle brackets as we want them to be
1560 stacked one above the other:
1563 << % combine ChoirStaff and PianoStaff one above the other
1565 \new Staff = "sopranos" <<
1566 \new Voice = "sopranos" @{ \global \sopMusic @}
1568 \new Lyrics \lyricsto "sopranos" @{ \sopWords @}
1569 \new Staff = "altos" <<
1570 \new Voice = "altos" @{ \global \altoMusic @}
1572 \new Lyrics \lyricsto "altos" @{ \altoWords @}
1573 \new Staff = "tenors" <<
1574 \clef "G_8" % tenor clef
1575 \new Voice = "tenors" @{ \global \tenorMusic @}
1577 \new Lyrics \lyricsto "tenors" @{ \tenorWords @}
1578 \new Staff = "basses" <<
1580 \new Voice = "basses" @{ \global \bassMusic @}
1582 \new Lyrics \lyricsto "basses" @{ bassWords @}
1586 \set PianoStaff.instrumentName = "Piano "
1587 \new Staff = "upper" \upper
1588 \new Staff = "lower" \lower
1593 Combining all these together and adding the music
1594 for the three bars of the example above gives:
1596 @lilypond[quote,verbatim,ragged-right]
1598 global = { \key d \major \time 4/4 }
1599 sopMusic = \relative c'' {
1601 r4 d2 a4 | d4. d8 a2 | cis4 d cis2 |
1603 sopWords = \lyricmode {
1604 Wor -- thy is the lamb that was slain
1606 altoMusic = \relative a' {
1608 r4 a2 a4 | fis4. fis8 a2 | g4 fis fis2 |
1610 altoWords = \sopWords
1611 tenorMusic = \relative c' {
1613 r4 fis2 e4 | d4. d8 d2 | e4 a, cis2 |
1615 tenorWords = \sopWords
1616 bassMusic = \relative c' {
1618 r4 d2 cis4 | b4. b8 fis2 | e4 d a'2 |
1620 bassWords = \sopWords
1621 upper = \relative a' {
1624 r4 <a d fis>2 <a e' a>4 |
1625 <d fis d'>4. <d fis d'>8 <a d a'>2 |
1626 <g cis g'>4 <a d fis> <a cis e>2 |
1628 lower = \relative c, {
1631 <d d'>4 <d d'>2 <cis cis'>4 |
1632 <b b'>4. <b' b'>8 <fis fis'>2 |
1633 <e e'>4 <d d'> <a' a'>2 |
1637 << % combine ChoirStaff and PianoStaff in parallel
1639 \new Staff = "sopranos" <<
1640 \set Staff.instrumentName = "Soprano"
1641 \new Voice = "sopranos" { \global \sopMusic }
1643 \new Lyrics \lyricsto "sopranos" { \sopWords }
1644 \new Staff = "altos" <<
1645 \set Staff.instrumentName = "Alto"
1646 \new Voice = "altos" { \global \altoMusic }
1648 \new Lyrics \lyricsto "altos" { \altoWords }
1649 \new Staff = "tenors" <<
1650 \set Staff.instrumentName = "Tenor"
1651 \new Voice = "tenors" { \global \tenorMusic }
1653 \new Lyrics \lyricsto "tenors" { \tenorWords }
1654 \new Staff = "basses" <<
1655 \set Staff.instrumentName = "Bass"
1656 \new Voice = "basses" { \global \bassMusic }
1658 \new Lyrics \lyricsto "basses" { \bassWords }
1662 \set PianoStaff.instrumentName = "Piano "
1663 \new Staff = "upper" \upper
1664 \new Staff = "lower" \lower
1671 @node Building a score from scratch
1672 @subsection Building a score from scratch
1674 After gaining some facility with writing LilyPond code you
1675 may find that it is easier to build a score from scratch
1676 rather than modifying one of the templates. You can also
1677 develop your own style this way to suit the sort of music you
1678 like. Let's see how to put together the score for an organ
1679 prelude as an example.
1681 We begin with a header section. Here go the title, name
1682 of composer, etc followed by the variable definitions
1683 and ending with the score block. Let's start with these and
1684 fill in the details later.
1686 We'll use the first two bars of Bach's prelude
1687 based on @emph{Jesu, meine Freude} which is set in two
1688 manuals and pedal organ. The top manual has two voices,
1689 the lower and pedal organ one each. So we need four
1690 music definitions and one to define the time signature
1696 title = "Jesu, meine Freude"
1697 composer = "J S Bach"
1699 TimeKey = @{ \time 4/4 \key c \minor @}
1700 ManualOneVoiceOneMusic = @{s1@}
1701 ManualOneVoiceTwoMusic = @{s1@}
1702 ManualTwoMusic = @{s1@}
1703 PedalOrganMusic = @{s1@}
1709 For now we've just used a spacer note, @code{s1},
1710 instead of the real music. We'll add that later.
1712 Next let's see what should go in the score block.
1713 We simply mirror the staff structure we want.
1714 Organ music is usually written on three staves,
1715 one for each manual and one for the pedals. The
1716 manual staves should be bracketed together so we
1717 need to use a PianoStaff for them. The first
1718 manual part needs two voices and the second manual
1723 \new Staff = "ManualOne" <<
1724 \new Voice @{ \ManualOneVoiceOneMusic @}
1725 \new Voice @{ \ManualOneVoiceTwoMusic @}
1726 >> % end ManualOne Staff context
1727 \new Staff = "ManualTwo" <<
1728 \new Voice @{ \ManualTwoMusic @}
1729 >> % end ManualTwo Staff context
1730 >> % end PianoStaff context
1733 Next we need to add a staff for the pedal organ.
1734 This goes underneath the PianoStaff, but it must
1735 be simultaneous with it, so we need angle brackets
1736 round the two. Missing these out would generate
1737 an error in the log file. It's a common mistake
1738 which you'll make sooner or later! Try copying
1739 the final example at the end of this section,
1740 remove these angle brackets, and compile it to
1741 see what errors it generates.
1744 << % PianoStaff and Pedal Staff must be simultaneous
1746 \new Staff = "ManualOne" <<
1747 \new Voice @{ \ManualOneVoiceOneMusic @}
1748 \new Voice @{ \ManualOneVoiceTwoMusic @}
1749 >> % end ManualOne Staff context
1750 \new Staff = "ManualTwo" <<
1751 \new Voice @{ \ManualTwoMusic @}
1752 >> % end ManualTwo Staff context
1753 >> % end PianoStaff context
1754 \new Staff = "PedalOrgan" <<
1755 \new Voice @{ \PedalOrganMusic @}
1760 It is not strictly necessary to use the simultaneous contruct
1761 @code{<< >>} for the manual two staff and the pedal organ staff,
1762 since they contain only one music expression, but it does no harm
1763 and always using angle brackets after @code{\new Staff} is a good
1764 habit to cultivate in case there are multiple voices.
1766 Let's add this structure to the score block, and adjust the
1767 indenting. We also add the appropriate clefs, ensure the
1768 second voice stems point down with @code{\voiceTwo} and
1769 enter the time signature and key to each staff using our
1770 predefined variable, @code{\TimeKey}.
1774 << % PianoStaff and Pedal Staff must be simultaneous
1776 \new Staff = "ManualOne" <<
1777 \TimeKey % set time signature and key
1779 \new Voice @{ \ManualOneVoiceOneMusic @}
1780 \new Voice @{ \voiceTwo \ManualOneVoiceTwoMusic @}
1781 >> % end ManualOne Staff context
1782 \new Staff = "ManualTwo" <<
1785 \new Voice @{ \ManualTwoMusic @}
1786 >> % end ManualTwo Staff context
1787 >> % end PianoStaff context
1788 \new Staff = "PedalOrgan" <<
1791 \new Voice @{ \PedalOrganMusic @}
1792 >> % end PedalOrgan Staff
1794 @} % end Score context
1797 That completes the structure. Any three-staff organ music
1798 will have a similar structure, although the number of voices
1799 may vary. All that remains now
1800 is to add the music, and combine all the parts together.
1802 @lilypond[quote,verbatim,ragged-right]
1805 title = "Jesu, meine Freude"
1806 composer = "J S Bach"
1808 TimeKey = { \time 4/4 \key c \minor }
1809 ManualOneVoiceOneMusic = \relative g' {
1810 g4 g f ees | d2 c2 |
1812 ManualOneVoiceTwoMusic = \relative c' {
1813 ees16 d ees8~ ees16 f ees s c8 d~ d c~ |
1814 c c4 b8 c8. g16 c b c d |
1816 ManualTwoMusic = \relative c' {
1817 c16 b c8~ c16 b c g a8 g~ g16 g aes ees |
1818 f ees f d g aes g f ees d e8~ ees16 f ees d |
1820 PedalOrganMusic = \relative c {
1821 r8 c16 d ees d ees8~ ees16 a, b g c b c8 |
1822 r16 g ees f g f g8 c,2 |
1826 << % PianoStaff and Pedal Staff must be simultaneous
1828 \new Staff = "ManualOne" <<
1829 \TimeKey % set time signature and key
1831 \new Voice { \ManualOneVoiceOneMusic }
1832 \new Voice { \voiceTwo \ManualOneVoiceTwoMusic }
1833 >> % end ManualOne Staff context
1834 \new Staff = "ManualTwo" <<
1837 \new Voice { \ManualTwoMusic }
1838 >> % end ManualTwo Staff context
1839 >> % end PianoStaff context
1840 \new Staff = "PedalOrgan" <<
1843 \new Voice { \PedalOrganMusic }
1844 >> % end PedalOrgan Staff
1846 } % end Score context
1849 @node Scores and parts
1850 @section Scores and parts
1852 TODO: this is really old stuff from the really old tutorial.
1853 Rewrite, fix, etc. Or maybe delete entirely. -gp
1854 Include section on tags -td
1855 and then move to section 5. Working ... -td
1857 In orchestral music, all notes are printed twice. Once in a part for
1858 the musicians, and once in a full score for the conductor. Variables can
1859 be used to avoid double work. The music is entered once, and stored in
1860 a variable. The contents of that variable is then used to generate
1861 both the part and the full score.
1863 It is convenient to define the notes in a special file. For example,
1864 suppose that the file @file{horn-music.ly} contains the following part
1865 of a horn/@/bassoon duo
1868 hornNotes = \relative c @{
1875 Then, an individual part is made by putting the following in a file
1878 \include "horn-music.ly"
1880 instrument = "Horn in F"
1884 \transpose f c' \hornNotes
1891 \include "horn-music.ly"
1895 substitutes the contents of @file{horn-music.ly} at this position in
1896 the file, so @code{hornNotes} is defined afterwards. The command
1897 @code{\transpose f@tie{}c'} indicates that the argument, being
1898 @code{\hornNotes}, should be transposed by a fifth upwards. Sounding
1899 @code{f} is denoted by notated @code{c'}, which corresponds with the
1900 tuning of a normal French Horn in@tie{}F. The transposition can be seen
1901 in the following output
1903 @lilypond[quote,ragged-right]
1904 \transpose f c' \relative c {
1910 In ensemble pieces, one of the voices often does not play for many
1911 measures. This is denoted by a special rest, the multi-measure
1912 rest. It is entered with a capital @code{R} followed by a duration
1913 (@code{1}@tie{}for a whole note, @code{2}@tie{}for a half note,
1914 etc.). By multiplying the
1915 duration, longer rests can be constructed. For example, this rest
1916 takes 3@tie{}measures in 2/4 time
1922 When printing the part, multi-rests
1923 must be condensed. This is done by setting a run-time variable
1926 \set Score.skipBars = ##t
1930 This command sets the property @code{skipBars} in the
1931 @code{Score} context to true (@code{##t}). Prepending the rest and
1932 this option to the music above, leads to the following result
1934 @lilypond[quote,ragged-right]
1935 \transpose f c' \relative c {
1937 \set Score.skipBars = ##t
1944 The score is made by combining all of the music together. Assuming
1945 that the other voice is in @code{bassoonNotes} in the file
1946 @file{bassoon-music.ly}, a score is made with
1949 \include "bassoon-music.ly"
1950 \include "horn-music.ly"
1953 \new Staff \hornNotes
1954 \new Staff \bassoonNotes
1961 @lilypond[quote,ragged-right]
1969 r4 d,8 f | gis4 c | b bes |
1970 a8 e f4 | g d | gis f