]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/global.itely
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / Documentation / user / global.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
3
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
7
8 @node Global issues
9 @chapter Global issues
10
11 This section deals with general lilypond issues, rather than
12 specific notation.
13
14 @menu
15 * Input files::                 
16 * A single music expression::   
17 * Titles and headers::          
18 * Paper and pages::             
19 * Music layout::                
20 * Multiple movements::          
21 * MIDI output::                 
22 * Displaying LilyPond notation::  
23 * Other::                       
24 @end menu
25
26
27 @node Input files
28 @section Input files
29
30 The main format of input for LilyPond are text files.  By convention,
31 these files end with ``@code{.ly}''.
32
33 @menu
34 * File structure (introduction)::  
35 * File structure::              
36 * Including LilyPond files::    
37 * Text encoding::               
38 @end menu
39
40
41 @node File structure (introduction)
42 @subsection File structure (introduction)
43
44 A basic example of a lilypond input file is
45
46 @example
47 \version "2.8.0"
48 \score @{
49   @{ @}     % this is a single music expression;
50             % all the music goes in here.
51   \header @{ @}
52   \layout @{ @}
53   \midi @{ @}
54 @}
55 @end example
56
57 @noindent
58 There are many variations of this basic pattern, but this
59 example serves as a useful starting place.
60
61 The major part of this manual is concerned with entering various
62 forms of music in LilyPond.  However, many music expressions are not
63 valid input on their own, for example, a @code{.ly} file containing
64 only a note
65 @example
66 c'4
67 @end example
68
69 @noindent
70 will result in a parsing error.  Instead, music should be inside other
71 expressions, which may be put in a file by themselves.  Such
72 expressions are called toplevel expressions.  The next section enumerates
73 them all.
74
75
76 @node File structure
77 @subsection File structure
78
79 A @code{.ly} file contains any number of toplevel expressions, where a
80 toplevel expression is one of the following
81
82 @itemize @bullet
83 @item
84 An output definition, such as @code{\paper}, @code{\midi}, and
85 @code{\layout}.  Such a definition at the toplevel changes the default
86 settings for the block entered.
87
88 @item
89 A direct scheme expression, such as
90 @code{#(set-default-paper-size "a7" 'landscape)} or
91 @code{#(ly:set-option 'point-and-click #f)}.
92
93 @item
94 A @code{\header} block.  This sets the global header block.  This
95 is the block containing the definitions for book-wide settings, like
96 composer, title, etc.
97
98 @item
99 An @code{\addquote} statement.  See @ref{Quoting other voices}
100 for more information.
101
102 @item
103 A @code{\score} block.  This score will be collected with other
104 toplevel scores, and combined as a single @code{\book}.
105
106 This behavior can be changed by setting the variable
107 @code{toplevel-score-handler} at toplevel.  The default handler is
108 defined in the init file @file{scm/@/lily@/.scm}.
109
110 The @code{\score} must begin with a music expression, and may
111 contain only one music expression.
112
113 @item
114 A @code{\book} block logically combines multiple movements
115 (i.e., multiple @code{\score} blocks) in one document.  If there are
116 a number of @code{\scores}, a single output file will be created
117 in which all movements are concatenated.
118
119 This behavior can be changed by setting the variable
120 @code{toplevel-book-handler} at toplevel.  The default handler is
121 defined in the init file @file{scm/@/lily@/.scm}.
122
123 @item
124 A compound music expression, such as
125 @example
126 @{ c'4 d' e'2 @}
127 @end example
128
129 This will add the piece in a @code{\score} and format it in a
130 single book together with all other toplevel @code{\score}s and music
131 expressions.  In other words, a file containing only the above
132 music expression will be translated into
133
134 @example
135 \book @{
136   \score @{
137     \new Staff @{
138       \new Voice @{
139         @{ c'4 d' e'2 @}
140       @}
141     @}
142   @}
143         \layout @{ @}
144         \header @{ @}
145 @}
146 @end example
147
148 This behavior can be changed by setting the variable
149 @code{toplevel-music-handler} at toplevel.  The default handler is
150 defined in the init file @file{scm/@/lily@/.scm}.
151
152 @item
153 A markup text, a verse for example
154 @example
155 \markup @{
156    2.  The first line verse two.
157 @}
158 @end example
159
160 Markup texts are rendered above, between or below the scores or music
161 expressions, wherever they appear.
162
163 @item
164 An identifier, such as
165 @example
166 foo = @{ c4 d e d @}
167 @end example
168
169 This can be used later on in the file by entering @code{\foo}.  The
170 name of an identifier should have alphabetic characters only; no
171 numbers, underscores or dashes.
172
173 @end itemize
174
175 The following example shows three things that may be entered at
176 toplevel
177
178 @example
179 \layout @{
180   % movements are non-justified by default
181   ragged-right = ##t
182 @}
183
184 \header @{
185    title = "Do-re-mi"
186 @}
187
188 @{ c'4 d' e2 @}
189 @end example
190
191
192 At any point in a file, any of the following lexical instructions can
193 be entered:
194
195 @itemize @bullet
196 @item @code{\version}
197 @item @code{\include}
198 @item @code{\renameinput}
199 @end itemize
200
201
202 @node Including LilyPond files
203 @subsection Including LilyPond files
204
205 @findex \include
206 @cindex including files
207
208 A large project may be split up into separate files.  To refer to another
209 file, use
210
211 @example
212 \include "otherfile.ly"
213 @end example
214
215 The line @code{\include "file.ly"} is equivalent to pasting the contents
216 of file.ly into the current file at the place where you have the
217 \include.  For example, for a large project you might write separate files
218 for each instrument part and create a ``full score'' file which brings
219 together the individual instrument files.
220
221 The initialization of LilyPond is done in a number of files that are
222 included by default when you start the program, normally transparent to the
223 user.  Run lilypond --verbose to see a list of paths and files that Lily
224 finds.
225
226 Files placed in directory @file{PATH/TO/share/lilypond/VERSION/ly/} (where
227 VERSION is in the form ``2.6.1'') are on the path and available to
228 @code{\include}.  Files in the
229 current working directory are available to \include, but a file of the same
230 name in LilyPond's installation takes precedence.  Files are
231 available to \include from directories in the search path specified as an
232 option when invoking @code{lilypond --include=DIR} which adds DIR to the
233 search path.
234
235 The @code{\include} statement can use full path information, but with the Unix
236 convention @code{"/"} rather than the DOS/Windows @code{"\"}.  For example,
237 if @file{stuff.ly} is located one directory higher than the current working
238 directory, use
239
240 @example
241 \include "../stuff.ly"
242 @end example
243
244
245 @node Text encoding
246 @subsection Text encoding
247
248 LilyPond uses the Pango library to format multi-lingual texts, and
249 does not perform any input-encoding conversions.  This means that any
250 text, be it title, lyric text, or musical instruction containing
251 non-ASCII characters, must be utf-8.  The easiest way to enter such text is
252 by using a Unicode-aware editor and saving the file with utf-8 encoding.  Most
253 popular modern editors have utf-8 support, for example, vim, Emacs,
254 jEdit, and GEdit do.
255
256 Depending on the fonts installed, the following fragment shows Hebrew
257 and Cyrillic lyrics,
258
259 @cindex Cyrillic
260 @cindex Hebrew
261 @cindex ASCII, non
262
263 @lilypondfile[fontload]{utf-8.ly}
264
265 The @TeX{} backend does not handle encoding specially at all.  Strings
266 in the input are put in the output as-is.  Extents of text items in the
267 @TeX{} backend, are determined by reading a file created via the
268 @file{texstr} backend,
269
270 @example
271 lilypond -b texstr input/les-nereides.ly
272 latex les-nereides.texstr
273 @end example
274
275 The last command produces @file{les-nereides.textmetrics}, which is
276 read when you execute
277
278 @example
279 lilypond -b tex input/les-nereides.ly
280 @end example
281
282 Both @file{les-nereides.texstr} and @file{les-nereides.tex} need
283 suitable LaTeX wrappers to load appropriate La@TeX{} packages for
284 interpreting non-ASCII strings.
285
286 To use a Unicode escape sequence, use
287
288 @example
289 #(ly:export (ly:wide-char->utf-8 #x2014))
290 @end example
291
292
293 @seealso
294
295 @inputfileref{input/regression,utf-8.ly}
296
297
298
299 @node A single music expression
300 @section A single music expression
301
302 A @code{\score} must contain a single music expression.  However,
303 this music expression may be of any size.  Recall that music
304 expressions may be included inside other expressions to form
305 larger expressions.  All of these examples are single music
306 expressions; note the curly braces @{ @} or angle brackets <<
307 >> at the beginning and ending of the music.
308
309 @example
310 @{ c'4 c' c' c' @}
311 @end example
312
313 @lilypond[ragged-right,verbatim,quote]
314 {
315   { c'4 c' c' c'}
316   { d'4 d' d' d'}
317 }
318 @end lilypond
319
320 @lilypond[ragged-right,verbatim,quote]
321 <<
322   \new Staff { c'4 c' c' c' }
323   \new Staff { d'4 d' d' d' }
324 >>
325 @end lilypond
326
327 @example
328 @{
329   \new GrandStaff <<
330     \new StaffGroup <<
331       \new Staff @{ \flute @}
332       \new Staff @{ \oboe @}
333     >>
334     \new StaffGroup <<
335       \new Staff @{ \violinI @}
336       \new Staff @{ \violinII @}
337     >>
338   >>
339 @}
340 @end example
341
342
343 @node Titles and headers
344 @section Titles and headers
345
346 Almost all printed music includes a title and the composer's name;
347 some pieces include a lot more information.
348
349 @menu
350 * Creating titles::             
351 * Custom titles::               
352 @end menu
353
354
355 @node Creating titles
356 @subsection Creating titles
357
358 Titles are created for each @code{\score} block, and over a
359 @code{\book}.
360
361 The contents of the titles are taken from the @code{\header} blocks.
362 The header block for a book supports the following
363 @table @code
364 @item dedication
365 The dedicatee of the music, centered at the top of the first page.
366
367 @item title
368 The title of the music, centered just below the dedication.
369
370 @item subtitle
371 Subtitle, centered below the title.
372
373 @item subsubtitle
374 Subsubtitle, centered below the subtitle.
375
376 @item poet
377 Name of the poet, flush-left below the subtitle.
378
379 @item composer
380 Name of the composer, flush-right below the subtitle.
381
382 @item meter
383 Meter string, flush-left below the poet.
384
385 @item opus
386 Name of the opus, flush-right below the composer.
387
388 @item arranger
389 Name of the arranger, flush-right below the opus.
390
391 @item instrument
392 Name of the instrument, centered below the arranger.  Also
393 centered at the top of pages (other than the first page).
394
395 @item piece
396 Name of the piece, flush-left below the instrument.
397
398 @cindex page breaks, forcing
399 @item breakbefore
400 This forces the title to start on a new page (set to ##t or ##f).
401
402 @item copyright
403 Copyright notice, centered at the bottom of the first page.  To
404 insert the copyright symbol, see @ref{Text encoding}.
405
406 @item tagline
407 Centered at the bottom of the last page.
408
409 @end table
410
411 Here is a demonstration of the fields available.  Note that you
412 may use any @ref{Text markup} commands in the header.
413
414 @lilypond[quote,verbatim,line-width=11.0\cm]
415 \paper {
416   line-width = 9.0\cm
417   paper-height = 10.0\cm
418 }
419
420 \book {
421   \header {
422     dedication = "dedicated to me"
423     title = \markup \center-align { "Title first line" "Title second line,
424 longer" }
425     subtitle = "the subtitle,"
426     subsubtitle = #(string-append "subsubtitle LilyPond version "
427 (lilypond-version))
428     poet = "Poet"
429     composer =  \markup \center-align { "composer" \small "(1847-1973)" }
430     texttranslator = "Text Translator"
431     meter = \markup { \teeny "m" \tiny "e" \normalsize "t" \large "e" \huge
432 "r" }
433     arranger = \markup { \fontsize #8.5 "a" \fontsize #2.5 "r" \fontsize
434 #-2.5 "r" \fontsize #-5.3 "a" \fontsize #7.5 "nger" }
435     instrument = \markup \bold \italic "instrument"
436     piece = "Piece"
437   }
438
439   \score {
440     { c'1 }
441     \header {
442       piece = "piece1"
443       opus = "opus1"
444     }
445   }
446   \markup {
447       and now...
448   }
449   \score {
450     { c'1 }
451     \header {
452       piece = "piece2"
453       opus = "opus2"
454     }
455   }
456 }
457 @end lilypond
458
459 As demonstrated before, you can use multiple @code{\header} blocks.
460 When same fields appear in different blocks, the latter is used.
461 Here is a short example.
462
463 @example
464 \header @{
465   composer = "Composer"
466 @}
467 \header @{
468   piece = "Piece"
469 @}
470 \score @{
471   \new Staff @{ c'4 @}
472   \header @{
473     piece = "New piece"  % overwrite previous one
474   @}
475 @}
476 @end example
477
478 If you define the @code{\header} inside the @code{\score} block, then
479 normally only the @code{piece} and @code{opus} headers will be printed.
480 Note that the music expression must come before the @code{\header}.
481
482 @lilypond[quote,verbatim,line-width=11.0\cm]
483 \score {
484   { c'4 }
485   \header {
486     title = "title"  % not printed
487     piece = "piece"
488     opus = "opus"
489   }
490 }
491 @end lilypond
492
493 @findex printallheaders
494 @noindent
495 You may change this behavior (and print all the headers when defining
496 @code{\header} inside @code{\score}) by using
497
498 @example
499 \paper@{
500   printallheaders=##t
501 @}
502 @end example
503
504
505 @node Custom titles
506 @subsection Custom titles
507
508 A more advanced option is to change the definitions of the following
509 variables in the @code{\paper} block.  The init file
510 @file{ly/titling-init.ly} lists the default layout.
511
512 @table @code
513 @findex bookTitleMarkup
514 @item bookTitleMarkup
515   This is the title put over an entire @code{\book} block.  Typically,
516   it has the composer and the title of the piece
517
518 @findex scoreTitleMarkup
519 @item scoreTitleMarkup
520   This is the title put over a @code{\score} block within a
521 @code{\book}.  Typically, it has the name of the movement (@code{piece}
522 field).
523
524 @findex oddHeaderMarkup
525 @item oddHeaderMarkup
526   This is the page header for odd-numbered pages.
527
528 @findex evenHeaderMarkup
529 @item evenHeaderMarkup
530   This is the page header for even-numbered pages.  If unspecified,
531   the odd header is used instead.
532
533   By default, headers are defined such that the page number is on the
534   outside edge, and the instrument is centered.
535
536 @findex oddFooterMarkup
537 @item oddFooterMarkup
538   This is the page footer for odd-numbered pages.
539
540 @findex evenFotterMarkup
541 @item evenFooterMarkup
542   This is the page footer for even-numbered pages.  If unspecified,
543   the odd header is used instead.
544
545   By default, the footer has the copyright notice on the first, and
546   the tagline on the last page.
547 @end table
548
549
550 @cindex \paper
551 @cindex header
552 @cindex footer
553 @cindex page layout
554 @cindex titles
555
556 The following definition will put the title flush left, and the
557 composer flush right on a single line.
558
559 @verbatim
560 \paper {
561   bookTitleMarkup = \markup {
562    \fill-line {
563      \fromproperty #'header:title
564      \fromproperty #'header:composer
565    }
566   }
567 }
568 @end verbatim
569
570
571 @refbugs
572
573 The @code{breakbefore=##t} header requires that there is a @code{piece}
574 header as well.  It may be used as a normal header, or left  blank
575 (@code{=""}) as in the example above, but it must be present.
576
577
578
579 @node Paper and pages
580 @section Paper and pages
581
582 This section deals with the display of music on physical paper.
583
584 @menu
585 * Paper size::                  
586 * Page formatting::             
587 @end menu
588
589
590 @node Paper size
591 @subsection Paper size
592
593 @cindex paper size
594 @cindex page size
595 @findex papersize
596
597 To change the paper size, there are two commands,
598 @example
599 #(set-default-paper-size "a4")
600 \paper @{
601   #(set-paper-size "a4")
602 @}
603 @end example
604
605 The first command sets the size of all pages.  The second command sets the
606 size
607 of the pages that the @code{\paper} block applies to -- if the @code{\paper}
608 block is at the top of the file, then it will apply to all pages.  If the
609 @code{\paper} block is inside a @code{\book}, then the paper size will only
610 apply to that book.
611
612 Support for the following paper sizes are included by default,
613 @code{a6}, @code{a5}, @code{a4}, @code{a3}, @code{legal}, @code{letter},
614 @code{11x17} (also known as tabloid).
615
616 Extra sizes may be added by editing the definition for
617 @code{paper-alist} in the initialization file @file{scm/paper.scm}.
618
619 @cindex orientation
620 @cindex landscape
621
622 If the symbol @code{landscape} is supplied as an argument to
623 @code{set-default-paper-size}, the pages will be rotated by 90 degrees,
624 and wider line widths will be set correspondingly.
625
626 @example
627 #(set-default-paper-size "a6" 'landscape)
628 @end example
629
630 Setting the paper size will adjust a number of @code{\paper} variables
631 (such as margins).  To use a particular paper size with altered
632 @code{\paper} variables, set the paper size before setting the variables.
633
634
635 @node Page formatting
636 @subsection Page formatting
637
638 @cindex page formatting
639 @cindex margins
640 @cindex header, page
641 @cindex footer, page
642
643 LilyPond will do page layout, set margins, and add headers and
644 footers to each page.
645
646 @findex annotate-spacing
647 @cindex Spacing, display of properties
648
649 To graphically display the dimensions of properties that may
650 be altered for page formatting, use
651
652 @example
653 \paper @{
654   annotate-spacing = ##t
655 @}
656 @end example
657
658 @noindent
659 All units dimensions are measured in staff spaces. The pairs
660 (@var{a},@var{b}) are intervals, where @var{a} is the lower edge and
661 @var{b} the upper edge of the interval.
662
663 The default layout responds to the following settings in the
664 @code{\paper} block.
665
666 @findex \paper
667
668 @quotation
669 @table @code
670 @findex first-page-number
671 @item first-page-number
672 The value of the page number of the first page.  Default is@tie{}1.
673
674 @findex printfirst-page-number
675 @item printfirst-page-number
676 If set to true, will print the page number in the first page.  Default is
677 false.
678
679 @findex print-page-number
680 @item print-page-number
681 If set to false, page numbers will not be printed.
682
683 @findex paper-width
684 @item paper-width
685 The width of the page.
686
687 @findex paper-height
688 @item paper-height
689 The height of the page.
690
691 @findex top-margin
692 @item top-margin
693 Margin between header and top of the page.
694
695 @findex bottom-margin
696 @item bottom-margin
697 Margin between footer and bottom of the page.
698
699 @findex left-margin
700 @item left-margin
701 Margin between the left side of the page and the beginning of the music.
702
703 @findex line-width
704 @item line-width
705 The length of the systems.
706
707 @findex head-separation
708 @item head-separation
709 Distance between the top-most music system and the page header.
710
711 @findex foot-separation
712 @item foot-separation
713 Distance between the bottom-most music system and the page footer.
714
715 @findex page-top-space
716 Distance from the top of the printable area to the center of the first
717 staff. This only works for staves which are vertically small. Big staves
718 are set with the top of their bounding box aligned to the top of the
719 printable area.
720
721 @findex ragged-bottom
722 @item ragged-bottom
723 If set to true, systems will not be spread vertically across the page.  This
724 does not affect the last page.
725
726 This should be set to true for pieces that have only two or three
727 systems per page, for example orchestral scores.
728
729 @findex ragged-last-bottom
730 @item ragged-last-bottom
731 If set to false, systems will be spread vertically to fill the last page.
732
733 Pieces that amply fill two pages or more should have this set to
734 true.
735
736 @findex system-count
737 @item system-count
738 This variable, if set, specifies into how many lines a score should be
739 broken.
740
741 @findex between-system-space
742 @item between-system-space
743 This dimensions determines the distance between systems.  It is the
744 ideal distance between the center of the bottom staff of one system
745 and the center of the top staff of the next system.
746
747 Increasing this will provide a more even appearance of the page at the
748 cost of using more vertical space.
749
750 @findex between-system-padding
751 @item between-system-padding
752 This dimension is the minimum amount of white space that will always
753 be present between the bottom-most symbol of one system, and the
754 top-most of the next system.
755
756 Increasing this will put systems whose bounding boxes almost touch
757 farther apart.
758
759
760 @findex horizontal-shift
761 @item horizontal-shift
762 All systems (including titles and system separators) are shifted by
763 this amount to the right. Page markup, such as headers and footers are
764 not affected by this. The purpose of this variable is to make space
765 for instrument names at the left.
766
767 @findex after-title-space
768 @item after-title-space
769 Amount of space between the title and the first system.
770
771 @findex after-title-space
772 @item before-title-space
773 Amount of space between the last system of the previous piece and the
774 title of the next.
775
776 @findex between-title-space
777 @item between-title-space
778 Amount of space between consecutive titles (e.g., the title of the
779 book and the title of a piece).
780
781 @findex printallheaders
782 @item printallheaders
783 Setting this to #t will print all headers for each \score in a
784 \book.  Normally only the piece and opus \headers are printed.
785
786 @findex systemSeparatorMarkup
787 @item systemSeparatorMarkup
788 This contains a markup object, which will be inserted between
789 systems.  This is often used for orchestral scores.
790
791 The markup command @code{\slashSeparator} is provided as a sensible
792 default,  for example
793
794 @lilypond[ragged-right]
795 \book {
796   \score {
797     \relative { c1 \break c1 }
798   }
799   \paper {
800     systemSeparatorMarkup = \slashSeparator
801   }
802 }
803 @end lilypond
804
805
806 @end table
807 @end quotation
808
809 Example:
810
811 @example
812 \paper@{
813   paper-width = 2\cm
814   top-margin = 3\cm
815   bottom-margin = 3\cm
816   ragged-last-bottom = ##t
817 @}
818 @end example
819
820 You can also define these values in Scheme.  In that case @code{mm},
821 @code{in}, @code{pt}, and @code{cm} are variables defined in
822 @file{paper-defaults.ly} with values in millimeters.  That's why the
823 value has to be multiplied in the example
824
825 @example
826 \paper @{
827   #(define bottom-margin (* 2 cm))
828 @}
829 @end example
830
831 @cindex copyright
832 @cindex tagline
833
834 The default footer is empty, except for the first page, where the
835 @code{copyright} field from @code{\header} is inserted, and the last
836 page, where @code{tagline} from @code{\header} is added.  The default
837 tagline is ``Music engraving by LilyPond (@var{version})''.@footnote{Nicely
838 printed parts are good PR for us, so please leave the tagline if you
839 can.}
840
841 The header and footer are created by the functions @code{make-footer}
842 and @code{make-header}, defined in @code{\paper}.  The default
843 implementations are in @file{ly/@/paper@/-defaults@/.ly} and
844 @file{ly/@/titling@/-init@/.ly}.
845
846 The page layout itself is done by two functions in the
847 @code{\paper} block, @code{page-music-height} and
848 @code{page-make-stencil}.  The former tells the line-breaking algorithm
849 how much space can be spent on a page, the latter creates the actual
850 page given the system to put on it.
851
852
853 @refbugs
854
855 The option right-margin is defined but doesn't set the right margin
856 yet.  The value for the right margin has to be defined adjusting the
857 values of @code{left-margin} and @code{line-width}.
858
859 The default page header puts the page number and the @code{instrument}
860 field from the @code{\header} block on a line.
861
862 The titles (from the @code{\header@{@}} section) are treated as a
863 system, so @code{ragged-bottom} and @code{ragged-last-bottom} will
864 add space between the titles and the first system of the score.
865
866
867 @node Music layout
868 @section Music layout
869
870 This section deals with the manner in which the music is printed
871 within the boundaries defined by the @code{\paper} block.
872
873 The global paper layout is determined by three factors: the page layout, the
874 line breaks, and the spacing.  These all influence each other.  The
875 choice of spacing determines how densely each system of music is set.
876 This influences where line breaks are chosen, and thus ultimately, how
877 many pages a piece of music takes.
878
879 Globally spoken, this procedure happens in three steps: first,
880 flexible distances (``springs'') are chosen, based on durations.  All
881 possible line breaking combinations are tried, and the one with the
882 best results -- a layout that has uniform density and requires as
883 little stretching or cramping as possible -- is chosen.
884
885 After spacing and linebreaking, the systems are distributed across
886 pages, taking into account the size of the page, and the size of the
887 titles.
888
889 @menu
890 * Setting global staff size::   
891 * Selecting notation font size::  
892 * Score layout::                
893 * Vertical spacing::            
894 * Vertical spacing of piano staves::  
895 * Horizontal spacing::          
896 * Line length::                 
897 * Line breaking::               
898 * Page breaking::               
899 @end menu
900
901
902 @node Setting global staff size
903 @subsection Setting global staff size
904
905 @cindex font size, setting
906 @cindex staff size, setting
907 @findex layout file
908
909 To set the global staff size, use @code{set-global-staff-size}.
910
911 @example
912 #(set-global-staff-size 14)
913 @end example
914
915 @noindent
916 This sets the global default size to 14pt staff height and scales all
917 fonts accordingly.
918
919 The Feta font provides musical symbols at eight different
920 sizes.  Each font is tuned for a different staff size: at a smaller size
921 the font becomes heavier, to match the relatively heavier staff lines.
922 The recommended font sizes are listed in the following table:
923
924 @quotation
925 @multitable @columnfractions .15 .2 .22 .2
926
927 @item @b{font name}
928 @tab @b{staff height (pt)}
929 @tab @b{staff height (mm)}
930 @tab @b{use}
931
932 @item feta11
933 @tab 11.22
934 @tab 3.9
935 @tab pocket scores
936
937 @item feta13
938 @tab 12.60
939 @tab 4.4
940 @tab
941
942 @item feta14
943 @tab 14.14
944 @tab 5.0
945 @tab
946
947 @item feta16
948 @tab 15.87
949 @tab 5.6
950 @tab
951
952 @item feta18
953 @tab 17.82
954 @tab 6.3
955 @tab song books
956
957 @item feta20
958 @tab 20
959 @tab 7.0
960 @tab standard parts
961
962 @item feta23
963 @tab 22.45
964 @tab 7.9
965 @tab
966
967 @item feta26
968 @tab 25.2
969 @tab 8.9
970 @tab
971 @c modern rental material?
972
973 @end multitable
974 @end quotation
975
976 These fonts are available in any sizes.  The context property
977 @code{fontSize} and the layout property @code{staff-space} (in
978 @internalsref{StaffSymbol}) can be used to tune the size for individual
979 staves.  The sizes of individual staves are relative to the global size.
980
981 @example
982
983 @end example
984
985 @seealso
986
987 This manual: @ref{Selecting notation font size}.
988
989
990 @node Selecting notation font size
991 @subsection Selecting notation font size
992
993 The easiest method of setting the font size of any context, is by
994 setting the @code{fontSize} property.
995
996 @lilypond[quote,fragment,relative=1,verbatim]
997 c8
998 \set fontSize = #-4
999 c f
1000 \set fontSize = #3
1001 g
1002 @end lilypond
1003
1004 @noindent
1005 It does not change the size of variable symbols, such as beams or
1006 slurs.
1007
1008 Internally, the @code{fontSize} context property will cause the
1009 @code{font-size} property to be set in all layout objects.  The value
1010 of @code{font-size} is a number indicating the size relative to the
1011 standard size for the current staff height.  Each step up is an
1012 increase of approximately 12% of the font size.  Six steps is exactly a
1013 factor two.  The Scheme function @code{magstep} converts a
1014 @code{font-size} number to a scaling factor.
1015
1016 @lilypond[quote,fragment,relative=1,verbatim]
1017 c8
1018 \override NoteHead #'font-size = #-4
1019 c f
1020 \override NoteHead #'font-size = #3
1021 g
1022 @end lilypond
1023
1024 LilyPond has fonts in different design sizes.  The music fonts for
1025 smaller sizes are chubbier, while the text fonts are relatively wider.
1026 Font size changes are achieved by scaling the design size that is
1027 closest to the desired size.  The standard font size (for
1028 @code{font-size} equals 0), depends on the standard staff height.  For
1029 a 20pt staff, a 10pt font is selected.
1030
1031 The @code{font-size} property can only be set on layout objects that
1032 use fonts. These are the ones supporting the
1033 @internalsref{font-interface} layout interface.
1034
1035 @refcommands
1036
1037 The following commands set @code{fontSize} for the current voice:
1038
1039 @findex \tiny
1040 @code{\tiny},
1041 @findex \small
1042 @code{\small},
1043 @findex \normalsize
1044 @code{\normalsize}.
1045
1046
1047 @node Score layout
1048 @subsection Score layout
1049
1050 @findex \layout
1051
1052 While @code{\paper} contains settings that relate to the page formatting
1053 of the whole document, @code{\layout} contains settings for score-specific
1054 layout.
1055
1056 @example
1057 \layout @{
1058   indent = 2.0\cm
1059   \context @{ \Staff
1060     \override VerticalAxisGroup #'minimum-Y-extent = #'(-6 . 6)
1061   @}
1062   \context @{ \Voice
1063     \override TextScript #'padding = #1.0
1064     \override Glissando #'thickness = #3
1065   @}
1066 @}
1067 @end example
1068
1069
1070 @seealso
1071
1072 This manual: @ref{Changing context default settings}
1073
1074
1075 @node Vertical spacing
1076 @subsection Vertical spacing
1077
1078 @cindex vertical spacing
1079 @cindex distance between staves
1080 @cindex staff distance
1081 @cindex between staves, distance
1082 @cindex staves per page
1083 @cindex space between staves
1084
1085 The height of each system is determined automatically.  To prevent
1086 systems from bumping into each other, some minimum distances are set.
1087 By changing these, you can put staves closer together, and thus put
1088 more systems onto one page.
1089
1090 Normally staves are stacked vertically.  To make staves maintain a
1091 distance, their vertical size is padded.  This is done with the
1092 property @code{minimum-Y-extent}.  When applied to a
1093 @internalsref{VerticalAxisGroup}, it controls the size of a horizontal
1094 line, such as a staff or a line of lyrics.  @code{minimum-Y-extent}
1095 takes a pair of numbers, so
1096 if you want to make it smaller than its default @code{#'(-4 . 4)}
1097 then you could set
1098
1099 @example
1100 \override Staff.VerticalAxisGroup #'minimum-Y-extent = #'(-3 . 3)
1101 @end example
1102
1103 @noindent
1104 This sets the vertical size of the current staff to 3 staff spaces on
1105 either side of the center staff line.  The value @code{(-3 . 3)} is
1106 interpreted as an interval, where the center line is the 0, so the
1107 first number is generally negative.  The staff can be made larger at
1108 the bottom by setting it to @code{(-6 . 4)}.
1109
1110 The spacing of staves in a system may also be tuned per system.  This is
1111 done with the command
1112
1113 @example
1114 \overrideProperty
1115 #"Score.NonMusicalPaperColumn"
1116 #'line-break-system-details
1117 #'((alignment-extra-space . 15))
1118 @end example
1119
1120 @noindent
1121 at the line break before the system to be changed. The distance
1122 @code{15} is distributed over all staves that have a fixed distance
1123 alignment.  For example,
1124
1125 @lilypond[ragged-right, fragment, relative=2, staffsize=13]
1126 \new StaffGroup <<
1127   \new Staff {
1128     c1\break
1129   
1130     \overrideProperty
1131     #"Score.NonMusicalPaperColumn"
1132     #'line-break-system-details
1133     #'((fixed-alignment-extra-space . 15))
1134
1135     c\break
1136   }
1137   \new Staff { c c }
1138 >>
1139 @end lilypond
1140
1141 The distance for @code{alignment-extra-space} may also be negative.
1142
1143
1144 To change the amount of space between systems, use
1145 @code{between-system-space}.  A score with only one staff is still
1146 considered to have systems, so setting @code{between-system-space} will
1147 be much more useful than changing @code{minimum-Y-extent} of a Staff
1148 context.
1149
1150 @example
1151 \paper @{
1152   between-system-space = 10\mm
1153 @}
1154 @end example
1155
1156 If you simply want to tell LilyPond ``fit as much as possible onto
1157 these pages, then expand to fill any available space on the pages,''
1158 then use the following
1159
1160 @example
1161 \paper @{
1162   between-system-padding = #1
1163   ragged-bottom=##f
1164   ragged-last-bottom=##f
1165 @}
1166 @end example
1167
1168
1169 @c let's wait for a some comments before writing more.
1170
1171 The vertical spacing on a page can also be changed for each system
1172 individually.
1173 Some examples are found in the example file
1174 @inputfileref{input/regression/,page-spacing.ly}.
1175
1176 When setting @code{annotate-spacing} in the @code{\paper} block LilyPond
1177 will graphically indicate the dimensions of properties that may be set
1178 for page spacing,
1179
1180 @lilypond[verbatim]
1181 #(set-default-paper-size "a7" 'landscape)
1182 \paper { annotate-spacing = ##t }
1183 { c4 }
1184 @end lilypond
1185
1186 @noindent
1187 All units dimensions are measured in staff spaces. The pairs
1188 (@var{a},@var{b}) are intervals, where @var{a} is the lower edge and
1189 @var{b} the upper edge of the interval.
1190
1191 @seealso
1192
1193 Internals: Vertical alignment of staves is handled by the
1194 @internalsref{VerticalAlignment} object. The context parameters
1195 specifying  the vertical extent are described in connection with
1196 the @internalsref{Axis_group_engraver}.
1197
1198 Example files: @inputfileref{input/regression/,page-spacing.ly},
1199 @inputfileref{input/regression/,alignment-vertical-spacing.ly}.
1200
1201
1202
1203
1204 @node Vertical spacing of piano staves
1205 @subsection Vertical spacing of piano staves
1206
1207 The distance between staves of a @internalsref{PianoStaff} cannot be
1208 computed during formatting.  Rather, to make cross-staff beaming work
1209 correctly, that distance has to be fixed beforehand.
1210
1211 The distance of staves in a @code{PianoStaff} is set with the
1212 @code{forced-distance} property of the
1213 @internalsref{VerticalAlignment} object, created in
1214 @internalsref{PianoStaff}.
1215
1216 It can be adjusted as follows
1217 @example
1218 \new PianoStaff \with @{
1219   \override VerticalAlignment #'forced-distance = #7
1220 @} @{
1221   ...
1222 @}
1223 @end example
1224
1225 @noindent
1226 This would bring the staves together at a distance of 7 staff spaces,
1227 measured from the center line of each staff.
1228
1229 The difference is demonstrated in the following example,
1230 @lilypond[quote,verbatim]
1231 \relative c'' <<
1232   \new PianoStaff \with {
1233     \override VerticalAlignment #'forced-distance = #7
1234   } <<
1235     \new Staff { c1 }
1236     \new Staff { c }
1237   >>
1238   \new PianoStaff <<
1239     \new Staff { c }
1240     \new Staff { c }
1241   >>
1242 >>
1243 @end lilypond
1244
1245
1246 It is also possible to change the distance between for each system
1247 individually.  This is done by including the command
1248
1249 @example
1250 \overrideProperty
1251 #"Score.NonMusicalPaperColumn"
1252 #'line-break-system-details
1253 #'((fixed-alignment-extra-space . 15))
1254 @end example
1255
1256 @noindent
1257 at the line break before the system to be changed. The distance
1258 @code{15} is distributed over all staves that have a fixed distance
1259 alignment.  For example,
1260
1261 @lilypond[ragged-right, fragment, relative=2, staffsize=13]
1262 \new PianoStaff <<
1263   \new Staff {
1264     c1\break
1265   
1266     \overrideProperty
1267     #"Score.NonMusicalPaperColumn"
1268     #'line-break-system-details
1269     #'((fixed-alignment-extra-space . 15))
1270
1271     c\break
1272   }
1273   \new Staff { c c }
1274 >>
1275 @end lilypond
1276
1277 The distance for @code{fixed-alignment-extra-space} may also be
1278 negative.
1279
1280 @seealso
1281
1282 Example files: @inputfileref{input/regression/,alignment-vertical-spacing.ly}.
1283
1284 @node Horizontal spacing
1285 @subsection Horizontal Spacing
1286
1287 The spacing engine translates differences in durations into stretchable
1288 distances (``springs'') of differring lengths.  Longer durations get
1289 more space, shorter durations get less.  The shortest durations get a
1290 fixed amount of space (which is controlled by
1291 @code{shortest-duration-space} in the @internalsref{SpacingSpanner}
1292 object).  The longer the duration, the more space it gets: doubling a
1293 duration adds a fixed amount (this amount is controlled by
1294 @code{spacing-increment}) of space to the note.
1295
1296 For example, the following piece contains lots of half, quarter, and
1297 8th notes; the eighth note is followed by 1 note head width (NHW).
1298 The quarter note is followed by 2 NHW, the half by 3 NHW, etc.
1299
1300 @lilypond[quote,fragment,verbatim,relative=1]
1301 c2 c4. c8 c4. c8 c4. c8 c8
1302 c8 c4 c4 c4
1303 @end lilypond
1304
1305 Normally, @code{spacing-increment} is set to 1.2 staff space, which is
1306 approximately the width of a note head, and
1307 @code{shortest-duration-space} is set to 2.0, meaning that the
1308 shortest note gets 2.4 staff space (2.0 times the
1309 @code{spacing-increment}) of horizontal space.  This space is counted
1310 from the left edge of the symbol, so the shortest notes are generally
1311 followed by one NHW of space.
1312
1313 If one would follow the above procedure exactly, then adding a single
1314 32nd note to a score that uses 8th and 16th notes, would widen up the
1315 entire score a lot.  The shortest note is no longer a 16th, but a 32nd,
1316 thus adding 1 NHW to every note.  To prevent this, the shortest
1317 duration for spacing is not the shortest note in the score, but rather
1318 the one which occurs most frequently.
1319
1320
1321 The most common shortest duration is determined as follows: in every
1322 measure, the shortest duration is determined.  The most common shortest
1323 duration is taken as the basis for the spacing, with the stipulation
1324 that this shortest duration should always be equal to or shorter than
1325 an 8th note.  The shortest duration is printed when you run
1326 @code{lilypond} with the @code{--verbose} option.
1327
1328 These durations may also be customized.  If you set the
1329 @code{common-shortest-duration} in @internalsref{SpacingSpanner}, then
1330 this sets the base duration for spacing.  The maximum duration for this
1331 base (normally an 8th), is set through @code{base-shortest-duration}.
1332
1333 @findex common-shortest-duration
1334 @findex base-shortest-duration
1335 @findex stem-spacing-correction
1336 @findex spacing
1337
1338 Notes that are even shorter than the common shortest note are
1339 followed by a space that is proportional to their duration relative to
1340 the common shortest note.  So if we were to add only a few 16th notes
1341 to the example above, they would be followed by half a NHW:
1342
1343 @lilypond[quote,fragment,verbatim,relative=2]
1344 c2 c4. c8 c4. c16[ c] c4. c8 c8 c8 c4 c4 c4
1345 @end lilypond
1346
1347
1348 In the introduction (see @ref{Engraving}), it was explained that stem
1349 directions influence spacing.  This is controlled with the
1350 @code{stem-spacing-correction} property in the
1351 @internalsref{NoteSpacing}, object.  These are generated for every
1352 @internalsref{Voice} context.  The @code{StaffSpacing} object
1353 (generated in @internalsref{Staff} context) contains the same property
1354 for controlling the stem/bar line spacing.  The following example shows
1355 these corrections, once with default settings, and once with
1356 exaggerated corrections:
1357
1358 @lilypond[quote,ragged-right]
1359 {
1360   c'4 e''4 e'4 b'4 |
1361   b'4 e''4 b'4 e''4|
1362   \override Staff.NoteSpacing #'stem-spacing-correction = #1.5
1363   \override Staff.StaffSpacing #'stem-spacing-correction = #1.5
1364   c'4 e''4 e'4 b'4 |
1365   b'4 e''4 b'4 e''4|
1366 }
1367 @end lilypond
1368
1369 Proportional notation is supported; see @ref{Proportional notation}.
1370
1371 By default, spacing in tuplets depends on various non-duration
1372 factors (such as accidentals, clef changes, etc).  To disregard
1373 such symbols and force uniform equal-duration spacing, use
1374 @code{Score.SpacingSpanner #'uniform-stretching}.  This
1375 property can only be changed at the beginning of a score,
1376
1377 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1378 \new Score \with {
1379   \override SpacingSpanner #'uniform-stretching = ##t
1380 } <<
1381   \new Staff{
1382     \times 4/5 {
1383       c8 c8 c8 c8 c8
1384     }
1385     c8 c8 c8 c8
1386   }
1387   \new Staff{
1388     c8 c8 c8 c8
1389     \times 4/5 {
1390       c8 c8 c8 c8 c8
1391     }
1392   }
1393 >>
1394 @end lilypond
1395
1396
1397 When @code{strict-note-spacing} is set, notes are spaced without
1398 regard for clefs, bar lines, and grace notes,
1399
1400 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1401 \override Score.SpacingSpanner #'strict-note-spacing = ##t
1402 \new Staff { c8[ c \clef alto c \grace { c16[ c] } c8 c c]  c32[ c32] }
1403 @end lilypond
1404
1405
1406 @seealso
1407
1408 Internals: @internalsref{SpacingSpanner}, @internalsref{NoteSpacing},
1409 @internalsref{StaffSpacing}, @internalsref{SeparationItem}, and
1410 @internalsref{SeparatingGroupSpanner}.
1411
1412 @refbugs
1413
1414 Spacing is determined on a score wide basis.  If you have a score that
1415 changes its character (measured in durations) halfway during the
1416 score, the part containing the longer durations will be spaced too
1417 widely.
1418
1419 There is no convenient mechanism to manually override spacing.  The
1420 following work-around may be used to insert extra space into a score.
1421 @example
1422  \once \override Score.SeparationItem #'padding = #1
1423 @end example
1424
1425 No work-around exists for decreasing the amount of space.
1426
1427
1428 @node Line length
1429 @subsection Line length
1430
1431 @cindex page breaks
1432 @cindex breaking pages
1433
1434 @findex indent
1435 @findex line-width
1436 @findex ragged-right
1437 @findex ragged-last
1438
1439 @c Although line-width can be set in \layout, it should be set in paper
1440 @c block, to get page layout right.
1441 @c Setting indent in \paper block makes not much sense, but it works.
1442
1443 @c Bit verbose and vague, use examples?
1444 The most basic settings influencing the spacing are @code{indent} and
1445 @code{line-width}.  They are set in the @code{\layout} block.  They
1446 control the indentation of the first line of music, and the lengths of
1447 the lines.
1448
1449 If @code{ragged-right} is set to true in the @code{\layout} block, then
1450 systems ends at their natural horizontal length, instead of being spread
1451 horizontally to fill the whole line.  This is useful for
1452 short fragments, and for checking how tight the natural spacing is.
1453
1454 @cindex page layout
1455 @cindex vertical spacing
1456
1457 The option @code{ragged-last} is similar to @code{ragged-right}, but
1458 only affects the last line of the piece.  No restrictions are put on
1459 that line.  The result is similar to formatting text paragraphs.  In a
1460 paragraph, the last line simply takes its natural horizontal length.
1461 @c Note that for text there are several options for the last line.
1462 @c While Knuth TeX uses natural length, lead typesetters use the same
1463 @c stretch as the previous line.  eTeX uses \lastlinefit to
1464 @c interpolate between both these solutions.
1465
1466 @example
1467 \layout @{
1468   indent = #0
1469   line-width = #150
1470   ragged-last = ##t
1471 @}
1472 @end example
1473
1474
1475 @node Line breaking
1476 @subsection Line breaking
1477
1478 @cindex line breaks
1479 @cindex breaking lines
1480
1481 Line breaks are normally computed automatically.  They are chosen so
1482 that lines look neither cramped nor loose, and that consecutive lines
1483 have similar density.
1484
1485 Occasionally you might want to override the automatic breaks; you can
1486 do this by specifying @code{\break}.  This will force a line break at
1487 this point.  Line breaks can only occur at places where there are bar
1488 lines.  If you want to have a line break where there is no bar line,
1489 you can force an invisible bar line by entering @code{\bar
1490 ""}.  Similarly, @code{\noBreak} forbids a line break at a
1491 point.
1492
1493
1494 @cindex regular line breaks
1495 @cindex four bar music.
1496
1497 For line breaks at regular intervals use @code{\break} separated by
1498 skips and repeated with @code{\repeat}:
1499 @example
1500 << \repeat unfold 7 @{
1501          s1 \noBreak s1 \noBreak
1502          s1 \noBreak s1 \break @}
1503    @emph{the real music}
1504 >>
1505 @end example
1506
1507 @noindent
1508 This makes the following 28 measures (assuming 4/4 time) be broken every
1509 4 measures, and only there.
1510
1511 @refcommands
1512
1513 @code{\break}, and @code{\noBreak}.
1514 @findex \break
1515 @findex \noBreak
1516
1517 @seealso
1518
1519 Internals: @internalsref{BreakEvent}.
1520
1521 A linebreaking configuration can now be saved as a @code{.ly} file
1522 automatically.  This allows vertical alignments to be stretched to
1523 fit pages in a second formatting run.  This is fairly new and
1524 complicated; see @inputfileref{input/regression/,page-layout-twopass.ly}
1525 for details.
1526
1527 @refbugs
1528
1529 Line breaks can only occur if there is a ``proper'' bar line.  A note
1530 which is hanging over a bar line is not proper, such as
1531
1532 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1533 c4 c2 c2 \break   % this does nothing
1534 c2 c4 |           % a break here would work
1535 c4 c2 c4 ~ \break % as does this break
1536 c4 c2 c4
1537 @end lilypond
1538
1539
1540 @node Page breaking
1541 @subsection Page breaking
1542
1543 The default page breaking may be overriden by inserting
1544 @code{\pageBreak} or @code{\noPageBreak} commands.  These commands are
1545 analogous to @code{\break} and @code{\noBreak}.  They should be
1546 inserted at a bar line.  These commands force and forbid a page-break
1547 from happening.  Of course, the @code{\pageBreak} command also forces
1548 a line break.
1549
1550 Page breaks are computed by the @code{page-breaking} function in the
1551 @code{\paper} block.
1552
1553 To force a new page for a new piece (in a collection of pieces or a
1554 piece in several movements), use @code{breakbefore} in the header.
1555
1556 @example
1557 \header@{
1558   breakbefore = ##t
1559   piece = ""
1560 @}
1561 @end example
1562
1563 @refcommands
1564
1565 @findex \pageBreak
1566 @code{\pageBreak}
1567 @findex \noPageBreak
1568 @code{\noPageBreak}
1569
1570
1571 @refbugs
1572
1573 The @code{breakbefore=##t} header requires that there is a @code{piece}
1574 header as well.  It may be used as a normal header, or left  blank
1575 (@code{=""}) as in the example above, but it must be present.
1576
1577
1578
1579 @node Multiple movements
1580 @section Multiple movements
1581
1582 @cindex bibliographic information
1583 @cindex titles
1584 @cindex composer
1585 @cindex Music engraving by LilyPond
1586
1587 A document may contain multiple pieces of music and texts.  Examples
1588 of these are an etude book, or an orchestral part with multiple
1589 movements.  Each movement is entered with a @code{\score} block,
1590
1591 @example
1592 \score @{
1593   @var{..music..}
1594 @}
1595 @end example
1596
1597 and texts are entered with a @code{\markup} block,
1598
1599 @example
1600 \markup @{
1601   @var{..text..}
1602 @}
1603 @end example
1604
1605 @findex \book
1606
1607 The movements and texts are combined together in a @code{\book} block,
1608 like
1609
1610 @example
1611 \book @{
1612   \score @{
1613     @var{..}
1614   @}
1615   \markup @{
1616     @var{..}
1617   @}
1618   \score @{
1619     @var{..}
1620   @}
1621 @}
1622 @end example
1623
1624
1625 The header for each piece of music can be put inside the @code{\score}
1626 block.  The @code{piece} name from the header will be printed before
1627 each movement.  The title for the entire book can be put inside the
1628 @code{\book}, but if it is not present, the @code{\header} which is at
1629 the top of the file is inserted.
1630
1631 @cindex Engraved by LilyPond
1632 @cindex signature line
1633
1634 @example
1635 \book @{
1636   \header @{
1637     title = "Eight miniatures"
1638     composer = "Igor Stravinsky"
1639   @}
1640   \score @{
1641     @dots{}
1642     \header @{ piece = "Romanze" @}
1643   @}
1644   \markup @{
1645      ..text of second verse..
1646   @}
1647   \markup @{
1648      ..text of third verse..
1649   @}
1650   \score @{
1651     @dots{}
1652     \header @{ piece = "Menuetto" @}
1653   @}
1654 @}
1655 @end example
1656
1657
1658
1659 @node MIDI output
1660 @section MIDI output
1661
1662 @cindex Sound
1663 @cindex MIDI
1664
1665 MIDI (Musical Instrument Digital Interface) is a standard for
1666 connecting and controlling digital instruments.  A MIDI file is a
1667 series of notes in a number of tracks.  It is not an actual
1668 sound file; you need special software to translate between the
1669 series of notes and actual sounds.
1670
1671 Pieces of music can be converted to MIDI files, so you can listen to
1672 what was entered.  This is convenient for checking the music; octaves
1673 that are off or accidentals that were mistyped stand out very much
1674 when listening to the MIDI output.
1675
1676 @refbugs
1677
1678 Many musically interesting effects, such as swing, articulation,
1679 slurring, etc., are not translated to midi.
1680
1681 The midi output allocates a channel for each staff, and one for global
1682 settings.  Therefore the midi file should not have more than 15 staves
1683 (or 14 if you do not use drums).  Other staves will remain silent.
1684
1685 Not all midi players correctly handle tempo changes in the midi
1686 output.  Players that are known to work include
1687 @uref{http://@/timidity@/.sourceforge@/.net/,timidity}.
1688
1689 @menu
1690 * Creating MIDI files::         
1691 * MIDI block::                  
1692 * MIDI instrument names::       
1693 @end menu
1694
1695 @node Creating MIDI files
1696 @subsection Creating MIDI files
1697
1698 To create a MIDI from a music piece of music, add a @code{\midi} block
1699 to a score, for example,
1700
1701 @example
1702 \score @{
1703   @var{...music...}
1704   \midi @{ \tempo 4=72 @}
1705 @}
1706 @end example
1707
1708 The tempo is specified using the @code{\tempo} command.  In this
1709 example the tempo of quarter notes is set to 72 beats per minute.
1710
1711
1712 If there is a @code{\midi} command in a @code{\score}, only MIDI will
1713 be produced.  When notation is needed too, a @code{\layout} block must
1714 be added
1715
1716 @example
1717 \score @{
1718   @var{...music...}
1719   \midi @{ \tempo 4=72 @}
1720   \layout @{ @}
1721 @}
1722 @end example
1723 @cindex layout block
1724
1725
1726
1727 Ties, dynamics, and tempo changes are interpreted.  Dynamic marks,
1728 crescendi and decrescendi translate into MIDI volume levels.  Dynamic
1729 marks translate to a fixed fraction of the available MIDI volume
1730 range, crescendi and decrescendi make the volume vary linearly between
1731 their two extremes.  The fractions can be adjusted by
1732 @code{dynamicAbsoluteVolumeFunction} in @internalsref{Voice} context.
1733 For each type of MIDI instrument, a volume range can be defined.  This
1734 gives a basic equalizer control, which can enhance the quality of
1735 the MIDI output remarkably.  The equalizer can be controlled by
1736 setting @code{instrumentEqualizer}, or by setting
1737
1738 @example
1739 \set Staff.midiMinimumVolume = #0.2
1740 \set Staff.midiMaximumVolume = #0.8
1741 @end example
1742
1743 To remove dynamics from the MIDI output, insert the following lines
1744 in the @code{\midi@{@}} section.
1745
1746 @example
1747 \midi @{
1748   ...
1749   \context @{
1750     \Voice
1751     \remove "Dynamic_performer"
1752     \remove "Span_dynamic_performer"
1753   @}
1754 @}
1755 @end example
1756
1757
1758 @refbugs
1759
1760 Unterminated (de)crescendos will not render properly in the midi file,
1761 resulting in silent passages of music.  The workaround is to explicitly
1762 terminate the (de)crescendo.  For example,
1763
1764 @example
1765 @{ a\< b c d\f @}
1766 @end example
1767
1768 @noindent
1769 will not work properly but
1770
1771 @example
1772 @{ a\< b c d\!\f @}
1773 @end example
1774
1775 @noindent
1776 will.
1777
1778
1779 @node MIDI block
1780 @subsection MIDI block
1781 @cindex MIDI block
1782
1783
1784 The MIDI block is analogous to the layout block, but it is somewhat
1785 simpler.  The @code{\midi} block can contain
1786 @cindex MIDI block
1787
1788 @itemize @bullet
1789   @item a @code{\tempo} definition, and
1790   @item context definitions.
1791 @end itemize
1792
1793 A number followed by a period is interpreted as a real number, so
1794 for setting the tempo for dotted notes, an extra space should be
1795 inserted, for example
1796
1797 @example
1798 \midi @{ \tempo 4 . = 120 @}
1799 @end example
1800
1801
1802 @cindex context definition
1803
1804 Context definitions follow precisely the same syntax as within the
1805 \layout block.  Translation modules for sound are called performers.
1806 The contexts for MIDI output are defined in @file{ly/@/performer@/-init@/.ly}.
1807
1808
1809 @node MIDI instrument names
1810 @subsection MIDI instrument names
1811
1812 @cindex instrument names
1813 @findex Staff.midiInstrument
1814
1815 The MIDI instrument name is set by the @code{Staff.midiInstrument}
1816 property.  The instrument name should be chosen from the list in
1817 @ref{MIDI instruments}.
1818
1819 @example
1820 \set Staff.midiInstrument = "glockenspiel"
1821 @var{...notes...}
1822 @end example
1823
1824 If the selected instrument does not exactly match an instrument from
1825 the list of MIDI instruments, the Grand Piano (@code{"acoustic grand"})
1826 instrument is used.
1827
1828
1829 @c  Yes, this is a cop-out; this info doesn't belong in the Scheme
1830 @c  chapter, but I'm not certain where to stick it.
1831 @c  I think I'll eventually split this chapter into a "paper/layout"
1832 @c  chapter and a "misc issues" chapter.  -gp
1833 @node Displaying LilyPond notation
1834 @section Displaying LilyPond notation
1835
1836 @findex \displayLilyMusc
1837 Displaying a music expression in LilyPond notation can be
1838 done using the music function @code{\displayLilyMusic}.  For example,
1839
1840 @example
1841 @{
1842   \displayLilyMusic \transpose c a, @{ c e g a bes @}
1843 @}
1844 @end example
1845
1846 will display
1847
1848 @example
1849 @{ a, cis e fis g @}
1850 @end example
1851
1852 By default, LilyPond will print these messages to the console along
1853 with all the other messages.  To split up these messages and save
1854 the results of @code{\display@{STUFF@}}, redirect the output to
1855 a file.
1856
1857 @example
1858 lilypond file.ly >display.txt
1859 @end example
1860
1861
1862 @node Other
1863 @section Other
1864
1865 @c  FIXME: yeah, it really needs to be moved soon.  -gp
1866 @menu
1867 * Skipping corrected music::    
1868 * Writing music in parallel::   
1869 @end menu
1870
1871 @node Skipping corrected music
1872 @subsection Skipping corrected music
1873
1874
1875 @findex skipTypesetting
1876 @findex showLastLength
1877
1878 When entering or copying music, usually only the music near the end (where
1879 you
1880 are adding notes) is interesting to view and correct.  To speed up
1881 this correction process, it is possible to skip typesetting of all but
1882 the last few measures. This is achieved by putting
1883
1884 @verbatim
1885 showLastLength = R1*5
1886 \score { ... }
1887 @end verbatim
1888
1889 @noindent
1890 in your source file. This will render only the last 5 measures
1891 (assuming 4/4 time signature) of every @code{\score} in the input
1892 file. For longer pieces, rendering only a small part is often an order
1893 of magnitude quicker than rendering it completely
1894
1895 Skipping parts of a score can be controlled in a more fine-grained
1896 fashion with the property @code{Score.skipTypesetting}.  When it is
1897 set, no typesetting is performed at all.
1898
1899 This property is also used to control output to the MIDI file. Note that
1900 it skips all events, including tempo and instrument changes. You have
1901 been warned.
1902
1903 @lilypond[quote,fragment,ragged-right,verbatim]
1904 \relative c'' {
1905   c8 d
1906   \set Score.skipTypesetting = ##t
1907   e e e e e e e e
1908   \set Score.skipTypesetting = ##f
1909   c d b bes a g c2 }
1910 @end lilypond
1911
1912 In polyphonic music, @code{Score.skipTypesetting} will affect all
1913 voices and staves, saving even more time.
1914
1915
1916 @node Writing music in parallel
1917 @subsection Writing music in parallel
1918 @cindex Writing music in parallel
1919 @cindex Interleaved music
1920
1921 Music for multiple parts can be interleaved
1922
1923 @lilypond[quote,fragment,verbatim]
1924 \parallelMusic #'(voiceA voiceB) {
1925   r8     g'16[ c''] e''[ g' c'' e''] r8     g'16[ c''] e''[ g' c'' e''] |
1926   c'2                                c'2                                |
1927   r8     a'16[ d''] f''[ a' d'' f''] r8     a'16[ d''] f''[ a' d'' f''] |
1928   c'2                                c'2                                |
1929 }
1930 \new StaffGroup <<
1931   \new Staff \new Voice \voiceA
1932   \new Staff \new Voice \voiceB
1933 >>
1934 @end lilypond
1935
1936