]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tricks.itely
5e1ac3a3cf6ed74ed8079d52c618a09e68258417
[lilypond.git] / Documentation / user / tricks.itely
1 @c -*-texinfo-*-
2 @ignore
3
4 TODO
5   * cue notes
6   * different staff sizes
7   * font selection
8
9   * move some stuff to refman
10   * merge some stuff with refman entries
11   
12   * add @ref{}s to lilypond-internals:
13      @rgrob{Name} to grob
14      @reng{Name} to engraver
15
16   there's a very simple, very general noXXX mechanism; try
17
18 noop    \property Staff.VoltaBrace = #'()
19 yes: \property Staff.VoltaBracket = #'((meta .  ((interfaces . ()))))
20
21
22   visibility?
23   brew_molecule?
24 @end ignore
25
26
27 @node Tricks
28 @chapter Tricks
29
30 @menu
31 * Manual beam settings::           Manual beam settings
32 * Slur attachments::               Slur attachments
33 * Text spanner::                   Text spanner
34 * Engraver hacking::               Engraver hacking
35 * Part combiner::                  Part combiner
36 * Markup text::                    Markup text
37 * Apply hacking::                  Apply hacking
38 * Output property::                Output property
39 * Embedded TeX::                   Embedded TeX
40 * Embedded PostScript::            Embedded PostScript
41 @c * Index::                          Checking Feature index
42 @end menu
43
44
45 @node Manual beam settings
46 @section Manual beam settings
47 @cindex beams
48 @cindex beam settings
49 @cindex manual beams
50
51
52 @c auto knees
53
54
55
56
57
58 @cindex @code{]}
59
60 In some cases it may be necessary to override LilyPond's automatic
61 beaming algorithm.  For example, the auto beamer will not beam over
62 rests, so if you want that, specify the begin and end point manually
63 using @code{[} and @code{]}:
64
65 @quotation
66 @lilypond[fragment,relative,verbatim]
67   \context Staff {
68     r4 [r8 g'' a]
69   }
70 @end lilypond
71 @end quotation
72
73 Similarly, for beams over bar lines:
74
75 @quotation
76 @lilypond[fragment,relative,verbatim]
77   \context Staff {
78     a''8 r a2 r8 [a a]
79   }
80 @end lilypond
81 @end quotation
82 @cindex @code{stemLeftBeamCount}
83
84 If you have specific wishes for the number of beams, you can fully
85 control the number of beams through the properties
86 @code{Voice.stemLeftBeamCount};
87
88 @quotation
89 @lilypond[fragment,relative,verbatim]
90   \context Staff {
91     [f'8 r16 f g a]
92     [f8 r16 \property Voice.stemLeftBeamCount = #1 f g a]
93   }
94 @end lilypond
95 @end quotation
96 @cindex @code{stemRightBeamCount}
97
98 and @code{Voice.stemRightBeamCount}:
99  
100 @quotation
101 @lilypond[fragment,relative,verbatim]
102   f'32 g a b b a g f
103
104   \property Voice.autoBeamSettings
105     \set #'(end * * * *) = #(make-moment 1 4)
106   f32 g a b b a g f
107
108   f32 g a
109   \property Voice.stemRightBeamCount = #1 b
110   \property Voice.stemLeftBeamCount = #1 b
111   a g f
112 @end lilypond
113 @end quotation
114 @cindex @code{no-stem-extend}
115
116 Conventionally, stems and beams extend to the middle staff line.  This
117 extension can be controlled through @code{Voice.Stem}'s grob-property
118 @code{no-stem-extend}:
119
120 @quotation
121 @lilypond[fragment,relative,verbatim]
122   \grace a'8 a4
123   \property Voice.Stem \set #'no-stem-extend = ##t
124   \grace g8 g4 [g8 g]
125 @end lilypond
126 @end quotation
127
128 The beam symbol can be tweaked through @code{Voice.Beam}'s
129 grob-properties @code{height-hs} and @code{y-position-hs}.
130
131 Set @code{height-hs} to zero, to get horizontal beams:
132
133 @quotation
134 @lilypond[fragment,relative,verbatim]
135   \property Voice.Beam \set #'direction = #1
136   \property Voice.Beam \set #'height-hs = #0
137   [a''8 e' d c]
138 @end lilypond
139 @end quotation
140
141 Both are in half spaces.  Here's how you'd specify a weird looking beam
142 that instead of being horizontal, falls two staff spaces (ie, four half
143 spaces):
144
145 @quotation
146 @lilypond[fragment,relative,verbatim]
147   \property Voice.Beam \set #'y-position-hs = #4
148   \property Voice.Beam \set #'height-hs = #-4
149   [c'8 c] 
150 @end lilypond
151 @end quotation
152 @cindex @code{default-neutral-direction}
153
154 The direction of a perfectly centred beams can be
155 controlled through @code{Voice.Beam}'s grob-property
156 @code{default-neutral-direction}
157
158 @quotation
159 @lilypond[fragment,relative,verbatim]
160   [b''8 b]
161   \property Voice.Beam \set #'default-neutral-direction = #-1
162   [b b]
163 @end lilypond
164 @end quotation
165
166 There are several ways to calculate the direction of a beam.
167 @table @code
168 @item majority
169 number count of up or down notes
170 @item mean
171 mean center distance of all notes
172 @item median
173 mean centre distance weighted per note
174 @end table
175
176 You can spot the differences of these settings from these simple
177 examples:
178
179 @quotation
180 @lilypond[fragment,relative,verbatim]
181   [d''8 a]
182   \property Voice.Beam \set #'dir-function = #beam-dir-mean
183   [d a] 
184   \property Voice.Beam \set #'dir-function = #beam-dir-median
185   [d a]
186 @end lilypond
187 @end quotation
188
189 @quotation    
190 @lilypond[fragment,relative,verbatim]
191   \time 3/8;
192   [d''8 a a]
193   \property Voice.Beam \set #'dir-function = #beam-dir-mean
194   [d a a] 
195   \property Voice.Beam \set #'dir-function = #beam-dir-median
196   [d a a] 
197 @end lilypond
198 @end quotation
199
200 These beam direction functions are defined in @file{scm/beam.scm}.  If
201 your favourite algorithm isn't one of these, you can hook up your own.
202
203
204
205 @node Slur attachments
206 @section Slur attachments
207
208 The ending of a slur should whenever possible be attached to a note
209 head.  Only in some instances where beams are involved, LilyPond may
210 attach a slur to a stem end.  In some cases, you may want to override
211 LilyPond's decision, e.g., to attach the slur to the stem end.  This can
212 be done through @code{Voice.Slur}'s grob-property @code{attachment}:
213 @c FIXME: make @ref{} to backend doco
214
215 @quotation
216 @lilypond[fragment,relative,verbatim]
217   \property Voice.Slur \set #'direction = #1
218   \property Voice.Stem \set #'length = #5.5
219   g''8(g)g4
220   \property Voice.Slur \set #'attachment = #'(stem . stem)
221   g8(g)g4
222 @end lilypond
223 @end quotation
224
225 Similarly, slurs can be attached to note heads even when beams are
226 involved:
227
228 @quotation
229 @lilypond[fragment,relative,verbatim]
230   \property Voice.Slur \set #'direction = #1
231   \property Voice.Slur \set #'attachment = #'(head . head)
232   g''16()g()g()g()d'()d()d()d
233 @end lilypond
234 @end quotation
235
236 If a slur would strike through a stem or beam, LilyPond will move the
237 slur away vertically (upward or downward).  In some cases, this may
238 cause ugly slurs that you may want to correct:
239
240 @quotation
241 @lilypond[fragment,relative,verbatim]
242   \property Voice.Stem \set #'direction = #1
243   \property Voice.Slur \set #'direction = #1
244   d'32( d'4 )d8..
245   \property Voice.Slur \set #'attachment = #'(stem . stem)
246   d,32( d'4 )d8..
247 @end lilypond
248 @end quotation
249
250 LilyPond will increase the curvature of a slur trying to stay free of
251 note heads and stems.  However, if the curvature would increase too much,
252 the slur will be reverted to its default shape.  This decision is based
253 on @code{Voice.Slur}'s grob-property @code{beautiful} value.  In some
254 cases, you may find ugly slurs beautiful, and tell LilyPond so by
255 increasing the @code{beautiful} value:
256
257 [hoe  gedefd?? wat betekent beautiful = X?]
258
259 @quotation
260 @lilypond[verbatim]
261 \score {
262   \notes \context PianoStaff <
263     \time 6/4;
264     \context Staff=up { s1 * 6/4 }
265     \context Staff=down <
266       \clef bass;
267       \autochange Staff \context Voice
268         \notes \relative c {
269           d,8( a' d f a d f d a f d )a
270         }
271     >
272   >
273   \paper {
274     linewidth = -1.;
275     \translator {
276       \VoiceContext
277       Slur \override #'beautiful = #5.0
278       Slur \override #'direction = #1
279       Stem \override #'direction = #-1
280       autoBeamSettings \override #'(end * * * *)
281         = #(make-moment 1 2)
282     }
283     \translator {
284       \PianoStaffContext
285       VerticalAlignment \override #'threshold = #'(5 . 5)
286     }
287   }
288 }
289 @end lilypond
290 @end quotation
291
292
293 @node Text spanner
294 @section Text spanner
295
296
297
298 Have crescendo set a text spanner instead of hairpin
299
300 @lilypond[fragment,relative,verbatim]
301   \context Voice {
302     \property Voice.crescendoText = "cresc."
303     \property Voice.crescendoSpanner = #'dashed-line
304     a''2\mf\< a a \!a 
305   }
306 @end lilypond
307
308 @subsection Ottava
309
310 @lilypond[fragment,relative,verbatim]
311   a'''' b c a
312   \property Voice.TextSpanner \set #'type = #'dotted-line
313   \property Voice.TextSpanner \set #'edge-height = #'(0 . 1.5)
314   \property Voice.TextSpanner \set #'edge-text = #'("8va " . "")
315   \property Staff.centralCPosition = #-13
316   a\spanrequest \start "text" b c a \spanrequest \stop "text"
317 @end lilypond
318
319
320
321 @node Engraver hacking
322 @section Engraver hacking
323
324 No time signature, no barlines... 
325 @lilypond[verbatim]
326 \score {
327   \notes \relative c'' {
328     a b c d
329     d c b a
330   }
331   \paper {
332     linewidth = -1.;
333     \translator {
334       \StaffContext
335       whichBar = #""
336       \remove "Time_signature_engraver";
337     }
338   }
339 }
340 @end lilypond
341
342 No staff, no clef, squash pitches
343 @lilypond[verbatim]
344 \score {
345   \notes { c4 c4 c8 c8 }
346   \paper {
347     linewidth = -1.;
348     \translator {
349       \StaffContext
350       \remove Staff_symbol_engraver;
351       \consists Pitch_squash_engraver;
352       \remove Clef_engraver;
353     }
354   }
355 }
356 @end lilypond
357
358
359 @node Part combiner
360 @section Part combiner
361
362 @lilypond[verbatim]
363 \score{
364   \context Staff = flauti <
365     \time 4/4;
366     \context Voice=one \partcombine Voice
367     \context Thread=one \notes\relative c'' {
368       c4 d e f | b,4 d c d | r2 e4 f | c4 d e f |
369       c4 r e f | c4 r e f | c4 r a r | a a r a |
370       a2 \property Voice.soloADue = ##f a |
371     }
372     \context Thread=two \notes\relative c'' {
373       g4 b d f | r2 c4 d | a c c d | a4. b8 c4 d
374       c r e r | r2 s2 | a,4 r a r | a r r a |
375       a2 \property Voice.soloADue = ##f a |
376     }
377   >
378   \paper{
379     linewidth = 80 * \staffspace;
380     \translator{
381       \ThreadContext
382       \consists Rest_engraver;
383     }
384     \translator{
385       \VoiceContext
386       \remove Rest_engraver;
387     }
388   }
389 }
390 @end lilypond
391
392
393
394
395 @node Markup text
396 @section Markup text
397
398
399 @ignore
400
401
402 #(define text-flat '((font-relative-size . -2 ) (music "accidentals--1")))
403
404   \property VoiceCombineStaff.instrument = #`((kern . 0.5) (lines
405     "2 Clarinetti" (rows "     (B" ,text-flat ")")))
406
407     % Ugh, markup burps
408     \property StaffCombineStaff.instrument = #'((kern . 0.5)
409     (lines "Violoncello" (rows "     e") (rows "Contrabasso")))
410
411
412 @end ignore
413
414
415
416 Metrome hack...
417
418 [todo: hack this into C++, use \tempo]
419
420 @lilypond[verbatim]
421 #(define note '(rows (music "noteheads-2" ((kern . -0.1) "flags-stem"))))
422 #(define eight-note `(rows ,note ((kern . -0.1) (music ((raise . 3.5) "flags-u3")))))
423 #(define dotted-eight-note `(rows ,eight-note (music "dots-dot")))
424
425 \score {
426   \notes\relative c'' {
427     a1^#`(rows ,dotted-eight-note " = 64")
428   }
429   \paper {
430     linewidth = -1.;
431     \translator{
432       \ScoreContext
433       TextScript \override #'font-shape = #'upright
434     }
435   }
436 }
437 @end lilypond
438
439
440 @node Output property
441 @section Output property
442
443 @lilypond[fragment,relative,verbatim]
444     \outputproperty #(make-type-checker 'note-head-interface) 
445       #'extra-offset = #'(2 . 3)
446     c''2 c
447 @end lilypond
448
449 Don't move the finger 2, only text "m.d." ...
450 @lilypond[verbatim]
451 #(define (make-text-checker text)
452    (lambda (grob) (equal? text (ly-get-elt-property grob 'text))))
453
454 \score {    
455   \notes\relative c''' {
456     \property Voice.Stem \set #'direction = #1
457     \outputproperty #(make-text-checker "m.d.")
458       #'extra-offset = #'(-3.5 . -4.5)
459     a^2^"m.d."    
460   }
461   \paper { linewidth = -1.; }
462 }
463 @end lilypond
464
465
466 @c  equalizer
467
468
469 @node Apply hacking
470 @section Apply hacking
471
472 @lilypond[verbatim]
473 music = \notes { c'4 d'4( e'4 f'4 }
474
475 #(define (reverse-music music)
476   (let* ((elements (ly-get-mus-property music 'elements))
477          (reversed (reverse elements))
478          (span-dir (ly-get-mus-property music 'span-direction)))
479     
480     (ly-set-mus-property music 'elements reversed)
481     
482     (if (dir? span-dir)
483         (ly-set-mus-property music 'span-direction (- span-dir)))
484     
485     (map reverse-music reversed)
486     
487     music))
488
489 \score {
490   \context Voice {
491     \music
492     \apply #reverse-music \music
493   }
494   \paper { linewidth = -1.; }
495 }
496 @end lilypond
497
498 @node Embedded TeX
499 @section Embedded TeX
500 @lilypond[fragment,relative,verbatim]
501   a''^"3 $\\times$ \\`a deux"
502 @end lilypond
503
504 @node Embedded PostScript
505 @section Embedded PostScript
506
507 Arbitrary lines and curves not supported...
508
509 [TODO:] Make a direct postscript command?
510
511 @lilypond[verbatim]
512 \score {
513   \notes \relative c'' {
514     a-#"\\embeddedps{3 4 moveto 5 3 rlineto stroke}"
515     -#"\\embeddedps{ [ 0 1 ] 0 setdash 3 5 moveto 5 -3 rlineto stroke}"
516     b-#"\\embeddedps{3 4 moveto 0 0 1 2 8 4 20 3.5 rcurveto stroke}"
517     s2
518     a'1
519   }
520   \paper { linewidth = 70 * \staffspace; }
521 }
522 @end lilypond
523
524 @ignore 
525 @node Index
526 @section Checking Feature index
527
528 @printindex cp
529
530
531 @bye
532 @end ignore
533
534