3 @c TODO: LilyPond LilyPond LilyPond
9 <!--- @@WEB-TITLE@@=Tutorial --->
13 * First steps:: Music language of LilyPond
14 * Simple legend:: Small table of music language symbols
15 * Running LilyPond:: Printing music
16 * The first real tune:: The first real tune
17 * Lyrics and chords:: Lyrics and chords
18 * More movements :: Joining separate pieces of music
19 * A piano excerpt:: Piano music
20 * An orchestral score:: Conductor's score and individual parts
21 * Other ways to run LilyPond:: Other ways to run LilyPond
22 * Integrating text and music:: Integrating text and music
23 * End of tutorial:: The end
27 The music is described in a text file, using a simple music language.
28 LilyPond reads that text file and generates music that you can print or
31 Therefore, creating music notation with LilyPond is done in two steps.
32 Using a text editor, you write down the notes to print. Then, you run
33 LilyPond to get your printed output.
35 This tutorial starts with a small introduction to the LilyPond music
36 language. After this first contact, we will show you how to run
37 LilyPond to produce printed output; you should then be able to create
38 your first sheets of music.
40 The tutorial continues with a slightly more elaborate example of real music.
41 This piece introduces and explains some finer details of LilyPond.
42 Then, a number of more complex examples follow, that will help you to
43 produce most complex music with LilyPond.
51 @c @node Music language of LilyPond
52 @c @section Music language of LilyPond
54 This section shows how easy writing music with LilyPond actually is. If
55 you have not seen LilyPond input source before, this section is for you.
57 The next section has a table (see @ref{Simple legend}) of all symbols
58 that are introduced here, you may want to keep an eye on that.
60 Writing music with LilyPond is explained below by a number of small
61 examples. Each example has a small piece of text; the LilyPond input
62 that you should type, with the resulting music printed below it.
64 You get a simple note by typing its note name, from @code{a} through
73 \property Score.timing = ##f
74 \property Staff.TimeSignature = \turnOff
75 \transpose c'' { c d e f g a b }
80 The length of a note is specified by adding a number, ``@code{1}'' for a
81 whole note, ``@code{2}'' for a half note, and so on:
88 @c missing clef seems to raise more questions than actual pitch of notes,
89 @c as these are snippets anyway
91 \property Score.timing = ##f
92 \property Staff.TimeSignature = \turnOff
93 \property Staff.noAutoBeaming = ##t
94 %\property Staff.Clef = \turnOff
95 \transpose c'' { a1 a2 a4 a16 a32 }
101 If you don't specify a duration, the previous duration is used:
108 @c missing clef seems to raise more questions than actual pitch of notes,
109 @c as these are snippets anyway
111 \property Score.timing = ##f
112 \property Staff.TimeSignature = \turnOff
113 %\property Staff.Clef = \turnOff
114 \transpose c'' { a a a2 a }
120 A sharp (@texisharp{}) is made by adding ``@code{is}'', a flat
121 (@texiflat{}) by adding ``@code{es}'':
129 \property Score.timing = ##f
130 \property Staff.TimeSignature = \turnOff
131 \transpose c'' { cis1 ees fisis aeses }
137 Add a dot ``@code{.}'' after the duration to get a dotted note:
143 @c missing clef seems to raise more questions than actual pitch of notes,
144 @c as these are snippets anyway
146 \property Score.timing = ##f
147 \property Staff.TimeSignature = \turnOff
148 %\property Staff.Clef = \turnOff
149 \transpose c'' { a2. a4 a8. a16 }
155 The meter (or time signature) can be set with the ``@code{\time}'' command:
164 @c a clef here may lead to confusion
166 \property Staff.Clef = \turnOff
177 The clef can be set using the ``@code{\clef}'' command:
179 @c what is more common name treble or violin?
180 @c in Dutch, its violin.
190 \property Score.timing = ##f
191 \property Staff.TimeSignature = \turnOff
204 From these commands and notes, a piece of music can be formed. A piece
205 of music is made by enclosing it in ``@code{\notes @{ ... @}}''.
206 LilyPond then knows that music follows (and not lyrics, for example):
220 At this point, the piece of music is ready to be printed. This is done
221 by combining the music with a printing command.
223 The printing command is the so-called ``@code{\paper}'' block. You will
224 see later that the \paper block is necessary to customize all kinds of
225 printing specifics. The music and the \paper block are combined by
226 enclosing them in ``@code{\score @{ ... @}}''. This is what a full
227 LilyPond source file looks like:
250 \paper { linewidth = 60 * \staffspace }
257 We continue with the introduction of the remaining musical constructs.
259 @c maybe legend here?
261 Normal rests are entered just like notes with the name ``@code{r}'':
269 \property Score.timing = ##f
270 \property Staff.Clef = \turnOff
271 \property Staff.TimeSignature = \turnOff
278 @c Tim wants to move this quotes example just before the: quotes-don't-work
279 @c score, but we'd need to remove quotes from the other two (key and
282 @c better to have this just before the `octaves are bad' snipped
283 @c but we'd need to remove the ', from \key and tie
284 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
285 the note name, to lower a note one octave, add a ``low quote'' @code{,}
286 (a comma). The central C is @code{c'}:
290 c'4 c'' c''' \clef bass c c,
294 \property Score.timing = ##f
295 \property Staff.TimeSignature = \turnOff
296 c'4 c'' c''' \clef bass c c,
301 A tie is created by entering a tilde ``@code{~}'' between the notes to
302 be tied. A tie between two notes means that the second note must not be
303 played separately, but just makes the first note sound longer:
306 @lilypond[fragment,verbatim]
312 The key signature is set with the command ``@code{\key}'':
322 \property Staff.TimeSignature = \turnOff
331 @c bit on the long/complex/scary taste
332 @c cheating a bit: two lines makes for a friendlier look
333 This example shows notes, ties, octave marks, and rests in action.
334 Don't worry about all the quotes.
343 r4 r8 d''8 cis''4 e''
345 cis''4 cis''8 cis'' bis'4 d''8 cis'' ~
358 r4 r8 d''8 cis''4 e''
360 cis''4 cis''8 cis'' bis'4 d''8 cis'' ~
363 \paper { linewidth = 50*\staffspace }
369 There are some interesting points to note in this example. Firstly,
370 accidentals (sharps and flats) don't have to be marked explicitly: you
371 just enter the note name, and LilyPond determines whether or not to
372 print an accidental. Secondly, bar lines and beams are drawn
373 automatically. Thirdly, LilyPond calculates line breaks for you; it
374 doesn't matter where you make new lines in the source file.
376 The example also indicates that a piece of music written in a high
377 register needs lots of quotes. This makes the input a bit unreadable,
378 and is therefore also a potential source of errors.
382 The solution is to use ``relative octave'' mode. In practice, most
383 music is entered using this mode.
385 To use relative mode, add @code{\relative} before the piece of music.
386 You must also give a note from which relative starts, in this case
389 @c In relative octave mode, quotes are used to mark large jumps in the
390 @c melody. Without any quotes or commas, the interval between a note and
391 @c its predecessor is assumed to be a fourth or less. Quotes and commas
392 @c add octaves in up and down direction.
394 If you type no octaviation quotes, relative mode chooses the note that
395 is closest to the previous one, which is often just the one you need.
396 @c don't use commas or quotes in this sentence
397 For example: @code{c f} goes up; @code{c g} goes down:
407 \property Score.timing = ##f
408 \property Staff.TimeSignature = \turnOff
416 @c needed better, maybe even redundant explanation
417 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
418 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
419 You can make a large interval by adding octaviation quotes. Note that
420 quotes or commas do not determine the absolute height of a note;
421 the height of a note is relative to the previous one.
422 @c don't use commas or quotes in this sentence
423 For example: @code{c f,} goes down; @code{f, f} are both the same;
424 @code{c c'} are the same; and @code{c g'} goes up:
434 \property Score.timing = ##f
435 \property Staff.TimeSignature = \turnOff
443 A slur is drawn across many notes, and indicates bound articulation
444 (legato). The starting note and ending note are marked with a
445 ``@code{(}'' and a ``@code{)}'' respectively:
448 @lilypond[fragment,relative 1, verbatim]
449 d4( )c16( cis d e c cis d )e( )d4
454 If you need two slurs at the same time (one for articulation, one for
455 phrasing), you can also make a phrasing slur with @code{\(} and
460 @lilypond[fragment,relative 1, verbatim]
461 a8(\( ais b ) c cis2 b'2 a4 cis, \) c
466 Beams are drawn automatically, but if you don't like the choices, you
467 can enter beams by hand. Surround the notes to be grouped with @code{[}
470 @lilypond[fragment,relative 1, verbatim]
476 To print more than one staff, each piece of music that makes up a staff
477 is marked by adding @code{\context Staff} before it. These
478 @code{Staff}'s can be grouped inside @code{<} and @code{>}, as is
482 @lilypond[fragment,verbatim]
484 \context Staff = staffA { \clef violin c'' }
485 \context Staff = staffB { \clef bass c }
490 In this example, @code{staffA} and @code{staffB} are names that are
491 given to the staves. For now, it doesn't matter what names you give, as
492 long as each staff has a unique name.
496 We can typeset a melody with two staves now:
502 < \context Staff = staffA {
505 \relative c'' { e2 ( d4 c2 b4 [a8 a] [b b] [g g] )a2. }
507 \context Staff = staffB {
518 Notice that the time signature is specified in one melody staff only
519 (the top staff), but is printed on both. LilyPond knows that the time
520 signature should be the same for all staves.
524 Common accents can be added to a note using @code{-.}, @code{--}, @code{->}:
526 @lilypond[verbatim,relative 1]
532 Dynamic signs are made by adding the markings to the note:
534 @lilypond[verbatim,relative 1]
540 Crescendi are started with the commands @code{\<} and @code{\>}. The
541 command @code{\!} finishes a crescendo on the following note.
543 @lilypond[verbatim,relative 1]
544 c2\< \!c2-\ff \>c2 \!c2
549 Chords can be made by surrounding notes with @code{<} and @code{>}:
551 @lilypond[relative 0, fragment,verbatim]
559 @c hmm, te losjes, iig
560 In general, @code{ < @var{stuff} > } is used when @var{stuff} all
561 happens at the same time, like in chords, or (like in the two-staff
562 example above) in a bunch of stacked staves.
565 Of course, you can combine beams and ties with chords. Notice that
566 beam and tie markings are placed outside the chord markers:
568 @lilypond[relative 0, fragment,verbatim]
569 r4 [<c8 e g> <c8 f a>] ~ <c8 f a>
573 When you want to combine chords with slurs and dynamics, an annoying
574 technical detail crops up: you have type these commands next to the
575 notes, which means that they have to be inside the @code{< >}:
578 @lilypond[relative 0, fragment,verbatim]
579 r4 <c8 e g \> ( > <c e g> <c e g> < ) \! c8 f a>
584 A nasty technical detail also crops up when you start a score with a
588 @lilypond[verbatim,singleline]
589 \score { \notes <c'1 e'1> }
594 The program can not guess that you want the notes on only one staff. To
595 force the chord on a staff, add @code{\context Staff} like this:
598 @lilypond[verbatim,singleline]
599 \score { \notes \context Staff <c'1 e'1> }
608 [TODO add some more here
619 This is the end of the simple tutorial. You know the basic ingredients
620 of a music file, so this is the right moment to try your at hand at
621 doing it yourself: try to type some simple examples, and experiment a
624 When you're comfortable with the basics, then you might want to read the
625 rest of this chapter. It also a manual in tutorial-style, but it is much
626 more in-depth. It will also be very intimidating if you're not familiar
627 with the basics. It deals with some of the more advanced features of
628 LilyPond. Topics include lyrics, chords, orchestral scores and parts,
629 fine tuning output, polyphonic music, and integrating text and music.
632 @c refer to this section
634 @section Simple legend
637 @c need texinfo-4.0a or later for this
640 @c both Tim and my father came independently with a request for a
641 @c `legend' like this.
643 @c what should be in it?
648 @multitable @columnfractions .10 .20 .40
653 @lilypond[fragment, relative 1]
654 \property Score.timing = ##f
655 \property Staff.TimeSignature = \turnOff
656 \property Staff.noAutoBeaming = ##t
657 \property Staff.Clef = \turnOff
664 @lilypond[fragment, relative 1]
665 \property Score.timing = ##f
666 \property Staff.TimeSignature = \turnOff
667 \property Staff.noAutoBeaming = ##t
668 \property Staff.Clef = \turnOff
675 @lilypond[fragment, relative 1]
676 \property Score.timing = ##f
677 \property Staff.TimeSignature = \turnOff
678 \property Staff.noAutoBeaming = ##t
679 \property Staff.Clef = \turnOff
685 @lilypond[fragment, relative 1]
686 \property Score.timing = ##f
687 \property Staff.TimeSignature = \turnOff
688 \property Staff.noAutoBeaming = ##t
689 \property Staff.Clef = \turnOff
696 @lilypond[fragment, relative 1]
697 \property Score.timing = ##f
698 \property Staff.TimeSignature = \turnOff
699 \property Staff.noAutoBeaming = ##t
700 \property Staff.Clef = \turnOff
707 @lilypond[fragment, relative 1]
708 \property Score.timing = ##f
709 \property Staff.TimeSignature = \turnOff
710 \property Staff.noAutoBeaming = ##t
711 \property Staff.Clef = \turnOff
712 \context Voice { <a c> }
718 @lilypond[fragment, relative 1]
719 \property Score.timing = ##f
720 \property Staff.TimeSignature = \turnOff
721 \property Staff.noAutoBeaming = ##t
722 \property Staff.Clef = \turnOff
729 @lilypond[fragment, relative 1]
730 \property Score.timing = ##f
731 \property Staff.TimeSignature = \turnOff
732 \property Staff.noAutoBeaming = ##t
733 \property Staff.Clef = \turnOff
742 @node Running LilyPond
743 @section Running LilyPond
745 You write music with LilyPond as follows: first you edit a text file
746 containing a description of the notes. Then you run LilyPond on the
747 file. This leaves you with an output file, which you can view or print.
749 In this section we explain how to run LilyPond, and view or print the
750 output. If you have not used LilyPond before, want to test your setup
751 of LilyPond, or try to run an example file yourself, then read this
754 The instructions that follow are for running LilyPond on Unix-like
755 systems. Some additional instructions for running LilyPond on Windows
756 are given at the end of this section.
758 You begin with opening a terminal window, and start up a text editor.
759 For example, open an xterm and execute @code{joe}. In your text editor,
760 enter the following input, and save the file as @file{test.ly}:
765 \notes @{ c'4 e' g' @}
772 @c now this is weird, running ly2dvi to run LilyPond
773 @c (therefore name change proposal)
775 To run LilyPond, you invoke ly2dvi to compile your LilyPond source file:
783 You will see the following on your screen:
788 Now processing: `/home/fred/ly/test.ly'
790 Interpreting music...[1]
791 @emph{ ... more interesting stuff ... }
792 PS output to `test.ps'...
793 DVI output to `test.dvi'...
797 @cindex Viewing music
800 The results of the ly2dvi run are two files, @file{test.dvi} and
801 @file{test.ps}. The PS file (@file{test.ps}) is the one you can print.
802 You can view the PS file using the program ghostview. If a version of
803 ghostview is installed on your system, one of these commands will
804 produce a window with some music notation on your screen:
814 If you are satisfied with the looks of the music displayed on your
815 screen, you can print the PS file by clicking File/Print inside
818 The DVI file (@file{test.dvi}) contains the same sheet music in a
819 different format. DVI files are more easily processed by the computer,
820 so viewing them usually is quicker. Execute @code{xdvi test.dvi}
821 to view the DVI file.
823 If your DVI viewer does not have a "Print" button, you can print the
824 file by executing @code{lpr test.ps}.
826 @c volgende alinea schrappen?
828 If you can't get the examples to print, then you should look into
829 installing and configuring ghostscript. Refer to GhostScript's website
830 at @uref{http://www.ghostscript.com}.
834 @cindex Printing output
837 @unnumberedsubsec Windows users
838 Windows users start the terminal by clicking on the LilyPond or Cygwin
839 icon. Notepad is sufficient for editing the LilyPond file. Viewing
840 the PS file can be done with:
843 @code{gsview32 test.ps}
846 You can also print from the command line by executing:
849 @code{gsview32 /s test.ps}
854 @node The first real tune
855 @section The first real tune
858 The rest of this tutorial will demonstrate how to use Lilypond by
859 presenting examples of input along with resulting output. We will use
860 English terms for notation. In case you are not familiar with those,
861 you may consult the glossary that is distributed with LilyPond.
863 The examples discussed are included in the distribution, in the
864 subdirectory @file{input/tutorial/}@footnote{When we refer to filenames,
865 they are relative to the top directory of the source package. }
867 To demonstrate what LilyPond input looks like, we start off with a
868 full-fledged, yet simple example. It is a convoluted version
869 of the famous minuet in J. S. Bach's @emph{Klavierb@"uchlein}. The file
870 is included in the distribution as @file{minuet.ly}.
871 @cindex Bach, Johann Sebastian
874 % all text after a percent sign is a comment
875 % and is ignored by LilyPond
876 \include "paper16.ly"
879 \relative c'' \sequential {
884 d4 g,8 a b c d4 g, g |
885 e'4 c8 d e fis g4 g, g |
886 c4 d8( )c b a( )b4 c8 b a g |
887 a4 [b8 a] [g fis] g2. |
892 g4 e8 fis g d cis4 b8 cis a4 |
893 a8-. b-. cis-. d-. e-. fis-.
900 % standard settings are too big and wide for a book
907 We will analyse the input, line by line.
910 % all text after a percent sign is a comment
911 % and is ignored by LilyPond
913 Percent signs introduce comments: everything after a percent sign is
914 ignored. You can use this to write down mental notes to yourself. You
915 can also make longer comments by enclosing text in @code{%@{} and
918 @cindex block comment
923 \include "paper16.ly"
926 @cindex @code{\include}
927 @cindex point, printer's
928 @cindex staff size, setting
929 @cindex font size, setting
931 By default, LilyPond will typeset the music in a size such that each
932 staff is 20 point (0.7 cm, or 0.27 inch) high. We want smaller output
933 (16 point staff height), so we must import the settings for that size,
941 Music is printed by combining a piece of music with directions for
942 outputting it. This combination is formed in the @code{\score} block.
949 Prepare LilyPond for accepting notes.
950 @cindex octaves, choosing
959 @c removed duplicate introduction to octave marks /MB
960 @c Shorten even more?
962 @c As we will see, each note is described by its note name, duration,
963 @c octave and possibly a chromatic alteration. In this setup, the octave
964 @c is indicated by using high quotes (@code{'}) and ``lowered quotes''
965 @c (commas: @code{,}). The central C is denoted by @code{c'}. The C one
966 @c octave higher is @code{c''}. One and two octaves below the central C is
967 @c denoted by @code{c} and @code{c,} respectively.
969 Even though a piece of music often spans a range of several octaves, it
970 mostly moves in small intervals. LilyPond has a special entry mode to
971 save typing in this situation. In this ``relative'' octave mode,
972 octaves of notes without quotes are chosen such that a note is as close
973 as possible (graphically, on the staff) to the preceding note. If you
974 add a high-quote an extra octave is added. A lowered quote (a comma)
975 will subtract an extra octave.
977 Because the first note has no predecessor,
978 you have to give the (absolute) pitch of the note to start with.
985 What follows is sequential music, i.e.,
986 @cindex sequential music
987 notes that are to be played and printed after each other.
994 @cindex time signature, setting
996 Set (or change) the time signature of the current piece: a 3/4 sign is
997 printed. The time signature setting is also used to generate bar lines
1005 @cindex key signature, setting
1007 Set (or change) the current key signature to G-major. Although in this
1008 example, the @code{\key} command happened to be entered after the
1009 @code{\time} command, in the output the time signature will be printed
1010 after the key signature; LilyPond knows about music typesetting
1018 The following piece of music is played twice. The first argument
1019 indicates the type of repeat. In this case, @code{"volta"} means that
1020 prima volta/secunda volta brackets are used for the alternative
1021 endings---if there were any.
1028 The subject of the repeat is again sequential music. Since
1029 @code{\sequential} is such a common construct, a shorthand is provided:
1030 just leave off @code{\sequential}, and the result is the same.
1037 Two notes. The first note is a quarter note with relative pitch
1038 @code{d}. The relative music was started with a @code{c''}, so the real
1039 pitch of this note is @code{d''}. The duration of a note is designated
1040 by a number; the @code{4} here represents a quarter note.
1042 The second note is an eight note with relative pitch @code{g,}. The
1043 pitch is taken relative to the previous @code{d''}, making this
1044 note have real pitch @code{g'}. The @code{8} represents an eight note.
1051 Two more notes, with pitch @code{a} and @code{b}. Because their
1052 duration is the same as the @code{g,8}, there is no need to enter the
1053 duration, but you may enter it anyway, i.e., @code{a8 b8}
1062 @cindex errors, finding
1063 Three more notes. The @code{|} character is a ``bar check''. LilyPond
1064 will verify that bar checks are found at the start of a measure. This can
1065 help you track down typing errors.
1067 @cindex alteration, chromatic
1068 @cindex chromatic alteration
1075 So far, no notes were chromatically altered. Here is the first one that
1076 is: @code{fis}. LilyPond by default uses Dutch@footnote{Note names are
1077 available in several languages, but we find the Dutch names quite
1078 convenient.} note names, and ``Fis'' is the Dutch note name for ``F
1079 sharp''. However, there is no sharp sign in the output. The program
1080 keeps track of key signatures, and will only print accidentals if they
1083 For groups of eighth notes and shorter, LilyPond can determine how the
1084 notes should form a beam. In this case, the 4 eights are automatically
1089 c4 d8( )c b a( )b4 c8 b a g |
1092 The beginning and ending notes of a slur are marked with parentheses,
1093 @code{(} and @code{)} for start and end respectively. The line above
1094 indicates two slurs. These slur markers (parentheses) are entered
1095 between the slurred notes.
1102 Automatic beaming can be overridden by inserting beam marks, @code{[}
1103 and @code{]}. These beam markers (brackets) are put around the notes
1111 @cindex augmentation dot
1113 A period adds a dot to the note.
1120 The end of the sequential music to be repeated. LilyPond will typeset a
1128 Accidentals are printed whenever necessary: the first C sharp of the bar
1129 will be printed with an accidental, the second one without.
1133 a8-. b-. cis-. d-. e-. fis-.
1136 @cindex articulation
1137 You can enter articulation signs either in a verbose form or using a
1138 shorthand. Here we demonstrate the shorthand: it is formed by a dash
1139 and the character for the articulation to use, e.g. @code{-.} for
1140 staccato as shown above.
1148 Rests are denoted by the special note name @code{r}.
1155 All articulations have a verbose form, like @code{\fermata}. The
1156 command @code{\fermata} is not part of the core of the language, but it
1157 is a shorthand for a more complicated description of a fermata symbol.
1158 @code{\fermata} names that description and is therefore called an
1161 @cindex @code{\fermata}
1167 Here the music ends. LilyPond does not automatically typeset an end
1168 bar, we must explicitly request one, using @code{"|."}.
1174 % standard settings are too big and wide for a book
1180 The @code{\paper} block specifies how entered music should be converted
1181 to notation output. Most of the details of the conversion (font sizes,
1182 dimensions, etc.) have been taken care of, but to fit the output in this
1183 document, it has to be narrower. We do this by setting the line width
1184 to 14 centimeters (approximately 5.5 inches).
1191 The last brace ends the @code{\score} block.
1196 @node Lyrics and chords
1197 @section Lyrics and chords
1199 In this section we show how to typeset a song. This file is
1200 included as @file{flowing.ly}.
1204 title = "The river is flowing"
1205 composer = "Traditional"
1207 \include "paper16.ly"
1208 melody = \notes \relative c' @{
1212 c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
1213 c4 c8 d [es () d] c4 | d4 es8 d c4.
1218 The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
1219 ri -- ver is flo -- wing down to the sea.
1222 accompaniment =\chords @{
1224 c2:3- f:3-.7 d:min es4 c8:min r8
1225 c2:min f:min7 g:7^3.5 c:min @}
1230 \context ChordNames \accompaniment
1233 \context Staff = mel @{
1234 \property Staff.noAutoBeaming = ##t
1235 \property Staff.automaticMelismata = ##t
1238 \context Lyrics \text
1240 \midi @{ \tempo 4=72 @}
1241 \paper @{ linewidth = 10.0\cm @}
1246 The result would look this.@footnote{The titling and font size shown
1247 may differ, since the titling in this document is not generated by
1250 @center @strong{The river is flowing}
1255 title = "The river is flowing"
1256 composer = "Traditional"
1258 \include "paper16.ly"
1259 melody = \notes \relative c' {
1263 c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
1264 c4 c8 d [es () d] c4 | d4 es8 d c4.
1269 The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
1270 ri -- ver is flo -- wing down to the sea.
1273 accompaniment =\chords {
1275 c2:3- f:3-.7 d:min es4 c8:min r8
1276 c2:min f:min7 g:7^3.5 c:min }
1281 \context ChordNames \accompaniment
1284 \context Staff = mel {
1285 \property Staff.noAutoBeaming = ##t
1286 \property Staff.automaticMelismata = ##t
1289 \context Lyrics \text
1291 \midi { \tempo 4=72 }
1292 \paper { linewidth = 10.0\cm }
1296 Again, we will dissect the file line by line.
1303 @cindex @code{\header}
1304 Information about the music you are about to typeset goes into a
1305 @code{\header} block. The information in this block is not used by
1306 LilyPond, but it is passed into the output. @file{ly2dvi} uses this
1307 information to print titles above the music.
1311 title = "The river is flowing"
1312 composer = "Traditional (?)"
1315 @cindex identifier assignment
1316 the @code{\header} block contains assignments. In each assignment, a
1317 variable is set to a value. Lexically, both the variable name and the
1318 assigned value are strings. The values have to be quoted here, because
1319 they contain spaces. The variable names could also be put within quotes
1320 but it is not necessary.
1324 \include "paper16.ly"
1327 Smaller size for inclusion in a book.
1331 melody = \notes \relative c' @{
1334 The structure of the file will be the same as the previous one, a
1335 @code{\score} block with music in it. To keep things readable, we will
1336 give names to the different parts of music, and use the names to
1337 construct the music within the score block.
1344 @cindex @code{\partial}
1346 The piece starts with an anacrusis of one eighth.
1351 The key is C minor: we have three flats.
1356 c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
1357 c4 c8 d [es () d] c4 | d4 es8 d c4.
1362 @cindex manual beaming
1363 @cindex automatic beaming, turning off
1364 We use explicit beaming. Since this is a song, we turn automatic
1365 beams off, and use explicit beaming where needed.
1372 This ends the definition of @code{melody}.
1381 @cindex identifier assignment
1382 @cindex syllables, entering
1383 Another identifier assignment. This one is for the lyrics.
1384 Lyrics are formed by syllables that have duration, and not by
1385 notes. To make LilyPond parse words as syllables, switch it into
1386 lyrics mode with @code{\lyrics}. Again, the brace after @code{\lyrics}
1387 is a shorthand for @code{\sequential @{}.
1391 The4 ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
1392 ri- ver is flo- __ wing down to the sea.
1396 @cindex extenders, lyric
1397 @cindex hyphens, lyric
1398 The syllables themselves are separated by spaces. You can get syllable
1399 extenders by entering @code{__}, and centered hyphens with
1400 @code{-}@code{-}. We enter the syllables as if they are all quarter notes
1401 in length (hence the @code{4}), and use a feature to align the
1402 syllables to the music, which obviously isn't all quarter notes.
1406 accompaniment =\chords @{
1410 @cindex mode, chords
1411 We'll put chords over the music. To enter them, there is a special mode
1412 analogous to @code{\lyrics} and @code{\notes} mode, where you can give
1413 the names of the chords you want, instead of listing the notes
1414 comprising the chord.
1421 There is no accompaniment during the anacrusis.
1430 @cindex chord modifier
1431 @cindex modifier, chord
1432 A chord is started by the tonic of the chord. The
1433 first one lasts a half note. An unadorned note creates a major
1434 triad. Since a minor triad is wanted, @code{3-} is added to modify the
1435 third to be small. @code{7} modifies (adds) a seventh, which is small by
1436 default to create the @code{f a c es} chord. Multiple modifiers must be
1445 Some modifiers have predefined names, e.g. @code{min} is the same as
1446 @code{3-}, so @code{d-min} is a minor @code{d} chord.
1450 c2:min f:min7 g:7^3.5 c:min @}
1453 @cindex named modifier
1455 A named modifier @code{min} and a normal modifier @code{7} do not have
1456 to be separated by a dot. Tones from a chord are removed with chord
1457 subtractions. Subtractions are started with a caret, and they are
1458 also separated by dots. In this example, @code{g:7^3.5} produces a
1459 minor seventh. The brace ends the sequential music.
1467 We assemble the music in the @code{\score} block. Melody, lyrics and
1468 accompaniment have to sound at the same time, so they should be
1469 @code{\simultaneous}.
1470 @cindex @code{\simultaneous}
1477 Chord mode generates notes grouped in @code{\simultaneous} music. If
1478 you remove the comment sign, you can see the chords in normal
1479 notation: they will be printed as note heads on a separate
1480 staff. To print them as chords names, they have to be interpreted as
1481 being chords, not notes. This is done with the following command:
1485 \context ChordNames \accompaniment
1489 @cindex interpretation context
1490 @cindex notation context
1493 Normally, the notes that you enter are transformed into note heads.
1494 Note heads alone make no sense, they need surrounding information: a key
1495 signature, a clef, staff lines, etc. They need @emph{context}. In
1496 LilyPond, these symbols are created by objects called `interpretation
1497 contexts'. Interpretation contexts exist for generating notation
1498 (`notation context') and for generating sound (`performance
1499 context'). These objects only exist during a run of LilyPond.
1501 By default, LilyPond will create a Staff context for you. If you would
1502 remove the @code{%} sign in the previous line, you would see that
1503 mechanism in action.
1505 We don't want that default here, because we want chord names. The
1506 command above explicitly creates an interpretation context of
1507 @code{ChordNames} type to interpret the music @code{\accompaniment}.
1514 @cindex @code{\addlyrics}
1515 @cindex lyrics and melody, combining
1516 @cindex combining lyrics and melody
1518 The lyrics should be aligned with the melody. This is done by
1519 combining both with @code{\addlyrics}. @code{\addlyrics} takes two
1520 pieces of music (usually a melody and lyrics, in that order) and
1521 aligns the syllables of the second piece under the notes of the
1522 first piece. If you would reverse the order, the notes would be
1523 aligned on the lyrics, which is not very useful, and looks
1528 \context Staff = mel @{
1532 The first argument of @code{\addlyrics} is the melody. We instantiate
1533 a @code{Staff} context explicitly: should you choose to remove the
1534 comment before the ``note heads'' version of the accompaniment, the
1535 accompaniment will be on a nameless staff. The melody has to be on
1536 staff different from the accompaniment. This is accomplished by giving
1537 the melody and accompaniment staves different names.
1541 \property Staff.noAutoBeaming = ##t
1545 @cindex context variables
1546 @cindex setting context variables
1547 An interpretation context has variables, called properties, that tune
1548 its behavior. One of the variables is @code{noAutoBeaming}. Setting
1549 this @code{Staff}'s property to @code{##t}, which is the boolean value
1550 @var{true}, turns the automatic beaming mechanism off for the current
1554 @cindex accessing Scheme
1555 @cindex evaluating Scheme
1558 LilyPond internally uses GUILE, a Scheme-interpreter. Scheme is a
1559 language from the LISP family. You can learn more about Scheme at
1560 @uref{http://www.scheme.org}. It is used to represent data throughout
1561 the whole program. The hash-sign (@code{#}) accesses GUILE directly: the
1562 code following the hash-sign is evaluated as Scheme. The boolean value
1563 @var{true} is @code{#t} in Scheme, so for LilyPond @var{true} looks like
1566 If Scheme scares you, don't worry. You don't need to know Scheme to
1567 create beautiful sheet music.
1574 \property Staff.automaticMelismata = ##t
1577 @cindex automaticMelismata
1579 @cindex @code{\addlyrics} and slurs
1580 Similarly, we don't want to print a syllable when there is
1581 a slur. This sets up @code{\addlyrics} to not put lyrics under each
1582 separate note while there is a slur.
1590 Finally, we put the melody on the current staff. Note that the
1591 @code{\property} directives and @code{\melody} are grouped in sequential
1592 music, so the property settings are done before the melody is
1597 \context Lyrics \text
1600 The second argument of @code{\addlyrics} is the text. The text also
1601 should not land on a Staff, but on a interpretation context for
1602 syllables, extenders, hyphens etc. This context is called
1607 \midi @{ \tempo 4=72@}
1610 MIDI (Musical Instrument Digital Interface) is a standard for
1611 connecting and recording digital instruments. So a MIDI file is like a
1612 tape recording of an instrument. The @code{\midi} block makes the
1613 music go to a MIDI file, so you can listen to the music you entered. It
1614 is great for checking the music. Whenever you hear something weird, you
1615 probably hear a typing error.
1617 Syntactically, @code{\midi} is similar to @code{\paper @{ @}}, since it
1618 also specifies an output method. You can specify the tempo using the
1619 @code{\tempo} command, in this case the tempo of quarter notes is set to
1620 72 beats per minute.
1624 \paper @{ linewidth = 10.0\cm @}
1627 We also want notation output. The linewidth is short so the piece
1628 will be set in two lines.
1630 @node More movements
1631 @section More movements
1633 [FIXME: merge here with, or move this to: Other ways to run LilyPond]
1635 You probably ran @file{ly2dvi} on the last example, and ended up with a
1636 viewable @file{.dvi} file. However, between there are a few steps of
1637 which LilyPond is only one. To enhance your understanding of what's
1638 happening under the hood when you run @code{ly2dvi}, we explain what
1641 @code{ly2dvi} is a program that calls a number of programs in sequence.
1642 The first thing it does, is running LilyPond on the input file. After
1643 some calculations, a @file{.tex} is produced. The contents
1644 of this file are very low-level instructions.
1646 For example, consider the following file (@file{miniatures.ly})
1651 title = "Two miniatures"
1652 tagline = "small is beautiful"
1655 #(set! point-and-click line-column-location)
1657 \paper @{ linewidth = -1.0 @}
1660 \notes @{ c'4 d'4 @}
1666 \notes @{ d'4 c'4 @}
1673 The titling in this manual was not generated by ly2dvi, so we can't
1674 exactly show what it would look like, but the result should resemble this:
1676 @center @strong{Two miniatures}
1686 \paper { linewidth = -1.0 }
1698 \paper { linewidth = -1.0 }
1702 This file is produced by ly2dvi in a few stages, with the help of text
1703 formatting tools. LilyPond produces two output files,
1704 @file{miniatures.tex} and @file{miniatures-1.tex}. Both files contain
1705 only graphical music notation. @file{ly2dvi} looks at what output
1706 LilyPond produces, and adds page layout and titling to those files. The
1707 result is a DVI file called @file{miniatures.dvi}.
1709 Next, now we'll look at the example line by line to explain new things.
1715 Lilypond and its language are still under development, and occasionally,
1716 details of the syntax are changed. This fragment indicates for which
1717 version the input file was written. When you compile this file, the
1718 version number will be checked, and you will get a warning when the file
1721 This version number is also used by the @code{convert-ly} program (See
1722 @ref{convert-ly}), which is used to update the file to the latest lily
1728 title = "Two miniatures" @}
1730 This sets the titling information for the entire file.
1733 tagline = "small is beautiful"
1735 A signature line is printed at the bottom of the last page.
1736 This signature is produced from the @code{tagline} field of
1737 @code{\header}. Many people find the default "Lily was here,
1738 @var{version number}" too droll. If that is the case, assign
1739 something else to @code{tagline}, as shown above.
1742 #(set! point-and-click line-column-location)
1745 This piece of Scheme code sets the Scheme variable
1746 @code{point-and-click} to the value @var{line-column-location} (which
1747 itself is a Scheme procedure).
1749 Editing input files can be quite complicated if you're working with
1750 large files: if you're digitizing existing music, you have to
1751 synchronize the .ly file, the sheet music on your lap and the sheet
1752 music on the screen. The point-and-click mechanism makes it easy to
1753 find the origin of an error in the LY file: when you view the file with
1754 Xdvi and click on a note, your editor will jump to the spot where that
1755 note was entered. For more information, see @ref{Point and click}.
1762 The @code{\score} blocks that follow in the file don't have
1763 @code{\paper} sections, so the settings of this block are substituted: A
1764 paper block at top level, i.e. not in a @code{\score} block sets the
1765 default page layout.
1774 The variable @code{linewidth} normally sets the length of the systems on
1775 the page. However, a negative value has a special meaning. If
1776 @code{linewidth} is less than 0, no line breaks are inserted into the
1777 score, and the spacing is set to natural length: a short phrase takes up
1778 little space, a longer phrase more space.
1783 \notes @{ c'4 d'4 @}
1786 In previous examples, notes were specified in relative octaves,
1787 i.e. each note was put in the octave that is closest to its
1788 predecessor. Besides relative, there is also absolute octave
1789 specification, which you get when you don't specify @code{\relative}. In
1790 this input mode, the central C is denoted by @code{c'}. Going down, you
1791 get @code{c} @code{c,} @code{c,,} etc. Going up, you get @code{c''}
1794 When you're copying music from existing sheet music, relative octaves
1795 are probably the easiest to use: it's less typing work and errors are
1796 easily spotted. However, if you write LilyPond input directly, either by
1797 hand (i.e. composing) or by computer, absolute octaves may be easier to use.
1805 The @code{\header} is normally at the top of the file, where it sets
1806 values for the rest of the file. If you want to typeset different pieces
1807 from one file (for example, if there are multiple movements, or if
1808 you're making an exercise book), you can put different @code{\score}
1809 blocks into the input file. ly2dvi will assemble all LilyPond output
1810 files into a big document. The contents of \header blocks specified
1811 within each score, are used for the titling of each movement.
1817 For example, the Opus number is put at the right, and the piece string
1818 will be at the left.
1822 @node A piano excerpt
1823 @section A piano excerpt
1825 Our fourth subject is a piece of piano music. The fragment in the input
1826 file is a piano reduction of the G major Sinfonia by Giovanni Battista
1827 Sammartini. It was composed around 1740. It's in the source package
1828 under the name @file{sammartini.ly}.
1831 \include "paper16.ly"
1833 stemDown = \property Voice.Stem \override #'direction = #-1
1834 stemUp = \property Voice.Stem \override #'direction = #1
1835 stemBoth = \property Voice.Stem \revert #'direction
1837 viola = \notes \relative c' \context Voice = viola {
1838 <c4-\f-\arpeggio g' c>
1844 oboes = \notes \relative c'' \context Voice = oboe {
1845 \stemUp s4 g8. b,16 c8 r <e'8.^\p g> <f16 a>
1846 \grace <e8( g> <d4 )f> <c2 e>
1847 \times 2/3 { <d8 \< f> <e g> <f a> }
1849 { \times 2/3 { a8 g c } \! c2 }
1850 \context Voice = oboeTwo {
1853 \property Voice.Stem \override #'direction = #-1
1855 \property Voice.Stem \revert #'direction
1861 \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |
1862 [<d ( f> < )f8. a>] <)b,8 d> r [<d16( f> <f8. )a>] <b,8 d> r |
1863 [<c16( e> < )e8. g>] <c8 e,>
1866 hoomPah = \repeat unfold 8 \notes
1867 \transpose c' { \stemUp c8 \stemBoth \stemDown c'8 \stemBoth }
1869 bassvoices = \notes \relative c' {
1871 \autochange Staff \hoomPah
1872 \translator Staff = down
1873 \stemDown [c8 c'8] r4
1875 < {\stemUp r2 <e4 c'> <c8 g'> }
1876 \context Voice = reallyLow {\stemDown g2 ~ | g4 c8 } >
1880 \context PianoStaff \notes <
1881 \context Staff = up < \time 2/2
1885 \context Staff = down < \time 2/2 \clef bass
1892 linewidth = 15.0 \cm }
1896 If this looks like incomprehensible gibberish to you, you are right.
1897 This example has been doctored to have as many quirks as possible.
1899 As you can see, this example features multiple voices on one staff. To
1900 make room for those voices, their notes have to be stemmed in opposite
1903 Printed symbols are internally represented by so-called Graphical
1904 Objects (more colloquially: Grobs). These statements concern the
1905 grob called `Stem'. Each grob is described by a bunch of settings. These
1906 setting determine the fonts, offsets, sub-routines to be called on the
1907 grob, etc. The initial values of these settings are set in the Scheme
1908 file @file{scm/grob-description.scm}.
1912 stemDown = \property Voice.Stem \override #'direction = #-1
1915 Set a property for all Stem grobs in the current Voice:
1916 @code{direction} is set to @code{-1}, which encodes down. The setting
1917 remains in effect until it is reverted.
1921 \property Voice.Stem \revert #'direction
1924 Revert the to the previous setting. The effect of precisely one
1925 @code{\stemDown} or @code{\stemUp} is neutralized.
1928 LilyPond includes the identifiers @code{\stemUp}, @code{\stemDown} along
1929 with some other commonly used formatting instructions, but to explain how
1930 it works, we wrote our own here. Of course, you should use predefined
1931 identifiers like these if possible: then you will be affected less by
1932 the implementation changes we occasionally make.
1936 viola = \notes \relative c' \context Voice = viola @{
1938 In this example, you can see multiple parts on a staff. Each part is
1939 associated with one notation context. This notation context handles
1940 stems and dynamics (among others). The type name of this context is
1941 @code{Voice}. For each part we have to make sure that there is
1942 precisely one @code{Voice} context, so we give it a unique name
1947 <c4-\f-\arpeggio g' c>
1949 The delimiters @code{<} and @code{>} are shorthands for
1950 @code{\simultaneous @{} and @code{@}}. The expression enclosed in
1951 @code{<} and @code{>} is a chord.
1958 @code{\f} places a forte symbol under the chord. The forte applies to
1959 the whole chord, but the syntax requires that commands like forte and
1960 arpeggio are attached to a note, so here we attach them to the first
1963 @code{\arpeggio} typesets an arpeggio sign (a wavy vertical line) before
1976 Relative octaves work a little differently with chords. The starting
1977 point for the note following a chord is the first note of the chord. So
1978 the @code{g} gets an octave up quote: it is a fifth above the starting
1979 note of the previous chord (the central C).
1985 @code{s} is a spacer rest. It does not print anything, but it does have
1986 the duration of a rest. It is useful for filling up voices that
1987 temporarily don't play. In this case, the viola doesn't come until one
1988 and a half measure later.
1992 oboes = \notes \relative c'' \context Voice = oboe @{
1994 Now comes a part for two oboes. They play homophonically, so we
1995 print the notes as one voice that makes chords. Again, we insure that
1996 these notes are indeed processed by precisely one context with
2000 \stemUp s4 g8. b,16 c8 r <e'8.-\p g> <f16 a>
2002 @code{\stemUp} is a reference to the @code{\property \override} command
2006 \grace <e8 g> < d4 f> <c2 e>
2008 @cindex @code{\grace}
2011 @code{\grace} introduces grace notes. It takes one argument, in this
2015 The slur started on the @code{e} of the chord
2016 will be attached to the next note.@footnote{LilyPond will squirm
2017 about unended Slurs. In this case, you can ignore the warning}.
2025 Tuplets are made with the @code{\times} keyword. It takes two
2026 arguments: a fraction and a piece of music. The duration of the piece
2027 of music is multiplied by the fraction. Triplets make notes occupy 2/3
2028 of their notated duration, so in this case the fraction is 2/3.
2031 @{ <d8 \< f> <e g> <f a> @}
2033 The piece of music to be `tripletted' is sequential music containing
2034 three notes. On the first chord, a crescendo is started with
2035 @code{\<}. To be precise, the crescendo start is syntactically attached
2036 to the preceding note, the @code{d}.
2046 At this point, the homophonic music splits into two rhythmically
2047 different parts. We can't use a sequence of chords to enter this, so
2048 we make a `chord' of sequences to do it. We start with the upper
2049 voice, which continues with upward stems:
2052 @{ \times 2/3 @{ a8 g c @} \! c2 @}
2057 The crescendo is ended at the half note by the escaped exclamation
2061 \context Voice = oboeTwo @{
2064 We can't share stems with the other voice, so we have to create a new
2065 @code{Voice} context. We give it the name @code{oboeTwo} to distinguish
2066 it from the other context. Stems go down in this voice.
2071 @cindex Grace context
2072 When a grace section is processed, a @code{Grace} context is
2073 created. This context acts like a miniature score of its own. It has
2074 its own time bookkeeping, and you can make notes, beams, slurs
2075 etc. Here we fiddle with a property and make a beam. The argument of
2076 @code{\grace} is sequential music.
2080 \property Voice.Stem \override #'direction = #-1
2082 \property Voice.Stem \revert #'direction
2085 Normally, grace notes are always stem up, but in this case, the upper
2086 voice interferes, so we set the stems down here.
2088 As far as relative mode is concerned, the previous note is the
2089 @code{c'''2} of the upper voice, so we have to go an octave down for
2097 This ends the two-part section.
2101 \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |
2106 @code{\stemBoth} ends the forced stem directions. From here, stems are
2107 positioned as if it were single part music.
2109 The bass has a little hoom-pah melody to demonstrate parts switching
2110 between staves. Since it is repetitive, we use repeats:
2113 hoomPah = \repeat unfold 8
2115 @cindex unfolded @code{\repeat}
2116 The unfolded repeat prints the notes in its argument as if they were
2117 written out in full eight times.
2120 \notes \transpose c' @{
2123 @cindex relative mode and transposing
2125 Transposing can be done with @code{\transpose}, which takes two arguments.
2126 The first specifies what central C should be transposed to. The second
2127 is the to-be-transposed music. As you can see, in this case, the
2128 transposition has no effect, as central C stays at central C.
2130 The purpose of this no-op is circumventing relative mode. Relative mode
2131 can not be used together with transposition, so @code{\relative} will
2132 leave the contents of @code{\hoomPah} alone. We can use it without
2133 having to worry about getting the motive in a wrong octave.
2136 bassvoices = \notes \relative c' @{
2138 \autochange Staff \hoomPah
2140 @cindex staff switch, automatic
2141 @cindex cross staff voice, automatic
2142 @cindex @code{\autochange}
2144 Voices can switch between staves. The easiest way to get this, is to use
2145 @code{\autochange}. This command looks at the pitch of each note, and if
2146 necessary, will cross to the other staff. For this to work, the two
2147 staves must be called @code{"up"} and @code{"down"}.
2150 \translator Staff = down
2152 @cindex staff switch
2153 @cindex cross staff voice
2154 We want the remaining part of this melody on the lower staff, so we do a
2155 manual staff switch here.
2160 \context Voice = reallyLow @{\stemDown g2 ~ | g4 c8 @} >
2164 After skipping some lines, we see @code{~}. This mark makes ties. Note
2165 that ties and slurs are different things. A tie can only connect two
2166 note heads of the same pitch, whereas a slur can connect many chords
2173 A special context is needed to get cross staff beaming right. This
2174 context is called @code{PianoStaff}.
2177 \context Staff = bottom < \time 2/2 \clef bass
2179 The bottom staff must have a different clef.
2184 To make some more room on the line, the first (in this case the only)
2185 line is not indented. The line still looks very cramped, but that is due
2186 to the page layout of this document.
2192 * font-size, multi-stanza.
2194 * Simple part combining in a Hymn
2198 @node An orchestral score
2199 @section An orchestral score
2203 * Extracting an individual part::
2207 Our last two examples show a way to setup the music for an orchestral
2208 score. When typesetting a piece for several instruments, you'll want to
2209 create a conductor's full score, alongside several individual parts.
2211 LilyPond is well suited for this task. We will declare the music for
2212 each instrument individually, giving the music of each instrument its
2213 own name. These pieces of music are then combined in different
2214 @code{\score} blocks to produce different combinations of the score.
2216 This orchestral score example consists of three input files. In the
2217 first file, @file{os-music.ly}, we define the music for all instruments.
2218 This file will be used both for producing the score and the separate
2221 If you were to run LilyPond on this file, no printable output would be
2227 title = "Zo, goed lieverd?"
2228 subtitle = "How's, this babe?"
2237 Key = \notes \key as \major
2238 flautoI = \notes\relative c'' @{
2240 bes as bes as bes as bes as
2242 flautoII = \notes\relative c'' @{
2243 as8 bes as bes R1 d4 ~ d
2245 tromboI = \notes\relative c'' @{
2246 c4. c8 c8 c4. es4 r as, r
2248 tromboII = \notes\relative c'' @{
2249 as4. as8 as8 as4. R1*1/2 as4 es'
2251 timpani = \notes\relative c, @{
2252 \times 2/3 @{ f4 f f @}
2253 \times 4/5 @{ as8 as as as as @}
2256 corno = \notes\relative c' @{
2257 bes4 d f, bes d f, bes d
2261 We will not go through the input line by line, but only indicate and
2262 explain the new elements.
2269 \skip 2*4 \bar "|.";
2273 Declare setting to be used globally. The @code{\skip} command produces
2274 no output, but moves forward in time: in this case, the duration of a
2275 half note (@code{2}), and that four times (@code{*4}). This brings us
2276 to the end of the piece, and we can set the end bar.
2280 Key = \notes \key as \major
2282 Declare the key signature of the piece and assign it to the identifier
2283 @var{Key}. Later on, we'll use @code{\Key} for all staves except those
2284 for transposing instruments.
2286 @node The full score
2287 @subsection The full score
2290 The second file, @file{os-score.ly} reads the definitions of the first
2291 (@file{os-music.ly}), and defines the @code{\score} block for the full
2297 \include "os-music.ly"
2298 \include "paper13.ly"
2300 #(set! point-and-click line-column-location)
2301 #(define text-flat '((font-relative-size . -2)
2302 (music "accidentals--1")))
2307 \property Score.BarNumber \override #'padding = #3
2308 \context StaffGroup = woodwind <
2309 \context Staff = flauti <
2310 \property Staff.midiInstrument = #"flute"
2311 \property Staff.instrument = "2 Flauti"
2312 \property Staff.instr = "Fl."
2314 \context Voice=one @{ \voiceOne \flautoI @}
2315 \context Voice=two @{ \voiceTwo \flautoII @}
2318 \context StaffGroup = timpani <
2319 \context Staff = timpani <
2320 \property Staff.midiInstrument = #"timpani"
2321 \property Staff.instrument = #'(lines "Timpani" "(C-G)")
2322 \property Staff.instr = #"Timp."
2328 \context StaffGroup = brass <
2329 \context Staff = trombe <
2330 \property Staff.midiInstrument = #"trumpet"
2331 \property Staff.instrument = #`(lines "2 Trombe" "(C)")
2332 \property Staff.instr = #`(lines "Tbe." "(C)")
2334 \context Voice=one \partcombine Voice
2335 \context Thread=one \tromboI
2336 \context Thread=two \tromboII
2338 \context Staff = corni <
2339 \property Staff.midiInstrument = #"french horn"
2340 \property Staff.instrument = #`(lines "Corno"
2341 (columns "(E" ,text-flat ")"))
2342 \property Staff.instr = #`(lines "Cor."
2343 (columns "(E" ,text-flat ")"))
2344 \property Staff.transposing = #3
2345 \notes \key bes \major
2346 \context Voice=one \corno
2351 indent = 15 * \staffspace
2352 linewidth = 60 * \staffspace
2353 textheight = 90 * \staffspace
2355 \HaraKiriStaffContext
2364 @center @strong{Zo, goed lieverd?}
2366 @center How's, this babe?
2374 @lilypondfile{os-score.ly}
2378 \include "os-music.ly"
2380 First, we need to include the music definitions we made in
2385 #(set! point-and-click line-column-location)
2387 In a large orchestral score like this you're bound to make some small
2388 mistakes, so we enable point and click (See @ref{Point and click})
2393 #(define text-flat '((font-relative-size . -2)
2394 (music "accidentals--1")))
2397 When naming the tuning of the french horn, we'll need a piece of text
2398 with a flat sign. LilyPond has a mechanism for font selection and
2399 kerning called Scheme markup text (See @ref{Text markup}). The flat
2400 sign is taken from the music font, and its name is @code{accidentals--1}
2401 (The natural sign is called @code{accidentals-0}). The default font is
2402 too big for text, so we select a relative size of @code{-2}.
2409 Of course, all staves are simultaneous and use the same global settings.
2413 \property Score.BarNumber \override #'padding = #3
2415 LilyPond prints bar numbers at the start of each line, but
2416 unfortunately, they end up a bit too close to the staff in this example.
2417 A bar number internally is a Grob called @var{BarNumber}. BarNumber
2418 Grobs can be manipulated through their @var{side-position-interface}. One
2419 of the properties of a @var{side-position-interface} that can be tweaked
2420 is the @var{padding}: the amount of extra space that is put between this
2421 Grob and other Grobs. We set the padding to three staff spaces.
2423 You can find information on all these kind of properties in LilyPond's
2424 automatically generated documentation in
2426 @ref{ (lilypond-internals)lilypond-internals, LilyPond Internals}.
2429 the online documentation.
2434 \context StaffGroup = woodwind <
2435 \context Staff = flauti <
2437 A new notation context: the @code{StaffGroup}. @code{StaffGroup} can
2438 hold one or more @code{Staff}'s, and will print a big bracket at the
2439 left of the score. Start a new staff group for the woodwind section
2440 (just the flutes in this case). Immediately after that, we start the
2441 staff for the two flutes, that also play simultaneously.
2445 \property Staff.midiInstrument = #"flute"
2447 Specify the instrument for MIDI output (see @ref{MIDI instrument
2452 \property Staff.instrument = "2 Flauti"
2453 \property Staff.instr = "Fl."
2455 And define the instrument names to be printed in the margin,
2456 @code{instrument} for the first line of the score, @code{instr} for the
2463 The flutes play in the default key.
2467 \context Voice=one @{ \voiceOne \flautoI @}
2468 \context Voice=two @{ \voiceTwo \flautoII @}
2470 Last come the actual flute parts. Remember that we're still in
2471 simultaneous mode. We name both voices differently, so that LilyPond
2472 will actually create two Voice contexts. The flute parts are simple, so
2473 we specify manually which voice is which: @code{\voiceOne} forces the
2474 direction of stems, beams, slurs and ties up, @code{\voiceTwo} sets
2482 Close the flutes staff and woodwind staff group.
2486 \property Staff.instrument = #'(lines "Timpani" "(C-G)")
2488 The timpani staff only shows a new piece of scheme markup, it sets two
2493 \context Voice=one \partcombine Voice
2494 \context Thread=one \tromboI
2495 \context Thread=two \tromboII
2497 You have seen the notation contexts Staff and Voice, but here's a new
2498 one: Thread. One or more Threads can be part of a Voice. The Thread
2499 takes care of note heads and rests, the Voice combine note heads onto a
2502 For the trumpets we use the automatic part combiner (see @ref{Automatic
2503 part combining}) to combine the two simultaneous trumpet parts onto the
2504 trumpet staff. Each trumpet gets its own Thread context, which must be
2505 named @code{one} and @code{two}). The part combiner makes these two
2506 threads share a Voice when they're similar, and splits the threads up
2507 when they're different.
2511 \property Staff.instrument = #`(lines "Corno"
2512 (columns "(E" ,text-flat ")"))
2514 The french horn has the most complex scheme markup name, made up of two
2515 lines of text. The second line has three elements (columns), the @code{(E},
2516 the flat sign @code{text-flat} that we defined before and a final @code{")"}.
2517 Note that we use a backquote instead of an ordinary quote at the
2518 beginning of the Scheme expression to be able to access the
2519 @code{text-flat} identifier, `unquoting' it with a @code{,}.
2523 \property Staff.transposing = #3
2525 The french horn is to be tuned in E-flat, so we tell the MIDI backend to
2526 transpose this staff by three steps.
2528 Note how we can choose different tuning for entering, printing and
2529 playing, using @code{\transpose} and the MIDI Staff property
2534 \notes \key bes \major
2536 Therefore, it has a different key.
2540 indent = 15 * \staffspace
2541 linewidth = 60 * \staffspace
2543 We specify a big indent for the first line and a small linewidth for this
2548 Usually, LilyPond's predefined setup of notation contexts (Thread,
2549 Voice, Staff, Staffgroup, Score) is just fine. But in this case, we
2550 want a different type of Staff context.
2554 \HaraKiriStaffContext
2558 In orchestral scores, it often happens that one instrument has only
2559 rests during one line of the score. The @code{HaraKiriStaffContext} can
2560 be used as a regular @code{StaffContext} drop-in and will take care of
2561 the automatic removing of empty staves.
2563 @node Extracting an individual part
2564 @subsection Extracting an individual part
2566 The third file, @file{os-flute-2.ly} also reads the definitions of the
2567 first (@file{os-music.ly}), and defines the @code{\score} block for the
2571 \include "os-music.ly"
2572 \include "paper16.ly"
2576 \property Score.skipBars = ##t
2577 \property Staff.midiInstrument = #"flute"
2583 instrument = "Flauto II"
2586 linewidth = 80 * \staffspace
2587 textheight = 200 * \staffspace
2595 @center @strong{Zo, goed lieverd?}
2597 @center How's, this babe?
2598 @center @emph{Flauto II}
2605 @lilypondfile{os-flute-2.ly}
2608 Because we separated the music definitions from the @code{\score}
2609 instantiations, we can easily define a second score with the music of
2610 the second flute. This then is the part for the second flute player.
2611 Of course, we make separate parts for all individual instruments.
2617 In this individual part the second flute has a whole staff for itself,
2618 so we don't want to force stem or tie directions.
2623 instrument = "Flauto II"
2626 The @code{\header} definitions were also read from @file{os-music.ly},
2627 but we need to set the instrument for this particular score.
2631 \property Score.skipBars = ##t
2633 In the conductor's full score, all bars with rests are printed, but for
2634 the individual parts, we want to contract pieces of consecutive empty
2635 bars. LilyPond will do this if Score's @var{skipBars} property to
2639 @node Other ways to run LilyPond
2640 @section Other ways to run LilyPond
2642 Until now, you have been using @file{ly2dvi} to invoke LilyPond.
2643 There are three other routes. Firstly, there is a script called
2644 @code{lilypond-book}, that allows you to freely mix LilyPond input with
2645 Texinfo or \LaTeX input. For example, this manual was written using
2646 @code{lilypond-book}. It is discussed below and in @ref{lilypond-book}.
2649 Secondly, you can generate PostScript directly. This is useful if you
2650 can not or do not want to run @TeX{} on your system. To obtain direct
2651 PostScript output, invoke LilyPond as follows:
2652 @cindex PostScript output
2654 lilypond -f ps test.ly
2656 You have to set some environment variables to view or print this output.
2657 More information can be found in @ref{Invoking LilyPond}. Since the
2658 direct Postscript generation has some problems, it is recommended
2659 to use @file{ly2dvi}.
2662 Thirdly, if you want to do special things with your output, you can run
2663 invoke LilyPond directly:
2667 to produce plain @TeX{} output. Note that La@TeX{} will not work on the
2668 resulting @file{test.tex}. You must run plain @TeX{} on it.
2676 @node Integrating text and music
2677 @section Integrating text and music
2679 Sometimes, you might want to use music examples in a text that you are
2680 writing. For example, if you are writing a musicological treatise, a
2681 songbook, or (like us) the LilyPond manual. You can make such texts by
2682 hand, simply by importing a PostScript figure into your wordprocessor.
2683 However, there is a also an automated procedure:
2685 If you use La@TeX{} or texinfo, you can mix text and LilyPond code. A
2686 script called @code{lilypond-book} will extract the music fragments, run
2687 LilyPond on them, and put back the resulting notation. lilypond-book is
2688 described fully in @ref{lilypond-book}, but here we show a small
2689 example. Since the example also contains explanatory text, we won't
2690 comment on the contents.
2693 \documentclass[a4paper]@{article@}
2696 In a lilypond-book document, you can freely mix music and text. For
2699 \score @{ \notes \relative c' @{
2700 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
2703 Notice that the music line length matches the margin settings of the
2706 If you have no \verb+\score+ block in the fragment,
2707 \texttt@{lilypond-book@} will supply one:
2713 In the example you see here, a number of things happened: a
2714 \verb+\score+ block was added, and the line width was set to natural
2715 length. You can specify many more options using \LaTeX style options
2718 \begin[verbatim,11pt,singleline,
2719 fragment,relative,intertext="hi there!"]@{lilypond@}
2723 \texttt@{verbatim@} also shows the LilyPond code, \texttt@{11pt@} selects
2724 the default music size, \texttt@{fragment@} adds a score block,
2725 \texttt@{relative@} uses relative mode for the fragment, and
2726 \texttt@{intertext@} specifies what to print between the
2727 \texttt@{verbatim@} code and the music.
2729 If you include large examples into the text, it may be more convenient
2730 to put the example in a separate file:
2732 \lilypondfile[printfilename]@{sammartini.ly@}
2734 The \texttt@{printfilename@} option adds the file name to the output.
2739 Under Unix, you can view the results as follows.
2742 $ lilypond-book --outdir=out/ lilbook.tex
2743 lilypond-book (GNU LilyPond) 1.3.146
2744 Reading `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/lilbook.tex'
2746 `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/sammartini.ly'
2747 @var{lots of stuff deleted}
2748 Writing `out/lilbook.latex'
2750 $ latex lilbook.latex
2751 @var{lots of stuff deleted}
2755 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
2756 and running latex creates a lot of temporary files, and you wouldn't want
2757 those to clutter up your working directory. Hence, we have them created
2758 in a separate subdirectory.
2760 The result more or less looks like this:
2764 In a lilypond-book document, you can freely mix music and text. For
2767 \score { \notes \relative c' {
2768 c2 g'2 \times 2/3 { f8 e d } c'2 g4
2771 Notice that the music line length matches the margin settings of the
2774 If you have no @code{\score} block in the fragment,
2775 @code{lilypond-book} will supply one:
2781 In the example you see here, a number of things happened: a
2782 @code{\score} block was added, and the line width was set to natural
2783 length. You can specify many more options using La@TeX{} style options
2786 @lilypond[verbatim,11pt,singleline,
2787 fragment,relative,intertext="hi there!"]
2791 @code{verbatim} also shows the LilyPond code, @code{11pt} selects
2792 the default music size, @code{fragment} adds a score block,
2793 @code{relative} uses relative mode for the fragment, and
2794 @code{intertext} specifies what to print between the
2795 @code{verbatim} code and the music.
2797 If you include large examples into the text, it may be more convenient
2798 to put the example in a separate file:
2800 @lilypondfile[printfilename]{sammartini.ly}
2802 The @code{printfilename} option adds the file name to the output.
2803 @node End of tutorial
2804 @section End of tutorial
2806 That's all folks. From here, you can either try fiddling with input
2807 files, or you can read the reference manual. You can find more example
2808 files in @file{input} and @file{input/test}. You can also look at some
2809 real music. The website @uref{http://www.mutopiaproject.org} has many
2810 examples of real music typeset by LilyPond.
2818 this should be on mutopia website.
2823 @c waar deze info? is uiteindelijk wel handig, schat ik.
2826 If you have a big music project, or just a lot of LilyPond input files,
2827 all generated output from LilyPond, @TeX{} and metafont will clutter
2828 your working directory. LilyPond comes with a one-size-fits-all
2829 pre-cooked makefile that helps you manage producing output. It will
2830 produce all output in the directory @file{out} , generate and track
2831 dependencies. Also, it helps in preparing your submission to @ref{Mutopia
2838 cp /usr/share/lilypond/make/ly.make GNUmakefile
2839 cp /usr/share/doc/lilypond/examples/input/tutorial/minuet.ly .
2842 Generated out/minuet.ps for target minuet.
2845 Type @samp{make help} to see possible targets.
2848 @file{/usr/share/lilypond/doc/lilypond/examples/input/mutopia-header.ly}
2854 [TODO: rewrite completely.]
2857 * Songs with additional verses::