]> git.donarmstrong.com Git - lilypond.git/blobdiff - Documentation/user/tutorial.itely
Merge commit 'ce4b499'
[lilypond.git] / Documentation / user / tutorial.itely
index 5769244075bc473fba08305831c0a87e9bd71295..765bd4aff14c58efd9975298da541a818ef53f38 100644 (file)
@@ -31,8 +31,9 @@ Tutorial guidelines:  (different from policy.txt!)
 @chapter Tutorial
 
 This tutorial starts with an introduction to the LilyPond music
-language and how to produce printed music.  After this first
-contact we will explain how to create common musical notation.
+language and explains how to produce printed music.  After this first
+contact we will explain how to create beautiful printed music 
+containing common musical notation.
 
 @menu
 * First steps::                 
@@ -52,14 +53,18 @@ This section gives a basic introduction to working with LilyPond.
 * Compiling a file::            
 * Simple notation::             
 * Working on text files::       
-* How to read the tutorial::    
+* How to read the manual::      
 @end menu
 
 
 @node Compiling a file
 @subsection Compiling a file
 
-The first example demonstrates how to start working with LilyPond.
+@qq{Compiling} is the term used for processing an input text file
+in LilyPond format to produce a file which can be printed and
+(optionally) a MIDI file which can be played.  The first example
+shows what a simple input text file looks like.
+
 To create sheet music, we write a text file that specifies the
 notation.  For example, if we write:
 
@@ -79,13 +84,13 @@ the result looks like this:
 }
 @end lilypond
 
