]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tricks.itely
cc5c4ed48a6c7ed4ff0bdd1270b3923ddcac556f
[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 * Markup text::                 Markup text
41 * Apply hacking::               Apply hacking
42 * Embedded TeX::                Embedded TeX
43 * Embedded PostScript::         Embedded PostScript
44 @end menu
45
46
47 @node Manual beam settings
48 @section Manual beam settings
49 @cindex beams
50 @cindex beam settings
51 @cindex manual beams
52
53
54 @c auto knees
55
56
57 @cindex @code{no-stem-extend}
58
59 Conventionally, stems and beams extend to the middle staff line.  This
60 extension can be controlled through @code{Voice.Stem}'s grob-property
61 @code{no-stem-extend}:
62
63 @quotation
64 @lilypond[fragment,relative,verbatim]
65   \grace a'8 a4
66   \property Voice.Stem \set #'no-stem-extend = ##t
67   \grace g8 g4 [g8 g]
68 @end lilypond
69 @end quotation
70
71 The beam symbol can be tweaked through @code{Voice.Beam}'s
72 grob-properties @code{height} and @code{staff-position},
73 in staff-spaces.
74
75 Set @code{height} to zero, to get horizontal beams:
76
77 @quotation
78 @lilypond[fragment,relative,verbatim]
79   \property Voice.Beam \set #'direction = #1
80   \property Voice.Beam \set #'height = #0
81   [a''8 e' d c]
82 @end lilypond
83 @end quotation
84
85 Here's how you'd specify a weird looking beam that instead of being
86 horizontal, falls two staff spaces:
87
88 @quotation
89 @lilypond[fragment,relative,verbatim]
90   \property Voice.Beam \set #'staff-position = #2
91   \property Voice.Beam \set #'height = #-2
92   [c'8 c] 
93 @end lilypond
94 @end quotation
95 @cindex @code{default-neutral-direction}
96
97 The direction of a perfectly centred beams can be
98 controlled through @code{Voice.Beam}'s grob-property
99 @code{default-neutral-direction}
100
101 @quotation
102 @lilypond[fragment,relative,verbatim]
103   [b''8 b]
104   \property Voice.Beam \set #'default-neutral-direction = #-1
105   [b b]
106 @end lilypond
107 @end quotation
108
109 There are several ways to calculate the direction of a beam.
110 @table @code
111 @item majority
112 number count of up or down notes
113 @item mean
114 mean center distance of all notes
115 @item median
116 mean centre distance weighted per note
117 @end table
118
119 You can spot the differences of these settings from these simple
120 examples:
121
122 @quotation
123 @lilypond[fragment,relative,verbatim]
124   [d''8 a]
125   \property Voice.Beam \set #'dir-function = #beam-dir-mean
126   [d a] 
127   \property Voice.Beam \set #'dir-function = #beam-dir-median
128   [d a]
129 @end lilypond
130 @end quotation
131
132 @quotation    
133 @lilypond[fragment,relative,verbatim]
134   \time 3/8;
135   [d''8 a a]
136   \property Voice.Beam \set #'dir-function = #beam-dir-mean
137   [d a a] 
138   \property Voice.Beam \set #'dir-function = #beam-dir-median
139   [d a a] 
140 @end lilypond
141 @end quotation
142
143 These beam direction functions are defined in @file{scm/beam.scm}.  If
144 your favourite algorithm isn't one of these, you can hook up your own.
145
146
147
148 @node Engraver hacking
149 @section Engraver hacking
150
151 No time signature, no barlines... 
152 @lilypond[verbatim]
153 \score {
154   \notes \relative c'' {
155     a b c d
156     d c b a
157   }
158   \paper {
159     linewidth = -1.;
160     \translator {
161       \StaffContext
162       whichBar = #""
163       \remove "Time_signature_engraver";
164     }
165   }
166 }
167 @end lilypond
168
169 No staff, no clef, squash pitches
170 @lilypond[verbatim]
171 \score {
172   \notes { c4 c4 c8 c8 }
173   \paper {
174     linewidth = -1.;
175     \translator {
176       \StaffContext
177       \remove Staff_symbol_engraver;
178       \consists Pitch_squash_engraver;
179       \remove Clef_engraver;
180     }
181   }
182 }
183 @end lilypond
184
185
186
187 @node Markup text
188 @section Markup text
189
190
191 @ignore
192
193
194 #(define text-flat '((font-relative-size . -2 ) (music "accidentals--1")))
195
196   \property VoiceCombineStaff.instrument = #`((kern . 0.5) (lines
197     "2 Clarinetti" (rows "     (B" ,text-flat ")")))
198
199     % Ugh, markup burps
200     \property StaffCombineStaff.instrument = #'((kern . 0.5)
201     (lines "Violoncello" (rows "     e") (rows "Contrabasso")))
202
203
204 @end ignore
205
206
207
208 Metrome hack...
209
210 [todo: hack this into C++, use \tempo]
211
212 @lilypond[verbatim]
213 #(define note '(rows (music "noteheads-2" ((kern . -0.1) "flags-stem"))))
214 #(define eight-note `(rows ,note ((kern . -0.1) (music ((raise . 3.5) "flags-u3")))))
215 #(define dotted-eight-note `(rows ,eight-note (music "dots-dot")))
216
217 \score {
218   \notes\relative c'' {
219     a1^#`((rows (font-relative-size . -1)) ,dotted-eight-note " = 64")
220   }
221   \paper {
222     linewidth = -1.;
223     \translator{
224       \ScoreContext
225       TextScript \override #'font-shape = #'upright
226     }
227   }
228 }
229 @end lilypond
230
231
232 @c  equalizer
233
234
235 @node Apply hacking
236 @section Apply hacking
237
238 [Add Parenthesed note head example?]
239
240 [Add Smart transpose example?]
241
242
243 @lilypond[verbatim]
244 music = \notes { c'4 d'4( e'4 f'4 }
245
246 #(define (reverse-music music)
247   (let* ((elements (ly-get-mus-property music 'elements))
248          (reversed (reverse elements))
249          (span-dir (ly-get-mus-property music 'span-direction)))
250     
251     (ly-set-mus-property music 'elements reversed)
252     
253     (if (dir? span-dir)
254         (ly-set-mus-property music 'span-direction (- span-dir)))
255     
256     (map reverse-music reversed)
257     
258     music))
259
260 \score {
261   \context Voice {
262     \music
263     \apply #reverse-music \music
264   }
265   \paper { linewidth = -1.; }
266 }
267 @end lilypond
268
269 @node Embedded TeX
270 @section Embedded TeX
271 @lilypond[fragment,relative,verbatim]
272   a''^"3 $\\times$ \\`a deux"
273 @end lilypond
274
275 @node Embedded PostScript
276 @section Embedded PostScript
277
278 Arbitrary lines and curves not supported...
279
280 [TODO:] Make a direct postscript command?
281
282 @lilypond[verbatim]
283 \score {
284   \notes \relative c'' {
285     a-#"\\embeddedps{3 4 moveto 5 3 rlineto stroke}"
286     -#"\\embeddedps{ [ 0 1 ] 0 setdash 3 5 moveto 5 -3 rlineto stroke}"
287     b-#"\\embeddedps{3 4 moveto 0 0 1 2 8 4 20 3.5 rcurveto stroke}"
288     s2
289     a'1
290   }
291   \paper { linewidth = 70 * \staffspace; }
292 }
293 @end lilypond