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