-@warning{Every piece of LilyPond input needs to have
-@strong{@{ curly braces @}} placed around the input.  The braces
+@warning{Notes and lyrics in LilyPond input must always be
+surrounded by @strong{@{ curly braces @}}.  The braces
 should also be surrounded by a space unless they are at the
 beginning or end of a line to avoid ambiguities.  The braces may
 be omitted in some examples in this manual, but don't forget them
 in your own music!  For more information about the display of
-examples in the manual, see @ref{How to read the tutorial}.}
+examples in the manual, see @ref{How to read the manual}.}
 
 @cindex case sensitive
 In addition, LilyPond input is @strong{case sensitive}.  @code{
@@ -106,7 +111,7 @@ Note that there are several other text editors available with
 better support for LilyPond.  For more information, see
 @rprogram{Text editor support}.
 
-@warning{the first time you ever run LilyPond, it may take a
+@warning{The first time you ever run LilyPond, it may take a
 minute or two because all of the system fonts have to be analyzed
 first.  After this, LilyPond will be much faster!}
 
@@ -138,7 +143,10 @@ pointer.
 To edit an existing @file{.ly} file, right-click on it and
 select @qq{Edit source}.  To get an empty file to start from, run
 the editor as described above and use @qq{New} in
-the @qq{File} menu.
+the @qq{File} menu, or right-click on the desktop and select
+@qq{New..Text Document}, change its name to a name of your choice
+and change the file extension to @code{.ly}.  Double-click the
+icon to type in your LilyPond source code as before.
 
 Double-clicking the file does not only result in a PDF file, but
 also produces a @file{.log} file that contains some information on
@@ -147,7 +155,7 @@ examine this file.
 
 @subsubheading Unix
 
-Create a file (such as @file{test.ly}) and enter:
+Create a text file called @file{test.ly} and enter:
 
 @example
 @{
@@ -260,9 +268,9 @@ above the B, and an A, G or F will be assumed to be below.
   b c  % c is 1 staff space up, so is the c above
   b d  % d is 2 up or 5 down, so is the d above
   b e  % e is 3 up or 4 down, so is the e above
-  b a  % a is 4 up or 3 down, so is the a below
+  b a  % a is 6 up or 1 down, so is the a below
   b g  % g is 5 up or 2 down, so is the g below
-  b f  % f is 6 up or 1 down, so is the f below
+  b f  % f is 4 up or 3 down, so is the f below
 }
 @end lilypond
 
@@ -290,7 +298,7 @@ To change a note by two (or more!) octaves, we use multiple
 quotes @code{''} and not one double quote @code{"}@tie{}!  The
 initial value in @code{\relative c'} may also be modified like
 this.
-
+@c " - keeps quotes in order for context-sensitive editor -td
 
 @subheading Durations (rhythms)
 
@@ -407,7 +415,7 @@ Notation Reference: @ruser{Writing pitches},
 
 LilyPond input files are similar to source files in many common
 programming languages.  They are case sensitive, and white-space
-is generally equivalent.  Expressions are formed with curly braces
+is generally ignored.  Expressions are formed with curly braces
 @{ @}, and comments are denoted with @code{%} or @code{%@{ ...
 %@}}.
 
@@ -454,8 +462,9 @@ that the input is a single music expression, just like parentheses
 space unless they are at the beginning or end of a line to avoid
 ambiguities.
 
-A function (such as @code{\relative @{ @}}) also counts as a
-single music expression.
+A LilyPond command followed by a simple expression in braces (such
+as @code{\relative @{ @}}) also counts as a single music 
+expression.
 
 @cindex comments
 @cindex line comment
@@ -466,10 +475,22 @@ a comment is a remark for the human reader of the music input; it
 is ignored while parsing, so it has no effect on the printed
 output.  There are two types of comments.  The percent symbol
 @code{%} introduces a line comment; anything after @code{%} on
-that line is ignored.  A block comment marks a whole section of
-music input as a comment.  Anything that is enclosed in @code{%@{}
-and @code{%@}} is ignored.  (Comments do not nest.)  The following
-fragment shows possible uses for comments:
+that line is ignored.  By convention, a line comment is placed
+@emph{above} the code it refers to.
+
+@example
+a4 a a a
+% this comment refers to the Bs
+b2 b
+@end example
+
+A block comment marks a whole section of music input as a comment.
+Anything that is enclosed in @code{%@{} and @code{%@}} is ignored.
+However, block comments do not @q{nest}.  This means that you
+cannot place a block comment inside another block comment.  If you
+try, the first @code{%@}} will terminate @emph{both} block
+comments.  The following fragment shows possible uses for
+comments:
 
 @example
 % notes for twinkle twinkle follow
@@ -487,8 +508,8 @@ fragment shows possible uses for comments:
 @end itemize
 
 
-@node How to read the tutorial
-@subsection How to read the tutorial
+@node How to read the manual
+@subsection How to read the manual
 
 LilyPond input must be surrounded by @{ @} marks or a
 @code{\relative c'' @{ ... @}}, as we saw in @ref{Working on text
@@ -538,7 +559,8 @@ cut-&-pastable section} to the bottom of the file.
 
 
 There are more tips for constructing input files in
-@ref{Suggestions for writing LilyPond files}.
+@ref{Suggestions for writing LilyPond files}.  But it might be
+best to read through the rest of the tutorial first.
 
 
 
@@ -609,7 +631,7 @@ note's @notation{pitch}!  This is a feature that often causes
 confusion to newcomers, so let us explain it in more detail.
 
 LilyPond makes a sharp distinction between musical content and
-layout.  The alteration (@notation{flat}, @notation{natural} or
+layout.  The alteration (@notation{flat}, @notation{natural sign} or
 @notation{sharp}) of a note is part of the pitch, and is therefore
 musical content.  Whether an accidental (a @emph{printed} flat,
 natural or sharp sign) is printed in front of the corresponding
@@ -627,8 +649,8 @@ d cis fis
 @end lilypond
 
 @noindent
-No note has a printed accidental, but you must still add the
-@code{is} to @code{cis} and @code{fis}.
+No note has a printed accidental, but you must still add
+@code{is} and type @code{cis} and @code{fis} in the input file.
 
 The code @code{e} does not mean @qq{print a black dot just below
 the first line of the staff.}  Rather, it means @qq{there is a
@@ -689,12 +711,12 @@ d4( c16) cis( d e c cis d) e( d4)
 @cindex phrasing slurs
 @subheading Phrasing slurs
 
-Music Glossary: @rglos{phrasing}, @rglos{legato}.
+Music Glossary: @rglos{slurs}, @rglos{phrasing}.
 
 Slurs to indicate longer @notation{phrasing} can be entered with
-@code{\(} and @code{\)}.  You can have both @notation{legato}
-slurs and phrasing slurs at the same time, but you cannot have
-simultaneous legato slurs or simultaneous phrasing slurs.
+@code{\(} and @code{\)}.  You can have both @notation{slurs}
+and phrasing slurs at the same time, but you cannot have
+simultaneous slurs or simultaneous phrasing slurs.
 
 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
 a8(\( ais b c) cis2 b'2 a4 cis,\)
@@ -780,8 +802,8 @@ c\ff c\mf c\p c\pp
 @cindex crescendo
 
 @notation{Crescendi} and @notation{decrescendi} are started with
-the commands @code{\<} and @code{\>}.  An ending dynamic, for
-example @code{\f}, will finish the (de)crescendo, or the command
+the commands @code{\<} and @code{\>}.  The next dynamics sign, for
+example @code{\f}, will end the (de)crescendo, or the command
 @code{\!} can be used:
 
 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
@@ -790,7 +812,7 @@ c2\< c2\ff\> c2 c2\!
 
 @seealso
 
-Notation Reference: @ruser{Articulations},
+Notation Reference: @ruser{Articulations and ornamentations},
 @ruser{Fingering instructions}, @ruser{Dynamics}.
 
 
@@ -887,7 +909,7 @@ Triplets make notes occupy 2/3 of their notated duration, so a
 @cindex appoggiatura
 @subheading Grace notes
 
-Music Glossary: @rglos{grace notes}, @rglos{acciacccatura},
+Music Glossary: @rglos{grace notes}, @rglos{acciaccatura},
 @rglos{appoggiatura}.
 
 @notation{Grace notes} are created with the @code{\grace} command,
@@ -920,7 +942,7 @@ than one voice on the same staff.
 @menu
 * Music expressions explained::  
 * Multiple staves::             
-* Piano staves::                
+* Staff groups::                
 * Combining notes into chords::  
 * Single staff polyphony::      
 @end menu
@@ -952,6 +974,34 @@ one).  The result is another music expression:
 { { a4 g } f g }
 @end lilypond
 
+@cindex expression
+@cindex music expression
+@subheading Analogy: mathematical expressions
+
+This mechanism is similar to mathematical formulas: a big formula
+is created by composing small formulas.  Such formulas are called
+expressions, and they can contain other expressions, so you can
+make arbitrarily complex and large expressions.  For example,
+
+@example
+1
+
+1 + 2
+
+(1 + 2) * 3
+
+((1 + 2) * 3) / (4 * 5)
+@end example
+
+This is a sequence of expressions, where each expression is
+contained in the next (larger) one.  The simplest expressions are
+numbers, and larger ones are made by combining expressions with
+operators (like @code{+}, @code{*} and @code{/}) and parentheses.
+Like mathematical expressions, music expressions can be nested
+arbitrarily deep, which is necessary for complex music like
+polyphonic scores.
+
+
 @subheading Simultaneous music expressions: multiple staves
 
 Music Glossary: @rglos{polyphony}.
@@ -980,6 +1030,7 @@ different amount of space.  LilyPond does not care how much (or
 little) space there is at the beginning of a line, but indenting
 LilyPond code like this makes it much easier for humans to read.
 
+@c FIXME: number of backslashes?!  works in html but not pdf.
 @warning{each note is relative to the previous note in
 the input, not relative to the @code{c''} in the initial
 @code{\\relative} command.}
@@ -988,9 +1039,9 @@ the input, not relative to the @code{c''} in the initial
 @subheading Simultaneous music expressions: single staff
 
 To determine the number of staves in a piece, LilyPond looks at
-the first expression.  If it is a single note, there is one staff;
-if there is a simultaneous expression, there is more than one
-staff.
+the beginning of the first expression.  If is a single note, there
+is one staff; if there is a simultaneous expression, there is more
+than one staff.
 
 @lilypond[verbatim,quote,ragged-right]
 \relative c'' {
@@ -999,34 +1050,6 @@ staff.
 }
 @end lilypond
 
-@cindex expression
-@cindex music expression
-@subheading Analogy: mathematical expressions
-
-This mechanism is similar to mathematical formulas: a big formula
-is created by composing small formulas.  Such formulas are called
-expressions, and they can contain other music expressions, so you
-can make arbitrarily complex and large expressions.  For example,
-
-@example
-1
-
-1 + 2
-
-(1 + 2) * 3
-
-((1 + 2) * 3) / (4 * 5)
-@end example
-
-This is a sequence of expressions, where each expression is
-contained in the next (larger) one.  The simplest expressions are
-numbers, and larger ones are made by combining expressions with
-operators (like @code{+}, @code{*} and @code{/}) and parentheses.
-Like mathematical expressions, music expressions can be nested
-arbitrarily deep, which is necessary for complex music like
-polyphonic scores.
-
-
 @node Multiple staves
 @subsection Multiple staves
 
@@ -1065,11 +1088,11 @@ creates a bigger music expression.  In this way it resembles the
 minus sign in mathematics.  The formula @math{(4+5)} is an
 expression, so @math{-(4+5)} is a bigger expression.
 
-Time signatures entered in one staff affect all other
-staves@footnote{This behavior may be changed if desired; for
-details, see @ruser{Polymetric notation}.}.  On the other hand,
-the key signature of one staff does @emph{not} affect other
-staves.
+Time signatures entered in one staff affects all other staves by
+default.  On the other hand, the key signature of one staff does
+@emph{not} affect other staves.  This different default behaviour
+is because scores with transposing instruments are more common
+than polyrhythmic scores.
 
 @lilypond[verbatim,quote,ragged-right]
 \relative c'' {
@@ -1083,11 +1106,12 @@ staves.
 
 
 
-@node Piano staves
-@subsection Piano staves
+@node Staff groups
+@subsection Staff groups
 
-@cindex staff switch, manual
-@cindex cross staff voice, manual
+@cindex piano staff
+@cindex choir staff
+@cindex grand staff
 
 Music Glossary: @rglos{brace}.
 
@@ -1115,9 +1139,18 @@ Here is a small example:
 }
 @end lilypond
 
+Other staff groupings are introduced with
+@code{\new GrandStaff,} suitable for orchestral
+scores, and @code{\new ChoirStaff,} suitable for
+vocal scores.  These staff groups each form another
+type of context, one that generates the brace at the
+left end of every system and also controls the extent
+of bar lines.
+
 @seealso
 
-Notation Reference: @ruser{Piano music}.
+Notation Reference: @ruser{Piano music}, 
+@ruser{Displaying staves}.
 
 
 @node Combining notes into chords
@@ -1127,23 +1160,26 @@ Notation Reference: @ruser{Piano music}.
 
 Music Glossary: @rglos{chord}.
 
-@notation{Chords} can be made by surrounding pitches with single
-angle brackets.  Angle brackets are the symbols @code{<} and
-@code{>}.
+We saw earlier how notes can be combined into @notation{chords} by
+indicating they are simultaneous by enclosing them in double angle
+brackets.  However, the normal way of indicating a chord is to
+surround the pitches with @emph{single} angle brackets.  Note that
+all the notes in a chord must have the same duration, and that the
+duration is placed after the closing bracket.
 
 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
 r4 <c e g>4 <c f a>2
 @end lilypond
 
-You can combine markings like beams and ties with chords.  They
-must be placed outside the angle brackets.
+Think of chords as almost equivalent to single notes:
+almost everything you can attach to a single note can be attached
+to a chord, and everything must go @emph{outside} the angle
+brackets.  For example, you can combine markings like beams and
+ties with chords.  They must be placed outside the angle brackets.
 
 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
 r4 <c e g>8[ <c f a>]~ <c f a>2
-@end lilypond
-
-@lilypond[verbatim,quote,ragged-right,fragment,relative=2]
-r4 <c e g>8\>( <c e g> <c e g>4 <c f a>\!)
+r4 <c e g>8( <c e g>\> <c e g>4 <c f a>\!)
 @end lilypond
 
 
@@ -1253,8 +1289,9 @@ separating each syllable with a space.
 @end lilypond
 
 Note the curly brackets delimiting both the music and the lyrics,
-and the angle brackets @code{<< ... >>} around the whole piece to
-show that the music and lyrics are to occur at the same time.
+and the double angle brackets @code{<< ... >>} around the whole 
+piece to show that the music and lyrics are to occur at the same 
+time.
 
 @node Aligning lyrics to a melody
 @subsection Aligning lyrics to a melody
@@ -1310,6 +1347,25 @@ Here we have also used manual beaming (the square brackets @code{[
 ]} ) to generate the beaming which is customarily used with lyrics
 (see @ref{Automatic and manual beams}).
 
+As an alternative to using slurs, the melismata may be indicated
+in just the lyrics by using an underscore, @code{_}, for each
+note that should be included in the melisma:
+
+@lilypond[verbatim,quote,ragged-right]
+<<
+  \relative c'' {
+    \key g \major
+    \time 6/8
+    d4 b8 c4 a8 d4 b8 g4 
+    g8 a4 b8 c[ b] a d4 b8 g4.
+  }
+  \addlyrics {
+    Girls and boys come out to play,
+    The moon doth shine _ as bright as day;
+  }
+>> 
+@end lilypond
+
 If a syllable extends over several notes or a single very long
 note an @notation{extender line} is usually drawn from the
 syllable extending under all the notes for that syllable.  It is
@@ -1416,16 +1472,18 @@ example from Handel's Judas Maccabæus:
 >>
 @end lilypond
 
+@noindent
 but scores any more complex than this simple example are
 better produced by separating out the staff structure
 from the notes and lyrics with variables.  These are
-discussed later (see @ref{Organizing pieces with variables}).
+discussed in @ref{Organizing pieces with variables}.
 
 @seealso
 
 Notation Reference: @ruser{Vocal music}.
 
 
+
 @node Final touches
 @section Final touches
 
@@ -1434,15 +1492,91 @@ add the final touches to simple pieces, and provides an
 introduction to the rest of the manual.
 
 @menu
+* Organizing pieces with variables::  
 * Version number::              
 * Adding titles::               
 * Absolute note names::         
-* Organizing pieces with variables::  
 * After the tutorial::          
-* How to read the manual::      
 @end menu
 
 
+@node Organizing pieces with variables
+@subsection Organizing pieces with variables
+
+When all of the elements discussed earlier are combined to produce
+larger files, the music expressions get a lot bigger.  In
+polyphonic music with many staves, the input files can become very
+confusing.  We can reduce this confusion by using
+@emph{variables}.
+
+With variables (also known as identifiers or macros), we can break
+up complex music expressions.  A variable is assigned as
+follows:
+
+@example
+namedMusic = @{ @dots{} @}
+@end example
+
+The contents of the music expression @code{namedMusic} can be used
+later by placing a backslash in front of the name
+(@code{\namedMusic}, just like a normal LilyPond command).
+
+@lilypond[verbatim,quote,ragged-right]
+violin = \new Staff { \relative c'' {
+  a4 b c b
+}}
+cello = \new Staff { \relative c {
+  \clef bass
+  e2 d
+}}
+{
+  <<
+    \violin
+    \cello
+  >>
+}
+@end lilypond
+
+@noindent
+The name of a variable must have alphabetic characters only, no
+numbers, underscores, or dashes.
+
+Variables must be defined @emph{before} the main music
+expression, but may be used as many times as required anywhere after
+they have been defined.  They may even be used in a later definition
+of another variable, giving a way of shortening the input if a
+section of music is repeated many times.
+
+@lilypond[verbatim,quote,ragged-right]
+tripletA = \times 2/3 { c,8 e g }
+barA = { \tripletA \tripletA \tripletA \tripletA }
+
+\relative c'' {
+ \barA \barA
+}
+@end lilypond
+
+Variables may be used for many other types of objects in
+the input.  For example,
+
+@example
+width = 4.5\cm
+name = "Wendy"
+aFivePaper = \paper @{ paperheight = 21.0 \cm @}
+@end example
+
+Depending on its contents, the variable can be used in different
+places.  The following example uses the above variables:
+
+@example
+\paper @{
+  \aFivePaper
+  line-width = \width
+@}
+@{ c4^\name @}
+@end example
+
+
 @node Version number
 @subsection Version number
 
@@ -1451,7 +1585,7 @@ The @code{\version} statement records the version of LilyPond that
 was used to write the file:
 
 @example
-\version "2.11.23"
+\version "2.11.38"
 @end example
 
 @noindent
@@ -1473,7 +1607,7 @@ main music expression; the @code{\header} block is usually placed
 underneath the @ref{Version number}.
 
 @example
-\version "2.11.23"
+\version "2.11.38"
 \header @{
   title = "Symphony"
   composer = "Me"
@@ -1540,9 +1674,9 @@ of quote @code{'} marks.  Consider this fragment from Mozart:
 }
 @end lilypond
 
-All these quotes makes the input less readable and it is a source
+All these quotes makes the input less readable and they are a source
 of errors.  With @code{\relative}, the previous example is much
-easier to read:
+easier to read and type:
 
 @lilypond[verbatim,quote,ragged-right]
 \relative c'' {
@@ -1564,73 +1698,13 @@ intervals, and is extremely useful for computer-generated LilyPond
 files.
 
 
-@node Organizing pieces with variables
-@subsection Organizing pieces with variables
-
-When all of the elements discussed earlier are combined to produce
-larger files, the music expressions get a lot bigger.  In
-polyphonic music with many staves, the input files can become very
-confusing.  We can reduce this confusion by using
-@emph{variables}.
-
-With variables (also known as identifiers or macros), we can break
-up complex music expressions.  A variable is assigned as
-follows:
-
-@example
-namedMusic = @{ @dots{} @}
-@end example
-
-The contents of the music expression @code{namedMusic} can be used
-later by placing a backslash in front of the name
-(@code{\namedMusic}, just like a normal LilyPond command).
-Variables must be defined @emph{before} the main music
-expression.
-
-@lilypond[verbatim,quote,ragged-right]
-violin = \new Staff { \relative c'' {
-  a4 b c b
-}}
-cello = \new Staff { \relative c {
-  \clef bass
-  e2 d
-}}
-{
-  <<
-    \violin
-    \cello
-  >>
-}
-@end lilypond
-
-@noindent
-The name of a variable must have alphabetic characters only, no
-numbers, underscores, or dashes.
-
-It is possible to use variables for many other types of objects in
-the input.  For example,
-
-@example
-width = 4.5\cm
-name = "Wendy"
-aFivePaper = \paper @{ paperheight = 21.0 \cm @}
-@end example
-
-Depending on its contents, the variable can be used in different
-places.  The following example uses the above variables:
-
-@example
-\paper @{
-  \aFivePaper
-  line-width = \width
-@}
-@{ c4^\name @}
-@end example
-
 
 @node After the tutorial
 @subsection After the tutorial
 
+FIXME: rewrite slightly after the rest of the LM has been
+stabilized.  Translators, ignore this section for now.
+
 After finishing the tutorial, you should probably try writing a
 piece or two.  Start by adding notes to one of the
 @ref{Templates}.  If you need any notation that was not covered in
@@ -1647,28 +1721,5 @@ wish to skim these chapters right now, and come back to them after
 you have more experience.
 
 
-@node How to read the manual
-@subsection How to read the manual
 
-Many examples in the tutorial omitted a @code{\relative c'' @{
-... @}} around the printed example, as we saw in
-@ref{How to read the tutorial}.
-
-In the rest of the manual, we are much more lax about the printed
-examples: sometimes they may have omitted a @code{\relative c'' @{
-... @}}, but other times a different initial pitch may be used
-(such as @code{c'} or @code{c,,}), and in some cases the whole
-example is in absolute note mode!  However, ambiguities like this
-only exist where the pitches are not important.  In any example
-where the pitch matters, we have explicitly stated
-@code{\relative} or absolute-mode @code{@{ @}}.
-
-If you are still confused about the exact LilyPond input that was
-used in an example, read the HTML version (if you are not already
-doing so) and click on the picture of the music.  This will
-display the exact input that LilyPond used to generate this
-manual.
-
-For information about the structure of the rest of the manual, see
-@ref{About this manual}.