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