4 @c * LilyPond Lilypond lilypond (sometimes: the program)
5 @c * more details about running lilypond; error messages,
6 @c compiling/viewing (emacs?)
7 @c * where to go from First steps+More basics?
13 <!--- @@WEB-TITLE@@=Tutorial --->
17 * First steps:: Music language of LilyPond
18 * Running LilyPond:: Printing music
22 * Listening to output::
24 * Single staff polyphony ::
26 * Organising larger pieces::
27 * Fine tuning a piece::
28 * An orchestral score:: Conductor's score and individual parts
29 * Integrating text and music:: Integrating text and music
32 Operating is done through text files: To print a piece of music, you
33 enter the music in a file. When LilyPond is run (normally using the
34 program @code{ly2dvi}) on that file, another file containing formatted
35 sheet music, is produced. That file may be printed or viewed.
37 This tutorial starts with a small introduction to the LilyPond music
38 language. After this first contact, we will show which commands to
39 run to produce printed output, so you should then be able to create
40 your first sheets of music. The tutorial continues with more and more
47 We start off by showing how very simple music is entered in LilyPond:
48 you get a note simply by typing its @htmlref{note name}, from @samp{a}
49 through @samp{g}. So if you enter
56 then the result looks like this:
59 @c \transpose c c' { c d e f g a b }
61 @c \property Score.timing = ##f
62 @lilypond[notime, relative=2]
66 We will continue with this format: First we show a snippet of input,
67 then the resulting output.
69 The length of a note is specified by adding a number, @samp{1} for a
70 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
77 \property Score.timing = ##f
78 \property Staff.autoBeaming = ##f
79 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
82 If you do not specify a @rglos{duration}, the previous one is used:
89 \property Score.timing = ##f
90 \transpose c c' { a a a2 a s16_" " }
93 A @rglos{sharp} (@texisharp{}) is made by adding @samp{is}, a
94 @rglos{flat} (@texiflat{}) by adding @samp{es}. As you might expect,
95 a @rglos{double sharp} or @rglos{double flat} is made by adding
96 @samp{isis} or @samp{eses}:@footnote{This syntax derived from note
97 naming conventions in Nordic and Germanic languages, like German and
105 \property Score.timing = ##f
106 \transpose c c' { cis1 ees fisis aeses s16_" " }
109 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
116 \property Score.timing = ##f
117 \transpose c c' { a2. a4 a8. a16 s16_" " }
120 Entering pitches and durations is fully explained in @ref{Pitches} and
124 The @rglos{meter} (or @rglos{time signature}) can be set with the
125 @code{\time} command:
133 @c a clef here may lead to confusion
135 \property Staff.Clef \set #'transparent = ##t
144 Time signatures and other timing commands are described in @ref{Time
148 The @rglos{clef} can be set using the @code{\clef} command:
150 @c what is more common name treble or violin?
151 @c in Dutch, its violin.
152 @c in English its definitely treble.
161 \property Score.timing = ##f
172 Clefs are fully explained in @ref{Clef}.
175 When you enter these commands in a file, you must to enclose them in
176 @code{\notes @{@dots{}@}}. This lets LilyPond know that music (as
177 opposed to @rglos{lyrics}) follows:
187 Now the piece of music is almost ready to be printed. The final step is to
188 combine the music with a printing command.
190 The printing command is the so-called @code{\paper} block. Later on
191 you will see that the @code{\paper} block is used to customize
192 printing specifics. The music and the @code{\paper} block are combined by
193 enclosing them in @code{\score @{ ... @}}. This is what a full source file looks like:
216 linewidth = 55 * \staffspace
222 @node Running LilyPond
223 @section Running LilyPond
225 In the last section we explained what kind of things you could enter
226 in a LilyPond file. In this section we explain what commands to run
227 and how to view or print the output. If you have not used LilyPond
228 before, want to test your setup, or want to run an example file
229 yourself, read this section. The instructions that follow are for
230 Unix-like systems. Some additional instructions for MS Windows are given
231 at the end of this section.
233 Begin by opening a terminal window and starting a text editor.
234 For example, you could open an xterm and execute @code{joe}. In your
235 text editor, enter the following input and save the file as
241 \notes @{ c'4 e' g' @}
248 @c now this is weird, running ly2dvi to run LilyPond
249 @c (therefore name change proposal)
251 LilyPond is the program that computes the sheet music. All other
252 things, such as adding titles, page breaking and other page layout,
253 are done by a small wrapper program called
254 @code{ly2dvi}. @code{ly2dvi} calls LilyPond to render the music, and
255 then adds the titling and page layout instructions. To process
256 @file{test.ly} with @code{ly2dvi}, proceed as follows:
264 You will see the following on your screen:
269 Now processing: `/home/fred/ly/test.ly'
271 Interpreting music...[1]
272 @emph{ ... more interesting stuff ... }
273 PDF output to `test.pdf'...
274 DVI output to `test.dvi'...
278 @cindex Viewing music
281 The results of the ly2dvi run are two files, @file{test.dvi} and
282 @file{test.pdf}. The PDF file (@file{test.pdf}) is the one you can
283 print or view. For example, viewing PDF can be done with ghostview.
284 If a version of ghostview is installed on your system, one of these
285 commands will produce a window with some music notation on your
298 If the music on your screen looks good, you can print it by clicking
299 File/Print inside ghostview.
301 The DVI file (@file{test.dvi}) contains the same sheet music in a
302 different format. DVI files are more easily processed by the computer,
303 so viewing them usually is quicker. You can run @code{xdvi test.dvi}
304 @c KDVI doesn't grok the PS specials.
306 @c @code{kdvi test.dvi}
308 to view the DVI file. In Xdvi, the mouse buttons
309 activate magnifying glasses. Unfortunately, variable symbols (such as
310 beams and slurs) are not displayed in the magnifying glasses.
315 @cindex Printing output
319 If you are familiar with @TeX{}, be warned: do not use other DVI
320 drivers like @code{dvilj}. LilyPond DVI use embedded PostScript code
321 and will not render correctly with other DVI drivers besides
329 Various commands for formatting and printing music are detailed in
330 @ref{Invoking LilyPond}.
333 @unnumberedsubsec Windows users
335 Windows users can start the terminal by clicking on the LilyPond or
336 Cygwin icon. Any text editor (such as NotePad, Emacs or Vim) may be
337 used to edit the LilyPond file. When Cygwin's @code{XFree86} X11
338 window system is installed along with @code{tetex-x11} and
339 @code{ghostscript-x11} packages, then the @code{dvi} output may be
340 viewed with @code{xdvi test.dvi} as described above. If you have
341 installed a PostScript/PDF viewer, such as @code{GSView} from
342 @uref{http://www.cs.wisc.edu/~ghost}, viewing the PDF file can be done
346 @code{gsview32 test.pdf}
349 Printing may be done by executing
352 @code{gsview32 /s test.pdf}
360 We continue with the introduction of more musical constructs. Normal
361 rests are entered just like notes with the name ``@code{r}'':
369 \property Score.timing = ##f
370 \property Staff.Clef = \turnOff
371 \property Staff.TimeSignature = \turnOff
378 Rests are described in full detail in @ref{Rests}.
381 @c Tim wants to move this quotes example just before the: quotes-do not-work
382 @c score, but we'd need to remove quotes from the other two (key and
385 @c better to have this just before the `octaves are bad' snipped
386 @c but we'd need to remove the ', from \key and tie
387 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
388 the note name, to lower a note one octave, add a ``low quote'' @code{,}
389 (a comma). Middle C is @code{c'}:
393 c'4 c'' c''' \clef bass c c,
397 \property Score.timing = ##f
398 \property Staff.TimeSignature = \turnOff
399 c'4 c'' c''' \clef bass c c,
404 A tie is created by adding a tilde ``@code{~}'' to the first note
407 @lilypond[fragment,verbatim]
412 A tie is different from a slur. A tie simply makes the first note
413 sound longer, and can only be used on pairs of notes with the same
414 pitch. Slurs indicate the articulations of notes, and can be used on
415 larger groups of notes. Slurs and ties are also nested in practice:
416 @lilypond[fragment, relative=1]
417 c2-~-( c8 fis fis4 ~ fis2 g2-)
420 The notation manual discusses ties in @ref{Ties}.
422 The key signature is set with the command ``@code{\key}'', followed by
423 a pitch and @code{\major} or @code{\minor}:
433 \property Staff.TimeSignature = \turnOff
443 @c bit on the long/complex/scary taste
444 @c cheating a bit: two lines makes for a friendlier look
445 This example shows notes, ties, octave marks, and rests in action.
454 r4 r8 d''8 cis''4 e''
456 cis''4 cis''8 cis'' bis'4 d''8 cis''-~
469 r4 r8 d''8 cis''4 e''
471 cis''4 cis''8 cis'' bis'4 d''8 cis''-~
474 \paper { linewidth = 50*\staffspace }
480 There are some interesting points to note in this example.
481 Accidentals (sharps and flats) do not have to be marked explicitly:
482 you just enter the note name, and an accidental is printed
483 automatically, only when necessary. Bar lines and beams are drawn
484 automatically. Line breaks are calculated automatically; it does not
485 matter where the lines breaks are in the source file. Finally, the
486 order of time, key and clef changes is not relevant: in the printout,
487 these are ordered using standard notation conventions.
489 The example also indicates that a piece of music written in a high
490 register needs lots of quotes. This makes the input less readable,
491 and is also a potential source of errors.
493 The solution is to use ``relative octave'' mode. In practice, this is
494 the most convenient way to copy existing music. To use relative mode,
495 add @code{\relative} before the piece of music. You must also give a
496 note from which relative starts, in this case @code{c''}. If you do
497 not use octavation quotes (i.e. do not add ' or , after a note),
498 relative mode chooses the note that is closest to the previous one.
499 @c do not use commas or quotes in this sentence
500 For example: @code{c f} goes up; @code{c g} goes down:
510 \property Score.timing = ##f
511 \property Staff.TimeSignature = \turnOff
520 Since most music has small intervals, in relative mode pieces can be
521 written almost without using octavation quotes.
523 @c needed better, maybe even redundant explanation
524 @c added another example below.
525 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
526 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
527 Larger intervals are made by adding octavation quotes. Quotes or
528 commas do not determine the absolute height of a note; the height of a
529 note is relative to the previous one.
530 @c do not use commas or quotes in this sentence
531 For example: @code{c f,} goes down; @code{f, f} are both the same;
532 @code{c' c} are the same; and @code{c g'} goes up:
542 \property Score.timing = ##f
543 \property Staff.TimeSignature = \turnOff
552 Here is an example of the difference between relative mode and
553 ``normal'' (non-relative) mode:
564 \property Score.timing = ##f
565 \property Staff.TimeSignature = \turnOff
581 \property Score.timing = ##f
582 \property Staff.TimeSignature = \turnOff
589 A slur is drawn across many notes, and indicates bound articulation
590 (legato). The starting note and ending note are marked with a
591 ``@code{(}'' and a ``@code{)}'' respectively:
594 @lilypond[fragment,relative 1, verbatim]
595 d4-( c16-)-( cis d e c cis d e-)-( d4-)
600 If you need two slurs at the same time (one for articulation, one for
601 phrasing), you can also make a phrasing slur with @code{\(} and
606 @c fragment of 1st hrn in Adams' The Chairman Dances, with creative
607 @c chromatic thing pasted in front. (admittedly the original does not
608 @c have a phrasing slur. The problem is that we do not want the slur
609 @c and the Phrasing slur to collide. We are trying to make a good
613 @lilypond[fragment,relative 1, verbatim]
614 a8-(-\( ais b c-) cis2 b'2 a4 cis, c-\)
619 Beams are drawn automatically, but if you do not like the choices, you
620 can enter beams by hand. Mark the first note to be beamed with
621 @code{[} and the last one with @code{]}:
623 @lilypond[fragment,relative 1, verbatim]
624 a8-[ ais-] d-[ es r d-]
629 To print more than one staff, each piece of music that makes up a staff
630 is marked by adding @code{\context Staff} before it. These
631 @code{Staff}'s are then grouped inside @code{<} and @code{>}, as is
635 @lilypond[fragment,verbatim]
637 \context Staff = staffA { \clef violin c'' }
638 \context Staff = staffB { \clef bass c }
643 In this example, @code{staffA} and @code{staffB} are names that are
644 given to the staves. It does not matter what names you give, as long
645 as each staff has a different name. If you give them the same name,
646 they are assumed to belong on the same staff, and will be printed like
651 We can now typeset a melody with two staves:
654 @lilypond[verbatim,singleline]
657 < \context Staff = staffA {
661 e2-( d4 c2 b4 a8-[ a-]
662 b-[ b-] g-[ g-] a2.-) }
664 \context Staff = staffB {
675 Notice that the time signature is specified in one melody staff only
676 (the top staff), but is printed on both. LilyPond knows that the time
677 signature should be the same for all staves.
681 Common accents can be added to a note using @code{-.}, @code{--}, @code{->}:
683 @lilypond[verbatim,relative 1]
689 Similarly, fingering indications can be added to a note using @code{-}
690 and the digit to be printed.
691 @lilypond[verbatim,relative 1]
699 Dynamic signs are made by adding the markings to the note:
701 @lilypond[verbatim,relative 1]
707 Crescendi and decrescendi are started with the commands @code{\<} and
708 @code{\>}. The command @code{\!} finishes a crescendo on the note it
711 @lilypond[verbatim,relative 1]
712 c2-\< c2-\!-\ff c2-\> c2-\!
717 Chords can be made by
718 surrounding pitches with @code{<<} and @code{>}>:
720 @lilypond[relative 0, fragment,verbatim]
721 r4 <<c e g>>4 <<c f a>>8
727 You can combine beams and ties with chords. Beam and tie markings
728 must be placed outside the chord markers:
730 @lilypond[relative 0, fragment,verbatim]
731 r4 <<c e g>>8-[ <<c f a>>-]-~ <<c f a>>
737 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
739 @lilypond[relative 0, fragment]
741 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>> <<c f a>>8-\!-)
747 A pickup (or upstep) is entered with the keyword @code{\partial}. It
748 is followed by a duration: @code{\partial 4} is a quarter note upstep.
749 @lilypond[relative 1,verbatim,fragment]
754 Tuplets are made with the @code{\times} keyword. It takes two
755 arguments: a fraction and a piece of music. The duration of the piece
756 of music is multiplied by the fraction. Triplets make notes occupy
757 2/3 of their notated duration, so for a triplet, the fraction is 2/3.
759 @lilypond[relative 0,verbatim,fragment]
760 \times 2/3 { f8 g a }
767 Comments are pieces of the input that are ignored. There are two
768 types of comments. A line comments are introduced by @code{%}: after
769 that, the rest of that line is ignored. Block comments span larger
770 sections of input. Anything that is enclosed in @code{%@{} and
771 @code{%@}} is ignored too. The following fragment shows possible uses
775 % notes for twinkle twinkle follow:
780 This line, and the notes below
781 are ignored, since they are in a
792 @node Printing lyrics
793 @section Printing lyrics
796 Lyrics are entered by separating each syllable with a space, and
797 surrounding them with @code{\lyrics @{ @dots{} @}}, for example
799 \lyrics @{ I want to break free @}
802 Like notes, lyrics are also a form of music, but they must not be
803 printed on a staff, which is the default way to print music. To print
804 them as lyrics, they must be marked with @code{ \context Lyrics}:
806 \context Lyrics \lyrics @{ I want to break free @}
808 The melody for this song is as follows
809 @lilypond[fragment,relative=1]
812 \times 2/3 { f4 g g } \times 2/3 { g4-( a2-) }
815 The lyrics can be set to these notes, combining both with the
816 @code{\addlyrics} keyword:
820 \context Lyrics @dots{}
824 @lilypond[singleline,verbatim]
831 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
833 \context Lyrics \lyrics { I want to break free }
839 This melody ends on a @rglos{melisma}, a single syllable (``free'')
840 sung to more than one note. This is indicated with a @emph{extender
841 line}. It is entered as two underscores, i.e.,
843 \lyrics @{ I want to break free __ @}
845 @lilypond[singleline]
852 \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
854 \context Lyrics \lyrics { I want to break free __ }
860 Similarly, hyphens between words can be entered as two dashes,
861 resulting in a centered hyphen between two syllables.
863 Twin -- kle twin -- kle
865 @lilypond[singleline]
867 \addlyrics \notes \relative f' { \time 2/4
869 \context Lyrics \lyrics { Twin -- kle twin -- kle
873 More options, like putting multiple lines of lyrics below a melody are
874 discussed in @ref{Vocal music}.
878 @section A lead sheet
880 In popular music, it is common to denote accompaniment as chord-names.
881 Using them in LilyPond has two parts, just like lyrics: entering the
882 chords (with @code{\chords}), and printing them (with @code{\context
885 Chord names are entered by starting chords mode (with @code{\chords}).
886 In chords mode, you can enter chords with a letter (indicating the
887 root of the chord), and a durations following that.
890 \chords { c2 f4. g8 }
892 The result of @code{\chords} is a list of chords, and is equivalent
893 to entering chords with @code{<<@dots{}>>}.
895 Other chords can be created by adding modifiers, after a colon. The
896 following example shows a few common modifiers
899 \chords { c2 f4:m g4:maj7 gis1:dim7 }
902 Printing chords is done by adding @code{\context ChordNames}
903 before the chords thus entered:
906 \context ChordNames \chords \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
909 A complete list of modifiers, and other options for layout are in the
910 reference manual section @ref{Chords}.
913 When put together, chord names, lyrics and a melody form
914 a lead sheet, for example,
919 \context ChordNames \chords @{ @emph{chords} @}
921 \notes @emph{the melody}
922 \context Lyrics \lyrics @{ @emph{the text} @}
927 @lilypond[singleline]
930 \context ChordNames \chords { r8 c2:sus4 f }
932 \notes \relative c' {
935 \times 2/3 { f g g } \times 2/3 { g4-( a2-) } }
936 \context Lyrics \lyrics { I want to break free __ }
943 @node Listening to output
944 @section Listening to output
946 MIDI (Musical Instrument Digital Interface) is a standard for
947 connecting and recording digital instruments. A MIDI file is like a
948 tape recording of a MIDI instrument. The @code{\midi} block makes the
949 music go to a MIDI file, so you can listen to the music you entered.
950 It is great for checking the music: octaves that are off, or
951 accidentals that were mistyped, stand out very much when listening to
952 the musical transcription.
954 @code{\midi} can be used in similarly to @code{\paper @{ @}}, for
959 \midi @{ \tempo 4=72@}
964 Here, the tempo is specified using the @code{\tempo} command. In this
965 case the tempo of quarter notes is set to 72 beats per minute. More
966 information on auditory output is in the @ref{Sound} section in the
973 Bibliographic information is entered in a separate block, the
974 @code{\header} block. The name of the piece, its composer, etc. are
975 entered as assignment within @code{\header @{ @dots{} @}}. For
979 title = "Eight miniatures"
980 composer = "Igor Stravinsky"
981 tagline = "small is beautiful"
987 @cindex bibliographic information
993 When the file is processed by @code{ly2dvi}, the title and composer
994 specified are printed above the music. The `tagline' is a short line
995 printed at bottom of the last page, which normally says ``Lily was
996 here, version @dots{}''. In the example above, it is replaced by the
997 line ``small is beautiful.''
999 Normally, the @code{\header} is put at the top of the file. However,
1000 for a document that contains multiple pieces (e.g. a etude book, or
1001 part with multiple movements), then the header can be put into the
1002 @code{\score} block as follows In this case, the name of each piece
1003 will be printed before each movement.
1006 @cindex Lily was here
1007 @cindex signature line
1012 title = "Eight miniatures"
1013 composer = "Igor Stravinsky"
1014 tagline = "small is beautiful"
1018 \header @{ piece = "Adagio" @}
1021 \header @{ piece = "Menuetto" @}
1025 More information on titling can be found in @ref{Invoking ly2dvi}.
1028 @node Single staff polyphony
1029 @section Single staff polyphony
1031 When different melodic lines are combined on a single staff, these are
1032 printed as polyphonic voices: each voice has its own stems, slurs
1033 and beams, and the top voice has the stems up, while the bottom voice
1036 Entering such parts is done by entering each voice as a sequence (with
1037 @code{@{ .. @}}), and combing those simultaneously, separating the
1038 voices with @code{\\}:
1040 @lilypond[verbatim,relative]
1041 < { a4 g2 f4-~ f4 } \\
1045 More features of polyphonic typesetting are in the notation manual,
1049 @section Piano staffs
1051 @cindex staff switch, manual
1052 @cindex cross staff voice, manual
1053 @cindex @code{\translator}
1058 @node Organising larger pieces
1059 @section Organising larger pieces
1061 TODO: discuss identifiers, p&c, .
1067 Lilypond and its language are still under development, and
1068 occasionally details of the syntax are changed. The @code{version}
1069 fragment indicates which LilyPond version the input file was written
1070 for. When you compile this file, the version number will be
1071 checked. When the file is too old, a warning is issued. The version
1072 number is also used by the @code{convert-ly} program (See
1073 @ref{Invoking convert-ly}), which updates the file to the latest
1074 version automatically.
1081 @code{s} is a spacer rest. It does not print anything, but it does have
1082 the duration of a rest. It is useful for filling up voices that
1083 temporarily do not play. In this case, the viola does not come until one
1084 and a half measure later.
1088 \grace <<e g>>-( <<d f>>4-) <<c e>>2
1090 @cindex @code{\grace}
1093 @code{\grace} introduces grace notes. It takes one argument, in this
1094 case a chord. A slur is introduced starting from the @code{\grace}
1095 ending on the following chord.
1106 @{ <<d f>>8 <<e g>> <<f a>> @}
1108 The piece of music to be `tripletted' is sequential music containing
1112 The bass has a little hoom-pah melody to demonstrate parts switching
1113 between staves. Since it is repetitive, we use repeats:
1116 hoomPah = \repeat unfold 8
1118 @cindex unfolded @code{\repeat}
1119 The unfolded repeat prints the notes in its argument as if they were
1120 written out in full eight times.
1123 @node Fine tuning a piece
1124 @section Fine tuning a piece
1126 In this section we show some ways to fine tune the final output of a
1127 piece. We do so using a single measure of a moderately complex piano
1128 piece: a Brahms intermezzo (opus 119, no. 1). Both fragments (the
1129 tuned and the untuned versions) are in @file{input/tutorial/}.
1131 The code for the untuned example shows us some new things.
1133 @lilypondfile[verbatim]{brahms-original.ly}
1144 Now that we have the basic piece of music entered, we want to fine
1145 tune it so that we get something that resembles the original printed
1146 edition by Schott/Universal Edition:
1148 @lilypondfile{brahms-tweaked.ly}
1150 @cindex tuning graphical objects
1152 Fine tuning involves overriding the defaults of the printing system.
1153 We do this by setting variables which control how Lilypond prints
1154 symbols. Printed symbols are called graphical objects (often
1155 abbreviated to @emph{grob}). Each object is described by a bunch of
1156 settings. Every setting is a variable: it has a name and a value
1157 which you can change. These values determine the fonts, offsets,
1158 sub-routines to be called on the object, etc. The initial values of
1159 these settings are set in the Scheme file
1160 @file{scm/grob-description.scm}.
1162 @cindex slur attachments
1164 We start with the slur in the upper part, running from F sharp to A. In
1165 the printed edition, this slur runs from stem to stem; in our version,
1166 the slur begins at the note head of the F sharp. The following property
1167 setting forces all slurs to run from stem to stem (not from or to note
1171 \property Voice.Slur \set #'attachment = #'(stem . stem)
1174 More precisely, this command modifies the definition of the @code{Slur}
1175 object in the current @code{Voice}. The variable @code{attachment} is
1176 set to the pair of symbols @code{'(stem . stem)}.
1178 @cindex internal documentation
1179 @cindex finding graphical objects
1180 @cindex graphical object descriptions
1182 This command fixes one particular problem with a slur. The rest of
1183 this section explains how to figure out which properties to tune for
1184 your own scores. To discover this, you must have a copy of the
1185 internals document. This is a set of HTML pages which should be
1186 included if you installed a binary distribution. [TODO: revise for
1187 new site.] These HTML pages are also available on the web: go to the
1188 LilyPond website, click ``Documentation: Index'' on the side bar, look
1189 in the ``Information for uses'' section, and click on ``Documentation
1192 You might want to bookmark either the HTML files on your disk, or the
1193 one on the web (the HTML on your hard drive will load much faster than
1194 the ones on the web!). One word of caution: the internals
1195 documentation is generated from the definitions that the program uses.
1196 Hence, the internals documentation is strongly tied to the version you
1197 use. Before you proceed, make sure that the program and documentation
1198 have matching version numbers.
1200 @c TODO: the quote is incorrect, although that shouldn't be a big
1201 @c problem for the reader.
1202 Suppose that you wanted to tune the behavior of the slur. The first
1203 step is to get some general information on slurs in LilyPond. Turn to
1204 the index, and look up ``slur''. The section on slurs says
1206 The grob for this object is @internalsref{Slur}, generally in
1207 @internalsref{Voice} context.
1210 So the graphical object for this object is called @code{Slur}, and
1211 slurs are created in the @code{Voice} context. If you are reading
1212 this tutorial in the HTML version, then you can simply click Slur,
1213 otherwise, you should look it up the internal documentation: click
1214 ``grob overview'' and select ``slur'' (the list is alphabetical).
1216 Now you get a list of all the properties that the slur object
1217 supports, along with their default values. Among the properties we
1218 find the @code{attachment} property with its default setting.
1219 The property documentation explains that the following setting will
1220 produce the desired effect:
1222 \property Voice.Slur \set #'attachment = #'(stem . stem)
1225 @c this is a long section, and adding an extra space here helps to
1226 @c break it into smaller subsections and thus is easier to understand.
1229 Next we want to move the fingering `3'. In the printed edition it is
1230 not above the stem, but a little lower and slightly left of the stem.
1231 From the user manual we find that the associated graphical object is
1232 called @code{Fingering}, but how do we know if we should use
1233 @code{Voice} or @code{Staff}? In many cases, @code{Voice} is a safe
1234 bet, but you can also deduce this information from the internals
1235 documentation: if you visit the documentation of @code{Fingering}, you
1238 Fingering grobs are created by: Fingering_engraver
1241 Clicking @code{Fingering_engraver} will show you the documentation of
1242 the module responsible for interpreting the fingering instructions and
1243 translating them to a @code{Fingering} object. Such a module is called
1244 an @emph{engraver}. The documentation of the @code{Fingering_engraver}
1247 Fingering_engraver is part of contexts: Voice and TabVoice
1249 so tuning the settings for Fingering should be done using either
1251 \property Voice.Fingering \set @dots{}
1255 \property TabVoice.Fingering \set @dots{}
1258 Since the @code{TabVoice} is only used for tab notation, we see that
1259 the first guess @code{Voice} was indeed correct.
1261 @cindex setting object properties
1262 @cindex @code{extra-offset}
1264 For shifting the fingering, we use the property @code{extra-offset}.
1265 The following command manually adds an offset to the object. We move
1266 it a little to the left, and 1.8 staff space downwards.
1268 \once \property Voice.Fingering \set #'extra-offset = #'(-0.3 . -1.8)
1270 The @code{extra-offset} is a low-level feature: it moves around
1271 objects in the printout; the formatting engine is completely oblivious
1272 to these offsets. The unit of these offsets are staff-spaces. The
1273 first number controls left-right movement; a positive number will move
1274 the object to the right. The second number controls up-down movement;
1275 a positive number will move it higher.
1276 We only want to offset a single object, so this statement is adorned
1279 @cindex property types
1280 @cindex translator properties
1281 @cindex grob properties
1282 @cindex music properties
1285 There are three different types of variables in LilyPond, something
1286 which can be confusing at first (and for some people it stays
1287 confusing). Variables such as @code{extra-offset} and
1288 @code{attachment} are called grob properties. They are not the same
1289 as translator properties, like @code{autoBeaming}. Finally, music
1290 expressions are internally stored using properties (so-called music
1291 properties). You will encounter music properties if you run Scheme
1292 functions on music using @code{\apply}.
1294 The second fingering instruction should be moved up a little to avoid
1295 a collision with the slur. This could be achieved with
1296 @code{extra-offset}, but in this case, a simpler mechanism also
1297 works. We insert an empty text between the 5 and the note. The empty
1298 text pushes the fingering instruction away:
1300 a-)^" "^\markup @{ \finger "5" @}
1303 A fingering instruction, which would be entered as @code{^5}, is put
1304 as close to the notes as possible, closer than the space entered to
1305 push away the 5. Hence, the 5 is entered as a normal text, with the
1306 formatting of fingering instructions.
1310 Normally one would specify all dynamics in the same voice, so that
1311 dynamics (such as @b{f} and @b{p}) will be aligned with hairpins. But
1312 in this case, we do not want the decrescendo to be aligned with the
1313 piano sign. We achieve this by putting the dynamic markings in different
1314 voices. The crescendo should be above the upper staff. This can be
1315 forced by using the precooked command
1320 However, if you do that the decrescendo will be too close to the upper
1321 voice and collide with the stems. Looking at the manual for dynamics,
1322 we notice that ``Vertical positioning of these symbols is handled by
1323 the @internalsref{DynamicLineSpanner} grob.''. If we turn to the
1324 documentation of @code{DynamicLineSpanner}, we find that
1325 @code{DynamicLineSpanner} supports several so-called `interfaces'.
1326 This object not only puts objects next to the staff
1327 (@code{side-position-interface}), but it also groups dynamic objects
1328 (@code{axis-group-interface}), is considered a dynamic sign itself
1329 (@code{dynamic-interface}), and is an spanning object
1330 (@code{spanner-interface}). It also has the standard
1331 @code{grob-interface} with all the variables that come with it.
1333 For the moment we are interested in side positioning:
1335 side-position-interface
1337 Position a victim object (this one) next to other objects (the
1338 support). In this case, the direction signifies where to put the
1339 victim object relative to the support (left or right, up or down?)
1341 Between the object and its support (in this case, the descending
1342 notes), there should be more space. This space is controlled by
1343 @code{padding}, so we increase it.
1345 \property Voice.DynamicLineSpanner \override #'padding = #5.0
1349 (TODO: huh? what's this: )
1351 This command resembles the one for setting slur attachments, but
1352 subtly differs in its details. Grob properties can be manipulated
1353 with two commands: @code{\override} extends the definition of a grob
1354 with one setting, and @code{\revert} releases this setting. This has
1355 a theoretical appeal: the operations are simple and symmetric. For
1356 practical use, it can be cumbersome. The commands act like
1357 parentheses: you should carefully balance the use of @code{\override}
1358 and @code{\revert}. The @code{\set} command is more friendly: it
1359 first does a @code{\revert} followed by @code{\override}.
1363 Brahms uses music notation is a slightly unorthodox way. Ties
1364 usually happen only within one voice. In this piece, the composer
1365 gladly produces ties that jump voices. We deal with this by faking
1366 these ties: whenever we need such a tie, we insert a notehead in a
1367 different voice, and blank the stem. This is done in the following
1370 @cindex transparent objects
1371 @cindex removing objects
1372 @cindex invisible objects
1374 \property Voice.Stem \set #'transparent = ##t
1377 Blanking the stem should be done for only one object. One of the ways
1378 to achieve that, is by setting the property before a note. Reverting
1379 it afterwards is tedious, so for setting a property only once, we have
1380 the syntax @code{\once}: it reverts the property directly before
1381 proceeding to the next step in time.
1383 The @code{\once} keyword is added to @code{\property}.
1386 Finally, the last tie is forced up using @code{\tieUp}.
1390 Here is the complete ``fine tuned'' version, which includes all the
1391 modifications we discussed in this section:
1393 @lilypondfile[verbatim]{brahms-tweaked.ly}
1396 @node An orchestral score
1397 @section An orchestral score
1401 * Extracting an individual part::
1405 Our next two examples demonstrate one way to create an orchestral
1406 score in LilyPond. When typesetting a piece for several instruments,
1407 you will want to create a full score (for the conductor) along with
1408 several individual parts (for the players).
1410 We will declare the music for each instrument individually, giving
1411 the music of each instrument its own name. These pieces of music are
1412 then combined in different @code{\score} blocks to produce different
1413 combinations of instruments (for example, one @code{\score} block may
1414 only include the cello part; another @code{\score} block may be for
1415 all the strings, and yet another @code{\score} block may be for all
1418 This orchestral score example consists of three input files. In the
1419 first file, @file{os-music.ly}, we define the music for all
1420 instruments. This file will be used for producing the score and the
1421 separate parts, but the file does not produce any sheet music itself.
1422 Other files reference it by stating @code{\include "os-music.ly"}.
1427 title = "Zo, goed lieverd?"
1428 subtitle = "How's, this babe?"
1437 Key = \notes \key as \major
1438 flautoI = \notes\relative c'' @{
1440 bes as bes as bes as bes as
1442 flautoII = \notes\relative c'' @{
1443 as8 bes as bes R1 d4 ~ d
1445 tromboI = \notes\relative c'' @{
1446 c4. c8 c8 c4. es4 r as, r
1448 tromboII = \notes\relative c'' @{
1449 as4. as8 as8 as4. R1*1/2 as4 es'
1451 timpani = \notes\relative c, @{
1452 \times 2/3 @{ f4 f f @}
1453 \times 4/5 @{ as8 as as as as @}
1456 corno = \notes\relative c' @{
1457 bes4 d f, bes d f, bes d
1461 We will not examine this example line by line, since you already know
1462 most of it. We'll examine a few lines which contain new elements.
1473 This declares settings to be used globally. The @code{\skip} command
1474 produces no output, but moves forward in time: in this case, the
1475 duration of a half note (@code{2}), and that four times (@code{*4}).
1476 This brings us to the end of the piece, and we can set the end bar.
1477 You can use @code{s} as a shortcut for @code{\skip} (the last line of
1478 this section would be @code{s2*4 \bar"|."}).
1482 Key = \notes \key as \major
1484 This declares the key signature of the piece and assign it to the
1485 identifier @var{Key}. Later on we will use @code{\Key} for all staves
1486 except those for transposing instruments.
1488 @node The full score
1489 @subsection The full score
1492 The second file, @inputfileref{input/tutorial,os-score.ly}, reads the
1493 definitions of the first (@inputfileref{input/tutorial,os-music.ly}), and
1494 defines the @code{\score} block for the full conductor's score.
1499 \include "os-music.ly"
1500 \include "paper13.ly"
1502 textFlat = \markup @{\smaller \musicglyph #"accidentals--1"@}
1506 \property Score.BarNumber \override #'padding = #3
1507 \context StaffGroup = woodwind <
1508 \context Staff = flauti <
1509 \property Staff.midiInstrument = #"flute"
1510 \property Staff.instrument = "2 Flauti"
1511 \property Staff.instr = "Fl."
1513 \context Voice=one @{ \voiceOne \flautoI @}
1514 \context Voice=two @{ \voiceTwo \flautoII @}
1517 \context StaffGroup = timpani <
1518 \context Staff = timpani <
1519 \property Staff.midiInstrument = #"timpani"
1520 \property Staff.instrument = \markup @{ \column << "Timpani" "(C-G)" >> @}
1521 \property Staff.instr = #"Timp."
1527 \context StaffGroup = brass <
1528 \context Staff = trombe <
1529 \property Staff.midiInstrument = #"trumpet"
1530 \property Staff.instrument = \markup @{ \column << "2 Trombe" "(C)" >> @}
1531 \property Staff.instr = \markup@{ \column << "Tbe." "(C)">> @}
1533 \context Voice=one \partcombine Voice
1534 \context Thread=one \tromboI
1535 \context Thread=two \tromboII
1537 \context Staff = corni <
1538 \property Staff.midiInstrument = #"french horn"
1539 \property Staff.instrument
1540 = \markup @{ \column << "Corno" @{ "(E" \textFlat ")" @} >> @}
1541 \property Staff.instr =
1542 \markup @{ \column << "Cor." @{ "(E" \textFlat ")" @} >> @}
1543 \property Staff.transposing = #3
1544 \notes \key bes \major
1545 \context Voice=one \corno
1550 indent = 15 * \staffspace
1551 linewidth = 60 * \staffspace
1552 textheight = 90 * \staffspace
1555 \consists "Multi_measure_rest_engraver"
1558 \HaraKiriStaffContext
1559 \remove "Multi_measure_rest_engraver"
1568 @center @strong{Zo, goed lieverd?}
1570 @center How's, this babe?
1578 @lilypondfile{os-score.ly}
1582 \include "os-music.ly"
1584 First we need to include the music definitions we made in
1589 [TODO: mention in a more relevant place]
1593 #(ly:set-point-and-click 'line-column)
1596 This piece of Scheme code executes the function
1597 @code{ly:set-point-and-click} with the argument
1598 @code{line-column}. Editing input files can be complicated if you are
1599 working with large files: if you are digitizing existing music, you have
1600 to synchronize the .ly file, the sheet music on your lap and the sheet
1601 music on the screen. The point-and-click mechanism makes it easy to
1602 find the origin of an error in the LY file: when you view the file with
1603 Xdvi and click on a note, your editor will jump to the spot where that
1604 note was entered. For more information, see @ref{Point and click}.
1610 #(define text-flat '((font-relative-size . -2)
1611 (music "accidentals--1")))
1614 To name the transposition of the french horn, we will need a piece of
1615 text with a flat sign. LilyPond has a mechanism for font selection and
1616 kerning called Scheme markup text (See @ref{Text markup}). The flat
1617 sign is taken from the music font, and its name is @code{accidentals--1}
1618 (The natural sign is called @code{accidentals-0}). The default font is
1619 too big for text, so we select a relative size of @code{-2}.
1626 All staves are simultaneous and use the same global settings.
1630 \property Score.BarNumber \override #'padding = #3
1632 LilyPond prints bar numbers at the start of each line, but
1633 unfortunately they end up a bit too close to the staff in this
1634 example. In LilyPond, a bar number is called @var{BarNumber}.
1635 BarNumber objects can be manipulated through their
1636 @var{side-position-interface}. One of the properties of a
1637 @var{side-position-interface} that can be tweaked is @var{padding}:
1638 the amount of extra space that is put between this and other objects.
1639 We set the padding to three staff spaces.
1641 You can find information on all these kind of properties in LilyPond's
1642 automatically generated documentation in
1644 @ref{ (lilypond-internals)lilypond-internals, LilyPond Internals}
1645 or in @ref{Fine tuning a piece}.
1648 the online documentation or in the previous section of the tutorial.
1655 \context StaffGroup = woodwind <
1656 \context Staff = flauti <
1658 A new notation context: the @code{StaffGroup}. @code{StaffGroup} can
1659 hold one or more @code{Staff}s, and will print a big bracket at the
1660 left of the score. This starts a new staff group for the woodwind
1661 section (just the flutes in this case). Immediately after that, we
1662 start the staff for the two flutes, who also play simultaneously.
1666 \property Staff.midiInstrument = #"flute"
1668 Specify the instrument for MIDI output (see @ref{MIDI instrument
1673 \property Staff.instrument = "2 Flauti"
1674 \property Staff.instr = "Fl."
1676 This defines the instrument names to be printed in the
1677 margin. @code{instrument} specifies the name for the first line
1678 of the score, @code{instr} is used for the rest of the score.
1684 The flutes play in the default key.
1688 \context Voice=one @{ \voiceOne \flautoI @}
1689 \context Voice=two @{ \voiceTwo \flautoII @}
1691 Last come the actual flute parts. Remember that we are still in
1692 simultaneous mode. We name both voices differently, so that LilyPond
1693 will create two Voice contexts. The flute parts are simple, so
1694 we specify manually which voice is which: @code{\voiceOne} forces the
1695 direction of stems, beams, slurs and ties up, @code{\voiceTwo} sets
1703 Close the flutes staff and woodwind staff group.
1707 \property Staff.instrument = #'(lines "Timpani" "(C-G)")
1709 The timpani staff demonstrates a new piece of scheme markup, it sets two
1714 \context Voice=one \partcombine Voice
1715 \context Thread=one \tromboI
1716 \context Thread=two \tromboII
1718 You have seen the notation contexts Staff and Voice, but here is a new
1719 one: Thread. One or more Threads can be part of a Voice. Thread
1720 takes care of note heads and rests; Voice combine note heads onto a
1723 For the trumpets we use the automatic part combiner (see @ref{Automatic
1724 part combining}) to combine the two simultaneous trumpet parts onto the
1725 trumpet staff. Each trumpet gets its own Thread context, which must be
1726 named @code{one} and @code{two}). The part combiner makes these two
1727 threads share a Voice when they are similar, and splits the threads up
1728 when they are different.
1732 \property Staff.instrument = #`(lines "Corno"
1733 (columns "(E" ,text-flat ")"))
1735 The french horn (``Corno'') has the most complex scheme markup name, made
1736 up of two lines of text. The second line has three elements (columns) --
1737 the @code{(E}, the flat sign @code{text-flat} that we defined previously,
1738 and a final @code{")"}. We use a backquote instead of an
1739 ordinary quote at the beginning of the Scheme expression to be able to
1740 access the @code{text-flat} identifier, `unquoting' it with a ``@code{,}''.
1744 \property Staff.transposing = #3
1746 The french horn is to be tuned in E-flat, so we tell the MIDI back-end to
1747 transpose this staff by three steps.
1749 Note how we can choose different tunings for the text input, sheet music
1750 output and, and MIDI output, using @code{\transpose} and the MIDI Staff
1751 property @var{transposing}.
1755 \notes \key bes \major
1757 Since the horn is transposing, it is in a different key.
1761 indent = 15 * \staffspace
1762 linewidth = 55 * \staffspace
1764 We specify a big indent for the first line and a small linewidth for this
1769 Usually the default setup of notation contexts (Thread, Voice, Staff,
1770 Staffgroup, Score) is just fine. But in this case we want a different
1771 type of Staff context.
1775 \HaraKiriStaffContext
1779 In orchestral scores it often happens that one instrument only has
1780 rests during one line of the score. @code{HaraKiriStaffContext} can
1781 be used as a regular @code{StaffContext} drop-in and will take care of
1782 the automatic removing of empty staves -- so if the strings are the
1783 only instruments playing for a line, LilyPond will only print the string
1784 parts for that line of the score. This reduces the number of page turns
1785 (and the number of dead trees!) required in a score.
1787 @node Extracting an individual part
1788 @subsection Extracting an individual part
1790 The third file, @file{os-flute-2.ly} also reads the definitions of the
1791 first (@file{os-music.ly}), and defines the @code{\score} block for the
1795 \include "os-music.ly"
1796 \include "paper16.ly"
1800 \property Score.skipBars = ##t
1801 \property Staff.midiInstrument = #"flute"
1807 instrument = "Flauto II"
1810 linewidth = 80 * \staffspace
1811 textheight = 200 * \staffspace
1819 @center @strong{Zo, goed lieverd?}
1821 @center How's, this babe?
1822 @center @emph{Flauto II}
1829 @lilypondfile{os-flute-2.ly}
1832 Because we separated the music definitions from the @code{\score}
1833 instantiations, we can easily define a second score with the music of
1834 the second flute. This is the part for the second flute player. Of
1835 course, we would make separate parts for all individual instruments if
1836 we were preparing the score for an orchestra.
1842 In this individual part the second flute has a whole staff for itself,
1843 so we do not want to force stem or tie directions.
1848 instrument = "Flauto II"
1851 The @code{\header} definitions were also read from @file{os-music.ly},
1852 but we need to set the instrument for this particular score.
1856 \property Score.skipBars = ##t
1858 In the conductor's full score, all bars with rests are printed, but for
1859 the individual parts, we want to print one multimeasure rest instead of
1860 many consecutive empty bars. LilyPond will do this if
1861 @code{Score.skipBars} is set to true (@code{##t}).
1864 @node Integrating text and music
1865 @section Integrating text and music
1868 @cindex La@TeX{}, music in
1869 @cindex HTML, music in
1870 @cindex Texinfo, music in
1872 Sometimes you might want to use music examples in a text that you are
1873 writing (for example a musicological treatise, a songbook, or (like us)
1874 the LilyPond manual). You can make such texts by hand, simply by
1875 importing a PostScript figure into your word processor. However,
1876 there is an automated procedure to reduce the amount of work.
1878 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1879 code. A script called @code{lilypond-book} will extract the music
1880 fragments, run LilyPond on them, and put back the resulting notation.
1881 This program is fully described in @ref{lilypond-book manual}. Here
1882 we show a small example. Since the example also contains explanatory
1883 text, we will not comment it further.
1886 \documentclass[a4paper]@{article@}
1889 In a lilypond-book document, you can freely mix music and text. For
1892 \score @{ \notes \relative c' @{
1893 c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1897 Notice that the music line length matches the margin settings of the
1900 If you have no \verb+\score+ block in the fragment,
1901 \texttt@{lilypond-book@} will supply one:
1907 In the example you see here, two things happened: a
1908 \verb+\score+ block was added, and the line width was set to natural
1909 length. You can specify many more options using \LaTeX style options
1912 \begin[verbatim,11pt,singleline,
1913 fragment,relative,intertext="hi there!"]@{lilypond@}
1917 The option \texttt@{verbatim@} prints the LilyPond code in addition to
1918 the graphical score, \texttt@{11pt@} selects the default music size,
1919 \texttt@{fragment@} adds a score block, \texttt@{relative@} uses
1920 relative mode for the fragment, and \texttt@{intertext@} specifies
1921 what to print between the \texttt@{verbatim@} code and the music.
1923 If you want to include large examples into the text, it may be more
1924 convenient to put the example in a separate file:
1926 \lilypondfile[printfilename]@{sammartini.ly@}
1928 The \texttt@{printfilename@} option adds the file name to the output.
1933 Under Unix, you can view the results as follows.
1937 $ lilypond-book --outdir=out/ lilbook.tex
1938 lilypond-book (GNU LilyPond) 1.7.16
1939 Reading `input/tutorial/lilbook.tex'
1940 Reading `input/tutorial/sammartini.ly'
1941 @var{lots of stuff deleted}
1942 Writing `out/lilbook.latex'
1944 $ latex lilbook.latex
1945 @var{lots of stuff deleted}
1949 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
1950 and running latex creates a lot of temporary files, and you would not want
1951 those to clutter up your working directory. Hence, we have them created
1952 in a separate subdirectory.
1954 The result looks more or less like this:
1958 In a lilypond-book document, you can freely mix music and text. For
1962 \notes \relative c' {
1963 c2 g'2 \times 2/3 { f8 e d } c'2 g4
1971 Notice that the music line length matches the margin settings of the
1974 If you have no @code{\score} block in the fragment,
1975 @code{lilypond-book} will supply one:
1981 In the example you see here, a number of things happened: a
1982 @code{\score} block was added, and the line width was set to natural
1983 length. You can specify many more options using La@TeX{} style options
1986 @lilypond[verbatim,11pt,singleline,
1987 fragment,relative,intertext="hi there!"]
1991 The option @code{verbatim} also shows the LilyPond code, @code{11pt} selects
1992 the default music size, @code{fragment} adds a score block,
1993 @code{relative} uses relative mode for the fragment, and
1994 @code{intertext} specifies what to print between the
1995 @code{verbatim} code and the music.
1997 If you include large examples into the text, it may be more convenient
1998 to put the example in a separate file:
2000 @lilypondfile[printfilename]{sammartini.ly}
2002 The @code{printfilename} option adds the file name to the output.