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