]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tweaks.itely
Trivial fix.
[lilypond.git] / Documentation / user / tweaks.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @node Tweaking output
3 @chapter Tweaking output
4
5 This chapter discusses how to modify output.  LilyPond is extremely
6 configurable; virtually every fragment of output may be changed.
7
8
9 @menu
10 * Moving objects::              
11 * Fixing overlapping notation::  
12 * Common tweaks::               
13 * Default files::               
14 * Advanced tweaks with Scheme::  
15 @end menu
16
17
18 @node Moving objects
19 @section Moving objects
20
21 This may come as a surprise, but LilyPond is not perfect.  Some notation
22 elements can overlap.  This is unfortunate, but (in most cases) is easily
23 solved.
24
25 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
26 e4^\markup{ \italic ritenuto } g b e
27 @end lilypond
28
29 @cindex padding
30
31 The easiest solution is to increase the distance between the object
32 (in this case text, but it could easily be fingerings or dynamics
33 instead) and the note.  In LilyPond, this is called the
34 @code{padding} property; it is measured in staff spaces.  For most
35 objects, this value is around 1.0 or less (it varies with each
36 object). We want to increase it, so let's try 1.5
37
38 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
39 \once \override TextScript #'padding = #1.5
40 e4^\markup{ \italic ritenuto } g b e
41 @end lilypond
42
43 That looks better, but it isn't quite big enough.  After experimenting
44 with a few values, we think 2.3 is the best number in this case.  However,
45 this number is merely the result of experimentation and my personal
46 taste in notation.  Try the above example with 2.3... but also try higher
47 (and lower) numbers.  Which do you think looks the best?
48
49 The @code{staff-padding} property is closely related.  @code{padding}
50 controls the minimum amount of space between an object and the nearest
51 other object (generally the note or the staff lines);
52 @code{staff-padding} controls the minimum amount of space between an
53 object and the staff.  This is a subtle difference, but you can see
54 the behavior here.
55
56 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
57 c4^"piu mosso" b a b
58 \once \override TextScript #'padding = #2.6
59 c4^"piu mosso" d e f
60 \once \override TextScript #'staff-padding = #2.6
61 c4^"piu mosso" fis a g
62 \break
63 c,,4^"piu mosso" b a b
64 \once \override TextScript #'padding = #2.6
65 c4^"piu mosso" d e f
66 \once \override TextScript #'staff-padding = #2.6
67 c4^"piu mosso" fis a g
68 @end lilypond
69
70 @cindex extra-offset
71
72 Another solution gives us complete control over placing the object -- we
73 can move it horizontally or vertically.  This is done with the
74 @code{extra-offset} property.  It is slightly more complicated and can
75 cause other problems.  When we move objects with @code{extra-offset},
76 the movement is done after LilyPond has placed all other objects.  This
77 means
78 that the result can overlap with other objects.
79
80 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
81 \once \override TextScript #'extra-offset = #'( 1.0 . -1.0 )
82 e4^\markup{ \italic ritenuto } g b e
83 @end lilypond
84
85 With @code{extra-offset}, the first number controls the horizontal
86 movement (left is negative); the second number controls the vertical
87 movement (up is positive).  After a bit of experimenting, we decided
88 that these values look good
89
90 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
91 \once \override TextScript #'extra-offset = #'( -1.6 . 1.0 )
92 e4^\markup{ \italic ritenuto } g b e
93 @end lilypond
94
95 @noindent
96 Again, these numbers are simply the result of a few experiments and
97 looking at the output.  You might prefer the text to be slightly higher,
98 or to the left, or whatever.  Try it and look at the result!
99
100 One final warning: in this section, we used
101
102 @example
103 \once \override TextScript @dots{}
104 @end example
105
106 This tweaks the display of text for the next note.  If the note has
107 no text, this tweak does nothing (and does @strong{not} wait until
108 the next bit of text).  To change the behavior of everything after
109 the command, omit the @code{\once}.  To stop this tweak, use a
110 @code{\revert}.  This is explained in depth in
111 @ref{The \override command}.
112
113 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
114 c4^"piu mosso" b
115 \once \override TextScript #'padding = #2.6
116   a4 b
117 c4^"piu mosso" d e f
118 \once \override TextScript #'padding = #2.6
119 c4^"piu mosso" d e f
120 c4^"piu mosso" d e f
121 \break
122 \override TextScript #'padding = #2.6
123 c4^"piu mosso" d e f
124 c4^"piu mosso" d e f
125 \revert TextScript #'padding
126 c4^"piu mosso" d e f
127 @end lilypond
128
129 @seealso
130
131 This manual: @ref{The \override command}, @ref{Common tweaks}.
132
133
134 @node Fixing overlapping notation
135 @section Fixing overlapping notation
136
137 In @ref{Moving objects}, we saw how to move a @code{TextScript}
138 object.  The same mechanism can be used to move other types of
139 objects; simply replace @code{TextScript} with the name of
140 another object.
141
142 To find the object name, look at the ``@strong{see also}'' at
143 bottom of the relevant documentation page.  For example, at
144 the bottom of @ref{Dynamics}, we see
145
146 @quotation
147 @seealso
148
149 Program reference: @internalsref{DynamicText}, @internalsref{Hairpin}.
150 Vertical positioning of these symbols is handled by
151 @internalsref{DynamicLineSpanner}.
152 @end quotation
153
154 @noindent
155 So to move dynamics around vertically, we use
156
157 @example
158 \override DynamicLineSpanner #'padding = #2.0
159 @end example
160
161 We cannot list every object, but here is a list of the most
162 common objects.
163
164 @multitable @columnfractions .33 .66
165 @headitem Object type           @tab Object name
166 @item Dynamics (vertically)     @tab @code{DynamicLineSpanner}
167 @item Dynamics (horizontally)   @tab @code{DynamicText}
168 @item Ties                      @tab @code{Tie}
169 @item Slurs                     @tab @code{Slur}
170 @item Articulations             @tab @code{Script}
171 @item Fingerings                @tab @code{Fingering}
172 @item Text e.g. @code{^"text"}  @tab @code{TextScript}
173 @item Rehearsal / Text marks    @tab @code{RehearsalMark}
174 @end multitable
175
176
177 @node Common tweaks
178 @section Common tweaks
179
180 Some overrides are so common that predefined commands are provided as
181 short-cuts, such as @code{\slurUp} and @code{\stemDown}.  These
182 commands are described in the Notation Reference under the appropriate
183 sections.
184
185 The complete list of modifications available for each type of
186 object (like slurs or beams) are documented in the Program
187 Reference.  However, many layout objects share properties which can be
188 used to apply generic tweaks.
189
190 @itemize @bullet
191
192 @cindex padding
193
194 @item
195 The @code{padding} property can be set to increase
196 (or decrease) the distance between symbols that are printed
197 above or below notes.  This applies to all objects with
198 @code{side-position-interface}.
199
200 @lilypond[quote,fragment,relative=1,verbatim]
201 c2\fermata
202 \override Script #'padding = #3
203 b2\fermata
204 @end lilypond
205
206 @lilypond[quote,fragment,relative=1,verbatim]
207 % This will not work, see below:
208 \override MetronomeMark #'padding = #3
209 \tempo 4=120
210 c1
211 % This works:
212 \override Score.MetronomeMark #'padding = #3
213 \tempo 4=80
214 d1
215 @end lilypond
216
217 Note in the second example how important it is to figure out what
218 context handles a certain object.  Since the @code{MetronomeMark} object
219 is handled in the @code{Score} context, property changes in the
220 @code{Voice} context will not be noticed.  For more details, see
221 @ref{Constructing a tweak}.
222
223 @cindex extra-offset
224
225 @item
226 The @code{extra-offset} property moves objects around
227 in the output; it requires a pair of numbers.  The first number
228 controls horizontal movement; a positive number will
229 move the object to the right.  The second number controls vertical
230 movement; a positive number will move it higher.  The
231 @code{extra-offset} property is a low-level feature: the
232 formatting engine is completely oblivious to these offsets.
233
234 In the following example, the second fingering is moved a little to
235 the left, and 1.8 staff space downwards:
236
237 @lilypond[quote,fragment,relative=1,verbatim]
238 \stemUp
239 f-5
240 \once \override Fingering
241     #'extra-offset = #'(-0.3 . -1.8)
242 f-5
243 @end lilypond
244
245  @item
246 Setting the @code{transparent} property will cause an object to be printed
247 in `invisible ink': the object is not printed, but all its other
248 behavior is retained.  The object still takes up space, it takes part in
249 collisions, and slurs, ties, and beams can be attached to it.
250
251 @cindex transparent objects
252 @cindex removing objects
253 @cindex hiding objects
254 @cindex invisible objects
255 The following example demonstrates how to connect different voices
256 using ties.  Normally, ties only connect two notes in the same
257 voice.  By introducing a tie in a different voice,
258
259 @lilypond[quote,fragment,relative=2]
260 << {
261   b8~ b8\noBeam
262 } \\ {
263   b[ g8]
264 } >>
265 @end lilypond
266
267 @noindent
268 and blanking the first up-stem in that voice, the tie appears to cross
269 voices:
270
271 @lilypond[quote,fragment,relative=2,verbatim]
272 << {
273   \once \override Stem #'transparent = ##t
274   b8~ b8\noBeam
275 } \\ {
276   b[ g8]
277 } >>
278 @end lilypond
279
280 @end itemize
281
282 @cindex Tweaks, distances
283 @cindex Distances
284
285 Distances in LilyPond are measured in staff-spaces, while most
286 thickness properties are measured in line-thickness.  Some
287 properties are different; for example, the thickness of beams
288 are measured in staff-spaces.  For more information, see the
289 relevant portion of the program reference.
290
291
292 @node Default files
293 @section Default files
294
295 The Program Reference documentation contains a lot of information
296 about LilyPond, but even more information can be gathered from
297 looking at the internal LilyPond files.
298
299 Some default settings (such as the definitions for
300 @code{\header@{@}}s) are stored as @code{.ly} files.  Other
301 settings (such as the definitions of markup commands) are
302 stored as @code{.scm} (Scheme) files.  Further explanation is
303 outside the scope of this manual; users should be warned that
304 a substantial amount of technical knowledge or time is required
305 to understand these files.
306
307 @itemize @bullet
308
309 @item Linux: @file{@{INSTALLDIR@}/lilypond/usr/share/lilypond/current/}
310
311 @item OSX:
312 @file{@{INSTALLDIR@}/LilyPond.app/Contents/Resources/share/lilypond/current/}.
313 To access this, either @code{cd} into this directory from
314 the Terminal, or control-click on the LilyPond application
315 and select "Show Package Contents".
316
317 @item Windows: @file{@{INSTALLDIR@}/LilyPond/usr/share/lilypond/current/}
318
319 @end itemize
320
321 The @file{ly/} and @file{scm/} directories will be of
322 particular interest.  Files such as @file{ly/property-init.ly} and
323 @file{ly/declarations-init.ly} define all the common tweaks.
324
325
326 @node Advanced tweaks with Scheme
327 @section Advanced tweaks with Scheme
328
329 We have seen how LilyPond output can be heavily modified using
330 commands like
331 @code{\override TextScript #'extra-offset = ( 1 . -1)}.  But
332 we have even more power if we use Scheme.  For a full explantion
333 of this, see the @ref{Scheme tutorial} and
334 @ref{Interfaces for programmers}.
335
336 We can use Scheme to simply @code{\override} commands,
337
338 @lilypond[quote,verbatim,ragged-right]
339 padText = #(define-music-function (parser location padding) (number?)
340 #{
341   \once \override TextScript #'padding = #$padding
342 #})
343
344 \relative c''' {
345   c4^"piu mosso" b a b
346   \padText #1.8
347   c4^"piu mosso" d e f
348   \padText #2.6
349   c4^"piu mosso" fis a g
350 }
351 @end lilypond
352
353 We can use it to create new commands,
354
355 @lilypond[quote,verbatim,ragged-right]
356 tempoMark = #(define-music-function (parser location padding marktext)
357                                     (number? string?)
358 #{
359   \once \override Score . RehearsalMark #'padding = $padding
360   \once \override Score . RehearsalMark #'no-spacing-rods = ##t
361   \mark \markup { \bold $marktext }
362 #})
363
364 \relative c'' {
365 c2 e
366 \tempoMark #3.0 #"Allegro"
367 g c
368 }
369 @end lilypond
370
371 Even music expressions can be passed in.
372
373 @lilypond[quote,verbatim,ragged-right]
374 pattern = #(define-music-function (parser location x y) (ly:music? ly:music?)
375 #{
376   $x e8 a b $y b a e
377 #})
378
379 \relative c''{
380   \pattern c8 c8\f
381   \pattern {d16 dis} { ais16-> b\p }
382 }
383 @end lilypond
384