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