]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
Expand 's to is.
[lilypond.git] / Documentation / user / tutorial.itely
1 @c -*-texinfo-*-
2 @c This file is part of lilypond.tely
3
4 @c TODO:
5 @c   * more details about running lilypond; error messages,
6 @c     compiling/viewing (emacs?)
7 @c   * where to go from First steps+More basics?
8
9 @c Your first LilyPond score in 10 minutes?
10
11 @node Tutorial
12 @chapter Tutorial
13
14 This tutorial starts with a short introduction to the LilyPond music
15 language.  After this first contact we will show you how to produce
16 printed output.  Then you will be able to create and print your own
17 sheets of music.
18
19 @ifhtml
20 Many people learn programs by trying and fiddling around with the
21 program.  This is also possible with LilyPond.  If you click on a
22 picture in the HTML version of this manual, you will see the exact
23 LilyPond input that was used to generate that image.
24 Try it on this image
25
26 @lilypond[fragment,quote,raggedright,relative=2]
27 c-\markup { \bold \huge { Click here.  } }
28 @end lilypond
29 @end ifhtml
30
31 By cutting and pasting the full input into a test file, you have a
32 starting template for experiments.  If you like learning in this way,
33 you will probably want to print out or bookmark
34 @ifhtml
35 the
36 @end ifhtml
37 @ref{Cheat sheet}, which is a table listing all commands for quick
38 reference.
39
40 @menu
41 * First steps::                 
42 * Running LilyPond for the first time::  
43 * More about pitches::          
44 * Entering ties::               
45 * Automatic and manual beams::  
46 * Octave entry::                
47 * Music expressions explained::  
48 * More staves::                 
49 * Adding articulation marks to notes::  
50 * Combining notes into chords::  
51 * Advanced rhythmic commands::   
52 * Commenting input files::      
53 * Printing lyrics::             
54 * A lead sheet::                
55 * Adding titles::               
56 * Single staff polyphony::      
57 * Piano staves::                
58 * Organizing larger pieces::    
59 * An orchestral part::          
60 @end menu
61
62
63 @node First steps
64 @section First steps
65
66 The first example demonstrates how to enter the most elementary piece
67 of music, a scale.  A note can be entered by typing its name, from
68 @samp{a} through @samp{g}.  So, if you enter
69
70 @example
71 c d e f g a b
72 @end example
73
74 @noindent
75 the result looks like this
76
77 @lilypond[fragment,quote,notime,relative=1]
78 c d e f g a b
79 @end lilypond
80
81 The duration of a note is specified by a number after the note name.
82 @samp{1} for a @rglos{whole note}, @samp{2} for a @rglos{half note},
83 @samp{4} for a @rglos{quarter note} and so on
84
85 @example
86 a1 a2 a4 a16 a32
87 @end example
88
89 @c FIXME: have NOTIME also remove Score.timing?
90 @lilypond[fragment,quote,notime,relative=2]
91 \set Score.timing = ##f
92 \set Staff.autoBeaming = ##f
93 { a1 a2 a4 a16 a32 s16_" " }
94 @end lilypond
95
96 If you do not specify a @rglos{duration}, the duration last entered is
97 used for the next notes.  The duration of the first note in input
98 defaults to a quarter
99
100 @example
101 a a8 a a2 a
102 @end example
103
104 @lilypond[fragment,quote,notime,relative=2]
105 \set Score.timing = ##f
106 { a a8 a a2 a s16_" " }
107 @end lilypond
108
109
110 Rests are entered just like notes, but with the name @samp{r}
111
112 @cindex rests
113 @example
114 r2 r4 r8 r16
115 @end example
116
117 @lilypond[fragment,quote,notime]
118 \set Score.timing = ##f
119 r2 r4 r8 r16 s16_" "
120 @end lilypond
121
122 Add a dot @samp{.} after the duration to get a @rglos{dotted note}
123
124 @example
125 a2. a4 a8. a16
126 @end example
127
128 @lilypond[fragment,quote,notime,relative=1]
129 \set Score.timing = ##f
130 { a2. a4 a8. a16 s16_" " }
131 @end lilypond
132
133 The @rglos{meter} (or @rglos{time signature}) can be set with the
134 @code{\time} command
135
136 @example
137 \time 3/4
138 \time 6/8
139 \time 4/4
140 @end example
141
142 @c A clef here may lead to confusion, remove it.
143 @lilypond[fragment,quote]
144 \override Staff.Clef #'transparent = ##t 
145 \time 3/4
146 s4_" "
147 \time 6/8
148 s4_" "
149 \time 4/4
150 s16_" "
151 @end lilypond
152
153 The @rglos{clef} can be set using the @code{\clef} command
154
155 @c what is more common name treble or violin?
156 @c in Dutch, it is violin.
157 @c in English it is definitely treble.
158 @example
159 \clef treble
160 \clef bass
161 \clef alto
162 \clef tenor
163 @end example
164
165 @lilypond[fragment,quote,notime]
166 \set Score.timing = ##f
167 \clef violin
168 s4_" "
169 \clef bass
170 s4_" "
171 \clef alto
172 s4_" "
173 \clef tenor
174 s16_" "
175 @end lilypond
176
177
178 Remember to enclose the notes and commands in curly braces
179 @code{@{@tie{}@dots{}@tie{}@}} to convert it to printable output.
180
181 @lilypond[fragment,quote,noindent,linewidth=55\staffspace]
182 {
183   \time 3/4
184   \clef bass
185   c2 e4 g2.
186   f4 e d c2 r4
187 }
188 @end lilypond
189
190 For more elaborate information on
191
192 @quotation
193 @table @asis
194 @item Entering pitches and durations
195 see 
196 @ref{Pitches}, and @ref{Durations}.
197 @item Clefs
198 see @ref{Clef}.
199 @item Rests
200 see @ref{Rests}.  
201 @item Time signatures and other timing commands
202 see @ref{Time signature}.
203 @end table
204 @end quotation
205
206
207 @node Running LilyPond for the first time
208 @section Running LilyPond for the first time
209
210 @c cheesy title to avoid clash with chapter name.
211
212 In the last section we explained what kind of things you could enter
213 in a LilyPond file.  In this section we will explain what commands to
214 run and how to view or print the output.  If you have not used
215 LilyPond before, want to test your setup, or want to run an example
216 file yourself, read this section.  The instructions that follow are
217 for Unix-like systems.  Some additional instructions for Microsoft
218 Windows are given at the end of this section.
219
220 Begin by opening a terminal window and starting a text editor.  For
221 example, you could open an xterm and execute
222 @code{joe}.@footnote{There are macro files for VIM addicts, and there
223 is a @code{LilyPond-mode} for Emacs addicts.  If they have not been
224 installed already, refer to
225 @c FIXME lousy reference.
226 the file @file{INSTALL.txt}.}  In your text editor, enter the following
227 input and save the file as @file{test.ly}
228
229 @example
230 @{ c'4 e' g' @}
231 @end example
232
233 @noindent
234 To process @file{test.ly}, proceed as follows
235
236 @example
237 lilypond test.ly
238 @end example
239
240 @noindent
241 You will see something resembling
242
243 @example
244 lilypond (GNU LilyPond) 2.2.0
245 Running lilypond...
246 Now processing `/home/fred/ly/test.ly'
247 Parsing...
248 Interpreting music...[1]
249 @emph{... more interesting stuff ... }
250 DVI output to `test.dvi'...
251 PDF output to `test.pdf'...
252 PS output to `test.ps'...
253 @end example
254
255 @cindex DVI file
256 @cindex Viewing music
257 @cindex xdvi
258 @noindent
259 The result is the file @file{test.pdf}@footnote{For @TeX{}
260 aficionados: there is also a @file{test.dvi} file.  It can be viewed
261 with @code{xdvi}.  The DVI uses a lot of PostScript specials, which do
262 not show up in the magnifying glass.  The specials also mean that the
263 DVI file cannot be processed with @code{dvilj}.  Use @code{dvips} for
264 printing.
265 @cindex dvips
266 @cindex dvilj
267 @cindex DVI driver
268 } which you can print or with the standard facilities of your
269 operating system.@footnote{If your system does not have any tools
270 installed, you can try
271 @uref{http://www.cs.wisc.edu/~ghost/,Ghostscript}, a freely available
272 package for viewing and printing PDF and PostScript files.}
273
274 On Windows, start up a text-editor@footnote{Any simple or
275 programmer-oriented editor will do, for example Notepad.  Do not use a
276 word processor, since these insert formatting codes that will confuse
277 LilyPond.} and enter
278
279 @example
280 @{ c'4 e' g' @}
281 @end example
282
283 Save it on the desktop as @file{test.ly} and make sure that it is not
284 called @file{test.ly.TXT}.  Double clicking @file{test.ly} will process
285 the file and show the resulting PDF file.
286
287
288 @node More about pitches
289 @section More about pitches 
290
291 A @rglos{sharp} (@texisharp{}) pitch is made by adding @samp{is} to
292 the name, a @rglos{flat} (@texiflat{}) pitch by adding @samp{es}.  As
293 you might expect, a @rglos{double sharp} or @rglos{double flat} is
294 made by adding @samp{isis} or @samp{eses}@footnote{This syntax
295 derived from note naming conventions in Nordic and Germanic languages,
296 like German and Dutch.}
297
298 @example
299 cis1 ees fisis aeses
300 @end example
301
302 @lilypond[fragment,quote,notime]
303 \set Score.timing = ##f
304 \transpose c c' { cis1 ees fisis aeses s16_" " }
305 @end lilypond
306
307 @cindex key signature, setting
308 The key signature is set with the command @code{\key}, followed by
309 a pitch and @code{\major} or @code{\minor}
310
311 @example
312 \key d \major
313 g1
314 \key c \minor
315 g
316 @end example
317
318 @lilypond[fragment,quote,notime,fragment]
319 \key d \major
320 g'1
321 \key c \minor
322 g'
323 @end lilypond
324
325 @noindent
326 Key signatures together with the pitches (including alterations) are
327 used to determine when to print accidentals.  This is a
328 feature that often causes confusion to newcomers, so let us explain it
329 in more detail.
330
331
332 LilyPond makes a sharp distinction between musical content and
333 layout.  The alteration (flat, natural or sharp) of a note is part of
334 the pitch, and is therefore musical content.  Whether an accidental (a
335 flat, natural or sharp @emph{sign}) is printed in front of the
336 corresponding note is a question of layout.  Layout is something that
337 follows rules, so accidentals are printed automatically according to
338 those rules.  The pitches in your music are works of art, so they will
339 not be added automatically, and you must enter what you want to hear.
340
341 In this example
342
343 @lilypond[quote,notime,fragment]
344 \key d \major
345 d' cis' fis'
346 @end lilypond
347
348 @noindent
349 no note has an explicit accidental, but you still must enter
350
351 @example
352 \key d \major
353 d cis fis
354 @end example
355
356 @noindent
357 The code @samp{d} does not mean `print a black dot just below the
358 staff.'  Rather, it means: `a note with pitch D-natural.'  In the key
359 of A-flat, it does get an accidental
360
361 @lilypond[quote,notime,fragment]
362 \key as \major
363 d'
364 @end lilypond
365
366 @example
367 \key as \major
368 d
369 @end example
370
371 Adding all alterations explicitly might require a little more effort
372 when typing, but the advantage is that transposing is easier, and
373 accidentals can be printed according to different conventions.  See
374 @ref{Accidentals}, for some examples how accidentals can be printed
375 according to different rules.
376
377
378 For more information on
379
380 @quotation
381 @table @asis
382 @item Accidentals
383 see @ref{Accidentals}.
384
385 @item Key signature
386 see @ref{Key signature}.
387 @end table
388 @end quotation
389
390 @node Entering ties
391 @section Entering ties
392
393 @cindex tie
394 A tie is created by appending a tilde @samp{~} to the first note
395 being tied
396
397 @lilypond[quote,notime,fragment,verbatim,relative=3]
398 g4~ g a2~ a4
399 @end lilypond
400
401 For more information on Ties see @ref{Ties}.
402
403
404
405 @node Automatic and manual beams
406 @section Automatic and manual beams
407
408 @cindex beams, by hand 
409 Beams are drawn automatically
410
411 @lilypond[quote,fragment,relative=2,verbatim]
412 a8 ais d es r d
413 @end lilypond
414
415 @noindent
416 If you do not like where beams are put, they can be entered by
417 hand.  Mark the first note to be beamed with @samp{[} and the last one
418 with @samp{]}.
419
420 @lilypond[quote,fragment,relative=2,verbatim]
421 a8[ ais] d[ es r d]
422 @end lilypond
423
424 For more information on beams, see @ref{Beaming}.
425
426
427 Here are key signatures, accidentals and ties in action
428
429 @example
430 @{
431   \time 4/4
432   \key g \minor
433   \clef violin
434   r4 r8 a8 gis4 b
435   a8 d4.~ d e8
436   fis4 fis8 fis8 eis4 a8 gis~
437   gis2 r2
438 @}
439 @end example
440
441 @ignore
442 FIXME
443 ugr: removing the ignore block, leaving the comment line below
444 @c TODO: use relative mode, verbatim, junk \transpose and above @example
445 @end ignore
446
447
448 @lilypond[fragment,quote,noindent,linewidth=50\staffspace]
449 \transpose c c' {
450   \time 4/4
451   \key g \minor
452   \clef violin
453   r4 r8 a8 gis4 b
454   a8 d4.~ d e8
455   fis4 fis8 fis8 eis4 a8 gis~
456   gis2 r2
457 }
458 @end lilypond
459
460 @cindex accidentals
461
462
463 @noindent
464 There are some interesting points to note in this example.  Bar lines
465 and beams are drawn automatically.  Line breaks are calculated
466 automatically; it does not matter where the line breaks are in the
467 source file.  Finally, the order in which time, key and clef changes
468 are entered is not relevant: in the printout, these are ordered
469 according to standard notation conventions.
470
471
472
473 @node Octave entry
474 @section Octave entry
475
476
477 @c Tim wants to move this quotes example just before the: quotes-do not-work
478 @c score, but we'd need to remove quotes from the other two (key and
479 @c tie) examples...
480
481 @c better to have this just before the `octaves are bad' snipped
482 @c but we'd need to remove the ', from \key and tie 
483 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
484 the note name, to lower a note one octave, add a `low quote' @code{,}
485 (a comma).  Middle C is @code{c'}
486
487 @example
488 c'4 c'' c''' \clef bass c c,
489 @end example
490
491 @lilypond[quote,notime,fragment]
492 c'4 c'' c''' \clef bass c c,
493 @end lilypond
494
495 An example of the use of quotes is in the following Mozart fragment
496
497 @lilypond[quote,raggedright,fragment,verbatim]
498 \key a \major
499 \time 6/8
500 cis''8. d''16 cis''8 e''4 e''8
501 b'8. cis''16 b'8 d''4 d''8 
502 @end lilypond
503
504 @noindent
505 The last example shows that music in a high register needs lots of quotes.
506 This makes the input less readable, and it is a source of errors.  The
507 solution is to use `relative octave' mode.   This is the
508 most convenient way to copy existing music.
509
510 In relative mode, a note without octavation quotes (i.e.  the @code{'}
511 or @code{,} after a note) is chosen so it it is closest to the
512 previous one.  For example, @samp{c f} goes up while @samp{c g} goes
513 down
514
515 To use relative mode, add @code{\relative} before the piece of
516 music.  The first note is taken relative to the middle C
517 @c no , for this sentence
518 (i.e. @code{c'})
519
520
521
522 @lilypond[quote,notime,fragment,verbatim]
523 \relative {
524   c' f c g c
525 }
526 @end lilypond
527
528
529 Since most music has small intervals, pieces can be written almost
530 without octavation quotes in relative mode.  The previous example is
531 entered as
532
533 @lilypond[quote,raggedright,verbatim]
534 \relative {
535   \key a \major
536   \time 6/8
537   cis'8. d16 cis8 e4 e8
538   b8. cis16 b8 d4 d8
539 }
540 @end lilypond
541
542 @c needed better, maybe even redundant explanation
543 @c   added another example below.
544 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
545 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
546 Larger intervals are made by adding octavation quotes.
547
548 @lilypond[quote,notime,verbatim,fragment]
549 \relative c {
550   c'' f, f c' c g' c,
551 }
552 @end lilypond
553
554 In summary, quotes or commas no longer determine the absolute height
555 of a note in @code{\relative} mode.  Rather, the height of a note is
556 relative to the previous one, and changing the octave of a single note
557 shifts all following notes an octave up or down.
558
559 For more information on Relative octaves see @ref{Relative octaves},
560 and @ref{Octave check}.
561
562
563 @node Music expressions explained
564 @section Music expressions explained
565
566
567 In input files, music is represent by so-called @emph{music
568 expression}.  We have already seen in the previous examples; 
569 a single note is a music expression
570
571 @lilypond[fragment,quote,verbatim,relative=3]
572 a4
573 @end lilypond
574
575 Enclosing group of notes in braces creates a new music
576 expression
577
578 @lilypond[fragment,quote,verbatim,relative=3]
579 { a4 g4 }
580 @end lilypond
581
582 Putting a bunch of music expressions (notes) in braces, means that
583 they should be played in sequence.  The result again is a music
584 expression, which can be grouped with other expressions sequentially.
585 Here, the expression from the previous example is combined with two
586 notes
587
588 @lilypond[fragment,quote,verbatim,relative=3]
589 { { a4 g } f g } 
590 @end lilypond
591
592 This technique is useful for non-monophonic music.  To enter music
593 with more voices or more staves, we also combine expressions in
594 parallel.  Two voices that should play at the same time, are entered
595 as a simultaneous combination of two sequences.  A `simultaneous'
596 music expression is formed by enclosing expressions in @code{<<} and
597 @code{>>}.  In the following example, three sequences (all containing
598 two other notes) are combined simultaneously
599
600 @lilypond[fragment,quote,verbatim,relative=3]
601 <<
602    { a4 g }
603    { f e }
604    { d b }
605 >>
606 @end lilypond
607
608 This mechanism is similar to mathematical
609 formulas: a big formula is created by composing small formulas.  Such
610 formulas are called expressions, and their definition is recursive, so
611 you can make arbitrarily complex and large expressions.  For example,
612
613 @example
614 1
615
616 1 + 2
617
618 (1 + 2) * 3
619
620 ((1 + 2) * 3) / (4 * 5)
621 @end example
622
623 @cindex expression
624 @cindex music expression
625 This is a sequence of expressions, where each expression is contained
626 in the next one.  The simplest expressions are numbers, and larger
627 ones are made by combining expressions with operators (like @samp{+},
628 @samp{*} and @samp{/}) and parentheses.  Like mathematical expressions,
629 music expressions can be nested arbitrarily deep, which is necessary
630 for complex music like polyphonic scores.
631
632 Note that this example only has one staff, whereas
633 the previous example had three seperate staves.  That is because this
634 example begins with a single note.  To determine the number of staves,
635 LilyPond looks at the first element.  If it is a single note, there is one
636 staff; if there is a simultaneous expression, there is more than one staff.
637
638 @lilypond[fragment,quote,verbatim,relative=2] 
639 {
640   c <<c e>>
641   << { e f } { c <<b d>> } >>
642 }
643 @end lilypond
644
645 Music files with deep nesting can be confusing to enter and
646 maintain.  One convention that helps against this confusion is
647 indenting.  When entering a file with deep nesting of braces and
648 angles, it is customary to use an indent that indicates the nesting
649 level.  Formatting music like this eases reading and helps you insert
650 the right number of closing braces at the end of an expression.  For
651 example,
652
653 @example
654 <<
655   @{
656     @dots{}
657   @}
658   @{
659     @dots{}
660   @}
661 >>
662 @end example
663
664 Some editors have special support for entering LilyPond, and can help
665 indenting source files.  See @ref{Editor support} for more information.
666
667 @node More staves
668 @section More staves
669
670 To print more than one staff, each piece of music that makes up a
671 staff is marked by adding @code{\new Staff} before it.  These
672 @code{Staff} elements are then combined parallel with @code{<<} and
673 @code{>>}, as demonstrated here
674
675 @lilypond[quote,fragment,verbatim]
676 <<
677   \new Staff { \clef treble c'' }
678   \new Staff { \clef bass c }
679 >>
680 @end lilypond
681
682
683 The command @code{\new} introduces a `notation context.'  A notation
684 context is an environment in which musical events (like notes or
685 @code{\clef} commands) are interpreted.  For simple pieces, such
686 notation contexts are created automatically.  For more complex pieces, it
687 is best to mark contexts explicitly.  This ensures that each fragment
688 gets its own stave.
689
690 There are several types of contexts: @code{Staff}, @code{Voice} and
691 @code{Score} handle melodic notation.  Other contexts are also
692 @code{Lyrics} (for setting lyric texts) and @code{ChordNames} (for
693 printing chord names).
694
695
696 In terms of syntax, prepending @code{\new} to a music expression
697 creates a bigger music expression.  In this way it resembles the minus
698 sign in mathematics.  The formula @math{(4+5)} is an expression, so
699 @math{-(4+5)} is a bigger expression.
700
701 We can now typeset a melody with two staves
702
703 @c TODO: (c) status of this Paul McCartney (?) song (let's all stand together)
704
705 @lilypond[fragment,quote,verbatim,raggedright]
706 \relative <<
707   \new Staff {
708     \time 3/4
709     \clef treble 
710     
711     e'2 d4 c2 b4 a8[ a]
712     b[ b] g[ g] a2. 
713   }
714   \new Staff {
715      \clef bass
716      c,,2 e4 g2.
717      f4 e d c2.
718   }
719 >>
720 @end lilypond
721
722 For more information on context see the description in
723 @ref{Interpretation contexts}.
724
725
726
727 @node Adding articulation marks to notes
728 @section Adding articulation marks to notes
729
730 @cindex articulation
731 @cindex accents
732 @cindex staccato
733
734 Common accents can be added to a note using a dash (@samp{-}) and a
735 single character
736
737 @lilypond[fragment,quote,verbatim,relative=2]
738 c-.  c-- c-> c-^ c-+ c-_
739 @end lilypond
740
741 @cindex fingering
742 Similarly, fingering indications can be added to a note using a dash
743 (@samp{-}) and the digit to be printed
744
745 @lilypond[fragment,quote,verbatim,relative=2]
746 c-3 e-5 b-2 a-1
747 @end lilypond
748
749 Articulations and fingerings are usually placed automatically, but you
750 can specify a direction using @samp{^} (up) or @samp{_} (down).  You can
751 also use multiple articulations on the same note.  In most cases, it is
752 best to let LilyPond determine the articulation directions.
753
754 @lilypond[fragment,quote,verbatim,relative=2]
755 c_-^1 d^. f^4_2-> e^-_+
756 @end lilypond
757
758 Dynamic signs are made by adding the markings (with a backslash) to
759 the note
760
761 @lilypond[fragment,quote,verbatim,relative=2]
762 c\ff c\mf
763 @end lilypond
764
765 @cindex dynamics
766 @cindex decrescendo
767 @cindex crescendo
768
769 Crescendi and decrescendi are started with the commands @code{\<} and
770 @code{\>}.  An ending dynamic, for example @code{\f}, will finish the
771 crescendo, or the command @code{\!} can be used
772
773 @lilypond[fragment,quote,verbatim,relative=2]
774 c2\< c2\ff\> c2 c2\!
775 @end lilypond
776
777
778
779 @cindex slur
780
781 A slur is a curve drawn across many notes, and indicates legato
782 articulation.  The starting note and ending note are marked with
783 @samp{(} and @samp{)}, respectively
784
785 @lilypond[fragment,quote,fragment,relative=2,verbatim]
786 d4( c16) cis( d e c cis d) e( d4)
787 @end lilypond
788
789 @cindex slurs versus ties
790 A slur looks like a tie, but it has a different meaning.  A tie simply
791 makes the first note sound longer, and can only be used on pairs of
792 notes with the same pitch.  Slurs indicate the articulations of notes,
793 and can be used on larger groups of notes.  Slurs and ties can be
794 nested
795
796 @lilypond[quote,fragment,relative=2]
797 c2~( c8 fis fis4 ~ fis2 g2)
798 @end lilypond
799
800 @cindex phrasing slurs
801 Slurs to indicate phrasing can be entered with @code{\(} and
802 @code{\)}, so you can have both legato slurs and phrasing slurs at the
803 same time.
804
805 @lilypond[quote,fragment,relative=2,verbatim]
806 a8(\( ais b c) cis2 b'2 a4 cis, c\)
807 @end lilypond
808
809
810 For more information on
811
812 @quotation
813 @table @asis
814 @item Fingering
815 see @ref{Fingering instructions}.
816 @item Articulations
817 see @ref{Articulations}.
818 @item Slurs
819 see @ref{Slurs}.
820 @item Phrasing slurs
821 see @ref{Phrasing slurs}.
822 @item Dynamics
823 see @ref{Dynamics}.
824 @end table
825 @end quotation
826
827
828 @node Combining notes into chords
829 @section Combining notes into chords
830
831 @cindex chords
832 Chords can be made by surrounding pitches with angle brackets.
833 Angle brackets are the symbols @samp{<} and @samp{>}.
834
835 @lilypond[quote,relative=1,fragment,verbatim]
836 r4 <c e g>4 <c f a>8
837 @end lilypond
838
839
840 You can combine markings like beams and ties with chords.  They must
841 be placed outside the angled brackets
842
843 @lilypond[quote,relative=1,fragment,verbatim]
844 r4 <c e g>8[ <c f a>]~ <c f a>
845 @end lilypond
846
847 @example
848 r4 <c e g>8\>( <c e g> <c e g> <c f a>\!)
849 @end example
850
851 @lilypond[quote,relative=1,fragment]
852 \slurUp
853 r4 <c e g>8\>( <c e g> <c e g> <c f a>\!)
854 @end lilypond
855
856
857 @node Advanced rhythmic commands
858 @section Advanced rhythmic commands
859
860 @cindex pickup
861 @cindex anacruse
862 @cindex partial measure
863 A pickup is entered with the keyword @code{\partial}.  It
864 is followed by a duration: @code{\partial 4} is a quarter note upstep
865 and @code{\partial 8} an eighth note
866
867 @lilypond[quote,relative=2,verbatim,fragment]
868 \partial 8
869 f8 c2 d e
870 @end lilypond
871
872 @cindex tuplets
873 @cindex triplets
874 Tuplets are made with the @code{\times} keyword.  It takes two
875 arguments: a fraction and a piece of music.  The duration of the piece
876 of music is multiplied by the fraction.  Triplets make notes occupy
877 2/3 of their notated duration, so a triplet has 2/3 as its fraction
878
879 @lilypond[quote,relative=1,verbatim,fragment]
880 \times 2/3 { f8 g a }
881 \times 2/3 { c r c }
882 @end lilypond
883
884 @cindex grace notes
885 @cindex acciaccatura
886 Grace notes are also made by prefixing a music expression with the
887 keyword @code{\appoggiatura} or @code{\acciaccatura}
888 @cindex appoggiatura
889 @cindex acciaccatura
890
891 @lilypond[quote,relative=2,verbatim,fragment]
892 c4 \appoggiatura b16 c4
893 c4 \acciaccatura b16 c4
894 @end lilypond
895
896 @noindent
897
898 For more information on
899
900 @quotation
901 @table @asis
902 @item Grace notes
903 see @ref{Grace notes},
904 @item Tuplets
905 see @ref{Tuplets},
906 @item Pickups
907 see @ref{Partial measures}.
908 @end table
909 @end quotation
910
911
912 @node Commenting input files
913 @section Commenting input files
914
915 @cindex comments
916 @cindex line comment
917 @cindex block comment
918 A comment is a remark for the human reader of the music input; it is
919 ignored while parsing, so it has no effect on the printed output.
920 There are two types of comments.  The percent symbol @samp{%}
921 introduces a line comment; after  @code{%} the rest of the line   is
922 ignored.  A block comments marks a whole section of music
923 input.  Anything that is enclosed in @code{%@{} and @code{%@}} is
924 ignored.  The following fragment shows possible uses for comments
925
926 @example
927 % notes for twinkle twinkle follow
928 c4 c g' g a a g2
929
930 %@{
931     This line, and the notes below
932     are ignored, since they are in a
933     block comment.
934
935     g g f f e e d d c2 
936 %@}
937 @end example
938
939 @c  FIXME
940 @c   This is good info, but I wouldn't call it a comment.  IMO it should
941 @c   be moved somewhere else.  I don't know exactly where yet, but I'll
942 @c   resolve it soon.  -gp
943
944 @cindex versioning
945
946 There is a special statement that is a kind of comment.  The @code{\version}
947 statement marks for which version of LilyPond the file was written.
948 To mark a file for version 2.1.17, use
949
950 @example
951 \version "2.3.16"
952 @end example
953
954 @noindent
955 These annotations make future upgrades of LilyPond go more
956 smoothly.  Changes in the syntax are handled with a special program,
957 @file{convert-ly} (see @ref{Invoking convert-ly}), and it uses
958 @code{\version} to determine what rules to apply.
959
960
961 @node Printing lyrics
962 @section Printing lyrics
963 @cindex lyrics
964
965 @c TODO: (c) status of the Queen fragment.
966
967 @cindex Lyrics
968 @cindex Songs
969 Lyrics are entered by separating each syllable with a space
970
971 @example
972 I want to break free
973 @end example
974
975 Consider the melody
976
977 @lilypond[quote,verbatim,fragment,raggedright]
978 \relative {
979     r4 c \times 2/3 { f g g }
980     \times 2/3 { g4( a2) }
981 }
982 @end lilypond
983
984 The lyrics can be set to these notes, combining both with the
985 @code{\addlyrics} keyword
986
987 @lilypond[quote,verbatim,fragment,raggedright]
988 <<
989   \relative {
990     r4 c \times 2/3 { f g g }
991     \times 2/3 { g4( a2) }
992   }
993   \addlyrics { I want to break free }
994 >>
995 @end lilypond
996
997 @cindex melisma
998 @cindex extender line
999 @c synonyms?
1000 This melody ends on a @rglos{melisma}, a single syllable (`free')
1001 sung to more than one note.  This is indicated with an @emph{extender
1002 line}.  It is entered as two underscores, i.e.,
1003
1004 @example
1005 @{ I want to break free __ @}
1006 @end example 
1007
1008 @lilypond[fragment,quote,raggedright]
1009 <<
1010   \relative {
1011     r4 c \times 2/3 { f g g }
1012     \times 2/3 { g4( a2) }
1013   }
1014   \addlyrics { I want to break free __ }
1015 >>
1016 @end lilypond
1017
1018 Similarly, hyphens between words can be entered as two dashes,
1019 resulting in a centered hyphen between two syllables
1020
1021 @example
1022 Twin -- kle twin -- kle
1023 @end example
1024
1025 @lilypond[fragment,quote,raggedright]
1026 <<
1027   \relative {
1028      \time 2/4
1029      f4 f c' c
1030    }
1031    \addlyrics { Twin -- kle twin -- kle }
1032 >>
1033 @end lilypond
1034
1035 More options, like putting multiple lines of lyrics below a melody are
1036 discussed in @ref{Vocal music}.
1037
1038
1039 @node A lead sheet
1040 @section A lead sheet
1041
1042 @cindex Lead sheets
1043 @cindex chords
1044 @cindex chord names
1045
1046 In popular music, it is common to denote accompaniment with chord names.
1047 Such chords can be entered like notes,
1048
1049 @lilypond[quote,verbatim,raggedright]
1050 \chordmode { c2 f4. g8 }
1051 @end lilypond
1052
1053 @noindent
1054 Now each pitch is read as the root of a chord instead of a note.
1055 This mode is switched on with @code{\chordmode}
1056
1057
1058 Other chords can be created by adding modifiers after a colon.  The
1059 following example shows a few common modifiers
1060
1061 @lilypond[quote,verbatim]
1062 \chordmode { c2 f4:m g4:maj7 gis1:dim7 }
1063 @end lilypond
1064
1065 For lead sheets, chords are not printed on staves, but as names on a
1066 line of themselves.  Hence, we have to override the context with
1067 @code{\new}, rendering the music expression in a @code{ChordNames}
1068 context
1069
1070 @lilypond[quote,verbatim]
1071 \chordmode { c2 f4.:m g4.:maj7 gis8:dim7 }
1072 @end lilypond
1073
1074 @cindex lead sheet
1075 When put together, chord names, lyrics and a melody form
1076 a lead sheet, for example,
1077
1078 @example
1079 <<
1080   \chordmode @{ @emph{chords} @}
1081   @emph{the melody}
1082   \addlyrics @{ @emph{the text} @}
1083 >>
1084 @}
1085 @end example
1086
1087 @lilypond[quote,raggedright]
1088 <<
1089   \chordmode { r2 c:sus4 f } 
1090   \relative {
1091     r4 c' \times 2/3 { f g g }
1092     \times 2/3 { g4( a2) }
1093   }
1094  \addlyrics { I want to break free __ }
1095 >>
1096 @end lilypond
1097
1098 A complete list of modifiers and other options for layout can be found
1099 in @ref{Chords}.
1100
1101
1102 @node Adding titles
1103 @section Adding titles
1104
1105 Bibliographic information is entered in a separate block, the
1106 @code{\header} block.  The name of the piece, its composer, etc., are
1107 entered as an assignment, within @code{\header
1108 @{@tie{}@dots{}@tie{}@}}.  The @code{\header} block is usually put at
1109 the top of the file.  For example,
1110
1111 @example 
1112 \header @{
1113   title = "Miniature" 
1114   composer = "Igor Stravinsky"
1115 @}
1116
1117 @{ @dots{} @}
1118 @end example
1119
1120
1121 When the file is processed the title and composer are printed above
1122 the music.  More information on titling can be found in @ref{Creating
1123 titles}.
1124
1125
1126 @node Single staff polyphony
1127 @section Single staff polyphony
1128
1129 @cindex polyphony
1130 @cindex multiple voices
1131 @cindex voices, more -- on a staff
1132 When different melodic lines are combined on a single staff they are
1133 printed as polyphonic voices; each voice has its own stems, slurs and
1134 beams, and the top voice has the stems up, while the bottom voice has
1135 them down.
1136
1137 Entering such parts is done by entering each voice as a sequence (with
1138 @code{@{...@}}), and combining those simultaneously, separating the
1139 voices with @code{\\}
1140
1141 @lilypond[quote,verbatim,relative=2,fragment]
1142 << { a4 g2 f4~ f4 } \\
1143    { r4 g4 f2 f4 } >>
1144 @end lilypond
1145
1146 For polyphonic music typesetting, spacer rests can also be convenient;
1147 these are rests that do not print.  They are useful for filling up
1148 voices that temporarily do not play.  Here is the same example with a
1149 spacer rest (@code{s}) instead of a normal rest (@code{r}),
1150
1151 @lilypond[quote,verbatim,relative=2,fragment]
1152 << { a4 g2 f4~ f4 } \\
1153    { s4 g4 f2 f4 } >>
1154 @end lilypond
1155
1156 @noindent
1157 Again, these expressions can be nested arbitrarily
1158
1159 @lilypond[quote,fragment,verbatim,relative=2,fragment]
1160 <<
1161   \new Staff <<
1162     { a4 g2 f4~ f4 } \\
1163     { s4 g4 f2 f4 }
1164   >>
1165   \new Staff <<
1166     \clef bass
1167     { <c, g>1 ~ <c g>4 } \\
1168     { f4 d e2 ~ e4}
1169   >>
1170 >>
1171 @end lilypond
1172
1173 More features of polyphonic typesetting in the notation manual are
1174 described in @ref{Polyphony}.
1175
1176
1177 @node Piano staves
1178 @section Piano staves
1179
1180 @cindex staff switch, manual
1181 @cindex cross staff voice, manual
1182 @cindex @code{\context}
1183 Piano music is typeset in two staves connected by a brace.  Printing
1184 such a staff is similar to the polyphonic example in @ref{More staves},
1185
1186 @example
1187 << \new Staff @{ @dots{} @}
1188    \new Staff @{ @dots{} @} >>
1189 @end example
1190
1191 @noindent
1192 but now this entire expression must be interpreted as a
1193 @code{PianoStaff}
1194
1195 @example
1196 \new PianoStaff << \new Staff @dots{} >>
1197 @end example
1198
1199 Here is a small example
1200
1201 @lilypond[quote,verbatim,relative=1,fragment]
1202 \new PianoStaff <<
1203   \new Staff { \time 2/4 c4 c g' g }
1204   \new Staff { \clef bass c,, c' e c }
1205 >>
1206 @end lilypond
1207
1208 More information on formatting piano music is in @ref{Piano music}.  
1209
1210
1211 @node Organizing larger pieces
1212 @section Organizing larger pieces
1213
1214 When all of the elements discussed earlier are combined to produce
1215 larger files, the @code{\score} blocks get a lot bigger, because the
1216 music expressions are longer, and, in the case of polyphonic pieces,
1217 more deeply nested.  Such large expressions can become unwieldy.
1218
1219 By using variables, also known as identifiers, it is possible to break
1220 up complex music expressions.  An identifier is assigned as follows
1221
1222 @example
1223 namedMusic = @{ @dots{} @}
1224 @end example
1225
1226 @noindent
1227 The contents of the music expression @code{namedMusic}, can be used
1228 later by preceding the name with a backslash, i.e., @code{\namedMusic}.
1229 In the next example, a two-note motive is repeated two times by using
1230 variable substitution
1231
1232 @lilypond[quote,raggedright,verbatim,nofragment]
1233 seufzer = {
1234   e'4( dis'4)
1235 }
1236 { \seufzer \seufzer }
1237 @end lilypond
1238
1239 The name of an identifier should have alphabetic characters only; no
1240 numbers, underscores or dashes.  The assignment should be outside of
1241 running music.
1242
1243 It is possible to use variables for many other types of objects in the
1244 input.  For example,
1245
1246 @example
1247 width = 4.5\cm
1248 name = "Wendy"
1249 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1250 @end example
1251
1252 Depending on its contents, the identifier can be used in different
1253 places.  The following example uses the above variables
1254
1255 @example
1256   \paper @{
1257     \aFivePaper
1258     linewidth = \width
1259   @}
1260   @{ c4^\name @}
1261 @end example
1262
1263 More information on the possible uses of identifiers is in the
1264 technical manual, in @ref{Input variables and Scheme}.
1265 @c fixme: the ref is too technical.
1266
1267
1268 @node An orchestral part
1269 @section An orchestral part
1270
1271 In orchestral music, all notes are printed twice.  Once in a part for
1272 the musicians, and once in a full score for the conductor.  Identifiers can
1273 be used to avoid double work.  The music is entered once, and stored in
1274 a variable.  The contents of that variable is then used to generate
1275 both the part and the score.
1276
1277 It is convenient to define the notes in a special file.  For example,
1278 suppose that the file @file{horn-music.ly} contains the following part
1279 of a horn/bassoon duo
1280
1281 @example
1282 hornNotes =  \relative c @{
1283   \time 2/4
1284   r4 f8 a cis4 f e d
1285 @}
1286 @end example
1287
1288 @noindent
1289 Then, an individual part is made by putting the following in a file
1290
1291 @example
1292 \include "horn-music.ly"
1293 \header @{
1294   instrument = "Horn in F"
1295 @}
1296
1297 @{
1298  \transpose f c' \hornNotes
1299 @}
1300 @end example
1301
1302 The line
1303
1304 @example
1305 \include "horn-music.ly"
1306 @end example
1307
1308 @noindent
1309 substitutes the contents of @file{horn-music.ly} at this position in
1310 the file, so @code{hornNotes} is defined afterwards.  The command
1311 @code{\transpose f@tie{}c'} indicates that the argument, being
1312 @code{\hornNotes}, should be transposed by a fifth downwards.  Sounding
1313 @samp{f} is denoted by notated @code{c'}, which corresponds with
1314 tuning of a normal French Horn in@tie{}F.  The transposition can be seen
1315 in the following output
1316
1317 @lilypond[quote,raggedright]
1318   \transpose f c' \relative c {
1319     \time 2/4
1320     r4 f8 a cis4 f e d
1321   }
1322 @end lilypond
1323
1324 In ensemble pieces, one of the voices often does not play for many
1325 measures.  This is denoted by a special rest, the multi-measure
1326 rest.  It is entered with a capital @samp{R} followed by a duration
1327 (1@tie{}for a whole note, 2@tie{}for a half note, etc.).  By multiplying the
1328 duration, longer rests can be constructed.  For example, this rest
1329 takes 3@tie{}measures in 2/4 time
1330
1331 @example
1332 R2*3
1333 @end example
1334
1335 When printing the part, multi-rests
1336 must be condensed.  This is done by setting a run-time variable
1337
1338 @example
1339 \set Score.skipBars = ##t
1340 @end example
1341
1342 @noindent
1343 This command sets the property @code{skipBars} in the
1344 @code{Score} context to true (@code{##t}).  Prepending the rest and
1345 this option to the music above, leads to the following result
1346
1347 @lilypond[quote,raggedright]
1348 \transpose f c' \relative c {
1349     \time 2/4
1350     \set Score.skipBars = ##t 
1351     R2*3
1352     r4 f8 a cis4 f e d
1353   }
1354 @end lilypond
1355
1356
1357 The score is made by combining all of the music together.  Assuming
1358 that the other voice is in @code{bassoonNotes} in the file
1359 @file{bassoon-music.ly}, a score is made with
1360
1361 @example
1362 \include "bassoon-music.ly"
1363 \include "horn-music.ly"
1364
1365   <<
1366     \new Staff \hornNotes
1367     \new Staff \bassoonNotes
1368   >>
1369 @end example
1370
1371 @noindent
1372 leading to 
1373
1374 @lilypond[quote,raggedright]
1375   \relative c <<
1376     \new Staff {
1377       \time 2/4 R2*3
1378       r4 f8 a cis4 f e d
1379     }
1380     \new Staff {
1381       \clef bass
1382       r4 d,8 f | gis4 c | b bes |
1383       a8 e f4 | g d | gis f
1384     }
1385   >>
1386 @end lilypond
1387
1388 More in-depth information on preparing parts and scores can be found
1389 in the notation manual; see @ref{Orchestral music}.
1390
1391 Setting run-time variables (`properties') is discussed in
1392 @ref{Changing context properties on the fly}.
1393
1394
1395 @ignore
1396
1397 * longer example
1398
1399 * discuss expectations (?)
1400
1401 * conclude tutorial
1402
1403 * overview of chapters?
1404
1405 @end ignore