]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/non-music.itely
ba315b7bc93ea21f19ff4890a0befa998cbb9495
[lilypond.git] / Documentation / user / non-music.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  See TRANSLATION for details.
8 @end ignore
9
10 @c A menu is needed before every deeper *section nesting of @node's; run
11 @c     M-x texinfo-all-menus-update
12 @c to automatically fill in these menus before saving changes
13
14 @node Non-musical notation
15 @chapter Non-musical notation
16
17 This section deals with general lilypond issues, rather than
18 specific notation.
19
20 @menu
21 * Input files::                 
22 * Titles and headers::          
23 * MIDI output::                 
24 * Displaying LilyPond notation::  
25 * Skipping corrected music::    
26 @end menu
27
28
29 @node Input files
30 @section Input files
31
32 The main format of input for LilyPond are text files.  By convention,
33 these files end with @samp{.ly}.
34
35 @menu
36 * File structure (introduction)::  
37 * File structure::              
38 * A single music expression::   
39 * Multiple scores in a book::   
40 * Extracting fragments of notation::  
41 * Including LilyPond files::    
42 * Text encoding::               
43 * Different editions from one source::  
44 @end menu
45
46
47 @node File structure (introduction)
48 @subsection File structure (introduction)
49
50 A basic example of a lilypond input file is
51
52 @example
53 \version "2.11.23"
54 \score @{
55   @{ @}     % this is a single music expression;
56             % all the music goes in here.
57   \header @{ @}
58   \layout @{ @}
59   \midi @{ @}
60 @}
61 @end example
62
63 @noindent
64 There are many variations of this basic pattern, but this
65 example serves as a useful starting place.
66
67 The major part of this manual is concerned with entering various
68 forms of music in LilyPond.  However, many music expressions are not
69 valid input on their own, for example, a @code{.ly} file containing
70 only a note
71 @example
72 c'4
73 @end example
74
75 @noindent
76 will result in a parsing error.  Instead, music should be inside other
77 expressions, which may be put in a file by themselves.  Such
78 expressions are called toplevel expressions; see @ref{File structure}, for
79 a list of all such expressions.
80
81
82 @node File structure
83 @subsection File structure
84
85 A @code{.ly} file contains any number of toplevel expressions, where a
86 toplevel expression is one of the following
87
88 @itemize @bullet
89 @item
90 An output definition, such as @code{\paper}, @code{\midi}, and
91 @code{\layout}.  Such a definition at the toplevel changes the default
92 settings for the block entered.
93
94 @item
95 A direct scheme expression, such as
96 @code{#(set-default-paper-size "a7" 'landscape)} or
97 @code{#(ly:set-option 'point-and-click #f)}.
98
99 @item
100 A @code{\header} block.  This sets the global header block.  This
101 is the block containing the definitions for book-wide settings, like
102 composer, title, etc.
103
104 @item
105 A @code{\score} block.  This score will be collected with other
106 toplevel scores, and combined as a single @code{\book}.
107
108 This behavior can be changed by setting the variable
109 @code{toplevel-score-handler} at toplevel.  The default handler is
110 defined in the init file @file{scm/@/lily@/.scm}.
111
112 The @code{\score} must begin with a music expression, and may
113 contain only one music expression.
114
115 @item
116 A @code{\book} block logically combines multiple movements
117 (i.e., multiple @code{\score} blocks) in one document.  If there are
118 a number of @code{\scores}, one output file will be created for
119 each @code{\book} block, in which all corresponding movements are
120 concatenated. The only reason to explicitly specify @code{\book} blocks
121 in a @code{.ly} file is if you wish multiple output files from a single
122 input file. One exception is within lilypond-book documents, where you
123 explicitly have to add a @code{\book} block if you want more than a
124 single @code{\score} or @code{\markup} in the same example.
125
126 This behavior can be changed by setting the variable
127 @code{toplevel-book-handler} at toplevel.  The default handler is
128 defined in the init file @file{scm/@/lily@/.scm}.
129
130 @item
131 A compound music expression, such as
132 @example
133 @{ c'4 d' e'2 @}
134 @end example
135
136 This will add the piece in a @code{\score} and format it in a
137 single book together with all other toplevel @code{\score}s and music
138 expressions.  In other words, a file containing only the above
139 music expression will be translated into
140
141 @example
142 \book @{
143   \score @{
144     \new Staff @{
145       \new Voice @{
146         @{ c'4 d' e'2 @}
147       @}
148     @}
149   @}
150         \layout @{ @}
151         \header @{ @}
152 @}
153 @end example
154
155 This behavior can be changed by setting the variable
156 @code{toplevel-music-handler} at toplevel.  The default handler is
157 defined in the init file @file{scm/@/lily@/.scm}.
158
159 @item
160 A markup text, a verse for example
161 @example
162 \markup @{
163    2.  The first line verse two.
164 @}
165 @end example
166
167 Markup texts are rendered above, between or below the scores or music
168 expressions, wherever they appear.
169
170 @cindex variables
171 @cindex identifiers
172
173 @item
174 An identifier, such as
175 @example
176 foo = @{ c4 d e d @}
177 @end example
178
179 This can be used later on in the file by entering @code{\foo}.  The
180 name of an identifier should have alphabetic characters only; no
181 numbers, underscores or dashes.
182
183 @end itemize
184
185 The following example shows three things that may be entered at
186 toplevel
187
188 @example
189 \layout @{
190   % movements are non-justified by default
191   ragged-right = ##t
192 @}
193
194 \header @{
195    title = "Do-re-mi"
196 @}
197
198 @{ c'4 d' e2 @}
199 @end example
200
201
202 At any point in a file, any of the following lexical instructions can
203 be entered:
204
205 @itemize @bullet
206 @item @code{\version}
207 @item @code{\include}
208 @item @code{\sourcefilename}
209 @item @code{\sourcefileline}
210
211 @end itemize
212
213
214 @node A single music expression
215 @subsection A single music expression
216
217 A @code{\score} must contain a single music expression.  However,
218 this music expression may be of any size.  Recall that music
219 expressions may be included inside other expressions to form
220 larger expressions.  All of these examples are single music
221 expressions; note the curly braces @{ @} or angle brackets <<
222 >> at the beginning and ending of the music.
223
224 @example
225 @{ c'4 c' c' c' @}
226 @end example
227
228 @lilypond[ragged-right,verbatim,quote]
229 {
230   { c'4 c' c' c'}
231   { d'4 d' d' d'}
232 }
233 @end lilypond
234
235 @lilypond[ragged-right,verbatim,quote]
236 <<
237   \new Staff { c'4 c' c' c' }
238   \new Staff { d'4 d' d' d' }
239 >>
240 @end lilypond
241
242 @example
243 @{
244   \new GrandStaff <<
245     \new StaffGroup <<
246       \new Staff @{ \flute @}
247       \new Staff @{ \oboe @}
248     >>
249     \new StaffGroup <<
250       \new Staff @{ \violinI @}
251       \new Staff @{ \violinII @}
252     >>
253   >>
254 @}
255 @end example
256
257
258 @node Multiple scores in a book
259 @subsection Multiple scores in a book
260
261 @funindex \book
262 @cindex movements, multiple
263
264 A document may contain multiple pieces of music and texts.  Examples
265 of these are an etude book, or an orchestral part with multiple
266 movements.  Each movement is entered with a @code{\score} block,
267
268 @example
269 \score @{
270   @var{..music..}
271 @}
272 @end example
273
274 and texts are entered with a @code{\markup} block,
275
276 @example
277 \markup @{
278   @var{..text..}
279 @}
280 @end example
281
282 @funindex \book
283
284 All the movements and texts which appear in the same @code{.ly} file 
285 will normally be typeset in the form of a single output file. 
286
287 @example
288 \score @{
289   @var{..}
290 @}
291 \markup @{
292   @var{..}
293 @}
294 \score @{
295   @var{..}
296 @}
297 @end example
298
299 However, if you want multiple output files from the same @code{.ly}
300 file, then you can add multiple @code{\book} blocks, where each such
301 @code{\book} block will result in a separate output. If you do not
302 specify any @code{\book} block in the file, LilyPond will implicitly
303 treat the full file as a single @code{\book} block, see @ref{File
304 structure}. One important exception is within lilypond-book documents,
305 where you explicitly have to add a @code{\book} block, otherwise only
306 the first @code{\score} or @code{\markup} will appear in the output.
307
308 The header for each piece of music can be put inside the @code{\score}
309 block.  The @code{piece} name from the header will be printed before
310 each movement.  The title for the entire book can be put inside the
311 @code{\book}, but if it is not present, the @code{\header} which is at
312 the top of the file is inserted.
313
314 @example
315 \header @{
316   title = "Eight miniatures"
317   composer = "Igor Stravinsky"
318 @}
319 \score @{
320   @dots{}
321   \header @{ piece = "Romanze" @}
322 @}
323 \markup @{
324    ..text of second verse..
325 @}
326 \markup @{
327    ..text of third verse..
328 @}
329 \score @{
330   @dots{}
331   \header @{ piece = "Menuetto" @}
332 @}
333 @end example
334
335 @node Extracting fragments of notation
336 @subsection Extracting fragments of notation
337
338 It is possible to quote small fragments of a large score directly from
339 the output. This can be compared to clipping a piece of a paper score
340 with scissors.
341
342 This is done by definining the measures that need to be cut out
343 separately. For example, including the following definition
344
345
346 @verbatim
347 \layout {
348   clip-regions
349   = #(list
350       (cons
351        (make-rhythmic-location 5 1 2)
352        (make-rhythmic-location 7 3 4)))
353 }       
354 @end verbatim
355
356 @noindent
357 will extract a fragment starting halfway the fifth measure, ending in
358 the seventh measure. The meaning of @code{5 1 2} is: after a 1/2 note
359 in measure 5, and @code{7 3 4} after 3 quarter notes in measure 7.
360
361 More clip regions can be defined by adding more pairs of
362 rhythmic-locations to the list. 
363
364 In order to use this feature, LilyPond must be invoked with
365 @code{-dclip-systems}. The clips are output as EPS files, and are
366 converted to PDF and PNG if these formats are switched on as well.
367
368 For more information on output formats, see @rprogram{Invoking lilypond}.
369
370 @seealso
371
372 Examples: @lsr{non-notation,clip-systems.ly}
373
374
375 @node Including LilyPond files
376 @subsection Including LilyPond files
377
378 @funindex \include
379 @cindex including files
380
381 A large project may be split up into separate files.  To refer to another
382 file, use
383
384 @example
385 \include "otherfile.ly"
386 @end example
387
388 The line @code{\include "file.ly"} is equivalent to pasting the contents
389 of file.ly into the current file at the place where you have the
390 \include.  For example, for a large project you might write separate files
391 for each instrument part and create a @q{full score} file which brings
392 together the individual instrument files.
393
394 The initialization of LilyPond is done in a number of files that are
395 included by default when you start the program, normally transparent to the
396 user.  Run lilypond --verbose to see a list of paths and files that Lily
397 finds.
398
399 Files placed in directory @file{PATH/TO/share/lilypond/VERSION/ly/} (where
400 VERSION is in the form @q{2.6.1}) are on the path and available to
401 @code{\include}.  Files in the
402 current working directory are available to \include, but a file of the same
403 name in LilyPond's installation takes precedence.  Files are
404 available to \include from directories in the search path specified as an
405 option when invoking @code{lilypond --include=DIR} which adds DIR to the
406 search path.
407
408 The @code{\include} statement can use full path information, but with the Unix
409 convention @samp{/} rather than the DOS/Windows @samp{\}.  For example,
410 if @file{stuff.ly} is located one directory higher than the current working
411 directory, use
412
413 @example
414 \include "../stuff.ly"
415 @end example
416
417
418 @node Text encoding
419 @subsection Text encoding
420
421 LilyPond uses the Pango library to format multi-lingual texts, and
422 does not perform any input-encoding conversions.  This means that any
423 text, be it title, lyric text, or musical instruction containing
424 non-ASCII characters, must be utf-8.  The easiest way to enter such text is
425 by using a Unicode-aware editor and saving the file with utf-8 encoding.  Most
426 popular modern editors have utf-8 support, for example, vim, Emacs,
427 jEdit, and GEdit do.
428
429 @c  Currently not working
430 @ignore
431 Depending on the fonts installed, the following fragment shows Hebrew
432 and Cyrillic lyrics,
433
434 @cindex Cyrillic
435 @cindex Hebrew
436 @cindex ASCII, non
437
438 @li lypondfile[fontload]{utf-8.ly}
439
440 The @TeX{} backend does not handle encoding specially at all.  Strings
441 in the input are put in the output as-is.  Extents of text items in the
442 @TeX{} backend, are determined by reading a file created via the
443 @file{texstr} backend,
444
445 @example
446 lilypond -dbackend=texstr input/les-nereides.ly
447 latex les-nereides.texstr
448 @end example
449
450 The last command produces @file{les-nereides.textmetrics}, which is
451 read when you execute
452
453 @example
454 lilypond -dbackend=tex input/les-nereides.ly
455 @end example
456
457 Both @file{les-nereides.texstr} and @file{les-nereides.tex} need
458 suitable LaTeX wrappers to load appropriate La@TeX{} packages for
459 interpreting non-ASCII strings.
460
461 @end ignore
462
463 To use a Unicode escape sequence, use
464
465 @example
466 #(ly:export (ly:wide-char->utf-8 #x2014))
467 @end example
468
469
470 @seealso
471
472 @lsr{text,utf-8.ly}
473
474
475 @node Different editions from one source
476 @subsection Different editions from one source
477
478 @funindex \tag
479 @cindex tag
480
481 The @code{\tag} command marks music expressions with a name.  These
482 tagged expressions can be filtered out later.  With this mechanism it
483 is possible to make different versions of the same music source.
484
485 In the following example, we see two versions of a piece of music, one
486 for the full score, and one with cue notes for the instrumental part
487
488 @example
489 c1
490 <<
491   \tag #'part <<
492     R1 \\
493     @{
494       \set fontSize = #-1
495       c4_"cue" f2 g4 @}
496   >>
497   \tag #'score R1
498 >>
499 c1
500 @end example
501
502 The same can be applied to articulations, texts, etc.: they are
503 made by prepending
504 @example
505 -\tag #@var{your-tag}
506 @end example
507 to an articulation, for example,
508 @example
509 c1-\tag #'part ^4
510 @end example
511
512 This defines a note with a conditional fingering indication.
513
514 @cindex keepWithTag
515 @cindex removeWithTag
516 By applying the @code{\keepWithTag} and @code{\removeWithTag}
517 commands, tagged expressions can be filtered.  For example,
518 @example
519 <<
520   @var{the music}
521   \keepWithTag #'score @var{the music}
522   \keepWithTag #'part @var{the music}
523 >>
524 @end example
525 would yield
526
527 @lilypondfile[ragged-right,quote]{tag-filter.ly}
528
529 The arguments of the @code{\tag} command should be a symbol
530 (such as @code{#'score} or @code{#'part}), followed by a
531 music expression.  It is possible to put multiple tags on
532 a piece of music with multiple @code{\tag} entries,
533
534 @example
535   \tag #'original-part \tag #'transposed-part @dots{}
536 @end example
537
538
539 @seealso
540
541 Examples: @lsr{parts,tag@/-filter@/.ly}
542
543
544 @refbugs
545
546 Multiple rests are not merged if you create the score with both tagged
547 sections.
548
549
550 @node Titles and headers
551 @section Titles and headers
552
553 Almost all printed music includes a title and the composer's name;
554 some pieces include a lot more information.
555
556 @menu
557 * Creating titles::             
558 * Custom titles::               
559 * Reference to page numbers::   
560 * Table of contents::           
561 @end menu
562
563
564 @node Creating titles
565 @subsection Creating titles
566
567 Titles are created for each @code{\score} block, as well as for the full
568 input file (or @code{\book} block).
569
570 The contents of the titles are taken from the @code{\header} blocks.
571 The header block for a book supports the following
572
573
574 @table @code
575 @funindex dedication
576 @item dedication
577 The dedicatee of the music, centered at the top of the first page.
578
579 @funindex title
580 @item title
581 The title of the music, centered just below the dedication.
582
583 @funindex subtitle
584 @item subtitle
585 Subtitle, centered below the title.
586
587 @funindex subsubtitle
588 @item subsubtitle
589 Subsubtitle, centered below the subtitle.
590
591 @funindex poet
592 @item poet
593 Name of the poet, flush-left below the subtitle.
594
595 @funindex composer
596 @item composer
597 Name of the composer, flush-right below the subtitle.
598
599 @funindex meter
600 @item meter
601 Meter string, flush-left below the poet.
602
603 @funindex opus
604 @item opus
605 Name of the opus, flush-right below the composer.
606
607 @funindex arranger
608 @item arranger
609 Name of the arranger, flush-right below the opus.
610
611 @funindex instrument
612 @item instrument
613 Name of the instrument, centered below the arranger.  Also
614 centered at the top of pages (other than the first page).
615
616 @funindex piece
617 @item piece
618 Name of the piece, flush-left below the instrument.
619
620 @cindex page breaks, forcing
621 @funindex breakbefore
622 @item breakbefore
623 This forces the title to start on a new page (set to ##t or ##f).
624
625 @funindex copyright
626 @item copyright
627 Copyright notice, centered at the bottom of the first page.  To
628 insert the copyright symbol, see @ref{Text encoding}.
629
630 @funindex tagline
631 @item tagline
632 Centered at the bottom of the last page.
633
634 @end table
635
636 Here is a demonstration of the fields available.  Note that you
637 may use any @ref{Text markup}, commands in the header.
638
639 @lilypond[quote,verbatim,line-width=11.0\cm]
640 \paper {
641   line-width = 9.0\cm
642   paper-height = 10.0\cm
643 }
644
645 \book {
646   \header {
647     dedication = "dedicated to me"
648     title = \markup \center-align { "Title first line" "Title second line,
649 longer" }
650     subtitle = "the subtitle,"
651     subsubtitle = #(string-append "subsubtitle LilyPond version "
652 (lilypond-version))
653     poet = "Poet"
654     composer =  \markup \center-align { "composer" \small "(1847-1973)" }
655     texttranslator = "Text Translator"
656     meter = \markup { \teeny "m" \tiny "e" \normalsize "t" \large "e" \huge
657 "r" }
658     arranger = \markup { \fontsize #8.5 "a" \fontsize #2.5 "r" \fontsize
659 #-2.5 "r" \fontsize #-5.3 "a" \fontsize #7.5 "nger" }
660     instrument = \markup \bold \italic "instrument"
661     piece = "Piece"
662   }
663
664   \score {
665     { c'1 }
666     \header {
667       piece = "piece1"
668       opus = "opus1"
669     }
670   }
671   \markup {
672       and now...
673   }
674   \score {
675     { c'1 }
676     \header {
677       piece = "piece2"
678       opus = "opus2"
679     }
680   }
681 }
682 @end lilypond
683
684 As demonstrated before, you can use multiple @code{\header} blocks.
685 When same fields appear in different blocks, the latter is used.
686 Here is a short example.
687
688 @example
689 \header @{
690   composer = "Composer"
691 @}
692 \header @{
693   piece = "Piece"
694 @}
695 \score @{
696   \new Staff @{ c'4 @}
697   \header @{
698     piece = "New piece"  % overwrite previous one
699   @}
700 @}
701 @end example
702
703 If you define the @code{\header} inside the @code{\score} block, then
704 normally only the @code{piece} and @code{opus} headers will be printed.
705 Note that the music expression must come before the @code{\header}.
706
707 @lilypond[quote,verbatim,line-width=11.0\cm]
708 \score {
709   { c'4 }
710   \header {
711     title = "title"  % not printed
712     piece = "piece"
713     opus = "opus"
714   }
715 }
716 @end lilypond
717
718 @funindex printallheaders
719 @noindent
720 You may change this behavior (and print all the headers when defining
721 @code{\header} inside @code{\score}) by using
722
723 @example
724 \paper@{
725   printallheaders=##t
726 @}
727 @end example
728
729 @cindex copyright
730 @cindex tagline
731
732 The default footer is empty, except for the first page, where the
733 @code{copyright} field from @code{\header} is inserted, and the last
734 page, where @code{tagline} from @code{\header} is added.  The default
735 tagline is @qq{Music engraving by LilyPond (@var{version})}.@footnote{Nicely
736 printed parts are good PR for us, so please leave the tagline if you
737 can.}
738
739 Headers may be completely removed by setting them to false.
740
741 @example
742 \header @{
743   tagline = ##f
744   composer = ##f
745 @}
746 @end example
747
748
749 @node Custom titles
750 @subsection Custom titles
751
752 A more advanced option is to change the definitions of the following
753 variables in the @code{\paper} block.  The init file
754 @file{ly/titling-init.ly} lists the default layout.
755
756 @table @code
757 @funindex bookTitleMarkup
758 @item bookTitleMarkup
759   This is the title added at the top of the entire output document.
760 Typically, it has the composer and the title of the piece
761
762 @funindex scoreTitleMarkup
763 @item scoreTitleMarkup
764   This is the title put over a @code{\score} block.  Typically, it has
765 the name of the movement (@code{piece} field).
766
767 @funindex oddHeaderMarkup
768 @item oddHeaderMarkup
769   This is the page header for odd-numbered pages.
770
771 @funindex evenHeaderMarkup
772 @item evenHeaderMarkup
773   This is the page header for even-numbered pages.  If unspecified,
774   the odd header is used instead.
775
776   By default, headers are defined such that the page number is on the
777   outside edge, and the instrument is centered.
778
779 @funindex oddFooterMarkup
780 @item oddFooterMarkup
781   This is the page footer for odd-numbered pages.
782
783 @funindex evenFooterMarkup
784 @item evenFooterMarkup
785   This is the page footer for even-numbered pages.  If unspecified,
786   the odd header is used instead.
787
788   By default, the footer has the copyright notice on the first, and
789   the tagline on the last page.
790 @end table
791
792
793 @cindex \paper
794 @cindex header
795 @cindex footer
796 @cindex page layout
797 @cindex titles
798
799 The following definition will put the title flush left, and the
800 composer flush right on a single line.
801
802 @verbatim
803 \paper {
804   bookTitleMarkup = \markup {
805    \fill-line {
806      \fromproperty #'header:title
807      \fromproperty #'header:composer
808    }
809   }
810 }
811 @end verbatim
812
813 @node Reference to page numbers
814 @subsection Reference to page numbers
815
816 A particular place of a score can be marked using the @code{\label}
817 command, either at top-level or inside music.  This label can then be
818 refered to in a markup, to get the number of the page where the marked
819 point is placed, using the @code{\page-ref} markup command.
820
821 @lilypond[verbatim,line-width=11.0\cm]
822 \header { tagline = ##f }
823 \book {
824   \label #'firstScore
825   \score {
826     {
827       c'1
828       \pageBreak \mark A \label #'markA
829       c'
830     }
831   }
832
833   \markup { The first score begins on page \page-ref #'firstScore "0" "?" }
834   \markup { Mark A is on page \page-ref #'markA "0" "?" }
835 }
836 @end lilypond
837
838 The @code{\page-ref} markup command takes three arguments:
839 @enumerate
840 @item the label, a scheme symbol, eg. @code{#'firstScore};
841 @item a markup that will be used as a gauge to estimate the dimensions
842 of the markup;
843 @item a markup that will be used in place of the page number if the label 
844 is not known;
845 @end enumerate
846
847 The reason why a gauge is needed is that, at the time markups are
848 interpreted, the page breaking has not yet occured, so the page numbers
849 are not yet known.  To work around this issue, the actual markup
850 interpretation is delayed to a later time; however, the dimensions of
851 the markup have to be known before, so a gauge is used to decide these
852 dimensions.  If the book has between 10 and 99 pages, it may be "00",
853 ie. a two digit number.
854
855 @refcommands
856
857 @funindex \label
858 @code{\label}
859 @funindex \page-ref
860 @code{\page-ref}
861
862 @node Table of contents
863 @subsection Table of contents
864 A table of contents is included using the @code{\markuplines \table-of-contents}
865 command.  The elements which should appear in the table of contents are
866 entered with the @code{\tocItem} command, which may be used either at
867 top-level, or inside a music expression.
868
869 @verbatim
870 \markuplines \table-of-contents
871 \pageBreak
872
873 \tocItem \markup "First score"
874 \score { 
875   {
876     c'  % ...
877     \tocItem \markup "Some particular point in the first score"
878     d'  % ... 
879   }
880 }
881
882 \tocItem \markup "Second score"
883 \score {
884   {
885     e' % ...
886   }
887 }
888 @end verbatim
889
890 The markups which are used to format the table of contents are defined
891 in the @code{\paper} block. The default ones are @code{tocTitleMarkup},
892 for formatting the title of the table, and @code{tocItemMarkup}, for
893 formatting the toc elements, composed of the element title and page
894 number. These variables may be changed by the user:
895
896 @verbatim
897 \paper {
898   %% Translate the toc title into French:
899   tocTitleMarkup = \markup \huge \column {
900     \fill-line { \null "Table des matières" \null }
901     \hspace #1
902   }
903   %% use larfer font size
904   tocItemMarkup = \markup \large \fill-line {
905     \fromproperty #'toc:text \fromproperty #'toc:page
906   }
907 }
908 @end verbatim
909
910 Note how the toc element text and page number are refered to in
911 the @code{tocItemMarkup} definition.
912
913 New commands and markups may also be defined to build more elaborated
914 table of contents:
915 @itemize @bullet
916 @item first, define a new markup variable in the @code{\paper} block
917 @item then, define a music function which aims at adding a toc element
918 using this markup paper variable.
919 @end itemize
920
921 In the following example, a new style is defined for entering act names
922 in the table of contents of an opera:
923
924 @verbatim
925 \paper {
926   tocActMarkup = \markup \large \column {
927     \hspace #1
928     \fill-line { \null \italic \fromproperty #'toc:text \null }
929     \hspace #1
930   }
931 }
932
933 tocAct = 
934 #(define-music-function (parser location text) (markup?)
935    (add-toc-item! 'tocActMarkup text))
936 @end verbatim
937
938 @lilypond[line-width=11.0\cm]
939 \header { tagline = ##f }
940 \paper {
941   tocActMarkup = \markup \large \column {
942     \hspace #1
943     \fill-line { \null \italic \fromproperty #'toc:text \null }
944     \hspace #1
945   }
946 }
947
948 tocAct = 
949 #(define-music-function (parser location text) (markup?)
950    (add-toc-item! 'tocActMarkup text))
951
952 \book {
953   \markuplines \table-of-contents
954   \tocAct \markup { Atto Primo }
955   \tocItem \markup { Coro. Viva il nostro Alcide }
956   \tocItem \markup { Cesare. Presti omai l'Egizzia terra }
957   \tocAct \markup { Atto Secondo }
958   \tocItem \markup { Sinfonia }
959   \tocItem \markup { Cleopatra. V'adoro, pupille, saette d'Amore }
960   \markup \null
961 }
962 @end lilypond
963
964 @seealso
965
966 Init files: @file{ly/@/toc@/-init@/.ly}.
967
968 @refcommands
969
970 @funindex \table-of-contents
971 @code{\table-of-contents}
972 @funindex \tocItem
973 @code{\tocItem}
974
975 @node MIDI output
976 @section MIDI output
977
978 @cindex Sound
979 @cindex MIDI
980
981 MIDI (Musical Instrument Digital Interface) is a standard for
982 connecting and controlling digital instruments.  A MIDI file is a
983 series of notes in a number of tracks.  It is not an actual
984 sound file; you need special software to translate between the
985 series of notes and actual sounds.
986
987 Pieces of music can be converted to MIDI files, so you can listen to
988 what was entered.  This is convenient for checking the music; octaves
989 that are off or accidentals that were mistyped stand out very much
990 when listening to the MIDI output.
991
992 @refbugs
993
994 Many musically interesting effects, such as swing, articulation,
995 slurring, etc., are not translated to midi.
996
997 The midi output allocates a channel for each staff, and one for global
998 settings.  Therefore the midi file should not have more than 15 staves
999 (or 14 if you do not use drums).  Other staves will remain silent.
1000
1001 Not all midi players correctly handle tempo changes in the midi
1002 output.  Players that are known to work include
1003 @uref{http://@/timidity@/.sourceforge@/.net/,timidity}.
1004
1005 @menu
1006 * Creating MIDI files::         
1007 * MIDI block::                  
1008 * MIDI instrument names::       
1009 @end menu
1010
1011 @node Creating MIDI files
1012 @subsection Creating MIDI files
1013
1014 To create a MIDI from a music piece of music, add a @code{\midi} block
1015 to a score, for example,
1016
1017 @example
1018 \score @{
1019   @var{...music...}
1020    \midi @{
1021      \context @{
1022        \Score
1023        tempoWholesPerMinute = #(ly:make-moment 72 4)
1024        @}
1025      @}
1026 @}
1027 @end example
1028
1029 The tempo can be specified using the @code{\tempo} command within the 
1030 actual music, see @ref{Metronome marks}.  An alternative, which does not
1031 result in a metronome mark in the printed score, is shown in the example
1032 above. In this example the tempo of quarter notes is set to 72 beats per
1033 minute. 
1034 This kind of tempo
1035 specification can not take dotted note lengths as an argument. In this
1036 case, break the dotted notes into smaller units. For example, a tempo
1037 of 90 dotted quarter notes per minute can be specified as 270 eighth
1038 notes per minute
1039
1040 @example
1041 tempoWholesPerMinute = #(ly:make-moment 270 8)
1042 @end example
1043
1044 If there is a @code{\midi} command in a @code{\score}, only MIDI will
1045 be produced.  When notation is needed too, a @code{\layout} block must
1046 be added
1047
1048 @example
1049 \score @{
1050   @var{...music...}
1051   \midi @{ @}
1052   \layout @{ @}
1053 @}
1054 @end example
1055 @cindex layout block
1056
1057
1058
1059 Ties, dynamics, and tempo changes are interpreted.  Dynamic marks,
1060 crescendi and decrescendi translate into MIDI volume levels.  Dynamic
1061 marks translate to a fixed fraction of the available MIDI volume
1062 range, crescendi and decrescendi make the volume vary linearly between
1063 their two extremes.  The fractions can be adjusted by
1064 @code{dynamicAbsoluteVolumeFunction} in @internalsref{Voice} context.
1065 For each type of MIDI instrument, a volume range can be defined.  This
1066 gives a basic equalizer control, which can enhance the quality of
1067 the MIDI output remarkably.  The equalizer can be controlled by
1068 setting @code{instrumentEqualizer}, or by setting
1069
1070 @example
1071 \set Staff.midiMinimumVolume = #0.2
1072 \set Staff.midiMaximumVolume = #0.8
1073 @end example
1074
1075 To remove dynamics from the MIDI output, insert the following lines
1076 in the @code{\midi@{@}} section.
1077
1078 @example
1079 \midi @{
1080   ...
1081   \context @{
1082     \Voice
1083     \remove "Dynamic_performer"
1084   @}
1085 @}
1086 @end example
1087
1088
1089 @refbugs
1090
1091 Unterminated (de)crescendos will not render properly in the midi file,
1092 resulting in silent passages of music.  The workaround is to explicitly
1093 terminate the (de)crescendo.  For example,
1094
1095 @example
1096 @{ a\< b c d\f @}
1097 @end example
1098
1099 @noindent
1100 will not work properly but
1101
1102 @example
1103 @{ a\< b c d\!\f @}
1104 @end example
1105
1106 @noindent
1107 will.
1108
1109
1110 MIDI output is only created when the @code{\midi} command is within
1111 a @code{\score} block.  If you put it within an explicitly instantiated
1112 context ( i.e. @code{\new Score} ) the file will fail.  To solve this,
1113 enclose the @code{\new Score} and the @code{\midi} in a @code{\score} block.
1114
1115 @example
1116 \score @{
1117   \new Score @{ @dots{}notes@dots{} @}
1118   \midi
1119 @}
1120 @end example
1121
1122
1123 @node MIDI block
1124 @subsection MIDI block
1125 @cindex MIDI block
1126
1127
1128 The MIDI block is analogous to the layout block, but it is somewhat
1129 simpler.  The @code{\midi} block is similar to @code{\layout}. It can contain
1130 context definitions.
1131
1132
1133 @cindex context definition
1134
1135 Context definitions follow precisely the same syntax as within the
1136 \layout block.  Translation modules for sound are called performers.
1137 The contexts for MIDI output are defined in @file{ly/@/performer@/-init@/.ly}.
1138
1139
1140 @node MIDI instrument names
1141 @subsection MIDI instrument names
1142
1143 @cindex instrument names
1144 @funindex Staff.midiInstrument
1145
1146 The MIDI instrument name is set by the @code{Staff.midiInstrument}
1147 property.  The instrument name should be chosen from the list in
1148 @ref{MIDI instruments}.
1149
1150 @example
1151 \set Staff.midiInstrument = "glockenspiel"
1152 @var{...notes...}
1153 @end example
1154
1155 If the selected instrument does not exactly match an instrument from
1156 the list of MIDI instruments, the Grand Piano (@code{"acoustic grand"})
1157 instrument is used.
1158
1159
1160 @c  Yes, this is a cop-out; this info doesn't belong in the Scheme
1161 @c  chapter, but I'm not certain where to stick it.
1162 @c  I think I'll eventually split this chapter into a "paper/layout"
1163 @c  chapter and a "misc issues" chapter.  -gp
1164 @node Displaying LilyPond notation
1165 @section Displaying LilyPond notation
1166
1167 @funindex \displayLilyMusc
1168 Displaying a music expression in LilyPond notation can be
1169 done using the music function @code{\displayLilyMusic}.  For example,
1170
1171 @example
1172 @{
1173   \displayLilyMusic \transpose c a, @{ c e g a bes @}
1174 @}
1175 @end example
1176
1177 will display
1178
1179 @example
1180 @{ a, cis e fis g @}
1181 @end example
1182
1183 By default, LilyPond will print these messages to the console along
1184 with all the other messages.  To split up these messages and save
1185 the results of @code{\display@{STUFF@}}, redirect the output to
1186 a file.
1187
1188 @example
1189 lilypond file.ly >display.txt
1190 @end example
1191
1192
1193 @node Skipping corrected music
1194 @section Skipping corrected music
1195
1196
1197 @funindex skipTypesetting
1198 @funindex showLastLength
1199
1200 When entering or copying music, usually only the music near the end (where
1201 you
1202 are adding notes) is interesting to view and correct.  To speed up
1203 this correction process, it is possible to skip typesetting of all but
1204 the last few measures. This is achieved by putting
1205
1206 @verbatim
1207 showLastLength = R1*5
1208 \score { ... }
1209 @end verbatim
1210
1211 @noindent
1212 in your source file. This will render only the last 5 measures
1213 (assuming 4/4 time signature) of every @code{\score} in the input
1214 file. For longer pieces, rendering only a small part is often an order
1215 of magnitude quicker than rendering it completely
1216
1217 Skipping parts of a score can be controlled in a more fine-grained
1218 fashion with the property @code{Score.skipTypesetting}.  When it is
1219 set, no typesetting is performed at all.
1220
1221 This property is also used to control output to the MIDI file. Note that
1222 it skips all events, including tempo and instrument changes. You have
1223 been warned.
1224
1225 @lilypond[quote,fragment,ragged-right,verbatim]
1226 \relative c'' {
1227   c8 d
1228   \set Score.skipTypesetting = ##t
1229   e e e e e e e e
1230   \set Score.skipTypesetting = ##f
1231   c d b bes a g c2 }
1232 @end lilypond
1233
1234 In polyphonic music, @code{Score.skipTypesetting} will affect all
1235 voices and staves, saving even more time.
1236
1237
1238