3 @c TODO: LilyPond Lilypond lilypond
10 * Running LilyPond:: Getting started
12 * The first tune:: The first tune
13 * Lyrics and chords:: Lyrics and chords
15 * A piano excerpt:: Piano music
16 * An orchestral score::
17 * Other ways to run LilyPond::
18 * Integrating text and music::
19 * end of tutorial:: The end
23 @node Running LilyPond
24 @section Running LilyPond
26 You make music notation with LilyPond as follows: first you edit a text
27 file containing a description of the notes. Then you run LilyPond on the
28 file. This leaves you with an output file, which you can view or print.
30 In this section we explain how to run LilyPond, and view or print the
31 output. If you want to test your setup of LilyPond, or try to run an
32 example file yourself, then read this section. Otherwise, you can skip
33 to the next section, which explains how to
36 The instructions that follow are for Unix. Windows instructions are
37 given at the end of this section. Start with opening a terminal window,
38 and start up a text editor. For example, start an xterm and execute
39 @code{joe}. Enter the following
40 input, and save the file as @file{test.ly}.
43 \notes @{ c'4 e' g' @}
46 If this code looks intimidating you, then don't worry, we explain all
47 about it in the next section.
51 @c dit is dus raar, dat je ly2dvi draait om lelie te draaien
52 @c (therefore name change proposal)
54 Invoke the program @code{ly2dvi} to run lilypond on your source file:
59 You will see the following on your screen:
62 Now processing: `/home/fred/ly/test.ly'
64 Interpreting music...[1]
65 @emph{ ... more interesting stuff ... }
66 PS output to `test.ps'...
67 DVI output to `test.dvi'...
74 The results of the ly2dvi run are two files, @file{test.dvi} and
75 @file{test.ps}. The PS file (@file{test.ps}) is the one you can
76 print. You can view the PS file using the program ghostview. If a
77 version of ghostview is installed on your system, one of these commands
78 will produce a window with some music notation on your screen.
85 When you're satisfied with the result, you can print the PS file by
86 clicking File/Print inside ghostview.
88 The DVI file (@file{test.dvi}) contains the same sheet music in a
89 different format. DVI files are more easily processed by the computer,
90 so viewing them usually is quicker. Execute @code{xdvi test}
93 If your DVI viewer does not have a "Print" button, you can print the
94 file by executing @code{lpr test.ps}.
96 @c volgende alinea schrappen?
98 If you can't get the examples to print, then you should look into
99 installing and configuring ghostscript. Refer to GhostScript's website
100 at @uref{http://www.ghostscript.com}.
104 @cindex Printing output
108 Windows users start the terminal by clicking on the lilypond icon.
109 Notepad is sufficient for editing the lilypond file. Viewing the PS file
110 can be done with @code{gsview32 test.ps}. Viewing DVI files can be done
111 with @code{yap test}. The "print" button in Yap will print files. You
112 can also print from the command line by executing @code{gsview32 /s
121 The basics of any piece of music are notes. Notes are entered
122 with letters @code{a} to @code{g}, followed by a
123 number that represents the duration: a @code{2} is a half note, a
124 @code{4} is a quarter note. A period adds a dot to the note, so
125 entering @code{2.} gives a dotted half note.
130 \property Score.timing = ##f
131 \property Staff.TimeSignature = \turnOff
132 \property Staff.Clef = \turnOff
135 If you don't specify a duration, then the duration last entered is used:
141 \property Score.timing = ##f
142 \property Staff.TimeSignature = \turnOff
143 \property Staff.Clef = \turnOff
144 \clef bass f4 e d c2.
146 The time signature can be set with a command of the form @code{\time},
147 and the clef with @code{\clef} as follows:
158 The commands together with the notes are combined to form a snippet of
159 music. They are combined by enclosing them with @code{\notes @{ @}}.
169 This snippet is ready to be printed. This is done by combining the music
170 with a printing command. The printing command is the so-called
171 @code{\paper} block. You will see later that the \paper block is
172 necessary to customize all kinds of printing specifics. The music and
173 paper block are combined by enclosing them in @code{\score}.
188 The @code{\paper} block looks empty, which means that we get default. That is because we did not contains page layout settings, such as the linewidth and
189 the staff size. For now, we'll use standard settings, hence the paper
190 block is empty (its braces enclose a blank space).
193 Rests are entered just like notes with the name @code{r}
194 @lilypond[fragment,verbatim]
198 Octaves are entered by adding apostrophes or commas to note names. For
199 example, the central C is entered as @code{c'}.
201 Pitches can be octaviated by adding apostrophes or commas. The central C is
202 @code{c'}. Going up octave by octave we get @code{c''},
203 @code{c'''}. Going down from central C, we get @code{c} @code{c,}
206 @lilypond[verbatim,fragment]
210 LilyPond uses Dutch note names: you can make a note sharp by appending
211 @code{is} to the name, and flat by appending @code{es} to the name.
212 @lilypond[verbatim,fragment]
216 Ties are created by entering a tilde (@code{~}) between the notes to be
218 @lilypond[fragment,verbatim]
221 Ties look almost the same as slurs, but they are different. Ties can
222 only indicate the extension of a note. Ties connect two note heads with
223 the same pitch. Slurs on the other hand, can be drawn across many
224 notes, and indicate bound articulation.
226 The key signature is set with the command @code{\key}:
227 @lilypond[fragment,verbatim]
234 The next example shows octave marks, ties, and rests in action.
241 r4 r8 d''8 cis''4 e''
243 cis''4 cis''8 cis'' bis'4 d''8 cis'' ~
249 There is one interesting point to note in this example: accidentals
250 don't have to be marked explicitly. You just enter the pitch, and
251 LilyPond determines wether or not to print an accidental.
253 If you look at the last piece, it is already apparent that entering
254 octaves using quotes is not very convenient. A score written in high
255 register will be encoded using lots quotes. This makes the input file
256 unreadable, and it also is a source of many errors.
258 This problem is solved by relative octave mode. In this mode, the quotes
259 are used to mark large jumps in the melody. Without any quotes or
260 commas, the interval between a note and its predecessor is assumed to be
261 a fourth or less. Quotes and commas add octaves in up and down
263 @lilypond[fragment,verbatim]
264 \relative c'' { c4 d4 b4 e4 a,4 f'4 g,4 a'4 }
266 You can enter a piece in relative mode, by putting @code{\relative} in
267 front. You also have to enter a starting pitch, in this case @code{c''}.
270 Slurs (not to be confused with ties) are entered with parentheses. You
271 mark the starting note and ending note with a @code{(} and a
272 @code{)} respectively.
274 @lilypond[fragment,relative 1, verbatim]
278 If you need two slurs at the same time (one for articulation, one for
279 phrasing), you can also make a phrasing slur with @code{\(} and
283 @lilypond[fragment,relative 1, verbatim]
284 a8(\( ais b ) c cis2 b'2 a4 cis, \) c
287 Beams are drawn automatically, but if you don't like the choices, you
288 can enter beams by hand. Surround the notes to be grouped with @code{[}
290 @lilypond[fragment,relative 1, verbatim]
294 You can make more than one staff, by specifying @code{\context Staff} before
295 snippets of music, and combining those snippets in @code{<} and
296 @code{>}, as is demonstrated here:
298 @lilypond[fragment,verbatim]
299 < \context Staff = staffA { \clef treble c'' }
300 \context Staff = staffB { \clef bass c }
303 Here, @code{staffA} and @code{staffB} are names that you give them to
304 the staff. For now, it doesn't matter what names you give them, as long
305 as they are different.
307 We can typeset a melody with two staffs now:
312 < \context Staff = staffA {
315 \relative c'' { e2 ( d4 c2 b4 [a8 a] [b b] [g g] )a2. }
317 \context Staff = staffB {
327 Notice that the time signature is specified in one melody staff only
328 (the top staff), but is printed on both. LilyPond knows that the time
329 signature should be the same for all staffs.
331 Dynamic signs are made by adding the markings after the note
332 @lilypond[verbatim,relative 1]
336 Crescendi are started with the commands @code{\<} and @code{\>}. The
337 command @code{\!} finishes a crescendo on the following.
338 @lilypond[verbatim,relative 1]
339 c2 \< \! c2-\ff \> c2 \! c2
342 Chords can be made by surrounding notes with @code{<} and @code{>}:
343 @lilypond[relative 0, fragment,verbatim]
349 In general, @code{ < @var{stuff} > } is used when @var{stuff} all
350 happens at the same time, like in chords, or (like in the two-staff
351 example above) in a bunch of stacked staffs.
353 Of course, you can combine beams and ties with chords:
354 @lilypond[relative 0, fragment,verbatim]
355 r4 [<c8 e g> <c8 f a>] ~ <c8 f a>
358 When you want to combine chords with slurs and dynamics, an annoying
359 technical detail crops up: you have type these commands next to the
360 notes, which means that they have to be inside the @code{< >}:
362 @lilypond[relative 0, fragment,verbatim]
363 r4 <c8 e g \> ( > <c e g> <c e g> < ) \! c8 f a>
366 A nasty technical detail also crops up when you start a score with a
368 @lilypond[verbatim,singleline]
369 \score { \notes <c'1 e'1> }
371 The program can not guess that you want the notes on only one staff. To
372 force the chord on a staff, add @code{\context Staff} like this:
373 @lilypond[verbatim,singleline]
374 \score { \notes \context Staff <c'1 e'1> }
381 [TODO add some more here
392 This is the end of the simple tutorial. You know the basic ingredients
393 of a music file, so this is the right moment to try your at hand at
394 doing it yourself: try to type some simple examples, and experiment a
397 When you're comfortable with the basics, then you might want to read the
398 rest of this chapter. It also a manual in tutorial-style, but it is much
399 more in-depth. It will also be very intimidating if you're not familiar
400 with the basics. It deals with some of the more advanced features of
401 lilypond. Topics include lyrics, chords, orchestral scores and parts,
402 fine tuning output, polyphonic music, and integrating text and music.
407 @section The first tune
410 This tutorial will demonstrate how to use Lilypond by presenting
411 examples of input along with resulting output. We will use English
412 terms for notation. In case you are not familiar with those, you may
413 consult the glossary that is distributed with LilyPond.
415 The examples discussed are included in the distribution, in the
416 subdirectory @file{input/tutorial/}@footnote{When we refer to filenames,
417 they are relative to the top directory of the source package. }
419 To demonstrate what LilyPond input looks like, we start off with a
420 full-fledged, yet simple example. It is a convoluted version
421 of the famous minuet in J. S. Bach's @emph{Klavierb@"uchlein}. The file
422 is included in the distribution as @file{minuet.ly}.
423 @cindex Bach, Johann Sebastian
426 % all text after a percent sign is a comment
427 % and is ignored by Lilypond
428 \include "paper16.ly"
431 \relative c'' \sequential {
436 d4 g,8 a b c d4 g, g |
437 e'4 c8 d e fis g4 g, g |
438 c4 d8( )c b a( )b4 c8 b a g |
439 a4 [b8 a] [g fis] g2. |
444 g4 e8 fis g d cis4 b8 cis a4 |
445 a8-. b-. cis-. d-. e-. fis-.
452 % standard settings are too wide for a book
458 We will analyse the input, line by line.
461 % all text after a percent sign is a comment
462 % and is ignored by Lilypond
464 Percent signs introduce comments: everything after a percent sign is
465 ignored. You can use this to write down mental notes to yourself. You
466 can also make longer comments by enclosing text in @code{%@{} and
469 @cindex block comment
474 \include "paper16.ly"
477 @cindex @code{\include}
478 @cindex point, printer's
479 @cindex staff size setting
480 By default, LilyPond will typeset the music in a size such that each
481 staff is 20 point (0.7 cm, or 0.27 inch) high. We want smaller output
482 (16 point staff height), so we must import the settings for that size,
490 Music is printed by combining a piece of music with directions for
491 outputting it. This combination is formed in the @code{\score} block.
498 Prepare LilyPond for accepting notes.
499 @cindex octaves, choosing
508 As we will see, each note is described by its note name, duration,
509 octave and possibly a chromatic alteration. In this setup, the octave
510 is indicated by using high quotes (@code{'}) and ``lowered quotes''
511 (commas: @code{,}). The central C is denoted by @code{c'}. The C one
512 octave higher is @code{c''}. One and two octaves below the central C is
513 denoted by @code{c} and @code{c,} respectively.
515 Even though a piece of music often spans a range of several octaves, it
516 mostly moves in small intervals. LilyPond has a special entry mode to
517 save typing in this situation. In this ``relative'' octave mode,
518 octaves of notes without quotes are chosen such that a note is as close
519 as possible (graphically, on the staff) to the preceding note. If you
520 add a high-quote an extra octave is added. A lowered quote (a comma)
521 will subtract an extra octave.
523 Because the first note has no predecessor,
524 you have to give the (absolute) pitch of the note to start with.
531 What follows is sequential music, i.e.,
532 @cindex sequential music
533 notes that are to be played and printed after each other.
540 @cindex time signature, setting
542 Set (or change) the time signature of the current piece: a 3/4 sign is
543 printed. The time signature setting is also used to generate bar lines
551 @cindex key signature, setting
553 Set (or change) the current key signature to G-major. Although in this
554 example, the @code{\key} command happened to be entered after the
555 @code{\time} command, in the output the time signature will be printed
556 after the key signature; LilyPond knows about music typesetting
564 The following piece of music is played twice. The first argument
565 indicates the type of repeat. In this case, @code{"volta"} means that
566 prima volta/secunda volta brackets are used for the alternative
567 endings---if there were any.
574 The subject of the repeat is again sequential music. Since
575 @code{\sequential} is such a common construct, a shorthand is provided:
576 just leave off @code{\sequential}, and the result is the same.
583 Two notes. The first note is a quarter note with relative pitch
584 @code{d}. The relative music was started with a @code{c''}, so the real
585 pitch of this note is @code{d''}. The duration of a note is designated
586 by a number; the @code{4} here represents a quarter note.
588 The second note is an eight note with relative pitch @code{g,}. The
589 pitch is taken relative to the previous @code{d''}, making this
590 note have real pitch @code{g'}. The @code{8} represents an eight note.
597 Two more notes, with pitch @code{a} and @code{b}. Because their
598 duration is the same as the @code{g,8}, there is no need to enter the
599 duration, but you may enter it anyway, i.e., @code{a4 b4}
608 @cindex errors, finding
609 Three more notes. The @code{|} character is a ``bar check''. LilyPond
610 will verify that bar checks are found at the start of a measure. This can
611 help you track down typing errors.
613 @cindex alteration, chromatic
614 @cindex chromatic alteration
621 So far, no notes were chromatically altered. Here is the first one that
622 is: @code{fis}. Lilypond by default uses Dutch@footnote{Note names are
623 available in several languages, but we find the Dutch names quite
624 convenient.} note names, and ``Fis'' is the Dutch note name for ``F
625 sharp''. However, there is no sharp sign in the output. The program
626 keeps track of key signatures, and will only print accidentals if they
629 For groups of eighth notes and shorter, LilyPond can determine how the
630 notes should form a beam. In this case, the 4 eights are automatically
635 c4 d8( )c b a( )b4 c8 b a g |
638 The beginning and ending notes of a slur are marked with parentheses,
639 @code{(} and @code{)} for start and end respectively. The line above
640 indicates two slurs. These slur markers (parentheses) are entered
641 between the slurred notes.
648 Automatic beaming can be overridden by inserting beam marks, @code{[}
649 and @code{]}. These beam markers (brackets) are put around the notes
657 @cindex augmentation dot
659 A period adds a dot to the note.
666 The end of the sequential music to be repeated. LilyPond will typeset a
674 Accidentals are printed whenever necessary: the first C sharp of the bar
675 will be printed with an accidental, the second one without.
679 a8-. b-. cis-. d-. e-. fis-.
683 You can enter articulation signs either in a verbose form or using a
684 shorthand. Here we demonstrate the shorthand: it is formed by a dash
685 and the character for the articulation to use, e.g. @code{-.} for
686 staccato as shown above.
694 Rests are denoted by the special notename @code{r}.
701 All articulations have a verbose form, like @code{\fermata}. The
702 command @code{\fermata} is not part of the core of the language, but it
703 is a shorthand for a more complicated description of a fermata symbol.
704 @code{\fermata} names that description and is therefore called an
707 @cindex @code{\fermata}
713 Here the music ends. LilyPond does not automatically typeset and end
714 bar, we must explicitely request one, using @code{"|."}.
724 The @code{\paper} block specifies how entered music should be converted
725 to notation output. Most of the details of the conversion (font sizes,
726 dimensions, etc.) have been taken care of, but to fit the output in this
727 document, it has to be narrower. We do this by setting the line width
728 to 14 centimeters (approximately 5.5 inches).
735 The last brace ends the @code{\score} block.
740 @node Lyrics and chords
741 @section Lyrics and chords
743 In this section we show how to typeset a song. This file is
744 included as @file{flowing.ly}.
748 title = "The river is flowing"
749 composer = "Traditional"
751 \include "paper16.ly"
752 melody = \notes \relative c' @{
756 c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
757 c4 c8 d [es () d] c4 | d4 es8 d c4.
762 The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
763 ri -- ver is flo -- wing down to the sea.
766 accompaniment =\chords @{
768 c2:3- f:3-.7 d:min es4 c8:min r8
769 c2:min f:min7 g:7^3.5 c:min @}
774 \context ChordNames \accompaniment
777 \context Staff = mel @{
778 \property Staff.noAutoBeaming = ##t
779 \property Staff.automaticMelismata = ##t
782 \context Lyrics \text
784 \midi @{ \tempo 4=72 @}
785 \paper @{ linewidth = 10.0\cm @}
790 The result would look this.@footnote{The titling and font size shown
791 may differ, since the titling in this document is not generated by
794 @center @strong{The river is flowing}
799 title = "The river is flowing"
800 composer = "Traditional"
802 \include "paper16.ly"
803 melody = \notes \relative c' {
807 c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
808 c4 c8 d [es () d] c4 | d4 es8 d c4.
813 The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
814 ri -- ver is flo -- wing down to the sea.
817 accompaniment =\chords {
819 c2:3- f:3-.7 d:min es4 c8:min r8
820 c2:min f:min7 g:7^3.5 c:min }
825 \context ChordNames \accompaniment
828 \context Staff = mel {
829 \property Staff.noAutoBeaming = ##t
830 \property Staff.automaticMelismata = ##t
833 \context Lyrics \text
835 \midi { \tempo 4=72 }
836 \paper { linewidth = 10.0\cm }
840 Again, we will dissect the file line by line.
847 @cindex @code{\header}
848 Information about the music you are about to typeset goes into a
849 @code{\header} block. The information in this block is not used by
850 LilyPond, but it is passed into the output. @file{ly2dvi} uses this
851 information to print titles above the music.
855 title = "The river is flowing"
856 composer = "Traditional (?)"
859 @cindex identifier assignment
860 the @code{\header} block contains assignments. In each assignment, a
861 variable is set to a value. Lexically, both the variable name and the
862 assigned value are strings. The values have to be quoted here, because
863 they contain spaces, the variable names could also be put within quotes
864 but it is not necessary.
868 \include "paper16.ly"
871 Smaller size for inclusion in a book.
875 melody = \notes \relative c' @{
878 The structure of the file will be the same as the previous one, a
879 @code{\score} block with music in it. To keep things readable, we will
880 give names to the different parts of music, and use the names to
881 construct the music within the score block.
888 @cindex @code{\partial}
890 The piece starts with an anacrusis of one eighth.
895 The key is C minor: we have three flats.
900 c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
901 c4 c8 d [es () d] c4 | d4 es8 d c4.
906 @cindex manual beaming
907 @cindex automatic beaming, turning off
908 We use explicit beaming. Since this is a song, we turn automatic
909 beams off, and use explicit beaming where needed.
916 This ends the definition of @code{melody}.
925 @cindex identifier assignment
926 @cindex syllables, entering
927 Another identifier assignment. This one is for the lyrics.
928 Lyrics are formed by syllables that have duration, and not by
929 notes. To make LilyPond parse words as syllables, switch it into
930 lyrics mode with @code{\lyrics}. Again, the brace after @code{\lyrics}
931 is a shorthand for @code{\sequential @{}.
935 The4 ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
936 ri- ver is flo- __ wing down to the sea.
940 @cindex extenders, lyric
941 @cindex hyphens, lyric
942 The syllables themselves are separated by spaces. You can get syllable
943 extenders by entering @code{__}, and centered hyphens with
944 @code{-}@code{-}. We enter the syllables as if they are all quarter notes
945 in length (hence the @code{4}), and use a feature to align the
946 syllables to the music, which obviously isn't all quarter notes.
950 accompaniment =\chords @{
955 We'll put chords over the music. To enter them, there is a special mode
956 analogous to @code{\lyrics} and @code{\notes} mode, where you can give
957 the names of the chords you want, instead of listing the notes
958 comprising the chord.
965 There is no accompaniment during the anacrusis.
974 @cindex chord modifier
975 @cindex modifier, chord
976 A chord is started by the tonic of the chord. The
977 first one lasts a half note. An unadorned note creates a major
978 triad. Since a minor triad is wanted, @code{3-} is added to modify the
979 third to be small. @code{7} modifies (adds) a seventh, which is small by
980 default to create the @code{f a c es} chord. Multiple modifiers must be
989 Some modifiers have predefined names, eg. @code{min} is the same as
990 @code{3-}, so @code{d-min} is a minor @code{d} chord.
994 c2:min f:min7 g:7^3.5 c:min @}
997 @cindex named modifier
999 A named modifier @code{min} and a normal modifier @code{7} do not have
1000 to be separated by a dot. Tones from a chord are removed with chord
1001 subtractions. Subtractions are started with a caret, and they are
1002 also separated by dots. In this example, @code{g:7^3.5} produces a
1003 minor seventh. The brace ends the sequential music.
1011 We assemble the music in the @code{\score} block. Melody, lyrics and
1012 accompaniment have to sound at the same time, so they should be
1013 @code{\simultaneous}.
1014 @cindex @code{\simultaneous}
1021 Chord mode generates notes grouped in @code{\simultaneous} music. If
1022 you remove the comment sign, you can see the chords in normal
1023 notation: they will be printed as note heads on a separate
1024 staff. To print them as chords names, they have to be interpreted as
1025 being chords, not notes. This is done with the following command:
1029 \context ChordNames \accompaniment
1033 @cindex interpretation context
1034 @cindex notation context
1037 Normally, the notes that you enter are transformed into note heads.
1038 Note heads alone make no sense, they need surrounding information: a key
1039 signature, a clef, staff lines, etc. They need @emph{context}. In
1040 LilyPond, these symbols are created by objects called `interpretation
1041 contexts'. Interpretation contexts exist for generating notation
1042 (`notation context') and for generating sound (`performance
1043 context'). These objects only exist during a run of LilyPond.
1045 By default, LilyPond will create a Staff context for you. If you would
1046 remove the @code{%} sign in the previous line, you would see that
1047 mechanism in action.
1049 We don't want that default here, because we want chord names. The
1050 command above explicitly creates an interpretation context of
1051 @code{ChordNames} type to interpret the music @code{\accompaniment}.
1058 @cindex @code{\addlyrics}
1059 @cindex lyrics and melody, combining
1060 @cindex combining lyrics and melody
1062 The lyrics should be aligned with the melody. This is done by
1063 combining both with @code{\addlyrics}. @code{\addlyrics} takes two
1064 pieces of music (usually a melody and lyrics, in that order) and
1065 aligns the syllables of the second piece under the notes of the
1066 first piece. If you would reverse the order, the notes would be
1067 aligned on the lyrics, which is not very useful, and looks
1072 \context Staff = mel @{
1076 The second argument of @code{\addlyrics} is the melody. We instantiate
1077 a @code{Staff} context explicitly: should you choose to remove the
1078 comment before the ``note heads'' version of the accompaniment, the
1079 accompaniment will be on a nameless staff. The melody has to be on
1080 staff different from the accompaniment. This is accomplished by giving
1081 the melody and accompaniment staffs different names.
1085 \property Staff.noAutoBeaming = ##t
1089 @cindex context variables
1090 @cindex setting context variables
1091 An interpretation context has variables, called properties, that tune
1092 its behaviour. One of the variables is @code{noAutoBeaming}. Setting
1093 this Staff's property to @code{##t}, which is the boolean value @var{true},
1094 turns the automatic beaming mechanism off for the current staff.
1097 @cindex accessing Scheme
1098 @cindex evaluating Scheme
1101 LilyPond internally uses GUILE, a Scheme-interpreter. Scheme is a
1102 language from the LISP family. You can learn more about Scheme at
1103 @uref{http://www.scheme.org}. It is used to represent data throughout
1104 the whole program. The hash-sign (@code{#}) accesses GUILE directly: the
1105 code following the hash-sign is evaluated as Scheme. The boolean value
1106 @var{true} is @code{#t} in Scheme, so for LilyPond @var{true} looks like
1109 If Scheme scares you, don't worry. You don't need to know Scheme to
1110 create beautiful sheet music.
1117 \property Staff.automaticMelismata = ##t
1120 @cindex automaticMelismata
1122 @cindex @code{\addlyrics} and slurs
1123 Similarly, we don't want to print a syllable when there is
1124 a slur. This sets up @code{\addlyrics} to not put lyrics under each
1125 separate note while there is a slur.
1133 Finally, we put the melody on the current staff. Note that the
1134 @code{\property} directives and @code{\melody} are grouped in sequential
1135 music, so the property settings are done before the melody is
1140 \context Lyrics \text
1143 The second argument of @code{\addlyrics} is the text. The text also
1144 should not land on a Staff, but on a interpretation context for
1145 syllables, extenders, hyphens etc. This context is called
1150 \midi @{ \tempo 4=72@}
1153 MIDI (Musical Instrument Digital Interface) is a standard for
1154 connecting and recording digital instruments. So a MIDI file is like a
1155 tape recording of an instrument. The @code{\midi} block causes makes the
1156 music go to a MIDI file, so you can listen to the music you entered. It
1157 is great for checking the music. Whenever you hear something weird, you
1158 probably hear a typing error.
1160 Syntactically, @code{\midi} is similar to @code{\paper @{ @}}, since it
1161 also specifies an output method. You can specify the tempo using the
1162 @code{\tempo} command, in this case the tempo of quarter notes is set to
1163 72 beats per minute.
1167 \paper @{ linewidth = 10.0\cm @}
1170 We also want notation output. The linewidth is short so the piece
1171 will be set in two lines.
1173 @node More movements
1174 @section More movements
1176 [FIXME: merge here with, or move this to: Other ways to run LilyPond]
1178 You probably ran @file{ly2dvi} on the last example, and ended up with a
1179 viewable @file{.dvi} file. However, between there are a few steps of
1180 which LilyPond is only one. To enhance your understanding of what's
1181 happening under the hood when you run @code{ly2dvi}, we explain what
1184 @code{ly2dvi} is a program that calls a number of programs in sequence.
1185 The first thing it does, is running LilyPond on the input file. After
1186 some calculations, a @file{.tex} is produced. The contents
1187 of this file are very low-level instructions.
1189 For example, the following file (@file{miniatures.ly})
1194 title = "Two miniatures"
1195 tagline = "small is beautiful"
1198 #(set! point-and-click line-column-location)
1200 \paper @{ linewidth = -1.0 @}
1203 \notes @{ c'4 d'4 @}
1209 \notes @{ d'4 c'4 @}
1216 The titling in this manual was not generated by ly2dvi, so we can't
1217 exactly show it would look, but the result should resemble this:
1219 @center @strong{Two miniatures}
1229 \paper { linewidth = -1.0 }
1241 \paper { linewidth = -1.0 }
1245 This file is produced by ly2dvi in a few stages, with the help of text
1246 formatting tools. LilyPond produces two output files,
1247 @file{miniatures.tex} and @file{miniatures-1.tex}. Both files contain
1248 only graphical music notation. @file{ly2dvi} looks at what output
1249 LilyPond produces, and adds page layout and titling to those files. The
1250 result is a DVI file called @file{miniatures.dvi}.
1252 Next, now we'll look at the example line by line to explain new things.
1258 Lilypond and its language are still under development, and occasionally,
1259 details of the syntax are changed. This fragment indicates for which
1260 version the input file was written. When you compile this file, the
1261 version number will be checked, and you will get a warning when the file
1264 This version number is also used by the @code{convert-ly} program (See
1265 @ref{convert-ly}), which uses it to update the file to the latest lily
1271 title = "Two miniatures" @}
1273 This sets the titling information for the entire file.
1276 tagline = "small is beautiful"
1278 A signature line is printed at the bottom of the last page.
1279 This signature is produced from the @code{tagline} field of
1280 @code{\header}. Many people find the default "Lily was here,
1281 @var{version number}" too droll. If that is the case, assign
1282 something else to @code{tagline}, as shown above.
1285 #(set! point-and-click line-column-location)
1288 This piece of Scheme code sets the Scheme variable
1289 @code{point-and-click} to the value @var{line-column-location} (which
1290 itself is a Scheme procedure).
1292 Editing input files can be quite complicated if you're working with
1293 large files: if you're digitizing existing music, you have to
1294 synchronize the .ly file, the sheet music on your lap and the sheet
1295 music on the screen. The point-and-click mechanism makes it easy to
1296 find the origin of an error in the LY file: when you view the file with
1297 Xdvi and click on a note, your editor will jump to the spot where that
1298 note was entered. For more information, see @ref{Point and click}.
1305 The @code{\score} blocks that follow in the file don't have
1306 @code{\paper} sections, so the settings of this block are substituted: A
1307 paper block, at top-level, i.e. not in a @code{\score} block sets the
1308 default page layout.
1317 The variable @code{linewidth} normally sets the length of the systems on
1318 the page. However, a negative value has a special meaning. If
1319 @code{linewidth} is less than 0, no line breaks are inserted into the
1320 score, and the spacing is set to natural length: a short phrase takes up
1321 little space, a longer phrase more space.
1326 \notes @{ c'4 d'4 @}
1329 In previous examples, notes were specified in relative octaves,
1330 i.e. each note was put in the octave that would put it closest to its
1331 predecessor. Besides relative, there is also absolute octave
1332 specification, which you get when you don't specify @code{\relative}. In
1333 this input mode, the central C is denoted by @code{c'}. Going down, you
1334 get @code{c} @code{c,} @code{c,,} etc. Going up, you get @code{c''}
1337 When you're copying music from existing sheet music, relative octaves
1338 are probably the easiest to use: it's less typing work and errors are
1339 easily spotted. However, if you write LilyPond input directly, either by
1340 hand (i.e. composing) or by computer, absolute octaves are easier to use.
1348 The @code{\header} is normally at the top of the file, where it sets
1349 values for the rest of the file. If you want to typeset different pieces
1350 from one file (for example, if there are multiple movements, or if
1351 you're making an exercise book), you can put different @code{\score}
1352 blocks into the input file. ly2dvi will assemble all LilyPond output
1353 files into a big document. The contents of \header blocks specified
1354 within each score, are used for the titling of each movement.
1360 For example, the Opus number is put at the right, and the piece string
1361 will be at the left.
1365 @node A piano excerpt
1366 @section A piano excerpt
1368 Our fourth subject is a piece of piano music. The fragment in the input
1369 file is a piano reduction of the G major Sinfonia by Giovanni Battista
1370 Sammartini. It was composed around 1740. It's in the source package
1371 under the name @file{sammartini.ly}.
1374 \include "paper16.ly"
1376 stemDown = \property Voice.Stem \override #'direction = #-1
1377 stemUp = \property Voice.Stem \override #'direction = #1
1378 stemBoth = \property Voice.Stem \revert #'direction
1380 viola = \notes \relative c' \context Voice = viola {
1381 <c4-\f-\arpeggio g' c>
1387 oboes = \notes \relative c'' \context Voice = oboe {
1388 \stemUp s4 g8. b,16 c8 r <e'8.^\p g> <f16 a>
1389 \grace <e8( g> <d4 )f> <c2 e>
1390 \times 2/3 { <d8 \< f> <e g> <f a> }
1392 { \times 2/3 { a8 g c } \! c2 }
1393 \context Voice = oboeTwo {
1396 \property Grace.Stem \override #'direction = #-1
1402 \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |
1403 [<d ( f> < )f8. a>] <)b,8 d> r [<d16( f> <f8. )a>] <b,8 d> r |
1404 [<c16( e> < )e8. g>] <c8 e,>
1407 hoomPah = \repeat unfold 8 \notes
1408 \transpose c' { \stemUp c8 \stemBoth \stemDown c'8 \stemBoth }
1410 bassvoices = \notes \relative c' {
1412 \autochange Staff \hoomPah
1413 \translator Staff = down
1414 \stemDown [c8 c'8] r4
1416 < {\stemUp r2 <e4 c'> <c8 g'> }
1417 \context Voice = reallyLow {\stemDown g2 ~ | g4 c8 } >
1421 \context PianoStaff \notes <
1422 \context Staff = up < \time 2/2
1426 \context Staff = down < \time 2/2 \clef bass
1433 linewidth = 15.0 \cm }
1437 If this looks like incomprehensible gibberish to you, you are right.
1438 This example has been doctored to have as many quirks as possible.
1440 As you can see, this example features multiple voices on one staff. To
1441 make room for those voices, their notes have to be stemmed in opposite
1444 Printed symbols are internally represented by so-called Graphical
1445 Objects (more colloquially: Grobs). These statements concern the
1446 grob called `Stem'. Each grob is described by a bunch of settings. These
1447 setting determine the fonts, offsets, sub-routines to be called on the
1448 grob, etc. The initial values of these settings are set in the Scheme
1449 file @file{scm/grob-description.scm}.
1453 stemDown = \property Voice.Stem \override #'direction = #-1
1456 Set a proprerty for all Stem grobs in the current Voice:
1457 @code{direction} is set to @code{-1}, which encodes down. The setting
1458 remains in effect until it is reverted.
1462 \property Voice.Stem \revert #'direction
1465 Revert the to the previous setting. The effect of precisely one
1466 @code{\stemDown} or @code{\stemUp} is neutralised.
1469 LilyPond includes the identifiers @code{\stemUp}, @code{\stemDown} along
1470 with some other commonly used formatting instructions, but to explain how
1471 it works, we wrote our own here. Of course, you should use predefined
1472 identifiers like these if possible: then you will be affected less by
1473 the implementation changes we occasionally make.
1477 viola = \notes \relative c' \context Voice = viola @{
1479 In this example, you can see multiple parts on a staff. Each part is
1480 associated with one notation context. This notation context handles
1481 stems and dynamics (among others). The name of this context is
1482 @code{Voice}. For each part we have to make sure that there is
1483 precisely one @code{Voice} context, so we give it an unique name
1488 <c4-\f-\arpeggio g' c>
1490 The delimiters @code{<} and @code{>} are shorthands for
1491 @code{\simultaneous @{} and @code{@}}. The expression enclosed in
1492 @code{<} and @code{>} is a chord.
1499 @code{\f} places a forte symbol under the chord. The forte applies to
1500 the whole chord, but the syntax requires that commands like forte and
1501 arpeggio are attached to a note, so here we attach them to the first
1504 @code{\arpeggio} typesets an arpeggio sign (a wavy vertical line) before
1517 Relative octaves work a little differently with chords. The starting
1518 point for the note following a chord is the first note of the chord. So
1519 the @code{g} gets an octave up quote: it is a fifth above the starting
1520 note of the previous chord (the central C).
1526 @code{s} is a spacer rest. It does not print anything, but it does have
1527 the duration of a rest. It is useful for filling up voices that
1528 temporarily don't play. In this case, the viola doesn't come until one
1529 and a half measure later.
1533 oboes = \notes \relative c'' \context Voice = oboe @{
1535 Now comes a part for two oboes. They play homophonically, so we
1536 print the notes as one voice that makes chords. Again, we insure that
1537 these notes are indeed processed by precisely one context with
1541 \stemUp s4 g8. b,16 c8 r <e'8.-\p g> <f16 a>
1543 @code{\stemUp} is a reference to the @code{\property \override} command
1547 \grace <e8 g> < d4 f> <c2 e>
1549 @cindex @code{\grace}
1553 @code{\grace} introduces grace notes. It takes one argument, in this
1557 The slur started on the @code{e} of the chord
1558 will be attached to the next note.@footnote{LilyPond will squirm
1559 about unended Slurs. In this case, you can ignore the warning}.
1567 Tuplets are made with the @code{\times} keyword. It takes two
1568 arguments: a fraction and a piece of music. The duration of the piece
1569 of music is multiplied by the fraction. Triplets make notes occupy 2/3
1570 of their notated duration, so in this case the fraction is 2/3.
1573 @{ <d8 \< f> <e g> <f a> @}
1575 The piece of music to be `tripletted' is sequential music containing
1576 three notes. On the first chord, a crescendo is started with
1577 @code{\<}. To be precise, the crescendo start is syntactically attached
1578 to the preceding note, the @code{d}.
1588 At this point, the homophonic music splits into two rhythmically
1589 different parts. We can't use a sequence of chords to enter this, so
1590 we make a `chord' of sequences to do it. We start with the upper
1591 voice, which continues with upward stems:
1594 @{ \times 2/3 @{ a8 g c @} \! c2 @}
1599 The crescendo is ended at the half note by the escaped exclamation
1603 \context Voice = oboeTwo @{
1606 We can't share stems with the other voice, so we have to create a new
1607 @code{Voice} context. We give it the name @code{oboeTwo} to distinguish
1608 it from the other context. Stems go down in this voice.
1613 @cindex Grace context
1614 When a grace section is processed, a @code{Grace} context is
1615 created. This context acts like a miniature score of its own. It has
1616 its own time bookkeeping, and you can make notes, beams, slurs
1617 etc. Here we fiddle with a property and make a beam. The argument of
1618 @code{\grace} is sequential music.
1622 \property Grace.Stem \override #'direction = #-1
1626 Normally, grace notes are always stem up, but in this case, the upper
1627 voice interferes. We set the stems down here.
1629 As far as relative mode is concerned, the previous note is the
1630 @code{c'''2} of the upper voice, so we have to go an octave down for
1638 This ends the two-part section.
1642 \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |
1647 @code{\stemBoth} ends the forced stem directions. From here, stems are
1648 positioned as if it were single part music.
1650 The bass has a little hoom-pah melody to demonstrate parts switching
1651 between staffs. Since it is repetitive, we use repeats:
1654 hoomPah = \repeat unfold 8
1656 @cindex unfolded @code{\repeat}
1657 The unfolded repeat prints the notes in its argument as if they were
1658 written out in full eight times.
1661 \notes \transpose c' @{
1664 @cindex relative mode and transposing
1666 Transposing can be done with @code{\transpose}. It takes two arguments
1667 the first specifies what central C should be transposed to. The second
1668 is the to-be-transposed music. As you can see, in this case, the
1669 transposition has no effect, as central C stays at central C.
1671 The purpose of this no-op is circumventing relative mode. Relative mode
1672 can not be used together with transposition, so @code{\relative} will
1673 leave the contents of @code{\hoomPah} alone. We can use it without
1674 having to worry about getting the motive in a wrong octave.
1677 bassvoices = \notes \relative c' @{
1679 \autochange Staff \hoomPah
1681 @cindex staff switch, automatic
1682 @cindex cross staff voice, automatic
1683 @cindex @code{\autochange}
1685 Voices can switch between staffs. The easiest way to get this, is to use
1686 @code{\autochange}. This command looks at the pitch of each note, and if
1687 necessary, will cross to the other staff. For this to work, the two
1688 staffs must be called @code{"up"} and @code{"down"}.
1691 \translator Staff = down
1693 @cindex staff switch
1694 @cindex cross staff voice
1695 We want the remaining part of this melody on the lower staff, so we do a
1696 manual staff switch here.
1701 \context Voice = reallyLow @{\stemDown g2 ~ | g4 c8 @} >
1705 After skipping some lines, we see @code{~}. This mark makes ties. Note
1706 that ties and slurs are different things. A tie can only connect two
1707 note heads of the same pitch, whereas a slur can connect many chords
1714 A special context is needed to get cross staff beaming right. This
1715 context is called @code{PianoStaff}.
1718 \context Staff = bottom < \time 2/2 \clef bass
1720 The bottom staff must have a different clef.
1725 To make some more room on the line, the first (in this case the only)
1726 line is not indented. The line still looks very cramped, but that is due
1727 to the page layout of this document.
1733 * font-size, multi-stanza.
1735 * Simple part combining in a Hymn
1739 @node An orchestral score
1740 @section An orchestral score
1744 * Extracting an individual part::
1748 Our last two examples show a way to setup the music for an orchestral
1749 score. When typesetting a piece for several instruments, you'll want to
1750 create a conductor's full score, alongside several individual parts.
1752 LilyPond is well suited for this task. We will declare the music for
1753 each instrument individually, giving the music of each instrument its
1754 own name. These pieces of music are then combined in different
1755 @code{\score} blocks to produce different combinations of the score.
1757 This orchestral score example consists of three input files. In the
1758 first file, @file{os-music.ly}, we define the music for all instruments.
1759 This file will be used both for producing the score and the separate
1762 If you were to run lilypond on this file, no printable output would be
1768 title = "Zo, goed lieverd?"
1769 subtitle = "How's, this babe?"
1778 Key = \notes \key as \major
1779 flautoI = \notes\relative c'' @{
1781 bes as bes as bes as bes as
1783 flautoII = \notes\relative c'' @{
1784 as8 bes as bes R1 d4 ~ d
1786 tromboI = \notes\relative c'' @{
1787 c4. c8 c8 c4. es4 r as, r
1789 tromboII = \notes\relative c'' @{
1790 as4. as8 as8 as4. R1*1/2 as4 es'
1792 timpani = \notes\relative c, @{
1793 \times 2/3 @{ f4 f f @}
1794 \times 4/5 @{ as8 as as as as @}
1797 corno = \notes\relative c' @{
1798 bes4 d f, bes d f, bes d
1802 We will not go through the input line by line, but only indicate and
1803 explain the new elements.
1810 \skip 2*4 \bar "|.";
1814 Declare setting to be used globally. The @code{\skip} command produces
1815 no output, but moves forward in time: in this case, the duration of a
1816 half note (@code{2}), and that four times (@code{*4}). This brings us
1817 to the end of the piece, and we can set the end bar.
1821 Key = \notes \key as \major
1823 Declare the key signature of the piece and assign it to the identifier
1824 @var{Key}. Lateron, we'll use @code{\Key} for all staffs except those
1825 for transposing instruments.
1827 @node The full score
1828 @subsection The full score
1831 The second file, @file{os-score.ly} reads the definitions of the first
1832 (@file{os-music.ly}), and defines the @code{\score} block for the full
1838 \include "os-music.ly"
1839 \include "paper13.ly"
1841 #(set! point-and-click line-column-location)
1842 #(define text-flat '((font-relative-size . -2)
1843 (music "accidentals--1")))
1848 \property Score.BarNumber \override #'padding = #3
1849 \context StaffGroup = woodwind <
1850 \context Staff = flauti <
1851 \property Staff.midiInstrument = #"flute"
1852 \property Staff.instrument = "2 Flauti"
1853 \property Staff.instr = "Fl."
1855 \context Voice=one @{ \voiceOne \flautoI @}
1856 \context Voice=two @{ \voiceTwo \flautoII @}
1859 \context StaffGroup = timpani <
1860 \context Staff = timpani <
1861 \property Staff.midiInstrument = #"timpani"
1862 \property Staff.instrument = #'(lines "Timpani" "(C-G)")
1863 \property Staff.instr = #"Timp."
1869 \context StaffGroup = brass <
1870 \context Staff = trombe <
1871 \property Staff.midiInstrument = #"trumpet"
1872 \property Staff.instrument = #`(lines "2 Trombe" "(C)")
1873 \property Staff.instr = #`(lines "Tbe." "(C)")
1875 \context Voice=one \partcombine Voice
1876 \context Thread=one \tromboI
1877 \context Thread=two \tromboII
1879 \context Staff = corni <
1880 \property Staff.midiInstrument = #"french horn"
1881 \property Staff.instrument = #`(lines "Corno"
1882 (columns "(E" ,text-flat ")"))
1883 \property Staff.instr = #`(lines "Cor."
1884 (columns "(E" ,text-flat ")"))
1885 \property Staff.transposing = #3
1886 \notes \key bes \major
1887 \context Voice=one \corno
1892 indent = 15 * \staffspace
1893 linewidth = 60 * \staffspace
1894 textheight = 90 * \staffspace
1897 \consists "Multi_measure_rest_engraver"
1900 \HaraKiriStaffContext
1901 \remove "Multi_measure_rest_engraver"
1910 @center @strong{Zo, goed lieverd?}
1912 @center How's, this babe?
1920 @lilypondfile{os-score.ly}
1924 \include "os-music.ly"
1926 First, we need to include the music definitions we made in
1931 #(set! point-and-click line-column-location)
1933 In a large orchestral score like this you're bound to make some small
1934 mistakes, so we enable point and click (See @ref{Point and click})
1939 #(define text-flat '((font-relative-size . -2)
1940 (music "accidentals--1")))
1943 When naming the tuning of the french horn, we'll need a piece of text
1944 with a flat sign. LilyPond has a mechanism for font selection and
1945 kerning called Scheme markup text (See @ref{Text markup}). The flat
1946 sign is taken from the music font, and its name is @code{accidentals--1}
1947 (The sharp sign is called @code{accidentals-+1}). The default font is
1948 too big for text, so we select a relative size of @code{-2}.
1955 Of course, all staffs are simultaneous and use the same global settings.
1959 \property Score.BarNumber \override #'padding = #3
1961 LilyPond prints bar numbers at the start of each line, but
1962 unfortunately, they end up a bit too close to the staff in this example.
1963 A bar number internally is a Grob called @var{BarNumber}. BarNumber
1964 Grobs can be manipulated through their @var{side-position-interface}. One
1965 of the properties of a @var{side-position-interface} that can be tweaked
1966 is the @var{padding}: the amount of extra space that is put between this
1967 Grob and other Grobs. We set the padding to three staff spaces.
1969 You can find all this kind of information in LilyPond's automatically
1970 generated documentation in
1972 @ref{ (lilypond-internals)lilypond-internals, LilyPond Internals}.
1975 the online documentation.
1980 \context StaffGroup = woodwind <
1981 \context Staff = flauti <
1983 A new notation context: the StaffGroup. StaffGroup can hold one or more
1984 Staffs, and will print a big bracket at the left of the score. Start a
1985 new staff group for the woodwind section (just the flutes in this case).
1986 Immediately after that, we start the staff for the two flutes, that also
1987 play simultaneously.
1991 \property Staff.midiInstrument = #"flute"
1993 Specify the instrument for MIDI output (see @ref{MIDI instrument
1998 \property Staff.instrument = "2 Flauti"
1999 \property Staff.instr = "Fl."
2001 And define the instrument names to be printed in the margin,
2002 @code{instrument} for the first line of the score, @code{instr} for the
2009 The flutes play in the default key.
2013 \context Voice=one @{ \voiceOne \flautoI @}
2014 \context Voice=two @{ \voiceTwo \flautoII @}
2016 Last come the actual flute parts. Remember that we're still in
2017 simultaneous mode. We name both voices differently, so that LilyPond
2018 will actually create two Voice contexts. The flute parts are simple, so
2019 we specify manually which voice is which: @code{\voiceOne} forces the
2020 direction of stems, beams, slurs and ties up, @code{\voiceTwo} sets
2028 Close the flutes staff and woodwind staff group.
2032 \property Staff.instrument = #'(lines "Timpani" "(C-G)")
2034 The timpani staff only shows a new piece of scheme markup, it sets two
2039 \context Voice=one \partcombine Voice
2040 \context Thread=one \tromboI
2041 \context Thread=two \tromboII
2043 You have seen the notation contexts Staff and Voice, but here's a new
2044 one: Thread. One or more Threads can be part of a Voice. The Thread
2045 takes care of note heads and rests, the Voice combine note heads onto a
2048 For the trumpets we use the automatic part combiner (see @ref{Automatic
2049 part combining}) to combine the two simultaneous trumpet parts onto the
2050 trumpet staff. Each trumpet gets its own Thread context, which must be
2051 named @code{one} and @code{two}). The part combiner makes these two
2052 threads share a Voice when they're similar, and splits the threads up
2053 when they're different.
2057 \property Staff.instrument = #`(lines "Corno"
2058 (columns "(E" ,text-flat ")"))
2060 The french horn has the most complex scheme markup name, made up of two
2061 lines of text. The second line has two elements (columns), the @code{E}
2062 and the flat sign @code{text-flat} that we defined before.
2066 \property Staff.transposing = #3
2068 The french horn is to be tuned in E-flat, so we tell the MIDI backend to
2069 transpose this staff by three steps.
2071 Note how we can choose different tuning for entering, printing and
2072 playing, using @code{\transpose} and the MIDI Staff proprerty
2077 \notes \key bes \major
2079 Therefore, it has a different key.
2083 indent = 15 * \staffspace
2084 linewidth = 60 * \staffspace
2086 We specify a big indent for the first line and a small linewidth for this
2091 Usually, LilyPond's predefined setup of notation contexts (Thread,
2092 Voice, Staff, Staffgroup, Score) is just fine. But in this case, we
2093 want a different type of Staff context.
2095 In orchestral scores, it often happens that one instrument has only
2096 rests during one line of the score. The @code{HaraKiriStaffContext} can
2097 be used as a regular @code{StaffContext} drop-in and will take care of
2098 the automatic removing of empty staffs.
2100 @node Extracting an individual part
2101 @subsection Extracting an individual part
2103 The third file, @file{os-flute-2.ly} also reads the definitions of the
2104 first (@file{os-music.ly}), and defines the @code{\score} block for the
2108 \include "os-music.ly"
2109 \include "paper16.ly"
2113 \property Score.skipBars = ##t
2114 \property Staff.midiInstrument = #"flute"
2120 instrument = "Flauto II"
2123 linewidth = 80 * \staffspace
2124 textheight = 200 * \staffspace
2132 @center @strong{Zo, goed lieverd?}
2134 @center How's, this babe?
2135 @center @emph{Flauto II}
2142 @lilypondfile{os-flute-2.ly}
2145 Because we separated the music definitions from the @code{\score}
2146 instantiations, we can easily define a second score from the music of
2147 the second flute. This then is the part for the second flute player.
2148 Of course, we make separate parts for all individual instruments.
2154 In this individual part the second flute has a whole staff for itself,
2155 so we don't want to force stem or tie directions.
2160 instrument = "Flauto II"
2163 The @code{\header} definitions were also read from @file{os-music.ly},
2164 but we need to set the instrument for this particular score.
2168 \property Score.skipBars = ##t
2170 In the conductor's full score, all bars with rests are printed, but for
2171 the individual parts, we want to contract pieces of consecutive empty
2172 bars. LilyPond will do this if Score's @var{skipBars} property to
2176 @node Other ways to run LilyPond
2177 @section Other ways to run LilyPond
2179 Until now, you have been using @file{ly2dvi} to invoke LilyPond.
2180 There are three other routes. Firstly, there is a script called
2181 @code{lilypond-book}, that allows you to freely mix LilyPond input with
2182 Texinfo or LaTeX input. For example, this manual was written using
2183 @code{lilypond-book}. It is discussed in @ref{lilypond-book}.
2186 Secondly, you can generate PostScript directly. This is useful if you
2187 can not or do not want to run @TeX{} on your system. To obtain direct
2188 PostScript output, invoke LilyPond as follows:
2189 @cindex PostScript output
2191 lilypond -f ps test.ly
2193 You have to set some environment variables to view or print this
2194 output. More information can be found in @ref{Invoking
2198 Thirdly, if you want to do special things with your output, you can run
2199 invoke lilypond directly:
2203 to produce plain @TeX{} output. Note that La@TeX{} will not work on the
2204 resulting @file{test.tex}. You must run plain @TeX{} on it.
2212 @node Integrating text and music
2213 @section Integrating text and music
2215 Sometimes, you might want to use music examples in a text that you are
2216 writing. For example, if you are writing a musicological treatise, a
2217 songbook, or (like us) the LilyPond manual. You can make such texts by
2218 hand, simply by importing a PostScript figure into your wordprocessor.
2219 However, there is a also an automated procedure:
2221 If you use La@TeX{} or texinfo, you can mix text and lilypond code. A
2222 script called @code{lilypond-book} will extract the music fragments, run
2223 lilypond on them, and put back the resulting notation. lilypond-book is
2224 described fully in @ref{lilypond-book}, but here we show a small
2225 example. Since the example also contains explanatory text, we won't
2226 comment on the contents.
2229 \documentclass[a4paper]@{article@}
2232 In a lilypond-book document, you can freely mix music and text. For
2235 \score @{ \notes \relative c' @{
2236 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
2239 Notice that the music line length matches the margin settings of the
2242 If you have no \verb+\score+ block in the fragment,
2243 \texttt@{lilypond-book@} will supply one:
2249 In the example you see here, a number of things happened: a
2250 \verb+\score+ block was added, and the line width was set to natural
2251 length. You can specify many more options using \LaTeX style options
2254 \begin[verbatim,11pt,singleline,
2255 fragment,relative,intertext="hi there!"]@{lilypond@}
2259 \texttt@{verbatim@} also shows the lilypond code, \texttt@{11pt@} selects
2260 the default music size, \texttt@{fragment@} adds a score block,
2261 \texttt@{relative@} uses relative mode for the fragment, and
2262 \texttt@{intertext@} specifies what to print between the
2263 \texttt@{verbatim@} code and the music.
2265 If you include large examples into the text, it may be more convenient
2266 to put the example in a separate file:
2268 \lilypondfile[printfilename]@{sammartini.ly@}
2270 The \texttt@{printfilename@} option adds the file name to the output.
2275 Under Unix, you can view the results as follows.
2278 $ lilypond-book --outdir=out/ lilbook.tex
2279 lilypond-book (GNU LilyPond) 1.3.146
2280 Reading `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/lilbook.tex'
2282 `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/sammartini.ly'
2283 @var{lots of stuff deleted}
2284 Writing `out/lilbook.latex'
2286 $ latex lilbook.latex
2287 @var{lots of stuff deleted}
2291 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
2292 and running latex creates a lot of temporary files, and you wouldn't
2293 those to clutter up your working directory. Hence, we have them created
2294 in a separate subdirectory.
2296 The result more or less looks like this:
2300 In a lilypond-book document, you can freely mix music and text. For
2303 \score { \notes \relative c' {
2304 c2 g'2 \times 2/3 { f8 e d } c'2 g4
2307 Notice that the music line length matches the margin settings of the
2310 If you have no @code{\score} block in the fragment,
2311 @code{lilypond-book} will supply one:
2317 In the example you see here, a number of things happened: a
2318 @code{\score} block was added, and the line width was set to natural
2319 length. You can specify many more options using La@TeX{} style options
2322 @lilypond[verbatim,11pt,singleline,
2323 fragment,relative,intertext="hi there!"]
2327 @code{verbatim} also shows the lilypond code, @code{11pt} selects
2328 the default music size, @code{fragment} adds a score block,
2329 @code{relative} uses relative mode for the fragment, and
2330 @code{intertext} specifies what to print between the
2331 @code{verbatim} code and the music.
2333 If you include large examples into the text, it may be more convenient
2334 to put the example in a separate file:
2336 @lilypondfile[printfilename]{sammartini.ly}
2338 The @code{printfilename} option adds the file name to the output.
2339 @node end of tutorial
2342 That's all folks. From here, you can either try fiddling with input
2343 files, or you can read the reference manual. You can find more example
2344 files in @file{input} and @file{input/test}. You can also look at some
2345 real music. The website @uref{http://www.mutopiaproject.org} has many
2346 examples of real music typeset by LilyPond.
2354 this should be on mutopia website.
2359 @c waar deze info? is uiteindelijk wel handig, schat ik.
2362 If you have a big music project, or just a lot of LilyPond input files,
2363 all generated output from LilyPond, @TeX{} and metafont will clutter
2364 your working directory. LilyPond comes with a one-size-fits-all
2365 pre-cooked makefile that helps you manage producing output. It will
2366 produce all output in the directory @file{out} , generate and track
2367 dependencies. Also, it helps in preparing your submission to @ref{Mutopia
2374 cp /usr/share/lilypond/make/ly.make GNUmakefile
2375 cp /usr/share/doc/lilypond/examples/input/tutorial/minuet.ly .
2378 Generated out/minuet.ps for target minuet.
2381 Type @samp{make help} to see possible targets.
2384 @file{/usr/share/lilypond/doc/lilypond/examples/input/mutopia-header.ly}
2390 [TODO: rewrite completely.]
2393 * Songs with additional verses::