1 @c -*- coding: latin-1; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
4 @c A menu is needed before every deeper *section nesting of @node's; run
5 @c M-x texinfo-all-menus-update
6 @c to automatically fill in these menus before saving changes
11 This is a placeholder until I can write a nice intro for this chapter.
17 * Creating MIDI files::
19 * MIDI instrument names::
24 @section Global layout
26 The global layout is determined by three factors: the page layout, the
27 line breaks, and the spacing. These all influence each other. The
28 choice of spacing determines how densely each system of music is set.
29 This influences where line breaks are chosen, and thus ultimately, how
30 many pages a piece of music takes.
32 Globally spoken, this procedure happens in three steps: first,
33 flexible distances (``springs'') are chosen, based on durations. All
34 possible line breaking combinations are tried, and the one with the
35 best results -- a layout that has uniform density and requires as
36 little stretching or cramping as possible -- is chosen.
38 After spacing and linebreaking, the systems are distributed across
39 pages, taking into account the size of the page, and the size of the
45 * Setting global staff size::
49 * Vertical spacing of piano staves::
50 * Horizontal spacing::
54 * Multiple movements::
59 @node Setting global staff size
60 @subsection Setting global staff size
62 @cindex font size, setting
63 @cindex staff size, setting
64 @cindex @code{layout} file
66 To set the global staff size, use @code{set-global-staff-size}.
69 #(set-global-staff-size 14)
73 This sets the global default size to 14pt staff height and scales all
76 The Feta font provides musical symbols at eight different
77 sizes. Each font is tuned for a different staff size: at a smaller size
78 the font becomes heavier, to match the relatively heavier staff lines.
79 The recommended font sizes are listed in the following table:
82 @multitable @columnfractions .15 .2 .22 .2
85 @tab @b{staff height (pt)}
86 @tab @b{staff height (mm)}
128 @c modern rental material?
133 These fonts are available in any sizes. The context property
134 @code{fontSize} and the layout property @code{staff-space} (in
135 @internalsref{StaffSymbol}) can be used to tune the size for individual
136 staves. The sizes of individual staves are relative to the global size.
144 This manual: @ref{Selecting font sizes}.
148 @subsection Paper size
152 @cindex @code{papersize}
154 To change the paper size, there are two equal commands,
156 #(set-default-paper-size "a4")
158 #(set-paper-size "a4")
162 The first command sets the size of all pages. The second command sets the size
163 of the pages that the @code{\paper} block applies to -- if the @code{\paper}
164 block is at the top of the file, then it will apply to all pages. If the
165 @code{\paper} block is inside a @code{\score}, then the paper size will only
168 The following paper sizes are supported: @code{a6}, @code{a5}, @code{a4},
169 @code{a3}, @code{legal}, @code{letter}, @code{tabloid}.
174 If the symbol @code{landscape} is supplied as an argument to
175 @code{set-default-paper-size}, the pages will be rotated by 90 degrees,
176 and wider line widths will be set correspondingly.
179 #(set-default-paper-size "a6" 'landscape)
184 @subsection Page layout
191 LilyPond will do page layout, set margins, and add headers and
192 footers to each page.
194 The default layout responds to the following settings in the
201 @item firstpagenumber
202 The value of the page number of the first page. Default is@tie{}1.
204 @item printfirstpagenumber
205 If set to true, will print the page number in the first page. Default is
209 The width of the page.
212 The height of the page.
215 Margin between header and top of the page.
218 Margin between footer and bottom of the page.
221 Margin between the left side of the page and the beginning of the music.
224 The length of the systems.
227 Distance between the top-most music system and the page header.
230 Distance between the bottom-most music system and the page footer.
233 If set to true, systems will not be spread across the page.
235 This should be set false for pieces that have only two or three
236 systems per page, for example orchestral scores.
238 @item raggedlastbottom
239 If set to false, systems will be spread to fill the last page.
241 Pieces that amply fill two pages or more should have this set to
244 @item betweensystemspace
245 This dimensions determines the distance between systems. It is the
246 ideal distance between the center of the bottom staff of one system
247 and the center of the top staff of the next system.
249 Increasing this will provide a more even appearance of the page at the
250 cost of using more vertical space.
252 @item betweensystempadding
253 This dimension is the minimum amount of white space that will always
254 be present between the bottom-most symbol of one system, and the
255 top-most of the next system.
257 Increasing this will put systems whose bounding boxes almost touch
260 @item aftertitlespace
261 Amount of space between the title and the first system.
263 @item beforetitlespace
264 Amount of space between the last system of the previous piece and the
267 @item betweentitlespace
268 Amount of space between consecutive titles (e.g., the title of the
269 book and the title of a piece).
271 @item systemSeparatorMarkup
272 This contains a markup object, which will be inserted between
273 systems. This is often used for orchestral scores.
275 The markup command @code{\slashSeparator} is provided as a sensible
278 @lilypond[raggedright]
280 systemSeparatorMarkup = \slashSeparator
283 \relative { c1 \break c1 }
297 raggedlastbottom = ##t
301 You can also define these values in Scheme. In that case @code{mm},
302 @code{in}, @code{pt}, and @code{cm} are variables defined in
303 @file{paper-defaults.ly} with values in millimeters. That's why the
304 value has to be multiplied in the example
308 #(define bottommargin (* 2 cm))
315 The default footer is empty, except for the first page, where the
316 @code{copyright} field from @code{\header} is inserted, and the last
317 page, where @code{tagline} from @code{\header} is added. The default
318 tagline is ``Engraved by LilyPond (@var{version})''.@footnote{Nicely
319 printed parts are good PR for us, so please leave the tagline if you
322 The header and footer are created by the functions @code{make-footer}
323 and @code{make-header}, defined in @code{\paper}. The default
324 implementations are in @file{scm/@/page@/-layout@/.scm}.
326 The following settings influence the header and footer layout.
330 @item printpagenumber
331 this boolean controls whether a pagenumber is printed.
335 The page layout itself is done by two functions in the
336 @code{\paper} block, @code{page-music-height} and
337 @code{page-make-stencil}. The former tells the line-breaking algorithm
338 how much space can be spent on a page, the latter creates the actual
339 page given the system to put on it.
344 The option rightmargin is defined but doesn't set the right margin
345 yet. The value for the right margin has to be defined adjusting the
346 values of the leftmargin and linewidth.
348 The default page header puts the page number and the @code{instrument}
349 field from the @code{\header} block on a line.
352 @node Vertical spacing
353 @subsection Vertical spacing
355 @cindex vertical spacing
356 @cindex distance between staves
357 @cindex staff distance
358 @cindex between staves, distance
359 @cindex staves per page
360 @cindex space between staves
362 The height of each system is determined automatically. To prevent
363 systems from bumping into each other, some minimum distances are set.
364 By changing these, you can put staves closer together, and thus put
365 more systems onto one page.
367 Normally staves are stacked vertically. To make staves maintain a
368 distance, their vertical size is padded. This is done with the
369 property @code{minimumVerticalExtent}. It takes a pair of numbers, so
370 if you want to make it smaller than its default @code{#'(-4 . 4)},
374 \set Staff.minimumVerticalExtent = #'(-3 . 3)
378 This sets the vertical size of the current staff to 3 staff spaces on
379 either side of the center staff line. The argument of
380 @code{minimumVerticalExtent} is interpreted as an interval, where the
381 center line is the 0, so the first number is generally negative. The
382 staff can be made larger at the bottom by setting it to @code{(-6 . 4)}.
384 To change the amount of space between systems, use
385 @code{betweensystemspace}. A score with only one staff is still
386 considered to have systems, so setting @code{betweensystemspace}
387 will be much more useful than changing @code{minimumVerticalExtent}.
391 betweensystemspace = 10\mm
398 Internals: Vertical alignment of staves is handled by the
399 @internalsref{VerticalAlignment} object.
403 @code{minimumVerticalExtent} is syntactic sugar for setting
404 @code{minimum-Y-extent} of the @internalsref{VerticalAxisGroup} of the
405 current context. It can only be changed score wide.
410 @node Vertical spacing of piano staves
411 @subsection Vertical spacing of piano staves
413 The distance between staves of a @internalsref{PianoStaff} cannot be
414 computed during formatting. Rather, to make cross-staff beaming work
415 correctly, that distance has to be fixed beforehand.
417 The distance of staves in a @code{PianoStaff} is set with the
418 @code{forced-distance} property of the
419 @internalsref{VerticalAlignment} object, created in
420 @internalsref{PianoStaff}.
422 It can be adjusted as follows
424 \new PianoStaff \with @{
425 \override VerticalAlignment #'forced-distance = #7
432 This would bring the staves together at a distance of 7 staff spaces,
433 measured from the center line of each staff.
435 The difference is demonstrated in the following example,
436 @lilypond[quote,verbatim]
438 \new PianoStaff \with {
439 \override VerticalAlignment #'forced-distance = #7
455 @code{forced-distance} cannot be changed per system.
458 @node Horizontal spacing
459 @subsection Horizontal Spacing
461 The spacing engine translates differences in durations into
462 stretchable distances (``springs'') of differring lengths. Longer
463 durations get more space, shorter durations get less. The shortest
464 durations get a fixed amount of space (which is controlled by
465 @code{shortest-duration-space} in the @internalsref{SpacingSpanner} object).
466 The longer the duration, the more space it gets: doubling a
467 duration adds a fixed amount (this amount is controlled by
468 @code{spacing-increment}) of space to the note.
470 For example, the following piece contains lots of half, quarter, and
471 8th notes; the eighth note is followed by 1 note head width (NHW).
472 The quarter note is followed by 2 NHW, the half by 3 NHW, etc.
474 @lilypond[quote,fragment,verbatim,relative=1]
475 c2 c4. c8 c4. c8 c4. c8 c8
479 Normally, @code{spacing-increment} is set to 1.2 staff space, which is
480 approximately the width of a note head, and
481 @code{shortest-duration-space} is set to 2.0, meaning that the
482 shortest note gets 2.4 staff space (2.0 times the
483 @code{spacing-increment}) of horizontal space. This space is counted
484 from the left edge of the symbol, so the shortest notes are generally
485 followed by one NHW of space.
487 If one would follow the above procedure exactly, then adding a single
488 32nd note to a score that uses 8th and 16th notes, would widen up the
489 entire score a lot. The shortest note is no longer a 16th, but a 32nd,
490 thus adding 1 NHW to every note. To prevent this, the shortest
491 duration for spacing is not the shortest note in the score, but rather
492 the one which occurs most frequently.
495 The most common shortest duration is determined as follows: in every
496 measure, the shortest duration is determined. The most common shortest
497 duration is taken as the basis for the spacing, with the stipulation
498 that this shortest duration should always be equal to or shorter than
499 an 8th note. The shortest duration is printed when you run
500 @code{lilypond} with the @code{--verbose} option.
502 These durations may also be customized. If you set the
503 @code{common-shortest-duration} in @internalsref{SpacingSpanner}, then
504 this sets the base duration for spacing. The maximum duration for this
505 base (normally an 8th), is set through @code{base-shortest-duration}.
507 @cindex @code{common-shortest-duration}
508 @cindex @code{base-shortest-duration}
509 @cindex @code{stem-spacing-correction}
510 @cindex @code{spacing}
512 Notes that are even shorter than the common shortest note are
513 followed by a space that is proportional to their duration relative to
514 the common shortest note. So if we were to add only a few 16th notes
515 to the example above, they would be followed by half a NHW:
517 @lilypond[quote,fragment,verbatim,relative=2]
518 c2 c4. c8 c4. c16[ c] c4. c8 c8 c8 c4 c4 c4
522 In the introduction (see @ref{Engraving}), it was explained that stem
523 directions influence spacing. This is controlled with the
524 @code{stem-spacing-correction} property in the
525 @internalsref{NoteSpacing}, object. These are generated for every
526 @internalsref{Voice} context. The @code{StaffSpacing} object
527 (generated in @internalsref{Staff} context) contains the same property
528 for controlling the stem/bar line spacing. The following example shows
529 these corrections, once with default settings, and once with
530 exaggerated corrections:
532 @lilypond[quote,raggedright]
536 \override Staff.NoteSpacing #'stem-spacing-correction = #1.5
537 \override Staff.StaffSpacing #'stem-spacing-correction = #1.5
546 Internals: @internalsref{SpacingSpanner}, @internalsref{NoteSpacing},
547 @internalsref{StaffSpacing}, @internalsref{SeparationItem}, and
548 @internalsref{SeparatingGroupSpanner}.
552 Spacing is determined on a score wide basis. If you have a score that
553 changes its character (measured in durations) halfway during the
554 score, the part containing the longer durations will be spaced too
557 There is no convenient mechanism to manually override spacing. The
558 following work-around may be used to insert extra space into a score.
560 \once \override Score.SeparationItem #'padding = #1
563 No work-around exists for decreasing the amount of space.
566 @subsection Line length
569 @cindex breaking pages
571 @cindex @code{indent}
572 @cindex @code{linewidth}
574 @c Although linewidth can be set in \layout, it should be set in paper
575 @c block, to get page layout right.
576 @c Setting indent in \paper block makes not much sense, but it works.
578 @c Bit verbose and vague, use examples?
579 The most basic settings influencing the spacing are @code{indent} and
580 @code{linewidth}. They are set in the @code{\layout} block. They
581 control the indentation of the first line of music, and the lengths of
584 If @code{raggedright} is set to true in the @code{\layout} block, then
585 the lines are justified at their natural length. This is useful for
586 short fragments, and for checking how tight the natural spacing is.
589 @cindex vertical spacing
591 The option @code{raggedlast} is similar to @code{raggedright}, but
592 only affects the last line of the piece. No restrictions are put on
593 that line. The result is similar to formatting text paragraphs. In a
594 paragraph, the last line simply takes its natural length.
595 @c Note that for text there are several options for the last line.
596 @c While Knuth TeX uses natural length, lead typesetters use the same
597 @c stretch as the previous line. eTeX uses \lastlinefit to
598 @c interpolate between both these solutions.
601 @subsection Line breaking
604 @cindex breaking lines
606 Line breaks are normally computed automatically. They are chosen so
607 that lines look neither cramped nor loose, and that consecutive lines
608 have similar density.
610 Occasionally you might want to override the automatic breaks; you can
611 do this by specifying @code{\break}. This will force a line break at
612 this point. Line breaks can only occur at places where there are bar
613 lines. If you want to have a line break where there is no bar line,
614 you can force an invisible bar line by entering @code{\bar
615 ""}. Similarly, @code{\noBreak} forbids a line break at a
619 @cindex regular line breaks
620 @cindex four bar music.
622 For line breaks at regular intervals use @code{\break} separated by
623 skips and repeated with @code{\repeat}:
625 << \repeat unfold 7 @{
626 s1 \noBreak s1 \noBreak
627 s1 \noBreak s1 \break @}
628 @emph{the real music}
633 This makes the following 28 measures (assuming 4/4 time) be broken every
634 4 measures, and only there.
638 @code{\break}, and @code{\noBreak}.
639 @cindex @code{\break}
640 @cindex @code{\noBreak}
644 Internals: @internalsref{BreakEvent}.
648 @subsection Page breaking
650 The default page breaking may be overriden by inserting
651 @code{\pageBreak} or @code{\noPageBreak} commands. These commands are
652 analogous to @code{\break} and @code{\noBreak}. They should be
653 inserted at a bar line. These commands force and forbid a page-break
654 from happening. Of course, the @code{\pageBreak} command also forces
657 Page breaks are computed by the @code{page-breaking} function in the
662 @cindex @code{\pageBreak}
664 @cindex @code{\noPageBreak}
668 @node Multiple movements
669 @subsection Multiple movements
671 @cindex bibliographic information
674 @cindex Engraved by LilyPond
676 A document may contain multiple pieces of music. Examples of these
677 are an etude book, or an orchestral part with multiple movements.
678 Each movement is entered with a @code{\score} block,
686 The movements are combined together in a @code{\book} block, like
700 The header for each piece of music can be put inside the @code{\score}
701 block. The @code{piece} name from the header will be printed before
702 each movement. The title for the entire book can be put inside the
703 @code{\book}, but if it is not present, the @code{\header} which is at
704 the top of the file is inserted.
706 @cindex Engraved by LilyPond
707 @cindex signature line
712 title = "Eight miniatures"
713 composer = "Igor Stravinsky"
717 \header @{ piece = "Romanze" @}
721 \header @{ piece = "Menuetto" @}
727 @node Creating titles
728 @subsection Creating titles
730 Titles are created for each @code{\score} block, and over a
733 The contents of the titles are taken from the @code{\header} blocks.
734 The header block for a book supports the following
737 The title of the music. Centered on top of the first page.
740 Subtitle, centered below the title.
743 Subsubtitle, centered below the subtitle.
746 Name of the poet, flush-left below the subtitle.
749 Name of the composer, flush-right below the subtitle.
752 Meter string, flush-left below the poet.
755 Name of the opus, flush-right below the composer.
758 Name of the arranger, flush-right below the opus.
761 Name of the instrument, centered below the arranger.
764 To whom the piece is dedicated.
767 Name of the piece, flush-left below the instrument.
769 @cindex page breaks, forcing
771 This forces the title to start on a new page.
774 Here is a demonstration of the fields available,
776 @lilypond[quote,verbatim,linewidth=11.0\cm]
785 subtitle = "the subtitle,"
786 subsubtitle = "and the sub sub title"
788 composer = "Composer"
789 texttranslator = "Text Translator"
791 arranger = "Arranger"
792 instrument = "Instrument"
813 Different fonts may be selected for each element by using
814 @code{\markup}, e.g.,
818 title = \markup @{ \italic @{ The italic title @} @}
822 A more advanced option is to change the definitions of the following
823 variables in the @code{\paper} block. The init file
824 @file{ly/titling-init.ly} lists the default layout.
827 @item bookTitleMarkup
828 This is the title put over an entire @code{\book} block. Typically,
829 it has the composer and the title of the piece
831 @item scoreTitleMarkup
832 This is the title put over a @code{\score} block within a
833 @code{\book}. Typically, it has the name of the movement (@code{piece}
836 @item oddHeaderMarkup
837 This is the page header for odd-numbered pages.
839 @item evenHeaderMarkup
840 This is the page header for even-numbered pages. If unspecified,
841 the odd header is used instead.
843 By default, headers are defined such that the page number is on the
844 outside edge, and the instrument is centered.
846 @item oddFooterMarkup
847 This is the page footer for odd-numbered pages.
849 @item evenFooterMarkup
850 This is the page footer for even-numbered pages. If unspecified,
851 the odd header is used instead.
853 By default, the footer has the copyright notice on the first, and
854 the tagline on the last page.
864 The following definition will put the title flush left, and the
865 composer flush right on a single line.
869 bookTitleMarkup = \markup {
871 \fromproperty #'header:title
872 \fromproperty #'header:composer
881 @section File structure
883 The major part of this manual is concerned with entering various
884 forms of music in LilyPond. However, many music expressions are not
885 valid input on their own, for example, a @code{.ly} file containing
892 will result in a parsing error. Instead, music should be inside other
893 expressions, which may be put in a file by themselves. Such
894 expressions are called toplevel expressions. This section enumerates
897 A @code{.ly} file contains any number of toplevel expressions, where a
898 toplevel expression is one of the following
902 An output definition, such as @code{\paper}, @code{\midi}, and
903 @code{\layout}. Such a definition at the toplevel changes the default
904 settings for the block entered.
907 A @code{\header} block. This sets the global header block. This
908 is the block containing the definitions for book-wide settings, like
909 composer, title, etc.
912 An @code{\addquote} statement. See @ref{Quoting other voices}
913 for more information.
916 A @code{\score} block. This score will be collected with other
917 toplevel scores, and combined as a single @code{\book}.
919 This behavior can be changed by setting the variable
920 @code{toplevel-score-handler} at toplevel. The default handler is
921 defined in the init file @file{scm/@/lily@/.scm}.
924 A @code{\book} block logically combines multiple movements
925 (i.e., multiple @code{\score} blocks) in one document. A number of
926 @code{\scores} creates a single output file, where all movement are
929 This behavior can be changed by setting the variable
930 @code{toplevel-book-handler} at toplevel. The default handler is
931 defined in the init file @file{scm/@/lily@/.scm}.
933 @item A compound music expression, such as
938 This will add the piece in a @code{\score} and format it in a
939 single book together with all other toplevel @code{\score}s and music
942 This behavior can be changed by setting the variable
943 @code{toplevel-music-handler} at toplevel. The default handler is
944 defined in the init file @file{scm/@/lily@/.scm}.
946 @item An indentifier, such as
951 This can be used later on in the file by entering @code{\foo}.
955 The following example shows three things that may be entered at
960 % movements are non-justified by default
972 At any point in a file, any of the following lexical instructions can
976 @item @code{\version}
977 @item @code{\include}
978 @item @code{\renameinput}
988 MIDI (Musical Instrument Digital Interface) is a standard for
989 connecting and controlling digital instruments. A MIDI file is a
990 series of notes in a number of tracks. It is not an actual
991 sound file; you need special software to translate between the
992 series of notes and actual sounds.
994 Pieces of music can be converted to MIDI files, so you can listen to
995 what was entered. This is convenient for checking the music; octaves
996 that are off or accidentals that were mistyped stand out very much
997 when listening to the MIDI output.
1001 Many musically interesting effects, such as swing, articulation,
1002 slurring, etc., are not translated to midi.
1004 The midi output allocates a channel for each staff, and one for global
1005 settings. Therefore the midi file should not have more than 15 staves
1006 (or 14 if you do not use drums). Other staves will remain silent.
1008 Not all midi players correctly handle tempo changes in the midi
1009 output. Players that are known to work include
1010 @uref{http://@/timidity@/.sourceforge@/.net/,timidity}.
1013 * Creating MIDI files::
1015 * MIDI instrument names::
1018 @node Creating MIDI files
1019 @section Creating MIDI files
1021 To create a MIDI from a music piece of music, add a @code{\midi} block
1022 to a score, for example,
1027 \midi @{ \tempo 4=72 @}
1031 The tempo is specified using the @code{\tempo} command. In this
1032 example the tempo of quarter notes is set to 72 beats per minute.
1035 If there is a @code{\midi} command in a @code{\score}, only MIDI will
1036 be produced. When notation is needed too, a @code{\layout} block must
1042 \midi @{ \tempo 4=72 @}
1046 @cindex layout block
1050 Ties, dynamics, and tempo changes are interpreted. Dynamic marks,
1051 crescendi and decrescendi translate into MIDI volume levels. Dynamic
1052 marks translate to a fixed fraction of the available MIDI volume
1053 range, crescendi and decrescendi make the volume vary linearly between
1054 their two extremes. The fractions can be adjusted by
1055 @code{dynamicAbsoluteVolumeFunction} in @internalsref{Voice} context.
1056 For each type of MIDI instrument, a volume range can be defined. This
1057 gives a basic equalizer control, which can enhance the quality of
1058 the MIDI output remarkably. The equalizer can be controlled by
1059 setting @code{instrumentEqualizer}.
1067 The MIDI block is analogous to the layout block, but it is somewhat
1068 simpler. The @code{\midi} block can contain
1072 @item a @code{\tempo} definition, and
1073 @item context definitions.
1076 A number followed by a period is interpreted as a real number, so
1077 for setting the tempo for dotted notes, an extra space should be
1078 inserted, for example
1081 \midi @{ \tempo 4 . = 120 @}
1085 @cindex context definition
1087 Context definitions follow precisely the same syntax as within the
1088 \layout block. Translation modules for sound are called performers.
1089 The contexts for MIDI output are defined in @file{ly/@/performer@/-init@/.ly}.
1092 @node MIDI instrument names
1093 @section MIDI instrument names
1095 @cindex instrument names
1096 @cindex @code{Staff.midiInstrument}
1098 The MIDI instrument name is set by the @code{Staff.midiInstrument}
1099 property. The instrument name should be chosen from the list in
1100 @ref{MIDI instruments}.
1103 \set Staff.midiInstrument = "glockenspiel"
1107 If the selected instrument does not exactly match an instrument from
1108 the list of MIDI instruments, the Grand Piano (@code{"acoustic grand"})