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