]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tricks.itely
8a7e3a539d4bf923851010afe2d30b1e579d035b
[lilypond.git] / Documentation / user / tricks.itely
1 @c -*-texinfo-*-
2 @c Note:
3 @c
4 @c A menu is needed before every deeper *section nesting of @nodes
5 @c Run M-x texinfo-all-menus-update
6 @c to automagically fill in these menus
7 @c before saving changes
8
9 @ignore
10
11 TODO
12   * cue notes
13   * different staff sizes
14   * font selection
15
16   * move some stuff to refman
17   * merge some stuff with refman entries
18   
19   * add @ref{}s to lilypond-internals:
20      @rgrob{Name} to grob
21      @reng{Name} to engraver
22
23   there's a very simple, very general noXXX mechanism; try
24
25 noop    \property Staff.VoltaBrace = #'()
26 yes: \property Staff.VoltaBracket = #'((meta .  ((interfaces . ()))))
27
28
29   visibility?
30   brew_molecule?
31 @end ignore
32
33
34 @node Tricks
35 @chapter Tricks
36
37 @menu
38 * Manual beam settings::        Manual beam settings
39 * Engraver hacking::            Engraver hacking
40 * Part combiner::               Part combiner
41 * Markup text::                 Markup text
42 * Apply hacking::               Apply hacking
43 * Embedded TeX::                Embedded TeX
44 * Embedded PostScript::         Embedded PostScript
45 @end menu
46
47
48 @node Manual beam settings
49 @section Manual beam settings
50 @cindex beams
51 @cindex beam settings
52 @cindex manual beams
53
54
55 @c auto knees
56
57
58 @cindex @code{no-stem-extend}
59
60 Conventionally, stems and beams extend to the middle staff line.  This
61 extension can be controlled through @code{Voice.Stem}'s grob-property
62 @code{no-stem-extend}:
63
64 @quotation
65 @lilypond[fragment,relative,verbatim]
66   \grace a'8 a4
67   \property Voice.Stem \set #'no-stem-extend = ##t
68   \grace g8 g4 [g8 g]
69 @end lilypond
70 @end quotation
71
72 The beam symbol can be tweaked through @code{Voice.Beam}'s
73 grob-properties @code{height} and @code{staff-position},
74 in staff-spaces.
75
76 Set @code{height} to zero, to get horizontal beams:
77
78 @quotation
79 @lilypond[fragment,relative,verbatim]
80   \property Voice.Beam \set #'direction = #1
81   \property Voice.Beam \set #'height = #0
82   [a''8 e' d c]
83 @end lilypond
84 @end quotation
85
86 Here's how you'd specify a weird looking beam that instead of being
87 horizontal, falls two staff spaces:
88
89 @quotation
90 @lilypond[fragment,relative,verbatim]
91   \property Voice.Beam \set #'staff-position = #2
92   \property Voice.Beam \set #'height = #-2
93   [c'8 c] 
94 @end lilypond
95 @end quotation
96 @cindex @code{default-neutral-direction}
97
98 The direction of a perfectly centred beams can be
99 controlled through @code{Voice.Beam}'s grob-property
100 @code{default-neutral-direction}
101
102 @quotation
103 @lilypond[fragment,relative,verbatim]
104   [b''8 b]
105   \property Voice.Beam \set #'default-neutral-direction = #-1
106   [b b]
107 @end lilypond
108 @end quotation
109
110 There are several ways to calculate the direction of a beam.
111 @table @code
112 @item majority
113 number count of up or down notes
114 @item mean
115 mean center distance of all notes
116 @item median
117 mean centre distance weighted per note
118 @end table
119
120 You can spot the differences of these settings from these simple
121 examples:
122
123 @quotation
124 @lilypond[fragment,relative,verbatim]
125   [d''8 a]
126   \property Voice.Beam \set #'dir-function = #beam-dir-mean
127   [d a] 
128   \property Voice.Beam \set #'dir-function = #beam-dir-median
129   [d a]
130 @end lilypond
131 @end quotation
132
133 @quotation    
134 @lilypond[fragment,relative,verbatim]
135   \time 3/8;
136   [d''8 a a]
137   \property Voice.Beam \set #'dir-function = #beam-dir-mean
138   [d a a] 
139   \property Voice.Beam \set #'dir-function = #beam-dir-median
140   [d a a] 
141 @end lilypond
142 @end quotation
143
144 These beam direction functions are defined in @file{scm/beam.scm}.  If
145 your favourite algorithm isn't one of these, you can hook up your own.
146
147
148
149 @node Engraver hacking
150 @section Engraver hacking
151
152 No time signature, no barlines... 
153 @lilypond[verbatim]
154 \score {
155   \notes \relative c'' {
156     a b c d
157     d c b a
158   }
159   \paper {
160     linewidth = -1.;
161     \translator {
162       \StaffContext
163       whichBar = #""
164       \remove "Time_signature_engraver";
165     }
166   }
167 }
168 @end lilypond
169
170 No staff, no clef, squash pitches
171 @lilypond[verbatim]
172 \score {
173   \notes { c4 c4 c8 c8 }
174   \paper {
175     linewidth = -1.;
176     \translator {
177       \StaffContext
178       \remove Staff_symbol_engraver;
179       \consists Pitch_squash_engraver;
180       \remove Clef_engraver;
181     }
182   }
183 }
184 @end lilypond
185
186
187 @node Part combiner
188 @section Part combiner
189
190 @lilypond[verbatim]
191 \score{
192   \context Staff = flauti <
193     \time 4/4;
194     \context Voice=one \partcombine Voice
195     \context Thread=one \notes\relative c'' {
196       c4 d e f | b,4 d c d | r2 e4 f | c4 d e f |
197       c4 r e f | c4 r e f | c4 r a r | a a r a |
198       a2 \property Voice.soloADue = ##f a |
199     }
200     \context Thread=two \notes\relative c'' {
201       g4 b d f | r2 c4 d | a c c d | a4. b8 c4 d
202       c r e r | r2 s2 | a,4 r a r | a r r a |
203       a2 \property Voice.soloADue = ##f a |
204     }
205   >
206   \paper{
207     linewidth = 80 * \staffspace;
208     \translator{
209       \ThreadContext
210       \consists Rest_engraver;
211     }
212     \translator{
213       \VoiceContext
214       \remove Rest_engraver;
215     }
216   }
217 }
218 @end lilypond
219
220
221
222
223 @node Markup text
224 @section Markup text
225
226
227 @ignore
228
229
230 #(define text-flat '((font-relative-size . -2 ) (music "accidentals--1")))
231
232   \property VoiceCombineStaff.instrument = #`((kern . 0.5) (lines
233     "2 Clarinetti" (rows "     (B" ,text-flat ")")))
234
235     % Ugh, markup burps
236     \property StaffCombineStaff.instrument = #'((kern . 0.5)
237     (lines "Violoncello" (rows "     e") (rows "Contrabasso")))
238
239
240 @end ignore
241
242
243
244 Metrome hack...
245
246 [todo: hack this into C++, use \tempo]
247
248 @lilypond[verbatim]
249 #(define note '(rows (music "noteheads-2" ((kern . -0.1) "flags-stem"))))
250 #(define eight-note `(rows ,note ((kern . -0.1) (music ((raise . 3.5) "flags-u3")))))
251 #(define dotted-eight-note `(rows ,eight-note (music "dots-dot")))
252
253 \score {
254   \notes\relative c'' {
255     a1^#`((rows (font-relative-size . -1)) ,dotted-eight-note " = 64")
256   }
257   \paper {
258     linewidth = -1.;
259     \translator{
260       \ScoreContext
261       TextScript \override #'font-shape = #'upright
262     }
263   }
264 }
265 @end lilypond
266
267
268 @c  equalizer
269
270
271 @node Apply hacking
272 @section Apply hacking
273
274 [Add Parenthesed note head example?]
275
276 [Add Smart transpose example?]
277
278
279 @lilypond[verbatim]
280 music = \notes { c'4 d'4( e'4 f'4 }
281
282 #(define (reverse-music music)
283   (let* ((elements (ly-get-mus-property music 'elements))
284          (reversed (reverse elements))
285          (span-dir (ly-get-mus-property music 'span-direction)))
286     
287     (ly-set-mus-property music 'elements reversed)
288     
289     (if (dir? span-dir)
290         (ly-set-mus-property music 'span-direction (- span-dir)))
291     
292     (map reverse-music reversed)
293     
294     music))
295
296 \score {
297   \context Voice {
298     \music
299     \apply #reverse-music \music
300   }
301   \paper { linewidth = -1.; }
302 }
303 @end lilypond
304
305 @node Embedded TeX
306 @section Embedded TeX
307 @lilypond[fragment,relative,verbatim]
308   a''^"3 $\\times$ \\`a deux"
309 @end lilypond
310
311 @node Embedded PostScript
312 @section Embedded PostScript
313
314 Arbitrary lines and curves not supported...
315
316 [TODO:] Make a direct postscript command?
317
318 @lilypond[verbatim]
319 \score {
320   \notes \relative c'' {
321     a-#"\\embeddedps{3 4 moveto 5 3 rlineto stroke}"
322     -#"\\embeddedps{ [ 0 1 ] 0 setdash 3 5 moveto 5 -3 rlineto stroke}"
323     b-#"\\embeddedps{3 4 moveto 0 0 1 2 8 4 20 3.5 rcurveto stroke}"
324     s2
325     a'1
326   }
327   \paper { linewidth = 70 * \staffspace; }
328 }
329 @end lilypond