]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/putting.itely
New section on modifying templates and misc small changes.
[lilypond.git] / Documentation / user / putting.itely
1 @c -*- coding: latin-1; mode: texinfo; -*-
2 @node Putting it all together
3 @chapter Putting it all together
4
5 This section explains how to use the rest of the documentation and
6 how to solve common problems.
7
8 @menu
9 * Suggestions for writing LilyPond files::  
10 * Extending the templates::     
11 @end menu
12
13
14 @node Suggestions for writing LilyPond files
15 @section Suggestions for writing LilyPond files
16
17 Now you're ready to begin writing larger LilyPond files -- not just the
18 little examples in the tutorial, but whole pieces.  But how should you
19 go about doing it?
20
21 The best answer is ``however you want to do it.''  As long as LilyPond
22 can understand your files and produces the output that you want, it
23 doesn't matter what your files look like.  That said, sometimes we
24 make mistakes when writing files.  If LilyPond can't understand your
25 files, or produces output that you don't like, how do you fix the
26 problem?
27
28 Here are a few suggestions that can help you to avoid or fix
29 problems:
30
31 @itemize @bullet
32 @item Include @code{\version} numbers in every file.  Note that all
33 templates contain a @code{\version "2.6.0"} string.  We
34 highly recommend that you always include the @code{\version}, no matter
35 how small your file is.  Speaking from personal experience, it's
36 quite frustrating to try to remember which version of LilyPond you were
37 using a few years ago.  @code{convert-ly} requires you to declare
38 which version of LilyPond you used.
39
40 @item Include checks: See @ref{Bar check} and @ref{Octave check}.  If you
41 include checks every so often, then if you make a mistake, you can pinpoint
42 it quicker.  How often is ``every so often''?  It depends on the complexity
43 of the music.  For very simple music, perhaps just once or twice.  For
44 very complex music, every bar.
45
46 @item One bar per line.  If there is anything complicated, either in the music
47 itself or in the output you desire, it's often good to write only one bar
48 per line.  Saving screen space by cramming eight bars per line just isn't
49 worth it if you have to `debug' your files.
50
51 @item Comment your files, with either bar numbers (every so often) or
52 references to musical themes (``second theme in violins'', ``fourth
53 variation'').  You may not need it when you're writing the piece for
54 the first time, but if you want to go back and change something two
55 or three years later, you won't know how your file is structured if you
56 don't comment the file.
57
58 @end itemize
59
60
61 @node Extending the templates
62 @section Extending the templates
63
64 You've read the tutorial, you know how to write music.  But how can you
65 get the staves that you want?  The templates are ok, but what if you
66 want something that isn't covered?
67
68 Start off with the template that seems closest to what you want to end
69 up with.  Let's say that you want to write something for soprano and
70 cello.  In this case, we would start with ``Notes and lyrics'' (for the
71 soprano part).
72
73 @example
74 \version "2.4.0"
75 melody = \relative c' @{
76   \clef treble
77   \key c \major
78   \time 4/4
79
80   a4 b c d
81 @}
82
83 text = \lyricmode @{
84   Aaa Bee Cee Dee
85 @}
86
87 \score@{
88   <<
89     \context Voice = one @{
90       \autoBeamOff
91       \melody
92     @}
93     \lyricsto "one" \new Lyrics \text
94   >>
95   \layout @{ @}
96   \midi @{ \tempo 4=60 @}
97 @}
98 @end example
99
100 Now we want to add a cello part.  Let's look at the ``Notes only'' example:
101
102 @example
103 \version "2.4.0"
104 melody = \relative c' @{
105   \clef treble
106   \key c \major
107   \time 4/4
108
109   a4 b c d
110 @}
111      
112 \score @{
113 \new Staff \melody
114 \layout @{ @}
115 \midi @{ \tempo 4=60 @}
116 @}
117 @end example
118
119 We don't need two @code{\version} commands.  We'll need the @code{melody}
120 section.  We don't want two @code{\score} sections -- if we had two
121 @code{\score}s, we'd get the two parts separately.  We want them together,
122 as a duet.  Within the @code{\score} section, we don't need two
123 @code{\layout} or @code{\midi}.
124
125 If we simply cut and paste the @code{melody} section, we would end up with
126 two @code{melody} sections.  So let's rename them.  We'll call the one
127 for the soprano @code{sopranoMusic}, and the one for the cello can be
128 called @code{celloMusic}.  While we're doing this, let's rename @code{text}
129 to be @code{sopranoLyrics}.  Remember to rename both instances of all
130 these names -- both the initial definition (the
131 @code{melody = relative c' @{ } part) and the name's use (in the
132 @code{\score} section).
133
134 While we're doing this, let's change the cello part's staff -- celli
135 normally use bass clef.  We'll also give the cello some different
136 notes.
137
138 @example
139 \version "2.4.0"
140 sopranoMusic = \relative c' @{
141   \clef treble
142   \key c \major
143   \time 4/4
144
145   a4 b c d
146 @}
147
148 sopranoLyrics = \lyricmode @{
149   Aaa Bee Cee Dee
150 @}
151
152 celloMusic = \relative c @{
153   \clef bass
154   \key c \major
155   \time 4/4
156
157   d4 g fis8 e d4
158 @}
159
160 \score@{
161   <<
162     \context Voice = one @{
163       \autoBeamOff
164       \sopranoMusic
165     @}
166     \lyricsto "one" \new Lyrics \sopranoLyrics
167   >>
168   \layout @{ @}
169   \midi @{ \tempo 4=60 @}
170 @}
171 @end example
172
173 This is looking promising, but the cello part won't appear in the
174 score -- we haven't used it in the @code{\score} section.  If we
175 want the cello part to appear under the soprano part, we need to add
176
177 @example
178 \new Staff \celloMusic
179 @end example
180
181 @noindent
182 underneath the soprano stuff.  We also need to add @code{<<} and
183 @code{>>} around the music -- that tells LilyPond that there's
184 more than one thing (in this case staff) happening at once.  The
185 @code{\score} looks like this now
186
187 @example
188 \score@{
189 <<
190   <<
191     \context Voice = one @{
192       \autoBeamOff
193       \sopranoMusic
194     @}
195     \lyricsto "one" \new Lyrics \sopranoLyrics
196   >>
197   \new Staff \celloMusic
198 >>
199   \layout @{ @}
200   \midi @{ \tempo 4=60 @}
201 @}
202 @end example
203
204 @noindent
205 This looks a bit messy; the indentation is messed up now.  That is
206 easily fixed.  Here's the complete soprano and cello template.
207
208 @lilypond[quote,verbatim,raggedright]
209 \version "2.4.0"
210 sopranoMusic = \relative c' {
211   \clef treble
212   \key c \major
213   \time 4/4
214
215   a4 b c d
216 }
217
218 sopranoLyrics = \lyricmode {
219   Aaa Bee Cee Dee
220 }
221
222 celloMusic = \relative c {
223   \clef bass
224   \key c \major
225   \time 4/4
226
227   d4 g fis8 e d4
228 }
229
230 \score{
231   <<
232   <<
233     \context Voice = one {
234       \autoBeamOff
235       \sopranoMusic
236     }
237     \lyricsto "one" \new Lyrics \sopranoLyrics
238   >>
239   \new Staff \celloMusic
240   >>
241   \layout { }
242   \midi { \tempo 4=60 }
243 }
244 @end lilypond
245
246