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