3 @c TODO: LilyPond LilyPond LilyPond
9 <!--- @@WEB-TITLE@@=Tutorial --->
13 * First steps:: Music language of LilyPond
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 * Fine tuning a piece::
21 * An orchestral score:: Conductor's score and individual parts
22 * Integrating text and music:: Integrating text and music
23 * End of tutorial:: The end
26 Operating lilypond is done through text files: to print a piece of
27 music, you enter the music in a file. When you run lilypond, that
28 file is read, and after some computations, the program produces a file
29 containing the sheet music that you can print or view.
31 This tutorial starts with a small introduction to the LilyPond music
32 language. After this first contact, we will show you how to run
33 LilyPond to produce printed output; you should then be able to create
34 your first sheets of music. The tutorial continues with more and more
43 @c @node Music language of LilyPond
44 @c @section Music language of LilyPond
46 In this section, we show how to make small, very simple pieces of
47 music in LilyPond. If you have not seen LilyPond input files before,
48 this section is for you. The contents of this section are summarized
49 in the Cheat Sheet (See @ref{Cheat sheet}).
51 You get a simple note by typing its note name, from @code{a} through
52 @code{g}. So if you enter
58 then the result looks like this:
61 \property Score.timing = ##f
62 \property Staff.TimeSignature = \turnOff
63 \transpose c'' { c d e f g a b }
68 We continue showing LilyPond input like we did previously: first a
69 snippet of input, then the resulting output.
71 The length of a note is specified by adding a number, ``@code{1}'' for a
72 whole note, ``@code{2}'' for a half note, and so on:
79 @c missing clef seems to raise more questions than actual pitch of notes,
80 @c as these are snippets anyway
82 \property Score.timing = ##f
83 \property Staff.TimeSignature = \turnOff
84 \property Staff.autoBeaming = ##f
85 %\property Staff.Clef = \turnOff
86 \transpose c'' { a1 a2 a4 a16 a32 }
92 If you don't specify a duration, the previous one is used:
98 @c missing clef seems to raise more questions than actual pitch of notes,
99 @c as these are snippets anyway
101 \property Score.timing = ##f
102 \property Staff.TimeSignature = \turnOff
103 %\property Staff.Clef = \turnOff
104 \transpose c'' { a a a2 a }
110 A sharp (@texisharp{}) is made by adding ``@code{is}'', a flat
111 (@texiflat{}) by adding ``@code{es}'':
119 \property Score.timing = ##f
120 \property Staff.TimeSignature = \turnOff
121 \transpose c'' { cis1 ees fisis aeses }
127 Add a dot ``@code{.}'' after the duration to get a dotted note:
133 @c missing clef seems to raise more questions than actual pitch of notes,
134 @c as these are snippets anyway
136 \property Score.timing = ##f
137 \property Staff.TimeSignature \set #'transparent = ##t
138 %\property Staff.Clef = \turnOff
139 \transpose c'' { a2. a4 a8. a16 }
145 The meter (or time signature) can be set with the @code{\time} command:
154 @c a clef here may lead to confusion
156 \property Staff.Clef \set #'transparent = ##t
167 The clef can be set using the ``@code{\clef}'' command:
169 @c what is more common name treble or violin?
170 @c in Dutch, its violin.
180 \property Score.timing = ##f
181 \property Staff.TimeSignature = \turnOff
194 From these commands and notes, a piece of music can be formed. A piece
195 of music is made by enclosing it in ``@code{\notes @{ ... @}}''.
196 LilyPond then knows that music follows (and not lyrics, for example):
210 At this point, the piece of music is ready to be printed. This is done
211 by combining the music with a printing command.
213 The printing command is the so-called ``@code{\paper}'' block. You
214 will see later that the \paper block is necessary to customize all
215 kinds of printing specifics. The music and the \paper block are
216 combined by enclosing them in ``@code{\score @{ ... @}}''. This is
217 what a full LilyPond source file looks like:
240 \paper { linewidth = 60 * \staffspace }
247 We continue with the introduction of the remaining musical constructs.
249 @c maybe legend here?
251 Normal rests are entered just like notes with the name ``@code{r}'':
259 \property Score.timing = ##f
260 \property Staff.Clef = \turnOff
261 \property Staff.TimeSignature = \turnOff
268 @c Tim wants to move this quotes example just before the: quotes-don't-work
269 @c score, but we'd need to remove quotes from the other two (key and
272 @c better to have this just before the `octaves are bad' snipped
273 @c but we'd need to remove the ', from \key and tie
274 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
275 the note name, to lower a note one octave, add a ``low quote'' @code{,}
276 (a comma). The central C is @code{c'}:
280 c'4 c'' c''' \clef bass c c,
284 \property Score.timing = ##f
285 \property Staff.TimeSignature = \turnOff
286 c'4 c'' c''' \clef bass c c,
291 A tie is created by entering a tilde ``@code{~}'' between the notes to
292 be tied. A tie between two notes means that the second note must not be
293 played separately, but just makes the first note sound longer:
296 @lilypond[fragment,verbatim]
302 The key signature is set with the command ``@code{\key}'':
312 \property Staff.TimeSignature = \turnOff
321 @c bit on the long/complex/scary taste
322 @c cheating a bit: two lines makes for a friendlier look
323 This example shows notes, ties, octave marks, and rests in action.
324 Don't worry about all the quotes.
333 r4 r8 d''8 cis''4 e''
335 cis''4 cis''8 cis'' bis'4 d''8 cis'' ~
348 r4 r8 d''8 cis''4 e''
350 cis''4 cis''8 cis'' bis'4 d''8 cis'' ~
353 \paper { linewidth = 50*\staffspace }
359 There are some interesting points to note in this example. Firstly,
360 accidentals (sharps and flats) don't have to be marked explicitly: you
361 just enter the note name, and LilyPond determines whether or not to
362 print an accidental. Secondly, bar lines and beams are drawn
363 automatically. Thirdly, LilyPond calculates line breaks for you; it
364 doesn't matter where you make new lines in the source file.
366 The example also indicates that a piece of music written in a high
367 register needs lots of quotes. This makes the input less readable,
368 and is therefore also a potential source of errors.
372 The solution is to use ``relative octave'' mode. In practice, most
373 music is entered using this mode.
375 To use relative mode, add @code{\relative} before the piece of music.
376 You must also give a note from which relative starts, in this case
379 @c In relative octave mode, quotes are used to mark large jumps in the
380 @c melody. Without any quotes or commas, the interval between a note and
381 @c its predecessor is assumed to be a fourth or less. Quotes and commas
382 @c add octaves in up and down direction.
384 If you type no octaviation quotes, relative mode chooses the note that
385 is closest to the previous one, which is often just the one you need.
386 @c don't use commas or quotes in this sentence
387 For example: @code{c f} goes up; @code{c g} goes down:
397 \property Score.timing = ##f
398 \property Staff.TimeSignature = \turnOff
406 @c needed better, maybe even redundant explanation
407 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
408 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
409 You can make a large interval by adding octaviation quotes. Note that
410 quotes or commas do not determine the absolute height of a note;
411 the height of a note is relative to the previous one.
412 @c don't use commas or quotes in this sentence
413 For example: @code{c f,} goes down; @code{f, f} are both the same;
414 @code{c c'} are the same; and @code{c g'} goes up:
424 \property Score.timing = ##f
425 \property Staff.TimeSignature = \turnOff
433 A slur is drawn across many notes, and indicates bound articulation
434 (legato). The starting note and ending note are marked with a
435 ``@code{(}'' and a ``@code{)}'' respectively:
438 @lilypond[fragment,relative 1, verbatim]
439 d4( )c16( cis d e c cis d )e( )d4
444 If you need two slurs at the same time (one for articulation, one for
445 phrasing), you can also make a phrasing slur with @code{\(} and
450 @lilypond[fragment,relative 1, verbatim]
451 a8(\( ais b ) c cis2 b'2 a4 cis, \) c
456 Beams are drawn automatically, but if you don't like the choices, you
457 can enter beams by hand. Surround the notes to be grouped with @code{[}
460 @lilypond[fragment,relative 1, verbatim]
466 To print more than one staff, each piece of music that makes up a staff
467 is marked by adding @code{\context Staff} before it. These
468 @code{Staff}'s can be grouped inside @code{<} and @code{>}, as is
472 @lilypond[fragment,verbatim]
474 \context Staff = staffA { \clef violin c'' }
475 \context Staff = staffB { \clef bass c }
480 In this example, @code{staffA} and @code{staffB} are names that are
481 given to the staves. For now, it doesn't matter what names you give, as
482 long as each staff has a unique name.
486 We can typeset a melody with two staves now:
492 < \context Staff = staffA {
495 \relative c'' { e2 ( d4 c2 b4 [a8 a] [b b] [g g] )a2. }
497 \context Staff = staffB {
508 Notice that the time signature is specified in one melody staff only
509 (the top staff), but is printed on both. LilyPond knows that the time
510 signature should be the same for all staves.
514 Common accents can be added to a note using @code{-.}, @code{--}, @code{->}:
516 @lilypond[verbatim,relative 1]
522 Dynamic signs are made by adding the markings to the note:
524 @lilypond[verbatim,relative 1]
530 Crescendi are started with the commands @code{\<} and @code{\>}. The
531 command @code{\!} finishes a crescendo on the following note.
533 @lilypond[verbatim,relative 1]
534 c2\< \!c2-\ff \>c2 \!c2
539 Chords can be made by surrounding notes with @code{<} and @code{>}:
541 @lilypond[relative 0, fragment,verbatim]
549 @c hmm, te losjes, iig
550 In general, @code{ < @var{stuff} > } is used when @var{stuff} all
551 happens at the same time, like in chords, or (like in the two-staff
552 example above) in a bunch of stacked staves.
555 Of course, you can combine beams and ties with chords. Notice that
556 beam and tie markings must be placed outside the chord markers:
558 @lilypond[relative 0, fragment,verbatim]
559 r4 [<c8 e g> <c8 f a>] ~ <c8 f a>
563 When you want to combine chords with slurs and dynamics, technical
564 detail crops up: you have type these commands next to the notes, which
565 means that they have to be inside the @code{< >}:
568 @lilypond[relative 0, fragment,verbatim]
569 r4 <c8 e g \> ( > <c e g> <c e g> < ) \! c8 f a>
574 There is one golden rule that you should keep in mind when writing
577 @strong{DO NOT START A PIECE WITH A CHORD}
579 Of course, it is a allowed, but the result might not be what you expect:
581 @lilypond[verbatim,singleline]
582 \score { \notes <c'2 e'2> }
587 Of course, it is possible to typeset pieces that start with a chord,
588 but you must make explicit that the notes of chord are to be put on
589 the same staff, in the same voice. This is done by specifying
590 @code{\context Staff} for the notes:
593 @lilypond[verbatim,singleline]
594 \score { \notes \context Voice <c'2 e'2> }
603 [TODO add some more here
614 This is the end of the simple tutorial. You know the basic ingredients
615 of a music file, so this is the right moment to try your at hand at
616 doing it yourself: try to type some simple examples, and experiment a
619 When you're comfortable with the basics, then you might want to read the
620 rest of this chapter. It also a manual in tutorial-style, but it is much
621 more in-depth. It will also be very intimidating if you're not familiar
622 with the basics. It deals with some of the more advanced features of
623 LilyPond. Topics include lyrics, chords, orchestral scores and parts,
624 fine tuning output, polyphonic music, and integrating text and music.
627 @c refer to this section
632 @c need texinfo-4.0a or later for this
635 @c both Tim and my father came independently with a request for a
636 @c `legend' like this.
638 @c what should be in it?
642 @multitable @columnfractions .20 .20 .30 .20
649 @item @code{1 2 8 16}
652 @lilypond[fragment, relative 1]
653 \property Staff.TimeSignature = \turnOff
654 \property Staff.autoBeaming = ##f
655 \property Staff.Clef = \turnOff
660 @tab augmentation dots
662 @lilypond[fragment, relative 1]
663 \property Staff.TimeSignature = \turnOff
664 \property Staff.Clef = \turnOff
667 @tab @internalsref{Dot}, @internalsref{DotColumn}
669 @item @code{c d e f g a b }
672 @lilypond[fragment, relative 1]
673 \property Staff.TimeSignature = \turnOff
674 \property Staff.Clef = \turnOff
677 @tab @internalsref{NoteHead}
682 @lilypond[fragment, relative 2]
683 \property Staff.TimeSignature = \turnOff
684 \property Staff.Clef = \turnOff
687 @tab @internalsref{Accidental}
689 @item @code{-. -^ ->}
690 @tab articulations (1)
692 @lilypond[fragment, relative 1]
693 \property Staff.TimeSignature = \turnOff
694 \property Staff.Clef = \turnOff
697 @tab @internalsref{Script}
699 @item @code{-\trill -\fermata}
700 @tab articulations (2)
702 @lilypond[fragment, relative 1]
703 \property Staff.TimeSignature = \turnOff
704 \property Staff.Clef = \turnOff
707 @tab @internalsref{Script}
709 @item @code{\time 3/4 \time 4/4 }
713 \property Staff.Clef \set #'transparent = ##t
719 @tab @internalsref{TimeSignature}
721 @item @code{\clef treble \clef bass }
725 \property Staff.TimeSignature \set #'transparent = ##t
731 @tab @internalsref{Clef}
733 @item @code{\sfz \mf }
736 @lilypond[fragment,relative 1]
737 \property Staff.TimeSignature = \turnOff
738 \property Staff.Clef = \turnOff
741 @tab @internalsref{DynamicText}
746 @lilypond[fragment, relative 1]
747 \property Score.timing = ##f
748 \property Staff.TimeSignature = \turnOff
749 \property Staff.autoBeaming = ##f
750 \property Staff.Clef = \turnOff
753 @tab @internalsref{Beam}
758 @lilypond[fragment, relative 1]
759 \property Score.timing = ##f
760 \property Staff.TimeSignature = \turnOff
761 \property Staff.autoBeaming = ##f
762 \property Staff.Clef = \turnOff
765 @tab @internalsref{Tie}
770 @lilypond[fragment, relative 1]
771 \property Score.timing = ##f
772 \property Staff.TimeSignature = \turnOff
773 \property Staff.autoBeaming = ##f
774 \property Staff.Clef = \turnOff
777 @tab @internalsref{Slur}
782 @lilypond[fragment, relative 1]
783 \property Score.timing = ##f
784 \property Staff.TimeSignature = \turnOff
785 \property Staff.autoBeaming = ##f
786 \property Staff.Clef = \turnOff
794 @lilypond[fragment, relative 1]
795 \property Score.timing = ##f
796 \property Staff.TimeSignature = \turnOff
797 \property Staff.autoBeaming = ##f
798 \property Staff.Clef = \turnOff
806 @lilypond[fragment, relative 1]
807 \property Score.timing = ##f
808 \property Staff.TimeSignature = \turnOff
809 \property Staff.autoBeaming = ##f
810 \property Staff.Clef = \turnOff
811 \context Voice { <a c> }
818 @lilypond[fragment, relative 1]
819 \property Score.timing = ##f
820 \property Staff.TimeSignature = \turnOff
821 \property Staff.autoBeaming = ##f
822 \property Staff.Clef = \turnOff
825 @tab @internalsref{Hairpin}
830 @lilypond[fragment, relative 1]
831 \property Score.timing = ##f
832 \property Staff.TimeSignature = \turnOff
833 \property Staff.autoBeaming = ##f
834 \property Staff.Clef = \turnOff
837 @tab @internalsref{Hairpin}
844 @node Running LilyPond
845 @section Running LilyPond
847 In the last section, we explained what kind of things you could enter
848 in a lilypond file. In this section we explain how to run LilyPond,
849 and how view or print the output. If you have not used LilyPond
850 before, want to test your setup of LilyPond, or try to run an example
851 file yourself, then read this section. The instructions that follow
852 are for running LilyPond on Unix-like systems. Some additional
853 instructions for running LilyPond on Windows are given at the end of
856 You begin with opening a terminal window, and start up a text editor.
857 For example, open an xterm and execute @code{joe}. In your text editor,
858 enter the following input, and save the file as @file{test.ly}:
863 \notes @{ c'4 e' g' @}
870 @c now this is weird, running ly2dvi to run LilyPond
871 @c (therefore name change proposal)
873 LilyPond is the program that computes the sheet music. All other
874 things, such as adding titles, page breaking and other page layout,
875 are done by a small wrapper program called
876 @code{ly2dvi}. @code{ly2dvi} calls lilypond to render the music, and
877 then adds the titling and page layout instructions. To process
878 @file{test.ly} with ly2dvi, proceed as follows:
886 You will see the following on your screen:
891 Now processing: `/home/fred/ly/test.ly'
893 Interpreting music...[1]
894 @emph{ ... more interesting stuff ... }
895 PS output to `test.ps'...
896 DVI output to `test.dvi'...
900 @cindex Viewing music
903 The results of the ly2dvi run are two files, @file{test.dvi} and
904 @file{test.ps}. The PS file (@file{test.ps}) is the one you can print.
905 You can view the PS file using the program ghostview. If a version of
906 ghostview is installed on your system, one of these commands will
907 produce a window with some music notation on your screen:
917 If you are satisfied with the looks of the music displayed on your
918 screen, you can print the PS file by clicking File/Print inside
921 The DVI file (@file{test.dvi}) contains the same sheet music in a
922 different format. DVI files are more easily processed by the computer,
923 so viewing them usually is quicker. Execute @code{xdvi test.dvi}
924 to view the DVI file.
926 If your DVI viewer does not have a "Print" button, you can print the
927 file by executing @code{lpr test.ps}.
929 @c volgende alinea schrappen?
931 If you can't get the examples to print, then you should look into
932 installing and configuring ghostscript. Refer to GhostScript's website
933 at @uref{http://www.ghostscript.com}.
937 @cindex Printing output
940 @unnumberedsubsec Windows users
941 Windows users start the terminal by clicking on the LilyPond or Cygwin
942 icon. Notepad is sufficient for editing the LilyPond file. Viewing
943 the PS file can be done with:
946 @code{gsview32 test.ps}
949 You can also print from the command line by executing:
952 @code{gsview32 /s test.ps}
957 @node The first real tune
958 @section The first real tune
961 The rest of this tutorial will demonstrate how to use Lilypond by
962 presenting examples of input along with resulting output. We will use
963 English terms for notation. In case you are not familiar with those,
964 you may consult the glossary that is distributed with LilyPond.
966 The examples discussed are included in the distribution, in the
967 subdirectory @file{input/tutorial/}@footnote{When we refer to filenames,
968 they are relative to the top directory of the source package. }
970 To demonstrate what LilyPond input looks like, we start off with a
971 full-fledged, yet simple example. It is a convoluted version
972 of the famous minuet in J. S. Bach's @emph{Klavierb@"uchlein}. The file
973 is included in the distribution as @file{minuet.ly}.
974 @cindex Bach, Johann Sebastian
977 % all text after a percent sign is a comment
978 % and is ignored by LilyPond
979 \include "paper16.ly"
982 \relative c'' \sequential {
987 d4 g,8 a b c d4 g, g |
988 e'4 c8 d e fis g4 g, g |
989 c4 d8( )c b a( )b4 c8 b a g |
990 a4 [b8 a] [g fis] g2. |
995 g4 e8 fis g d cis4 b8 cis a4 |
996 a8-. b-. cis-. d-. e-. fis-.
1003 % standard settings are too big and wide for a book
1005 linewidth = 15.0 \cm
1010 We will analyse the input, line by line.
1013 % all text after a percent sign is a comment
1014 % and is ignored by LilyPond
1016 Percent signs introduce comments: everything after a percent sign is
1017 ignored. You can use this If you want to write down mental notes to
1018 yourself in a file, then you can enter preceded with a @code{%} sign.
1019 These lines are called comments. If you have long winded mental notes,
1020 you can make comments that span several lines by enclosing text in
1021 @code{%@{} and @code{%@}}.
1023 @cindex block comment
1024 @cindex line comment
1028 \include "paper16.ly"
1031 @cindex @code{\include}
1032 @cindex point, printer's
1033 @cindex staff size, setting
1034 @cindex font size, setting
1036 By default, LilyPond will typeset the music in a size such that each
1037 staff is 20 point (0.7 cm, or 0.27 inch) high. We want smaller output
1038 (16 point staff height), so we must import the settings for that size,
1046 Music is printed by combining a piece of music with directions for
1047 outputting it. This combination is formed in the @code{\score} block.
1054 Prepare LilyPond for accepting notes.
1055 @cindex octaves, choosing
1064 @c removed duplicate introduction to octave marks /MB
1065 @c Shorten even more?
1067 @c As we will see, each note is described by its note name, duration,
1068 @c octave and possibly a chromatic alteration. In this setup, the octave
1069 @c is indicated by using high quotes (@code{'}) and ``lowered quotes''
1070 @c (commas: @code{,}). The central C is denoted by @code{c'}. The C one
1071 @c octave higher is @code{c''}. One and two octaves below the central C is
1072 @c denoted by @code{c} and @code{c,} respectively.
1074 Even though a piece of music often spans a range of several octaves,
1075 often melodies move in small intervals. Such melodies can be entered
1076 easily using @code{\relative}. In this ``relative octave mode'',
1077 octaves of notes without quotes are chosen such that a note is as
1078 close as possible (graphically, on the staff) to the preceding note.
1079 If you add a high-quote an extra octave is added. A lowered quote (a
1080 comma) will subtract an extra octave.
1082 Absolute starting pitch for this relative mode is given as the
1083 argument to @code{\relative}. In this case it is the @code{c''}, one
1084 octave above central C.
1092 What follows is sequential music, i.e.,
1093 @cindex sequential music
1094 notes that are to be played and printed after each other.
1101 @cindex time signature, setting
1102 @cindex @code{\time}
1103 The @code{\time} command sets (or changes) the time signature of the
1104 current piece: a 3/4 sign is printed. This setting is also used to
1105 generate bar lines at the right spots.
1112 @cindex key signature, setting
1114 Set (or change) the current key signature to G-major. Although in this
1115 example, the @code{\key} command happened to be entered after the
1116 @code{\time} command, in the output the time signature will be printed
1117 after the key signature; LilyPond knows about music typesetting
1125 The following piece of music is played twice. The first argument
1126 indicates the type of repeat. In this case, @code{"volta"} means that
1127 prima volta/secunda volta brackets are used for the alternative
1128 endings---if there were any.
1130 A special notation for repeats allows you to get correct repeats in
1131 MIDI output. However, some extra trickery is needed to get this
1132 working, See @ref{Repeats and MIDI}.
1139 The subject of the repeat is again sequential music. Since
1140 @code{\sequential} is such a common construct, a shorthand is provided:
1141 just leave off @code{\sequential}, and the result is the same.
1148 Two notes. The first note is a quarter note with relative pitch
1149 @code{d}. The relative music was started with a @code{c''}, so the real
1150 pitch of this note is @code{d''}. The duration of a note is designated
1151 by a number; the @code{4} here represents a quarter note.
1153 The second note is an eight note with relative pitch @code{g,}. The
1154 pitch is taken relative to the previous @code{d''}, making this
1155 note have real pitch @code{g'}. The @code{8} represents an eight note.
1162 Two more notes, with pitch @code{a} and @code{b}. Because their
1163 duration is the same as the @code{g,8}, there is no need to enter the
1164 duration, but you may enter it anyway, i.e., @code{a8 b8}
1173 @cindex errors, finding
1174 Three more notes. The @code{|} character is a ``bar check''. LilyPond
1175 will verify that bar checks are found at the start of a measure. This can
1176 help you track down typing errors.
1178 @cindex alteration, chromatic
1179 @cindex chromatic alteration
1186 So far, no notes were chromatically altered. Here is the first one
1187 that is: @code{fis}. LilyPond uses Dutch note names, and ``Fis'' is
1188 the name for ``F sharp''. There is no sharp sign in the output. The
1189 program keeps track of key signatures, and will only print accidentals
1190 if they are needed. If you can not get used to Dutch names, then
1191 there also are names available in several other languages.
1194 For groups of eighth notes and shorter, LilyPond can determine how the
1195 notes should form a beam. In this case, the 4 eights are automatically
1200 c4 d8( )c b a( )b4 c8 b a g |
1203 The beginning and ending notes of a slur are marked with parentheses,
1204 @code{(} and @code{)} for start and end respectively. The line above
1205 indicates two slurs. These slur markers (parentheses) are entered
1206 between the slurred notes.
1213 Automatic beaming can be overridden by inserting beam marks, @code{[}
1214 and @code{]}. These beam markers (brackets) are put around the notes
1222 @cindex augmentation dot
1224 A period adds a dot to the note.
1231 The end of the sequential music to be repeated. LilyPond will typeset a
1239 Accidentals are printed whenever necessary: the first C sharp of the bar
1240 will be printed with an accidental, the second one without.
1244 a8-. b-. cis-. d-. e-. fis-.
1247 @cindex articulation
1248 Staccato signs are entered as a dash and a period. Some other
1249 articulations may also be entered in this short form.
1257 Rests are denoted by the special note name @code{r}.
1264 All articulations have a verbose form, like @code{\fermata}. The
1265 command @code{\fermata} is not part of the core of the language, but it
1266 is a shorthand for a more complicated description of a fermata symbol.
1267 @code{\fermata} names that description and is therefore called an
1270 @cindex @code{\fermata}
1276 Here the music ends. LilyPond does not automatically typeset an end
1277 bar, we must explicitly request one, using @code{"|."}.
1283 % standard settings are too big and wide for a book
1289 The @code{\paper} block specifies how entered music should be converted
1290 to notation output. Most of the details of the conversion (font sizes,
1291 dimensions, etc.) have been taken care of, but to fit the output in this
1292 document, it has to be narrower. We do this by setting the line width
1293 to 14 centimeters (approximately 5.5 inches).
1300 The last brace ends the @code{\score} block.
1305 @node Lyrics and chords
1306 @section Lyrics and chords
1308 In this section we show how to typeset a song. This file is
1309 included as @file{flowing.ly}.
1313 title = "The river is flowing"
1314 composer = "Traditional"
1316 \include "paper16.ly"
1317 melody = \notes \relative c' @{
1321 c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
1322 c4 c8 d [es () d] c4 | d4 es8 d c4.
1327 The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
1328 ri -- ver is flo -- wing down to the sea.
1331 accompaniment =\chords @{
1333 c2:3- f:3-.7 d:min es4 c8:min r8
1334 c2:min f:min7 g:7^3.5 c:min @}
1339 \context ChordNames \accompaniment
1342 \context Staff = mel @{
1343 \property Staff.autoBeaming = ##f
1344 \property Staff.automaticMelismata = ##t
1347 \context Lyrics \text
1349 \midi @{ \tempo 4=72 @}
1350 \paper @{ linewidth = 10.0\cm @}
1355 The result would look this.@footnote{The titling and font size shown
1356 may differ, since the titling in this document is not generated by
1359 @center @strong{The river is flowing}
1364 title = "The river is flowing"
1365 composer = "Traditional"
1367 \include "paper16.ly"
1368 melody = \notes \relative c' {
1372 c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
1373 c4 c8 d [es () d] c4 | d4 es8 d c4.
1378 The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
1379 ri -- ver is flo -- wing down to the sea.
1382 accompaniment =\chords {
1384 c2:3- f:3-.7 d:min es4 c8:min r8
1385 c2:min f:min7 g:7^3.5 c:min }
1390 \context ChordNames \accompaniment
1393 \context Staff = mel {
1394 \property Staff.autoBeaming = ##f
1395 \property Staff.automaticMelismata = ##t
1398 \context Lyrics \text
1400 \midi { \tempo 4=72 }
1401 \paper { linewidth = 10.0\cm }
1405 Again, we will dissect the file line by line.
1412 @cindex @code{\header}
1413 Information about the music you are about to typeset goes into a
1414 @code{\header} block. The information in this block is not used by
1415 LilyPond, but it is passed into the output. @file{ly2dvi} uses this
1416 information to print titles above the music.
1420 title = "The river is flowing"
1421 composer = "Traditional (?)"
1424 @cindex identifier assignment
1425 the @code{\header} block contains assignments. In each assignment, a
1426 variable is set to a value.
1430 \include "paper16.ly"
1433 Smaller size for inclusion in a book.
1437 melody = \notes \relative c' @{
1440 The structure of the file will be the same as the previous one, a
1441 @code{\score} block with music in it. To keep things readable, we will
1442 give names to the different parts of music, and use the names to
1443 construct the music within the score block.
1450 @cindex @code{\partial}
1452 The piece starts with an anacrusis of one eighth.
1457 The key is C minor: we have three flats.
1462 c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
1463 c4 c8 d [es () d] c4 | d4 es8 d c4.
1468 @cindex manual beaming
1469 @cindex automatic beaming, turning off
1470 We use explicit beaming. Since this is a song, we turn automatic
1471 beams off, and use explicit beaming where needed.
1478 This ends the definition of @code{melody}.
1487 @cindex identifier assignment
1488 @cindex syllables, entering
1489 Another identifier assignment. This one is for the lyrics.
1490 Lyrics are formed by syllables that have duration, and not by
1491 notes. To make LilyPond parse words as syllables, switch it into
1492 lyrics mode with @code{\lyrics}. Again, the brace after @code{\lyrics}
1493 is a shorthand for @code{\sequential @{}.
1497 The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
1498 ri- ver is flo- __ wing down to the sea.
1502 @cindex extenders, lyric
1503 @cindex hyphens, lyric
1504 The syllables themselves are separated by spaces. You can get syllable
1505 extenders by entering @code{__}, and centered hyphens with
1506 @code{-}@code{-}. We don't enter durations for the syllables. They
1507 are aligned with the melody later.
1511 accompaniment =\chords @{
1515 @cindex mode, chords
1516 We'll put chords over the music. To enter them, there is a special mode
1517 analogous to @code{\lyrics} and @code{\notes} mode, where you can give
1518 the names of the chords you want, instead of listing the notes
1519 comprising the chord.
1526 There is no accompaniment during the anacrusis.
1535 @cindex chord modifier
1536 @cindex modifier, chord
1537 This is a c minor chord, lasting half a note. Chord are entered by
1538 entering the tonic. Then notes can be changed. In this case, a small third
1539 is used. The cod for this is @code{3-}.
1545 Similarly, @code{7} modifies (adds) a seventh, which is small by
1546 default to create the @code{f a c es} chord. Multiple modifiers must be
1554 Some modifiers have predefined names, e.g. @code{min} is the same as
1555 @code{3-}, so @code{d-min} is a minor @code{d} chord.
1559 c2:min f:min7 g:7^3.5 c:min @}
1562 @cindex named modifier
1564 A named modifier @code{min} and a normal modifier @code{7} do not have
1565 to be separated by a dot. Tones from a chord are removed with chord
1566 subtractions. Subtractions are started with a caret, and they are
1567 also separated by dots. In this example, @code{g:7^3.5} produces a
1568 minor seventh. The brace ends the sequential music.
1576 We assemble the music in the @code{\score} block. Melody, lyrics and
1577 accompaniment have to sound at the same time, so they should be
1578 @code{\simultaneous}.
1579 @cindex @code{\simultaneous}
1586 Chord mode generates notes grouped in @code{\simultaneous} music. If
1587 you remove the comment sign, you can see the chords in normal
1588 notation: they will be printed as note heads on a separate
1589 staff. To print them as chords names, they have to be interpreted as
1590 being chords, not notes. This is done with the following command:
1594 \context ChordNames \accompaniment
1598 @cindex interpretation context
1599 @cindex notation context
1602 Normally, the notes that you enter are transformed into note heads.
1603 Note heads alone make no sense, they need surrounding information: a key
1604 signature, a clef, staff lines, etc. They need @emph{context}. In
1605 LilyPond, these symbols are created by objects called `interpretation
1606 contexts'. Interpretation contexts exist for generating notation
1607 (`notation context') and for generating sound (`performance
1608 context'). These objects only exist during a run of LilyPond.
1610 When LilyPond interprets music, it will create a Staff context. If
1611 the @code{%} sign in the previous line were removed, you could see
1612 that mechanism in action.
1614 We don't want that default here, because we want chord names. The
1615 command above explicitly creates an interpretation context of
1616 @code{ChordNames} type to interpret the music @code{\accompaniment}.
1623 @cindex @code{\addlyrics}
1624 @cindex lyrics and melody, combining
1625 @cindex combining lyrics and melody
1627 The lyrics should be aligned with the melody. This is done by
1628 combining both with @code{\addlyrics}. @code{\addlyrics} takes two
1629 pieces of music (usually a melody and lyrics, in that order) and
1630 aligns the syllables of the second piece under the notes of the
1635 \context Staff = mel @{
1639 We place the melody on a staff called @code{mel}. We give it a name to
1640 differentiate it from the one that would contain note heads for the
1641 chords, if you would remove the comment before the ``note heads''
1642 version of the accompaniment. By giving this staff a name, it is
1643 forced to be different.
1647 \property Staff.autoBeaming = ##f
1651 @cindex context variables
1652 @cindex setting context variables
1653 An interpretation context has variables, called properties, that tune
1654 its behavior. One of the variables is @code{autoBeaming}. Setting
1655 this @code{Staff}'s property to @code{##f}, which is the boolean value
1656 @var{false}, turns the automatic beaming mechanism off for the current
1662 @cindex accessing Scheme
1663 @cindex evaluating Scheme
1666 LilyPond internally uses GUILE, a Scheme-interpreter. Scheme is a
1667 language from the LISP family. You can learn more about Scheme at
1668 @uref{http://www.scheme.org}. It is used to represent data throughout
1669 the whole program. The hash-sign (@code{#}) accesses GUILE directly: the
1670 code following the hash-sign is evaluated as Scheme. The boolean value
1671 @var{true} is @code{#t} in Scheme, so for LilyPond @var{true} looks like
1674 If Scheme scares you, don't worry. You don't need to know Scheme to
1675 create beautiful sheet music.
1682 \property Staff.automaticMelismata = ##t
1685 @cindex automaticMelismata
1687 @cindex @code{\addlyrics} and slurs
1688 Similarly, we don't want to print a syllable when there is
1689 a slur. This sets up @code{\addlyrics} to not put lyrics under each
1690 separate note while there is a slur.
1698 Finally, we put the melody on the current staff. Note that the
1699 @code{\property} directives and @code{\melody} are grouped in sequential
1700 music, so the property settings are done before the melody is
1705 \context Lyrics \text
1708 The second argument of @code{\addlyrics} is the text. The text also
1709 should not land on a Staff, but on a interpretation context for
1710 syllables, extenders, hyphens etc. This context is called
1715 \midi @{ \tempo 4=72@}
1718 MIDI (Musical Instrument Digital Interface) is a standard for
1719 connecting and recording digital instruments. So a MIDI file is like a
1720 tape recording of an instrument. The @code{\midi} block makes the
1721 music go to a MIDI file, so you can listen to the music you entered. It
1722 is great for checking the music. Whenever you hear something weird, you
1723 probably hear a typing error.
1725 Syntactically, @code{\midi} is similar to @code{\paper @{ @}}, since it
1726 also specifies an output method. You can specify the tempo using the
1727 @code{\tempo} command, in this case the tempo of quarter notes is set to
1728 72 beats per minute.
1732 \paper @{ linewidth = 10.0\cm @}
1735 We also want notation output. The linewidth is short so the piece
1736 will be set in two lines.
1738 @node More movements
1739 @section More movements
1741 [FIXME: merge here with, or move this to: Other ways to run LilyPond]
1743 You probably ran @file{ly2dvi} on the last example, and ended up with a
1744 viewable @file{.dvi} file. However, between there are a few steps of
1745 which LilyPond is only one. To enhance your understanding of what's
1746 happening under the hood when you run @code{ly2dvi}, we explain what
1749 @code{ly2dvi} is a program that calls a number of programs in sequence.
1750 The first thing it does, is running LilyPond on the input file. After
1751 some calculations, a @file{.tex} is produced. The contents
1752 of this file are very low-level instructions.
1754 For example, consider the following file (@file{miniatures.ly})
1759 title = "Two miniatures"
1760 tagline = "small is beautiful"
1763 #(set! point-and-click line-column-location)
1765 \paper @{ linewidth = -1.0 @}
1768 \notes @{ c'4 d'4 @}
1774 \notes @{ d'4 c'4 @}
1781 The titling in this manual was not generated by ly2dvi, so we can't
1782 exactly show what it would look like, but the result should resemble this:
1784 @center @strong{Two miniatures}
1794 \paper { linewidth = -1.0 }
1806 \paper { linewidth = -1.0 }
1810 This file is produced by ly2dvi in a few stages, with the help of text
1811 formatting tools. LilyPond produces two output files,
1812 @file{miniatures.tex} and @file{miniatures-1.tex}. Both files contain
1813 only graphical music notation. @file{ly2dvi} looks at what output
1814 LilyPond produces, and adds page layout and titling to those files. The
1815 result is a DVI file called @file{miniatures.dvi}.
1817 Next, now we'll look at the example line by line to explain new things.
1823 Lilypond and its language are still under development, and occasionally,
1824 details of the syntax are changed. This fragment indicates for which
1825 version the input file was written. When you compile this file, the
1826 version number will be checked, and you will get a warning when the file
1829 This version number is also used by the @code{convert-ly} program (See
1830 @ref{Upgrading from older LilyPond versions}), which is used to update
1831 the file to the latest lily version.
1836 title = "Two miniatures" @}
1838 This sets the titling information for the entire file.
1841 tagline = "small is beautiful"
1843 A signature line is printed at the bottom of the last page.
1844 This signature is produced from the @code{tagline} field of
1845 @code{\header}. Many people find the default "Lily was here,
1846 @var{version number}" too droll. If that is the case, assign
1847 something else to @code{tagline}, as shown above.
1850 #(set! point-and-click line-column-location)
1853 This piece of Scheme code sets the Scheme variable
1854 @code{point-and-click} to the value @var{line-column-location} (which
1855 itself is a Scheme procedure).
1857 Editing input files can be complicated if you're working with
1858 large files: if you're digitizing existing music, you have to
1859 synchronize the .ly file, the sheet music on your lap and the sheet
1860 music on the screen. The point-and-click mechanism makes it easy to
1861 find the origin of an error in the LY file: when you view the file with
1862 Xdvi and click on a note, your editor will jump to the spot where that
1863 note was entered. For more information, see @ref{Point and click}.
1870 The @code{\score} blocks that follow in the file don't have
1871 @code{\paper} sections, so the settings of this block are substituted: A
1872 paper block at top level, i.e. not in a @code{\score} block sets the
1873 default page layout.
1882 The variable @code{linewidth} normally sets the length of the systems on
1883 the page. However, a negative value has a special meaning. If
1884 @code{linewidth} is less than 0, no line breaks are inserted into the
1885 score, and the spacing is set to natural length: a short phrase takes up
1886 little space, a longer phrase more space.
1891 \notes @{ c'4 d'4 @}
1894 In previous examples, notes were specified in relative octaves,
1895 i.e. each note was put in the octave that is closest to its
1896 predecessor. Besides relative, there is also absolute octave
1897 specification, which you get when you don't specify @code{\relative}. In
1898 this input mode, the central C is denoted by @code{c'}. Going down, you
1899 get @code{c} @code{c,} @code{c,,} etc. Going up, you get @code{c''}
1902 When you're copying music from existing sheet music, relative octaves
1903 are probably the easiest to use: it's less typing work and errors are
1904 easily spotted. However, if you write LilyPond input directly, either by
1905 hand (i.e. composing) or by computer, absolute octaves may be easier to use.
1913 The @code{\header} is normally at the top of the file, where it sets
1914 values for the rest of the file. If you want to typeset different pieces
1915 from one file (for example, if there are multiple movements, or if
1916 you're making an exercise book), you can put different @code{\score}
1917 blocks into the input file. ly2dvi will assemble all LilyPond output
1918 files into a big document. The contents of \header blocks specified
1919 within each score, are used for the titling of each movement.
1925 For example, the Opus number is put at the right, and the piece string
1926 will be at the left.
1930 @node A piano excerpt
1931 @section A piano excerpt
1933 Our fourth subject is a piece of piano music. The fragment in the
1934 input file is a piano reduction of the G major Sinfonia by Giovanni
1935 Battista Sammartini. It was composed around 1740. It's in the source
1936 package under the name @file{sammartini.ly}.
1938 @lilypondfile[verbatim]{sammartini.ly}
1940 As you can see, this example features multiple voices on one staff. To
1941 make room for those voices, their notes have to be stemmed in opposite
1944 LilyPond includes the identifiers @code{\stemUp}, @code{\stemDown} along
1945 with some other commonly used formatting instructions, but to explain how
1946 it works, we wrote our own here. Of course, you should use predefined
1947 identifiers like these if possible: then you will be affected less by
1948 the implementation changes we occasionally make.
1952 viola = \notes \relative c' \context Voice = viola @{
1954 In this example, you can see multiple parts on a staff. Each part is
1955 associated with one notation context. This notation context handles
1956 stems and dynamics (among others). The type name of this context is
1957 @code{Voice}. For each part we have to make sure that there is
1958 precisely one @code{Voice} context, so we give it a unique name
1965 The delimiters @code{<} and @code{>} are shorthands for
1966 @code{\simultaneous @{} and @code{@}}. The expression enclosed in
1967 @code{<} and @code{>} is a chord.
1971 @code{\arpeggio} typesets an arpeggio sign (a wavy vertical line) before
1979 We want the viola to have stems down, and have all the other
1980 characteristics of a second voice. This is enforced using the
1981 @code{\voiceTwo} command: it inserts instructions that makes stem,
1982 ties, slurs, etc. go down.
1990 Relative octaves work a little differently with chords. The starting
1991 point for the note following a chord is the first note of the chord. So
1992 the @code{g} gets an octave up quote: it is a fifth above the starting
1993 note of the previous chord (the central C).
1999 @code{s} is a spacer rest. It does not print anything, but it does have
2000 the duration of a rest. It is useful for filling up voices that
2001 temporarily don't play. In this case, the viola doesn't come until one
2002 and a half measure later.
2006 oboes = \notes \relative c'' \context Voice = oboe @{
2008 Now comes a part for two oboes. They play homophonically, so we
2009 print the notes as one voice that makes chords. Again, we insure that
2010 these notes are indeed processed by precisely one context with
2014 \voiceOne s4 g8. b,16 c8 r <e'8. g> <f16 a>
2017 The oboes should have stems up, so they should have stems up, to keep
2018 them from interfering with the staff-jumping bass figure.
2022 \grace <e8( g> < d4 )f> <c2 e>
2024 @cindex @code{\grace}
2027 @code{\grace} introduces grace notes. It takes one argument, in this
2028 case a chord. A slur is introduced starting from the @code{\grace}
2029 ending on the following chord.
2037 Tuplets are made with the @code{\times} keyword. It takes two
2038 arguments: a fraction and a piece of music. The duration of the piece
2039 of music is multiplied by the fraction. Triplets make notes occupy 2/3
2040 of their notated duration, so in this case the fraction is 2/3.
2043 @{ <d8 f> <e g> <f a> @}
2045 The piece of music to be `tripletted' is sequential music containing
2052 At this point, the homophonic music splits into two rhythmically
2053 different parts. We can't use a sequence of chords to enter this, so
2054 we make a `chord' of sequences to do it. We start with the upper
2055 voice, which continues with upward stems:
2058 @{ \times 2/3 @{ a8 g c @} c2 @}
2065 The easiest way to enter multiple voices is demonstrated
2066 here. Separate the components of the voice (single notes or entire
2067 sequences) with @code{\\} in a simultaneous music expression. The
2068 @code{\\} separators split first voice, second voice, third voice, and
2071 As far as relative mode is concerned, the previous note is the
2072 @code{c'''2} of the upper voice, so we have to go an octave down for
2080 This ends the two-part section.
2084 \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |
2089 @code{\stemBoth} ends the forced stem directions. From here, stems are
2090 positioned as if it were single part music.
2092 The bass has a little hoom-pah melody to demonstrate parts switching
2093 between staves. Since it is repetitive, we use repeats:
2096 hoomPah = \repeat unfold 8
2098 @cindex unfolded @code{\repeat}
2099 The unfolded repeat prints the notes in its argument as if they were
2100 written out in full eight times.
2103 \notes \transpose c' @{
2106 @cindex relative mode and transposing
2108 Transposing can be done with @code{\transpose}, which takes two arguments.
2109 The first specifies what central C should be transposed to. The second
2110 is the to-be-transposed music. As you can see, in this case, the
2111 transposition has no effect, as central C stays at central C.
2113 The purpose of this no-op is to protect it from being interpreted as
2114 relative notes. Relative mode can not be used together with
2115 transposition, so @code{\relative} will leave the contents of
2116 @code{\hoomPah} alone. We can use it without having to worry about
2117 getting the motive in a wrong octave.
2119 @cindex staff switch, manual
2120 @cindex cross staff voice, manual
2121 @cindex @code{\translator}
2124 \translator Staff = down
2127 \translator Staff = up
2131 Voices can switch between staves. Here you see two staff switching
2132 commands. The first one moves to the lower staff, the second one to
2133 the lower one. If you set stem directions explicitly (using the
2134 identifiers @code{\stemUp} and @code{\stemDown}.
2138 bassvoices = \notes \relative c' @{
2140 \autochange Staff \hoomPah \context Voice
2145 \translator Staff = down
2147 @cindex staff switch
2148 @cindex cross staff voice
2149 We want the remaining part of this melody on the lower staff, so we do a
2150 manual staff switch here.
2155 \context Voice = reallyLow @{\stemDown g2 ~ | g4 c8 @} >
2159 After skipping some lines, we see @code{~}. This mark makes ties. Note
2160 that ties and slurs are different things. A tie can only connect two
2161 note heads of the same pitch, whereas a slur can connect many chords
2168 A special context is needed to get cross staff beaming right. This
2169 context is called @code{PianoStaff}.
2172 \context Staff = bottom < \time 2/2 \clef bass
2174 The bottom staff must have a different clef.
2179 To make some more room on the line, the first (in this case the only)
2180 line is not indented. The line still looks very cramped, but that is due
2181 to the page layout of this document.
2187 * font-size, multi-stanza.
2189 * Simple part combining in a Hymn
2193 @node Fine tuning a piece
2194 @section Fine tuning a piece
2196 In this section, we show some ways to fine tune the final output of a
2197 piece. We do so using a single measure of a moderately complex piano
2198 piece: a Brahms intermezzo (opus 119, no. 1).
2199 @cindex Brahms, Johannes
2201 The code for the untuned example shows us some new things.
2203 @lilypondfile[verbatim]{brahms-original.ly}
2213 The crescendo is ended at the half note by the escaped exclamation
2216 Hairpin dynamics can be indicated using @code{\>} to start a
2217 decrescendo, and @code{\!} to end one. The crescendo is started using
2218 @code{\<} and also ended using @code{\!}. Absolute dynamics can be
2219 entered using @code{\p}, @code{\mf}, etc. All these commands apply to
2220 the complete chord where they are entered, but for syntactical
2221 reasons, they must be attached to one of the notes of the chord.
2223 @cindex fingering instructions
2225 Fingering indications are entered simply using @code{-@var{N}}, where
2228 Now that we have the basic piece of music entered, we want to fine
2229 tune it, so we get something that resembles the original printed
2230 edition by Schott/Universal Edition:
2232 @lilypondfile{brahms-tweaked.ly}
2234 @cindex tuning grob behavior
2236 The basic process that we follow is that we override defaults in the
2237 printing system. We do this by setting variables in so-called grobs.
2238 Printed symbols are internally represented by Graphical Objects
2239 (Grobs). Each grob is described by a bunch of settings. These setting
2240 determine the fonts, offsets, sub-routines to be called on the grob,
2241 etc. The initial values of these settings are set in the Scheme file
2242 @file{scm/grob-description.scm}.
2244 @cindex slur attachments
2246 We start with the slur: the slur in the upper part, running from the F
2247 sharp to the A, runs from stem to stem in the printed edition, while
2248 ours starts from the note head at the left. The following property
2249 setting forces all slurs to run from stem to stem (and not from or to
2253 \property Voice.Slur \set #'attachment = #'(stem . stem)
2256 More precisely, this command extends the definition of the @code{Slur}
2257 object in the current @code{Voice}. The variable @code{attachment} is
2258 set to the pair of symbols @code{'(stem . stem)}.
2260 Although this is useful information, it is not very helpful: the
2261 lilypond backend supports approximately 240 variables like
2262 @code{attachment}, each with their own meaning and own type
2263 (eg. number, symbol, list, etc). Besides slur, LilyPond has 80
2264 different types of Grobs, that may be created in 14 different context
2265 types besides Voice.
2267 @cindex internal documentation
2268 @cindex finding grobs
2269 @cindex grob descriptiosn
2271 The interesting information is how you can figure out which properties
2272 to tune for your own scores. To discover this, you must have a copy of
2273 the internals document. This is a set of HTML pages, which should be
2274 included if you run a binary distribution@footnote{You can also
2275 compile them by executing @code{make -C Documentation/user/
2276 out/lilypond-internals.html} in the source package.}. This document is
2277 also available on the web: go to the lilypond website, click
2278 ``Documentation: other'' on the side bar, click
2279 ``lilypond-internals'', under information for users.
2281 You might want to bookmark either the HTML files on disk, or the one
2282 on the web. One word of caution is in place here: the internals
2283 documentation is generated from the definitions that lily uses. For
2284 that reason, it is strongly tied to the version of LilyPond that you
2285 use. Before you proceed, please make sure that you are using the
2286 documentation that corresponds to the LilyPond version that you use.
2288 Suppose that you wanted to tune the behavior of the slur. The first
2289 step is to get some general info on slurs in lilypond. Turn to the
2290 index, and look up slur. The section on slurs says
2292 The grob for this object is @internalsref{Slur}, generally in
2293 @internalsref{Voice} context.
2296 So the grob for this object is called @code{Slur}, and slurs are
2297 created in the @code{Voice} context. If you are reading this tutorial
2298 in the HTML version, then you can simply click Slur, otherwise, you
2299 must look it up the internal documentation: click ``grob overview'' ,
2300 and select ``slur'' (the list is alphabetical.)
2302 Now you get a list of all the properties that the slur object
2303 supports, along with their default values. Among the properties we
2304 find the @code{attachment} property, leading to
2306 \property Voice.Slur \set #'attachment = #'(stem . stem)
2309 If you ran the previous example, you have unknowingly already used
2310 this kind of command. The @file{ly/property-init.ly} contains the
2311 definition of @code{\stemUp}
2313 stemUp = \property Voice.Stem \set #'direction = #1
2317 We also want to move around the fingering `3'. In the printed edition
2318 it is not above the stem, but a little lower, slightly left of the
2319 stem. From the user manual, we find that the associated grob is called
2320 @code{Fingering}, but how do we know if we should use @code{Voice} or
2321 @code{Staff}. In many cases, @code{Voice} is a safe bet, but you can
2322 also deduce this information from the internals documentation: if you
2323 visit the documentation of @code{Fingering}, you will notice
2325 Fingering grobs are created by: Fingering_engraver
2330 Clicking @code{Fingering_engraver} will show you the documentation of
2331 the module responsible for interpreting the fingering instructions and
2332 translating them to a @code{Fingering} grob. Such a module is called
2333 an @emph{engraver}. The documentation of the @code{Fingering_engraver}
2336 Fingering_engraver is part of contexts: Voice and TabVoice
2338 so tuning the settings for Fingering should be done using either
2340 \property Voice.Fingering \set @dots{}
2344 \property TabVoice.Fingering \set @dots{}
2347 Since the @code{TabVoice} is only used for tab notation, we see that
2348 the first guess @code{Voice} was indeed correct.
2350 @cindex setting grob properties
2351 @cindex @code{extra-offset}
2353 For shifting the fingering, we use the grob property
2354 @code{extra-offset}. The following command manually adds an offset to
2355 the object. We move it a little to the left, and 1.8 staff space
2358 \property Voice.Fingering \set #'extra-offset = #'(-0.3 . -1.8)
2360 The @code{extra-offset} is a low-level feature: it moves around
2361 objects in the printout; the formatting engine is completely oblivious
2364 @cindex reverting grob properties
2365 @cindex undoing grob properties
2367 We only want to offset a single grob, so after the F-sharp, we must
2368 undo the setting. The technical term is to revert the grob property.
2370 \property Voice.Fingering \revert #'extra-offset
2373 @cindex property types
2374 @cindex translator properties
2375 @cindex grob properties
2376 @cindex music properties
2379 There is three different types of variables in LilyPond, something
2380 which is confusing at first (and for some, it stays like that).
2381 Variables such as @code{extra-offset} and @code{attachment} are called
2382 grob properties. They are something different from the translator
2383 properties, like @code{autoBeaming} and
2384 @code{automaticMelismata}. Finally, music expressions are internally
2385 also stored using properties, so-called music properties. You will
2386 encounter the latter type if you run Scheme functions on music using
2389 The second fingering instruction should be moved up a little, to avoid
2390 a collision with the slur. This could be achieved with
2391 @code{extra-offset}, but in this case, a simpler mechanism also
2392 works. We insert an empty text between the 5 and the note. The empty
2393 text pushes the fingering instruction away:
2395 a^" "^#'(finger "5")
2398 Lilypond tries to put fingering instructions closer to the notes as
2399 text instructions. To insert an empty text (@code{^" "}) between the
2400 finger and the note, we have disguised the fingering instruction as a
2401 text: @code{(finger "5")}.
2403 Normally, one would specify dynamics in a single voice, and start and
2404 end dynamics (such as @b{f} and @b{p}) will be aligned with
2405 hairpins. In this case, we want the decrescendo to be in a different
2406 place from the piano sign. We achieve this by putting the dynamic
2407 markings in different voices. The crescendo should be above the upper
2408 staff. This can be forced by the precooked command
2413 However, if you do that, the decrescendo will be too close to the
2414 upper voice, and collide with the stems. Looking at the manual for
2415 dynamics, we notice that ``Vertical positioning of these symbols is
2416 handled by the @internalsref{DynamicLineSpanner} grob.''. If we turn
2417 to the documentation of @code{DynamicLineSpanner}, we find that the
2418 @code{DynamicLineSpanner} supports several so-called
2419 `interfaces'. This grob not only puts dynamic objects next to the
2420 staff (@code{side-position-interface}), but it also groups dynamic
2421 objects (@code{axis-group-interface}), is considered a dynamic sign
2422 itself (@code{dynamic-interface}) and is a grob: it has the
2423 @code{grob-interface}, with all the variables that come with it.
2425 For the moment, we are interested in the side positioning:
2427 side-position-interface
2429 Position a victim object (this one) next to other objects (the
2430 support). In this case, the direction signifies where to put the
2431 victim object relative to the support (left or right, up or down?)
2433 Between the grob and its support (in this case: the notes in the voice
2434 going down), there should be more space. This space is controlled by
2435 @code{padding}, so we increase it.
2437 \property Voice.DynamicLineSpanner \override #'padding = #5.0
2440 This command is almost like the command for setting slur attachments,
2441 but subtly different in its details. Grob properties can be
2442 manipulated with two commands: @code{\override} extends the grob
2443 variables with a setting, and @code{\revert} releases this
2444 setting. This has a certain theoretical appeal: the operations are
2445 simple and symmetric. For practical use, it can be cumbersome. Both
2446 commands act like parentheses: you should carefully balance the use of
2447 @code{\override} and @code{\revert}. The @code{\set} command is more
2448 friendly: it first does a @code{\revert} followed by @code{\override}.
2450 Finally, Brahms uses music notation is a slightly unorthodox way. Ties
2451 usually happen only within one voice. In this piece, the composer
2452 gladly produces ties that jump voices. We deal with this by faking
2453 these ties: whenever we need such a tie, we insert a notehead in a
2454 different voice, and blank the stem. This is done in the following
2458 \property Voice.Stem \set #'transparent = ##t
2460 \property Voice.Stem \revert #'transparent
2463 Finally, the last tie is forced up using @code{\tieUp}.
2466 @node An orchestral score
2467 @section An orchestral score
2471 * Extracting an individual part::
2475 Our last two examples show a way to setup the music for an orchestral
2476 score. When typesetting a piece for several instruments, you'll want to
2477 create a conductor's full score, alongside several individual parts.
2479 LilyPond is well suited for this task. We will declare the music for
2480 each instrument individually, giving the music of each instrument its
2481 own name. These pieces of music are then combined in different
2482 @code{\score} blocks to produce different combinations of the score.
2484 This orchestral score example consists of three input files. In the
2485 first file, @file{os-music.ly}, we define the music for all instruments.
2486 This file will be used both for producing the score and the separate
2489 If you were to run LilyPond on this file, no printable output would be
2495 title = "Zo, goed lieverd?"
2496 subtitle = "How's, this babe?"
2505 Key = \notes \key as \major
2506 flautoI = \notes\relative c'' @{
2508 bes as bes as bes as bes as
2510 flautoII = \notes\relative c'' @{
2511 as8 bes as bes R1 d4 ~ d
2513 tromboI = \notes\relative c'' @{
2514 c4. c8 c8 c4. es4 r as, r
2516 tromboII = \notes\relative c'' @{
2517 as4. as8 as8 as4. R1*1/2 as4 es'
2519 timpani = \notes\relative c, @{
2520 \times 2/3 @{ f4 f f @}
2521 \times 4/5 @{ as8 as as as as @}
2524 corno = \notes\relative c' @{
2525 bes4 d f, bes d f, bes d
2529 We will not go through the input line by line, but only indicate and
2530 explain the new elements.
2537 \skip 2*4 \bar "|.";
2541 Declare setting to be used globally. The @code{\skip} command produces
2542 no output, but moves forward in time: in this case, the duration of a
2543 half note (@code{2}), and that four times (@code{*4}). This brings us
2544 to the end of the piece, and we can set the end bar.
2548 Key = \notes \key as \major
2550 Declare the key signature of the piece and assign it to the identifier
2551 @var{Key}. Later on, we'll use @code{\Key} for all staves except those
2552 for transposing instruments.
2554 @node The full score
2555 @subsection The full score
2558 The second file, @file{os-score.ly} reads the definitions of the first
2559 (@file{os-music.ly}), and defines the @code{\score} block for the full
2565 \include "os-music.ly"
2566 \include "paper13.ly"
2568 #(set! point-and-click line-column-location)
2569 #(define text-flat '((font-relative-size . -2)
2570 (music "accidentals--1")))
2575 \property Score.BarNumber \override #'padding = #3
2576 \context StaffGroup = woodwind <
2577 \context Staff = flauti <
2578 \property Staff.midiInstrument = #"flute"
2579 \property Staff.instrument = "2 Flauti"
2580 \property Staff.instr = "Fl."
2582 \context Voice=one @{ \voiceOne \flautoI @}
2583 \context Voice=two @{ \voiceTwo \flautoII @}
2586 \context StaffGroup = timpani <
2587 \context Staff = timpani <
2588 \property Staff.midiInstrument = #"timpani"
2589 \property Staff.instrument = #'(lines "Timpani" "(C-G)")
2590 \property Staff.instr = #"Timp."
2596 \context StaffGroup = brass <
2597 \context Staff = trombe <
2598 \property Staff.midiInstrument = #"trumpet"
2599 \property Staff.instrument = #`(lines "2 Trombe" "(C)")
2600 \property Staff.instr = #`(lines "Tbe." "(C)")
2602 \context Voice=one \partcombine Voice
2603 \context Thread=one \tromboI
2604 \context Thread=two \tromboII
2606 \context Staff = corni <
2607 \property Staff.midiInstrument = #"french horn"
2608 \property Staff.instrument = #`(lines "Corno"
2609 (columns "(E" ,text-flat ")"))
2610 \property Staff.instr = #`(lines "Cor."
2611 (columns "(E" ,text-flat ")"))
2612 \property Staff.transposing = #3
2613 \notes \key bes \major
2614 \context Voice=one \corno
2619 indent = 15 * \staffspace
2620 linewidth = 60 * \staffspace
2621 textheight = 90 * \staffspace
2623 \HaraKiriStaffContext
2632 @center @strong{Zo, goed lieverd?}
2634 @center How's, this babe?
2642 @lilypondfile{os-score.ly}
2646 \include "os-music.ly"
2648 First, we need to include the music definitions we made in
2653 #(set! point-and-click line-column-location)
2655 In a large orchestral score like this you're bound to make some small
2656 mistakes, so we enable point and click (See @ref{Point and click})
2661 #(define text-flat '((font-relative-size . -2)
2662 (music "accidentals--1")))
2665 When naming the tuning of the french horn, we'll need a piece of text
2666 with a flat sign. LilyPond has a mechanism for font selection and
2667 kerning called Scheme markup text (See @ref{Text markup}). The flat
2668 sign is taken from the music font, and its name is @code{accidentals--1}
2669 (The natural sign is called @code{accidentals-0}). The default font is
2670 too big for text, so we select a relative size of @code{-2}.
2677 Of course, all staves are simultaneous and use the same global settings.
2681 \property Score.BarNumber \override #'padding = #3
2683 LilyPond prints bar numbers at the start of each line, but
2684 unfortunately, they end up a bit too close to the staff in this
2685 example. A bar number internally is a Grob called @var{BarNumber}.
2686 BarNumber Grobs can be manipulated through their
2687 @var{side-position-interface}. One of the properties of a
2688 @var{side-position-interface} that can be tweaked is the
2689 @var{padding}: the amount of extra space that is put between this Grob
2690 and other Grobs. We set the padding to three staff spaces.
2692 You can find information on all these kind of properties in LilyPond's
2693 automatically generated documentation in
2695 @ref{ (lilypond-internals)lilypond-internals, LilyPond Internals}.
2698 the online documentation.
2703 \context StaffGroup = woodwind <
2704 \context Staff = flauti <
2706 A new notation context: the @code{StaffGroup}. @code{StaffGroup} can
2707 hold one or more @code{Staff}'s, and will print a big bracket at the
2708 left of the score. Start a new staff group for the woodwind section
2709 (just the flutes in this case). Immediately after that, we start the
2710 staff for the two flutes, that also play simultaneously.
2714 \property Staff.midiInstrument = #"flute"
2716 Specify the instrument for MIDI output (see @ref{MIDI instrument
2721 \property Staff.instrument = "2 Flauti"
2722 \property Staff.instr = "Fl."
2724 And define the instrument names to be printed in the margin,
2725 @code{instrument} for the first line of the score, @code{instr} for the
2732 The flutes play in the default key.
2736 \context Voice=one @{ \voiceOne \flautoI @}
2737 \context Voice=two @{ \voiceTwo \flautoII @}
2739 Last come the actual flute parts. Remember that we're still in
2740 simultaneous mode. We name both voices differently, so that LilyPond
2741 will actually create two Voice contexts. The flute parts are simple, so
2742 we specify manually which voice is which: @code{\voiceOne} forces the
2743 direction of stems, beams, slurs and ties up, @code{\voiceTwo} sets
2751 Close the flutes staff and woodwind staff group.
2755 \property Staff.instrument = #'(lines "Timpani" "(C-G)")
2757 The timpani staff only shows a new piece of scheme markup, it sets two
2762 \context Voice=one \partcombine Voice
2763 \context Thread=one \tromboI
2764 \context Thread=two \tromboII
2766 You have seen the notation contexts Staff and Voice, but here's a new
2767 one: Thread. One or more Threads can be part of a Voice. The Thread
2768 takes care of note heads and rests, the Voice combine note heads onto a
2771 For the trumpets we use the automatic part combiner (see @ref{Automatic
2772 part combining}) to combine the two simultaneous trumpet parts onto the
2773 trumpet staff. Each trumpet gets its own Thread context, which must be
2774 named @code{one} and @code{two}). The part combiner makes these two
2775 threads share a Voice when they're similar, and splits the threads up
2776 when they're different.
2780 \property Staff.instrument = #`(lines "Corno"
2781 (columns "(E" ,text-flat ")"))
2783 The french horn has the most complex scheme markup name, made up of two
2784 lines of text. The second line has three elements (columns), the @code{(E},
2785 the flat sign @code{text-flat} that we defined before and a final @code{")"}.
2786 Note that we use a backquote instead of an ordinary quote at the
2787 beginning of the Scheme expression to be able to access the
2788 @code{text-flat} identifier, `unquoting' it with a @code{,}.
2792 \property Staff.transposing = #3
2794 The french horn is to be tuned in E-flat, so we tell the MIDI backend to
2795 transpose this staff by three steps.
2797 Note how we can choose different tuning for entering, printing and
2798 playing, using @code{\transpose} and the MIDI Staff property
2803 \notes \key bes \major
2805 Therefore, it has a different key.
2809 indent = 15 * \staffspace
2810 linewidth = 60 * \staffspace
2812 We specify a big indent for the first line and a small linewidth for this
2817 Usually, LilyPond's predefined setup of notation contexts (Thread,
2818 Voice, Staff, Staffgroup, Score) is just fine. But in this case, we
2819 want a different type of Staff context.
2823 \HaraKiriStaffContext
2827 In orchestral scores, it often happens that one instrument has only
2828 rests during one line of the score. The @code{HaraKiriStaffContext} can
2829 be used as a regular @code{StaffContext} drop-in and will take care of
2830 the automatic removing of empty staves.
2832 @node Extracting an individual part
2833 @subsection Extracting an individual part
2835 The third file, @file{os-flute-2.ly} also reads the definitions of the
2836 first (@file{os-music.ly}), and defines the @code{\score} block for the
2840 \include "os-music.ly"
2841 \include "paper16.ly"
2845 \property Score.skipBars = ##t
2846 \property Staff.midiInstrument = #"flute"
2852 instrument = "Flauto II"
2855 linewidth = 80 * \staffspace
2856 textheight = 200 * \staffspace
2864 @center @strong{Zo, goed lieverd?}
2866 @center How's, this babe?
2867 @center @emph{Flauto II}
2874 @lilypondfile{os-flute-2.ly}
2877 Because we separated the music definitions from the @code{\score}
2878 instantiations, we can easily define a second score with the music of
2879 the second flute. This then is the part for the second flute player.
2880 Of course, we make separate parts for all individual instruments.
2886 In this individual part the second flute has a whole staff for itself,
2887 so we don't want to force stem or tie directions.
2892 instrument = "Flauto II"
2895 The @code{\header} definitions were also read from @file{os-music.ly},
2896 but we need to set the instrument for this particular score.
2900 \property Score.skipBars = ##t
2902 In the conductor's full score, all bars with rests are printed, but for
2903 the individual parts, we want to contract pieces of consecutive empty
2904 bars. LilyPond will do this if Score's @var{skipBars} property to
2908 @node Integrating text and music
2909 @section Integrating text and music
2911 Sometimes, you might want to use music examples in a text that you are
2912 writing. For example, if you are writing a musicological treatise, a
2913 songbook, or (like us) the LilyPond manual. You can make such texts by
2914 hand, simply by importing a PostScript figure into your wordprocessor.
2915 However, there is a also an automated procedure:
2917 If you use HTML, La@TeX{} or texinfo, you can mix text and LilyPond
2918 code. A script called @code{lilypond-book} will extract the music
2919 fragments, run LilyPond on them, and put back the resulting notation.
2920 This utility program is described fully in the chapter @ref{Merging text
2921 and music with lilypond-book}. Here we show a small example. Since the
2922 example also contains explanatory text, we won't comment on the
2926 \documentclass[a4paper]@{article@}
2929 In a lilypond-book document, you can freely mix music and text. For
2932 \score @{ \notes \relative c' @{
2933 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
2936 Notice that the music line length matches the margin settings of the
2939 If you have no \verb+\score+ block in the fragment,
2940 \texttt@{lilypond-book@} will supply one:
2946 In the example you see here, a number of things happened: a
2947 \verb+\score+ block was added, and the line width was set to natural
2948 length. You can specify many more options using \LaTeX style options
2951 \begin[verbatim,11pt,singleline,
2952 fragment,relative,intertext="hi there!"]@{lilypond@}
2956 \texttt@{verbatim@} also shows the LilyPond code, \texttt@{11pt@} selects
2957 the default music size, \texttt@{fragment@} adds a score block,
2958 \texttt@{relative@} uses relative mode for the fragment, and
2959 \texttt@{intertext@} specifies what to print between the
2960 \texttt@{verbatim@} code and the music.
2962 If you include large examples into the text, it may be more convenient
2963 to put the example in a separate file:
2965 \lilypondfile[printfilename]@{sammartini.ly@}
2967 The \texttt@{printfilename@} option adds the file name to the output.
2972 Under Unix, you can view the results as follows.
2975 $ lilypond-book --outdir=out/ lilbook.tex
2976 lilypond-book (GNU LilyPond) 1.3.146
2977 Reading `input/tutorial/lilbook.tex'
2978 Reading `input/tutorial/sammartini.ly'
2979 @var{lots of stuff deleted}
2980 Writing `out/lilbook.latex'
2982 $ latex lilbook.latex
2983 @var{lots of stuff deleted}
2987 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
2988 and running latex creates a lot of temporary files, and you wouldn't want
2989 those to clutter up your working directory. Hence, we have them created
2990 in a separate subdirectory.
2992 The result more or less looks like this:
2996 In a lilypond-book document, you can freely mix music and text. For
2999 \score { \notes \relative c' {
3000 c2 g'2 \times 2/3 { f8 e d } c'2 g4
3003 Notice that the music line length matches the margin settings of the
3006 If you have no @code{\score} block in the fragment,
3007 @code{lilypond-book} will supply one:
3013 In the example you see here, a number of things happened: a
3014 @code{\score} block was added, and the line width was set to natural
3015 length. You can specify many more options using La@TeX{} style options
3018 @lilypond[verbatim,11pt,singleline,
3019 fragment,relative,intertext="hi there!"]
3023 @code{verbatim} also shows the LilyPond code, @code{11pt} selects
3024 the default music size, @code{fragment} adds a score block,
3025 @code{relative} uses relative mode for the fragment, and
3026 @code{intertext} specifies what to print between the
3027 @code{verbatim} code and the music.
3029 If you include large examples into the text, it may be more convenient
3030 to put the example in a separate file:
3032 @lilypondfile[printfilename]{sammartini.ly}
3034 The @code{printfilename} option adds the file name to the output.
3035 @node End of tutorial
3036 @section End of tutorial
3038 That's all folks. From here, you can either try fiddling with input
3039 files, or you can read the reference manual. You can find more example
3040 files in @file{input} and @file{input/test}. You can also look at some
3041 real music. The website @uref{http://www.mutopiaproject.org} has many
3042 examples of real music typeset by LilyPond.
3050 this should be on mutopia website.
3055 @c waar deze info? is uiteindelijk wel handig, schat ik.
3058 If you have a big music project, or just a lot of LilyPond input files,
3059 all generated output from LilyPond, @TeX{} and metafont will clutter
3060 your working directory. LilyPond comes with a one-size-fits-all
3061 pre-cooked makefile that helps you manage producing output. It will
3062 produce all output in the directory @file{out} , generate and track
3063 dependencies. Also, it helps in preparing your submission to @ref{Mutopia
3070 cp /usr/share/lilypond/make/ly.make GNUmakefile
3071 cp /usr/share/doc/lilypond/examples/input/tutorial/minuet.ly .
3074 Generated out/minuet.ps for target minuet.
3077 Type @samp{make help} to see possible targets.
3080 @file{/usr/share/lilypond/doc/lilypond/examples/input/mutopia-header.ly}
3086 [TODO: rewrite completely.]
3089 * Songs with additional verses::