]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/fundamental.itely
Move fundamental voices stuff into Fundamental.
[lilypond.git] / Documentation / user / fundamental.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond-learning.tely
3
4 @node Fundamental concepts
5 @chapter Fundamental concepts
6
7 @menu
8 * How LilyPond files work::     
9 * Score is a single musical expression::  
10 * I'm seeing Voices::           
11 @end menu
12
13
14 @node How LilyPond files work
15 @section How LilyPond files work
16
17 The LilyPond input format is quite free-form, giving experienced
18 users a lot of flexibility to structure their files however they
19 wish.  However, this flexibility can make things confusing for new
20 users.  This section will explain some of this structure, but may
21 gloss over some details in favor of simplicity.  For a complete
22 description of the input format, see @ruser{File structure}.
23
24 A basic example of a lilypond input file is
25
26 @example
27 \version "2.11.23"
28 \score @{
29   @{@var{...music expression...}@}  % all the music goes here!
30   \header @{ @}
31   \layout @{ @}
32   \midi @{ @}
33 @}
34 @end example
35
36 @noindent
37 There are many variations of this basic pattern, but this
38 example serves as a useful starting place.
39
40 At this point, you may be confused, since you have never seen a
41 @code{\score@{@}} before.  This is because LilyPond automatically
42 adds the extra commands when you give it simple input.  LilyPond
43 treats input like this:
44
45 @example
46 \relative c'' @{
47   c4 a d c
48 @}
49 @end example
50
51 @noindent
52 as shorthand for this:
53
54 @example
55 \score @{
56   \relative c'' @{
57     c4 a b c
58   @}
59   \layout @{ @}
60 @}
61 @end example
62
63 In other words, if the input contains a single music expression,
64 LilyPond will interpret the file as though the music expression
65 was wrapped up inside a @code{\score@{@}}.
66
67 @smallspace
68
69 A @code{\score} must begin with a single music
70 expression.  Remember that a music expression could
71 be anything from a single note to a huge
72
73 @example
74 @{
75   \new GrandStaff <<
76     @var{...insert the whole score of a Wagner opera in here...}
77   >>
78 @}
79 @end example
80
81 @noindent
82 Since everything is inside @code{@{ ... @}}, it counts
83 as one music expression.
84
85 As we saw previously, the @code{\score} can contain other things,
86 such as
87
88 @example
89 \score @{
90   @{ c'4 a b c' @}
91   \header @{ @}
92   \layout @{ @}
93   \midi @{ @}
94 @}
95 @end example
96
97 @noindent
98 Some people put some of those commands outside the @code{\score}
99 block -- for example, @code{\header} is often placed above the
100 @code{\score}.  That's just another shorthand that LilyPond
101 accepts.
102
103 @smallspace
104
105 @cindex variables
106 @cindex identifiers
107
108 Another great shorthand is the ability to define identifiers.  All
109 the templates use this
110
111 @example
112 melody = \relative c' @{
113   c4 a b c
114 @}
115
116 \score @{
117   @{ \melody @}
118 @}
119 @end example
120
121 When LilyPond looks at this file, it takes the value of
122 @code{melody} (everything after the equals sign) and inserts it
123 whenever it sees @code{\melody}.  There's nothing special about
124 the names -- it could be @code{melody}, @code{global},
125 @code{pianorighthand}, or @code{foofoobarbaz}.  You can use
126 whatever variable names you want.  For more details, see
127 @ruser{Saving typing with identifiers and functions}.
128
129
130 @seealso
131
132 For a complete definition of the input format, see @ruser{File
133 structure}.
134
135
136 @node Score is a single musical expression
137 @section Score is a single musical expression
138
139 We saw the general organization of LilyPond input files in the
140 previous section, @ref{How LilyPond files work}.  But we seemed to
141 skip over the most important part: how do we figure out what to
142 write after @code{\score}?
143
144 We didn't skip over it at all.  The big mystery is simply that
145 there @emph{is} no mystery.  This line explains it all:
146
147 @quotation
148 @emph{A @code{\score} must begin with a single music expression.}
149 @end quotation
150
151 @noindent
152 You may find it useful to review @ruser{Music expressions
153 explained}.  In that section, we saw how to build big music
154 expressions from small pieces -- we started from notes, then
155 chords, etc.  Now we're going to start from a big music expression
156 and work our way down.
157
158 @example
159 \score @{
160   @{ % this brace begins the overall music expression
161     \new GrandStaff <<
162       @var{...insert the whole score of a Wagner opera in here...}
163     >>
164   @} % this brace ends the overall music expression
165   \layout @{ @}
166 @}
167 @end example
168
169 A whole Wagner opera would easily double the length of this
170 manual, so let's just add a singer and piano.  We don't need a
171 @code{GrandStaff} for this ensemble, so we shall remove it.  We
172 @emph{do} need a singer and a piano, though.
173
174 @example
175 \score @{
176   @{
177     <<
178       \new Staff = "singer" <<
179       >>
180       \new PianoStaff = piano <<
181       >>
182     >>
183   @}
184   \layout @{ @}
185 @}
186 @end example
187
188 Remember that we use @code{<<} and @code{>>} to show simultaneous
189 music.  And we definitely want to show the vocal part and piano
190 part at the same time, not one after the other!
191
192 @example
193 \score @{
194   @{
195     <<
196       \new Staff = "singer" <<
197         \new Voice = "vocal" @{ @}
198       >>
199       \new Lyrics \lyricsto vocal \new Lyrics @{ @}
200       \new PianoStaff = "piano" <<
201         \new Staff = "upper" @{ @}
202         \new Staff = "lower" @{ @}
203       >>
204     >>
205   @}
206   \layout @{ @}
207 @}
208 @end example
209
210 Now we have a lot more details.  We have the singer's staff: it
211 contains a @code{Voice} (in LilyPond, this term refers to a set of
212 notes, not necessarily vocal notes -- for example, a violin
213 generally plays one voice) and some lyrics.  We also have a piano
214 staff: it contains an upper staff (right hand) and a lower staff
215 (left hand).
216
217 At this stage, we could start filling in notes.  Inside the curly
218 braces next to @code{\new Voice = vocal}, we could start writing
219
220 @example
221 \relative c'' @{
222   a4 b c d
223 @}
224 @end example
225
226 But if we did that, the @code{\score} section would get pretty
227 long, and it would be harder to understand what was happening.  So
228 let's use identifiers (or variables) instead.
229
230 @example
231 melody = @{ @}
232 text = @{ @}
233 upper = @{ @}
234 lower = @{ @}
235 \score @{
236   @{
237     <<
238       \new Staff = "singer" <<
239         \new Voice = "vocal" @{ \melody @}
240       >>
241       \new Lyrics \lyricsto vocal \new Lyrics @{ \text @}
242       \new PianoStaff = "piano" <<
243         \new Staff = "upper" @{ \upper @}
244         \new Staff = "lower" @{ \lower @}
245       >>
246     >>
247   @}
248   \layout @{ @}
249 @}
250 @end example
251
252 @noindent
253 Remember that you can use almost any name you like.  The
254 limitations on identifier names are detailed in @ruser{File
255 structure}.
256
257 When writing (or reading) a @code{\score} section, just take it
258 slowly and carefully.  Start with the outer layer, then work on
259 each smaller layer.  It also really helps to be strict with
260 indentation -- make sure that each item on the same layer starts
261 on the same horizontal position in your text editor.
262
263
264
265 @node I'm seeing Voices
266 @section I'm seeing Voices
267
268 @cindex polyphony
269
270 The easiest way to enter fragments with more than one voice on a
271 staff is to enter each voice as a sequence (with @code{@{...@}}),
272 and combine them simultaneously, separating the voices with
273 @code{\\}
274
275 @funindex \\
276
277 @lilypond[quote,verbatim,fragment]
278 \new Staff \relative c' {
279   c16 d e f
280   <<
281     { g4 f e | d2 e2 } \\
282     { r8 e4 d c8 ~ | c b16 a b8 g ~ g2 } \\
283     { s2. | s4 b4 c2 }
284   >>
285 }
286 @end lilypond
287
288 @cindex layers
289
290 The separator causes @internalsref{Voice}
291 contexts@footnote{Polyphonic voices are sometimes
292 called @q{layers} in other notation packages} to be instantiated.
293 They bear the names @code{"1"}, @code{"2"}, etc.  In each of these
294 contexts, vertical direction of slurs, stems, etc., is set
295 appropriately.
296
297 These voices are all separate from the voice that contains the
298 notes just outside the @code{<< \\ >>} construct.  This should be
299 noted when making changes at the voice level.  This also means
300 that slurs and ties cannot go into or out of a @code{<< \\ >>}
301 construct.  Conversely, parallel voices from separate @code{<< \\
302 >>} constructs on the same staff are the same voice.  Here is the
303 same example, with different noteheads and colors for each voice.
304 Note that the change to the note-head style in the main voice does
305 not affect the inside of the @code{<< \\ >>} constructs.  Also,
306 the change to the second voice in the first @code{<< \\ >>}
307 construct is effective in the second @code{<< \\ >>}, and the
308 voice is tied across the two constructs.
309
310 @cindex note heads, styles
311
312 @lilypond[quote,verbatim,fragment]
313 \new Staff \relative c' {
314   \override NoteHead #'style = #'cross
315   \override NoteHead #'color = #red
316   c16 d e f
317   <<
318     { g4 f e } \\
319     { \override NoteHead #'style = #'triangle
320       \override NoteHead #'color = #blue
321     r8 e4 d c8 ~ }
322   >> |
323   <<
324     { d2 e2 } \\
325     { c8 b16 a b8 g ~ g2 } \\
326     { \override NoteHead #'style = #'slash 
327       \override NoteHead #'color = #green
328       s4 b4 c2 }
329   >>
330 }
331 @end lilypond
332
333 Polyphony does not change the relationship of notes within a
334 @code{\relative @{ @}} block.  Each note is calculated relative to
335 the note immediately preceding it.
336
337 @example
338 \relative @{ noteA << noteB \\ noteC >> noteD @}
339 @end example
340
341 @code{noteC} is relative to @code{noteB}, not @code{noteA};
342 @code{noteD} is relative to @code{noteC}, not @code{noteB} or
343 @code{noteA}.
344
345
346