]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/learning/tweaks.itely
Merge branch 'master' into translation
[lilypond.git] / Documentation / learning / tweaks.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  For details, see the Contributors'
8     Guide, node Updating translation committishes..
9 @end ignore
10
11 @c \version "2.19.16"
12
13 @node Tweaking output
14 @chapter Tweaking output
15
16 This chapter discusses how to modify output.  LilyPond is extremely
17 configurable; virtually every fragment of output may be changed.
18
19
20 @menu
21 * Tweaking basics::
22 * The Internals Reference manual::
23 * Appearance of objects::
24 * Placement of objects::
25 * Vertical spacing::
26 * Collisions of objects::
27 * Further tweaking::
28 @end menu
29
30 @node Tweaking basics
31 @section Tweaking basics
32
33 @menu
34 * Introduction to tweaks::
35 * Objects and interfaces::
36 * Naming conventions of objects and properties::
37 * Tweaking methods::
38 @end menu
39
40 @node Introduction to tweaks
41 @subsection Introduction to tweaks
42
43 @q{Tweaking} is a LilyPond term for the various methods available
44 to the user for modifying the actions taken during interpretation
45 of the input file and modifying the appearance of the printed
46 output.  Some tweaks are very easy to use; others are more
47 complex.  But taken together the methods available for tweaking
48 permit almost any desired appearance of the printed music to be
49 achieved.
50
51 In this section we cover the basic concepts required to understand
52 tweaking.  Later we give a variety of ready-made commands which can
53 simply be copied to obtain the same effect in your own scores, and
54 at the same time we show how these commands may be constructed so
55 that you may learn how to develop your own tweaks.
56
57 Before starting on this Chapter you may wish to review the section
58 @ref{Contexts and engravers}, as Contexts, Engravers, and the
59 Properties contained within them are fundamental to understanding
60 and constructing Tweaks.
61
62 @node Objects and interfaces
63 @subsection Objects and interfaces
64
65 @cindex object
66 @cindex grob
67 @cindex spanner
68 @cindex interface
69 @cindex properties, object
70 @cindex object properties
71 @cindex layout object
72 @cindex object, layout
73 @cindex interface
74
75 Tweaking involves modifying the internal operation and structures
76 of the LilyPond program, so we must first introduce some terms
77 which are used to describe those internal operations and
78 structures.
79
80 The term @q{Object} is a generic term used to refer to the
81 multitude of internal structures built by LilyPond during the
82 processing of an input file.  So when a command like @code{\new
83 Staff} is encountered a new object of type @code{Staff} is
84 constructed.  That @code{Staff} object then holds all the
85 properties associated with that particular staff, for example, its
86 name and its key signature, together with details of the engravers
87 which have been assigned to operate within that staff's context.
88 Similarly, there are objects to hold the properties of all other
89 contexts, such as @code{Voice} objects, @code{Score} objects,
90 @code{Lyrics} objects, as well as objects to represent all
91 notational elements such as bar lines,
92 note heads, ties, dynamics, etc.  Every object has its own set of
93 property values.
94
95 Some types of object are given special names.  Objects which represent
96 items of notation on the printed output such as note heads, stems,
97 slurs, ties, fingering, clefs, etc are called @q{Layout objects},
98 often known as @q{Graphical Objects}, or @q{Grobs} for short.  These
99 are still objects in the generic sense above, and so they too all have
100 properties associated with them, such as their position, size, color,
101 etc.
102
103 Some layout objects are still more specialized.  Phrasing slurs,
104 crescendo hairpins, ottava marks, and many other grobs are not
105 localized in a single place -- they have a starting point, an
106 ending point, and maybe other properties concerned with their
107 shape.  Objects with an extended shape like these are called
108 @q{Spanners}.
109
110 What is more, there are @q{abstract} grobs which do not print
111 anything of their own, but rather collect, position and manage
112 other grobs.  Common examples for this are
113 @code{DynamicLineSpanner}, @code{BreakAlignment},
114 @code{NoteColumn}, @code{VerticalAxisGroup},
115 @code{NonMusicalPaperColumn} and similar.  We will see how some of
116 these are used later.
117
118 It remains to explain what @q{Interfaces} are.  Many objects, even
119 though they are quite different, share common features which need to
120 be processed in the same way.  For example, all grobs have a color, a
121 size, a position, etc, and all these properties are processed in the
122 same way during LilyPond's interpretation of the input file.  To
123 simplify these internal operations these common actions and properties
124 are grouped together in an object called a @code{grob-interface}.
125 There are many other groupings of common properties like this, each
126 one given a name ending in @code{interface}.  In total there are over
127 100 such interfaces.  We shall see later why this is of interest and
128 use to the user.
129
130 These, then, are the main terms relating to objects which we
131 shall use in this chapter.
132
133 @node Naming conventions of objects and properties
134 @subsection Naming conventions of objects and properties
135
136 @cindex naming conventions for objects
137 @cindex naming conventions for properties
138 @cindex objects, naming conventions
139 @cindex properties, naming conventions
140
141 We met some object naming conventions previously, in
142 @ref{Contexts and engravers}.  Here for reference is a list
143 of the most common object and property types together with
144 the conventions for naming them and a couple of examples of
145 some real names.  We have used @q{A} to stand for any capitalized
146 alphabetic character and @q{aaa} to stand for any number of
147 lower-case alphabetic characters.  Other characters are used
148 verbatim.
149
150 @multitable @columnfractions .33 .33 .33
151 @headitem Object/property type
152   @tab Naming convention
153   @tab Examples
154 @item Contexts
155   @tab Aaaa or AaaaAaaaAaaa
156   @tab Staff, GrandStaff
157 @item Layout Objects
158   @tab Aaaa or AaaaAaaaAaaa
159   @tab Slur, NoteHead
160 @item Engravers
161   @tab Aaaa_aaa_engraver
162   @tab Clef_engraver, Note_heads_engraver
163 @item Interfaces
164   @tab aaa-aaa-interface
165   @tab grob-interface, break-aligned-interface
166 @item Context Properties
167   @tab aaa or aaaAaaaAaaa
168   @tab alignAboveContext, skipBars
169 @item Layout Object Properties
170   @tab aaa or aaa-aaa-aaa
171   @tab direction, beam-thickness
172 @end multitable
173
174 As we shall see shortly, the properties of different types of object are
175 modified by different commands, so it is useful to be able to recognize
176 the types of objects and properties from their names.
177
178
179 @node Tweaking methods
180 @subsection Tweaking methods
181
182 @cindex tweaking methods
183
184 @menu
185 * The override command::
186 * The revert command::
187 * The once prefix::
188 * The overrideProperty command::
189 * The tweak command::
190 * The single prefix::
191 @end menu
192
193 @node The override command
194 @unnumberedsubsubsec The @code{@bs{}override} command
195
196 @cindex override command
197 @cindex override syntax
198
199 @funindex \override
200 @funindex override
201
202 We have already met the commands @code{\set} and @code{\with}, used to
203 change the properties of @strong{contexts} and to remove and add
204 @strong{engravers}, in @ref{Modifying context properties}, and
205 @ref{Adding and removing engravers}.  We must now introduce some more
206 important commands.
207
208 The command to change the properties of @strong{layout objects} is
209 @code{\override}.  Because this command has to modify
210 internal properties deep within LilyPond its syntax is not
211 as simple as the commands you have used so far.  It needs to
212 know precisely which property of which object in which context
213 has to be modified, and what its new value is to be.  Let's see
214 how this is done.
215
216 The general syntax of this command is:
217
218 @example
219 \override @var{Context}.@var{LayoutObject}.@var{layout-property} = #@var{value}
220 @end example
221
222 @noindent
223 This will set the property with the name @var{layout-property} of the
224 layout object with the name @var{LayoutObject}, which is a member of
225 the @var{Context} context, to the value @var{value}.
226
227 The @var{Context} may be omitted (and usually is) when the
228 required context is unambiguously implied and is one of lowest
229 level contexts, i.e., @code{Voice}, @code{ChordNames} or
230 @code{Lyrics}, and we shall omit it in many of the following
231 examples.  We shall see later when it must be specified.
232
233 Later sections deal comprehensively with properties and their
234 values, see @ref{Types of properties}.  But in this section we shall
235 use just a few simple properties and values which are easily
236 understood in order to illustrate the format and use of these
237 commands.
238
239 LilyPond's primary expressions are musical items like notes,
240 durations, and markups.  More basic expressions like numbers,
241 strings, and lists are processed in @q{Scheme mode}, which is
242 invoked by prefixing the value with @samp{#}.  Although the
243 values may sometimes have a valid representation in LilyPond's
244 musical mode, this manual will always use @samp{#} for their
245 entry for the sake of consistency.  For more information about
246 Scheme mode, see @rextend{LilyPond Scheme syntax}.
247
248 @code{\override} is the most common command used in tweaking, and
249 most of the rest of this chapter will be directed to presenting
250 examples of how it is used.  Here is a simple example to change the
251 color of the note head:
252
253 @cindex color property, example
254 @cindex NoteHead, example of overriding
255
256 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
257 c4 d
258 \override NoteHead.color = #red
259 e4 f |
260 \override NoteHead.color = #green
261 g4 a b c |
262 @end lilypond
263
264
265 @node The revert command
266 @unnumberedsubsubsec The @code{@bs{}revert} command
267
268 @cindex revert command
269
270 @funindex \revert
271 @funindex revert
272
273 Once overridden, the property retains its new value until it is
274 overridden again or a @code{\revert} command is encountered.
275 The @code{\revert} command has the following syntax and causes
276 the value of the property to revert to its original default
277 value; note, not its previous value if several @code{\override}
278 commands have been issued.
279
280 @example
281 \revert @var{Context}.@var{LayoutObject}.@var{layout-property}
282 @end example
283
284 Again, just like @var{Context} in the @code{\override} command,
285 @var{Context} is often not needed.  It will be omitted
286 in many of the following examples.  Here we revert the color
287 of the note head to the default value for the final two notes:
288
289 @cindex color property, example
290 @cindex NoteHead, example of overriding
291
292 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
293 c4 d
294 \override NoteHead.color = #red
295 e4 f |
296 \override NoteHead.color = #green
297 g4 a
298 \revert NoteHead.color
299 b4 c |
300 @end lilypond
301
302
303 @node The once prefix
304 @unnumberedsubsubsec The @code{@bs{}once} prefix
305
306 @funindex \once
307 @funindex once
308
309 Both the @code{\override} and the @code{\set} commands may be prefixed
310 by @code{\once}.  This causes the following @code{\override} or
311 @code{\set} command to be effective only during the current musical
312 moment before the property reverts back to its previous value (this can
313 be different from the default if another @code{\override} is still in
314 effect).  Using the same example, we can change the color of a single
315 note like this:
316
317 @cindex color property, example
318 @cindex NoteHead, example of overriding
319
320 @lilypond[quote,verbatim,relative=1]
321 c4 d
322 \override NoteHead.color = #red
323 e4 f |
324 \once \override NoteHead.color = #green
325 g4 a
326 \revert NoteHead.color
327 b c |
328 @end lilypond
329
330 The @code{\once} prefix may also be used in front of many
331 predefined commands to limit their effect to one musical moment:
332
333 @lilypond[quote,verbatim,relative=1]
334 c4 d
335 \once \stemDown
336 e4 f |
337 g4 a
338 \once \hideNotes
339 b c |
340 @end lilypond
341
342 However, predefined commands of the form @code{\@dots{}Neutral},
343 @code{\@dots{}Off} and @code{\un@dots{}} use @code{\revert} internally
344 rather than @code{\override} so prefixing these with @code{\once} has no
345 effect.
346
347
348 @node The overrideProperty command
349 @unnumberedsubsubsec The @code{@bs{}overrideProperty} command
350
351 @cindex overrideProperty command
352
353 @funindex \overrideProperty
354 @funindex overrideProperty
355
356 There is another form of the override command,
357 @code{\overrideProperty}, which is occasionally required.
358 We mention it here for completeness, but for details see
359 @rextend{Difficult tweaks}.
360 @c Maybe explain in a later iteration  -td
361
362
363 @node The tweak command
364 @unnumberedsubsubsec The @code{@bs{}tweak} command
365
366 @cindex tweak command
367
368 @funindex \tweak
369 @funindex tweak
370
371 The final tweaking command which is available is @code{\tweak}.  This
372 should be used when several objects occur at the same musical moment,
373 but you only want to change the properties of selected ones, such as a
374 single note within a chord.  Using @code{\override} would affect all the
375 notes within a chord, whereas @code{\tweak} affects just the following
376 item in the input stream.
377
378 Here's an example.  Suppose we wish to change the size of the
379 middle note head (the E) in a C major chord.  Let's first see what
380 @code{\once \override} would do:
381
382 @cindex font-size property, example
383 @cindex NoteHead, example of overriding
384
385 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
386 <c e g>4
387 \once \override NoteHead.font-size = #-3
388 <c e g>4
389 <c e g>4
390 @end lilypond
391
392 We see the override affects @emph{all} the note heads in the chord.
393 This is because all the notes of a chord occur at the same
394 @emph{musical moment}, and the action of @code{\once} is to
395 apply the override to all layout objects of the type specified
396 which occur at the same musical moment as the @code{\override}
397 command itself.
398
399 The @code{\tweak} command operates in a different way.  It acts on
400 the immediately following item in the input stream.  In its simplest
401 form, it is effective only on objects which are created directly
402 from the following item, essentially note heads and articulations.
403
404 So to return to our example, the size of the middle note of
405 a chord would be changed in this way:
406
407 @cindex font-size property, example
408 @cindex @code{\tweak}, example
409
410 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
411 <c e g>4
412 <c \tweak font-size #-3 e g>4
413 @end lilypond
414
415 Note that the syntax of @code{\tweak} is different from that of the
416 @code{\override} command.  The context should not be specified; in
417 fact, it would generate an error to do so.  Both context and layout
418 object are implied by the following item in the input stream.  Note
419 also that an equals sign should not be present.  So the simple form
420 of the @code{\tweak} command is
421
422 @example
423 \tweak @var{layout-property} #@var{value}
424 @end example
425
426 A @code{\tweak} command can also be used to modify just one in
427 a series of articulations, as shown here:
428
429 @cindex color property, example
430 @cindex @code{\tweak}, example
431
432 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
433 a4^"Black"
434   -\tweak color #red ^"Red"
435   -\tweak color #green _"Green"
436 @end lilypond
437
438 @noindent
439 Note that the @code{\tweak} command must be preceded by an articulation
440 mark since the tweaked expression needs to be applied as an articulation
441 itself.  In case of multiple direction overrides (@code{^} or @code{_}),
442 the leftmost override wins since it is applied last.
443
444 @cindex @code{\tweak}, Accidental
445 @cindex @code{\tweak}, specific layout object
446
447 Objects such as stems and accidentals are created later, and not
448 directly from the following event.  It is still possible to use
449 @code{\tweak} on such indirectly created objects by explicitly naming
450 the layout object, provided that LilyPond can trace its origin back to
451 the original event:
452
453 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
454 <\tweak Accidental.color #red   cis4
455  \tweak Accidental.color #green es
456  g>
457 @end lilypond
458
459 This long form of the @code{\tweak} command can be described as
460
461 @example
462 \tweak @var{LayoutObject}.@var{layout-property} #@var{value}
463 @end example
464
465 @cindex tuplets, nested
466 @cindex triplets, nested
467 @cindex bracket, tuplet
468 @cindex bracket, triplet
469 @cindex tuplet bracket
470 @cindex triplet bracket
471
472 @funindex TupletBracket
473
474 The @code{\tweak} command must also be used to change the
475 appearance of one of a set of nested tuplets which begin at the
476 same musical moment.  In the following example, the long tuplet
477 bracket and the first of the three short brackets begin at the
478 same musical moment, so any @code{\override} command would apply
479 to both of them.  In the example, @code{\tweak} is used to
480 distinguish between them.  The first @code{\tweak} command
481 specifies that the long tuplet bracket is to be placed above the
482 notes and the second one specifies that the tuplet number is to be
483 printed in red on the first short tuplet bracket.
484
485 @cindex @code{\tweak}, example
486 @cindex direction property, example
487 @cindex color property, example
488
489 @lilypond[quote,ragged-right,verbatim,fragment,relative=2]
490 \tweak direction #up
491 \tuplet 3/4 {
492   \tweak color #red
493   \tuplet 3/2 { c8[ c c] }
494   \tuplet 3/2 { c8[ c c] }
495   \tuplet 3/2 { c8[ c c] }
496 }
497 @end lilypond
498
499 If nested tuplets do not begin at the same moment, their
500 appearance may be modified in the usual way with
501 @code{\override} commands:
502
503 @cindex text property, example
504 @cindex tuplet-number function, example
505 @cindex transparent property, example
506 @cindex TupletNumber, example of overriding
507
508 @lilypond[quote,ragged-right,verbatim,fragment,relative=1]
509 \tuplet 3/2 { c8[ c c] }
510 \once \override TupletNumber.text = #tuplet-number::calc-fraction-text
511 \tuplet 3/2 {
512   c8[ c]
513   c8[ c]
514   \once \override TupletNumber.transparent = ##t
515   \tuplet 3/2 { c8[ c c] }
516   \tuplet 3/2 { c8[ c c] }
517 }
518 @end lilypond
519
520
521 @seealso
522 Notation Reference:
523 @ruser{The tweak command}.
524
525 @node The single prefix
526 @unnumberedsubsubsec The @code{@bs{}single} prefix
527
528 @funindex \single
529 @cindex tweak, generated from override
530
531 Suppose we wanted to emphasize particular note heads by coloring them
532 red and increasing their size, and to make it easy suppose also we
533 have defined a function to do this:
534
535 @lilypond[quote,verbatim]
536 emphNoteHead = {
537   \override NoteHead.color = #red
538   \override NoteHead.font-size = 2
539 }
540 \relative c'' {
541   c4 a \once \emphNoteHead f d |
542 }
543 @end lilypond
544
545 The @code{\once} prefix works fine to emphasize single notes or
546 complete chords, but it cannot be used to emphasize a single note
547 @emph{within} a chord.  Earlier we have seen how @code{\tweak} can
548 be used to do this, see
549 @ref{The tweak command,,The @code{@bs{}tweak} command}.  But
550 @code{\tweak} cannot be used with a function; that's where
551 @code{\single} comes in:
552
553 @lilypond[quote,verbatim]
554 emphNoteHead = {
555   \override NoteHead.color = #red
556   \override NoteHead.font-size = 2
557 }
558 \relative c'' {
559    <c a \single \emphNoteHead f d>4
560 }
561 @end lilypond
562
563 In summary, @code{\single} converts overrides into tweaks so when
564 there are several objects at the same point in musical time (like
565 noteheads in a chord), @code{\single} will only affect a single one,
566 the one generated by the immediately following music expression, in
567 contrast to @code{\once} which will affect all of those objects.
568
569 By using @code{\single} in this way any shorthand function
570 containing just overrides may be applied to individual notes in a
571 chord.  However, @code{\single} does not convert @code{\revert},
572 @code{\set} or @code{\unset} into tweaks.
573
574 @seealso
575 Learning Manual:
576 @ref{The tweak command,,The @code{@bs{}tweak} command},
577 @ref{Using variables for layout adjustments}.
578
579
580 @node The Internals Reference manual
581 @section The Internals Reference manual
582
583 @cindex Internals Reference
584
585 @menu
586 * Properties of layout objects::
587 * Properties found in interfaces::
588 * Types of properties::
589 @end menu
590
591 @node Properties of layout objects
592 @subsection Properties of layout objects
593
594 @cindex properties of layout objects
595 @cindex properties of grobs
596 @cindex grobs, properties of
597 @cindex layout objects, properties of
598 @cindex Internals Reference manual
599
600 Suppose you have a slur in a score which, to your mind,
601 appears too thin and you'd like to draw it a little heavier.
602 How do you go about doing this?  You know from the statements
603 earlier about the flexibility of LilyPond that such a thing
604 should be possible, and you would probably guess that an
605 @code{\override} command would be needed.  But is there a
606 heaviness property for a slur, and if there is, how might it
607 be modified?  This is where the Internals Reference manual
608 comes in.  It contains all the information you might need to
609 construct this and all other @code{\override} commands.
610
611 Before we look at the Internals Reference a word of warning.
612 This is a @strong{reference} document, which means there is
613 little or no explanation contained within it: its purpose is
614 to present information precisely and concisely.  This
615 means it might look daunting at first sight.  Don't worry!
616 The guidance and explanation presented here will enable you
617 to extract the information from the Internals Reference for
618 yourself with just a little practice.
619
620 @cindex override example
621 @cindex Internals Reference, example of using
622 @cindex @code{\addlyrics} example
623
624 Let's use a concrete example with a simple fragment of real
625 music:
626
627 @c Mozart, Die Zauberflöte Nr.7 Duett
628
629 @lilypond[quote,verbatim,relative=2]
630 {
631   \key es \major
632   \time 6/8
633   {
634     r4 bes8 bes[( g]) g |
635     g8[( es]) es d[( f]) as |
636     as8 g
637   }
638   \addlyrics {
639     The man who | feels love's sweet e -- | mo -- tion
640   }
641 }
642 @end lilypond
643
644 Suppose now that we decide we would like the slurs to be a
645 little heavier.  Is this possible?  The slur is certainly a
646 layout object, so the question is, @q{Is there a property
647 belonging to a slur which controls the heaviness?}  To answer
648 this we must look in the Internals Reference, or IR for short.
649
650 The IR for the version of LilyPond you are using may be found
651 on the LilyPond website at @uref{http://lilypond.org}.  Go to the
652 documentation page and click on the Internals Reference link.
653 For learning purposes you should use the standard HTML version,
654 not the @q{one big page} or the PDF.  For the next few
655 paragraphs to make sense you will need to actually do this
656 as you read.
657
658 Under the heading @strong{Top} you will see five links.  Select
659 the link to the @emph{Backend}, which is where information about
660 layout objects is to be found.  There, under the heading
661 @strong{Backend}, select the link to @emph{All layout objects}.
662 The page that appears lists all the layout objects used in your
663 version of LilyPond, in alphabetic order.  Select the link to
664 Slur, and the properties of Slurs are listed.
665
666 An alternative way of finding this page is from the Notation
667 Reference.  On one of the pages that deals with slurs you may find a
668 link to the Internals Reference.  This link will take you directly to
669 this page, but if you have an idea about the name of the layout object
670 to be tweaked, it is easier to go straight to the IR and search there.
671
672 This Slur page in the IR tells us first that Slur objects are created
673 by the Slur_engraver.  Then it lists the standard settings.  Browse
674 through them looking for a property that might control the heaviness of
675 slurs, and you should find
676
677 @example
678 @code{thickness} (number)
679      @code{1.2}
680      Line thickness, generally measured in @code{line-thickness}
681 @end example
682
683 This looks a good bet to change the heaviness.  It tells us that
684 the value of @code{thickness} is a simple @emph{number},
685 that the default value is 1.2, and that the units are
686 in another property called @code{line-thickness}.
687
688 As we said earlier, there are few to no explanations in the IR,
689 but we already have enough information to try changing the
690 slur thickness.  We see that the name of the layout object
691 is @code{Slur}, that the name of the property to change is
692 @code{thickness} and that the new value should be a number
693 somewhat larger than 1.2 if we are to make slurs thicker.
694
695 We can now construct the @code{\override} command by simply
696 substituting the values we have found for the names, omitting
697 the context.  Let's use a very large value for the thickness
698 at first, so we can be sure the command is working.  We get:
699
700 @example
701 \override Slur.thickness = #5.0
702 @end example
703
704 Don't forget the@tie{}@code{#} preceding the new value!
705
706 The final question is, @q{Where should this command be
707 placed?}  While you are unsure and learning, the best
708 answer is, @q{Within the music, before the first slur and
709 close to it.}  Let's do that:
710
711 @cindex Slur example of overriding
712 @cindex thickness property, example
713
714 @lilypond[quote,verbatim,relative=2]
715 {
716   \key es \major
717   \time 6/8
718   {
719     % Increase thickness of all following slurs from 1.2 to 5.0
720     \override Slur.thickness = #5.0
721     r4 bes8 bes[( g]) g |
722     g8[( es]) es d[( f]) as |
723     as8 g
724   }
725   \addlyrics {
726     The man who | feels love's sweet e -- | mo -- tion
727   }
728 }
729 @end lilypond
730
731 @noindent
732 and we see that the slur is indeed heavier.
733
734 So this is the basic way of constructing @code{\override}
735 commands.  There are a few more complications that we
736 shall meet in later sections, but you now know all the
737 essentials required to make up your own -- but you will
738 still need some practice.  This is provided in the examples
739 which follow.
740
741 @subsubsubheading Finding the context
742
743 @cindex context, finding
744 @cindex context, identifying correct
745
746 But first, what if we had needed to specify the Context?
747 What should it be?  We could guess that slurs are in
748 the Voice context, as they are clearly closely associated
749 with individual lines of music, but can we be sure?  To
750 find out, go back to the top of the IR page describing the
751 Slur, where it says @q{Slur objects are created by: Slur
752 engraver}.  So slurs will be created in whichever context
753 the @code{Slur_engraver} is in.  Follow the link to the
754 @code{Slur_engraver} page.  At the very bottom it tells
755 us that @code{Slur_engraver} is part of seven Voice contexts,
756 including the standard voice context, @code{Voice}, so our
757 guess was correct.  And because @code{Voice} is one of the
758 lowest level contexts which is implied unambiguously by
759 the fact that we are entering notes, we can omit it in this
760 location.
761
762 @subsubsubheading Overriding once only
763
764 @cindex overriding once only
765 @cindex once override
766
767 @funindex \once
768 @funindex once
769
770 As you can see, @emph{all} the slurs are thicker in the final example
771 above.  But what if we wanted just the first slur to be thicker?  This
772 is achieved with the @code{\once} command.  Placed immediately before
773 the @code{\override} command it causes it to change only the slur
774 which begins on the @strong{immediately following} note.  If the
775 immediately following note does not begin a slur the command has no
776 effect at all -- it is not remembered until a slur is encountered, it
777 is simply discarded.  So the command with @code{\once} must be
778 repositioned as follows:
779
780 @cindex Slur, example of overriding
781 @cindex thickness property, example
782
783 @lilypond[quote,verbatim,relative=2]
784 {
785   \key es \major
786   \time 6/8
787   {
788     r4 bes8
789     % Increase thickness of immediately following slur only
790     \once \override Slur.thickness = #5.0
791     bes8[( g]) g |
792     g8[( es]) es d[( f]) as |
793     as8 g
794   }
795   \addlyrics {
796     The man who | feels love's sweet e -- | mo -- tion
797   }
798 }
799 @end lilypond
800
801 @noindent
802 Now only the first slur is made heavier.
803
804 The @code{\once} command can also be used before the @code{\set}
805 command.
806
807 @subsubsubheading Reverting
808
809 @cindex revert
810 @cindex default properties, reverting to
811
812 @funindex \revert
813 @funindex revert
814
815 Finally, what if we wanted just the first two slurs to be
816 heavier?  Well, we could use two commands, each preceded by
817 @code{\once} placed immediately before each of the notes where
818 the slurs begin:
819
820 @cindex Slur, example of overriding
821 @cindex thickness property, example
822
823 @lilypond[quote,verbatim,relative=2]
824 {
825   \key es \major
826   \time 6/8
827   {
828     r4 bes8
829     % Increase thickness of immediately following slur only
830     \once \override Slur.thickness = #5.0
831     bes[( g]) g |
832     % Increase thickness of immediately following slur only
833     \once \override Slur.thickness = #5.0
834     g8[( es]) es d[( f]) as |
835     as8 g
836   }
837   \addlyrics {
838     The man who | feels love's sweet e -- | mo -- tion
839   }
840 }
841 @end lilypond
842
843 @noindent
844 or we could omit the @code{\once} command and use the @code{\revert}
845 command to return the @code{thickness} property to its default value
846 after the second slur:
847
848 @cindex Slur, example of overriding
849 @cindex thickness property, example
850
851 @lilypond[quote,verbatim,relative=2]
852 {
853   \key es \major
854   \time 6/8
855   {
856     r4 bes8
857     % Increase thickness of all following slurs from 1.2 to 5.0
858     \override Slur.thickness = #5.0
859     bes[( g]) g |
860     g8[( es]) es
861     % Revert thickness of all following slurs to default of 1.2
862     \revert Slur.thickness
863     d8[( f]) as |
864     as8 g
865   }
866   \addlyrics {
867     The man who | feels love's sweet e -- | mo -- tion
868   }
869 }
870 @end lilypond
871
872 @noindent
873 The @code{\revert} command can be used to return any property
874 changed with @code{\override} back to its default value.
875 You may use whichever method best suits what you want to do.
876
877 That concludes our introduction to the IR, and the basic
878 method of tweaking.  Several examples follow in the later
879 sections of this Chapter, partly to introduce you to some of the
880 additional features of the IR, and partly to give you more
881 practice in extracting information from it.  These examples will
882 contain progressively fewer words of guidance and explanation.
883
884
885 @node Properties found in interfaces
886 @subsection Properties found in interfaces
887
888 @cindex interface
889 @cindex interface properties
890 @cindex properties in interfaces
891
892 Suppose now that we wish to print the lyrics in italics.  What form of
893 @code{\override} command do we need to do this?  We first look in the
894 IR page listing @q{All layout objects}, as before, and look for an
895 object that might control lyrics.  We find @code{LyricText}, which
896 looks right.  Clicking on this shows the settable properties for lyric
897 text.  These include the @code{font-series} and @code{font-size}, but
898 nothing that might give an italic shape.  This is because the shape
899 property is one that is common to all font objects, so, rather than
900 including it in every layout object, it is grouped together with other
901 similar common properties and placed in an @strong{Interface}, the
902 @code{font-interface}.
903
904 So now we need to learn how to find the properties of interfaces,
905 and to discover what objects use these interface properties.
906
907 Look again at the IR page which describes LyricText.  At the bottom of
908 the page is a list of clickable interfaces which LyricText supports.
909 The list has several items, including @code{font-interface}.  Clicking
910 on this brings up the properties associated with this interface, which
911 are also properties of all the objects which support it, including
912 LyricText.
913
914 Now we see all the user-settable properties which control fonts,
915 including @code{font-shape(symbol)}, where @code{symbol} can be
916 set to @code{upright}, @code{italics} or @code{caps}.
917
918 You will notice that @code{font-series} and @code{font-size} are also
919 listed there.  This immediately raises the question: Why are the
920 common font properties @code{font-series} and @code{font-size} listed
921 under @code{LyricText} as well as under the interface
922 @code{font-interface} but @code{font-shape} is not?  The answer is
923 that @code{font-series} and @code{font-size} are changed from their
924 global default values when a @code{LyricText} object is created, but
925 @code{font-shape} is not.  The entries in @code{LyricText} then tell
926 you the values for those two properties which apply to
927 @code{LyricText}.  Other objects which support @code{font-interface}
928 will set these properties differently when they are created.
929
930 Let's see if we can now construct the @code{\override} command
931 to change the lyrics to italics.  The object is @code{LyricText},
932 the property is @code{font-shape} and the value is
933 @code{italic}.  As before, we'll omit the context.
934
935 As an aside, although it is an important one, note that some
936 properties take values that are symbols, like @code{italic}, and
937 must be preceded by an apostrophe, @code{'}.  Symbols are then
938 read internally by LilyPond.  Note the distinction from arbitrary
939 text strings, which would appear as @code{"a text string"}; for
940 more details about symbols and strings, see @rextend{Scheme tutorial}.
941
942 So we see that the @code{\override} command needed to print the lyrics
943 in italics is:
944
945 @example
946 \override LyricText.font-shape = #'italic
947 @end example
948
949 @noindent
950 This should be placed just in front of the lyrics we wish to affect,
951 like so:
952
953 @cindex font-shape property, example
954 @cindex italic, example
955 @cindex LyricText, example of overriding
956 @cindex @code{\addlyrics}, example
957
958 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
959 {
960   \key es \major
961   \time 6/8
962   {
963     r4 bes8 bes[( g]) g |
964     g8[( es]) es d[( f]) as |
965     as8 g
966   }
967   \addlyrics {
968     \override LyricText.font-shape = #'italic
969     The man who | feels love's sweet e -- | mo -- tion
970   }
971 }
972 @end lilypond
973
974 @noindent
975 and the lyrics are all printed in italics.
976
977 @warning{In lyrics always leave whitespace between the final
978 syllable and the terminating brace.}
979
980
981 @seealso
982 Extending: @rextend{Scheme tutorial}.
983
984
985 @node Types of properties
986 @subsection Types of properties
987
988 @cindex property types
989
990 So far we have seen two types of property: @code{number} and
991 @code{symbol}.  To be valid, the value given to a property
992 must be of the correct type and obey the rules for that type.
993 The type of property is always shown in brackets after the
994 property name in the IR.  Here is a list of the types you may
995 need, together with the rules for that type, and some examples.
996 You must always add a hash symbol, @code{#}, of course,
997 to the front of these values when they are entered in the
998 @code{\override} command, even if the value itself already
999 starts with@tie{}@code{#}.  We only give examples for constants
1000 here: if you want to compute a value using Scheme, see
1001 @rextend{Calculations in Scheme}.
1002
1003 @multitable @columnfractions .2 .45 .35
1004 @headitem Property type
1005   @tab Rules
1006   @tab Examples
1007 @item Boolean
1008   @tab Either True or False, represented by #t or #f
1009   @tab @code{#t}, @code{#f}
1010 @item Dimension (in staff space)
1011   @tab A decimal number (in units of staff space)
1012   @tab @code{2.5}, @code{0.34}
1013 @item Direction
1014   @tab A valid direction constant or its numerical equivalent
1015   (@code{0} or @code{CENTER} indicate a neutral direction)
1016   @tab @code{LEFT}, @code{CENTER}, @code{UP},
1017        @code{1}, @w{@code{-1}}
1018 @item Integer
1019   @tab A whole number
1020   @tab @code{3}, @code{-1}
1021 @item List
1022   @tab A sequence of constants or symbols separated by spaces, enclosed
1023   in parentheses
1024 and preceded by an apostrophe (quote mark)
1025   @tab @code{'(left-edge staff-bar)}, @code{'(1)}, @code{'()},
1026        @code{'(1.0 0.25 0.5)}
1027 @item Markup
1028   @tab Any valid markup
1029   @tab @code{\markup @{ \italic "cresc." @}}, @code{"bagpipe"}
1030 @item Moment
1031   @tab A fraction of a whole note constructed with the
1032 make-moment function
1033   @tab @code{(ly:make-moment 1/4)},
1034        @code{(ly:make-moment 3/8)}
1035 @item Number
1036   @tab Any positive or negative, possibly decimal, value
1037   @tab @code{3}, @w{@code{-2.45}}
1038 @item Pair (of numbers)
1039   @tab Two numbers separated by a @q{space . space} and enclosed
1040 in brackets preceded by an apostrophe
1041   @tab @code{'(2 . 3.5)}, @code{'(0.1 . -3.2)}
1042 @item Symbol
1043   @tab Any of the set of permitted symbols for that property,
1044 preceded by an apostrophe
1045   @tab @code{'italic}, @code{'inside}
1046 @item Unknown
1047   @tab A procedure, or @code{#f} to cause no action
1048   @tab @code{bend::print}, @code{ly:text-interface::print},
1049        @code{#f}
1050 @item Vector
1051   @tab Constants
1052   enclosed in @code{#(}@dots{}@code{)}.
1053   @tab @code{#(#t #t #f)}
1054 @end multitable
1055
1056
1057 @seealso
1058 Extending: @rextend{Scheme tutorial}.
1059
1060
1061 @node Appearance of objects
1062 @section Appearance of objects
1063
1064 Let us now put what we have learned into practice with a few
1065 examples which show how tweaks may be used to change the
1066 appearance of the printed music.
1067
1068 @menu
1069 * Visibility and color of objects::
1070 * Size of objects::
1071 * Length and thickness of objects::
1072 @end menu
1073
1074 @node Visibility and color of objects
1075 @subsection Visibility and color of objects
1076
1077 In the educational use of music we might wish to print a score
1078 with certain elements omitted as an exercise for the student,
1079 who is required to supply them.  As a simple example,
1080 let us suppose the exercise is to supply the missing bar lines
1081 in a piece of music.  But the bar lines are normally inserted
1082 automatically.  How do we prevent them printing?
1083
1084 Before we tackle this, let us remember that object properties are
1085 grouped in what are called @emph{interfaces} -- see @ref{Properties
1086 found in interfaces}.  This is simply to group together those
1087 properties that may be used together to tweak a graphical object -- if
1088 one of them is allowed for an object, so are the others.  Some objects
1089 then use the properties in some interfaces, others use them from other
1090 interfaces.  The interfaces which contain the properties used by a
1091 particular grob are listed in the IR at the bottom of the page
1092 describing that grob, and those properties may be viewed by looking at
1093 those interfaces.
1094
1095 We explained how to find information about grobs in @ref{Properties of
1096 layout objects}.  Using the same approach, we go to the IR to find the
1097 layout object which prints bar lines.  Going via @emph{Backend} and
1098 @emph{All layout objects} we find there is a layout object called
1099 @code{BarLine}.  Its properties include two that control its
1100 visibility: @code{break-visibility} and @code{stencil}.  Barline also
1101 supports a number of interfaces, including the @code{grob-interface},
1102 where we find the @code{transparent} and the @code{color} properties.
1103 All of these can affect the visibility of bar lines (and, of course,
1104 by extension, many other layout objects too.)  Let's consider each of
1105 these in turn.
1106
1107 @menu
1108 * The stencil property::
1109 * The break-visibility property::
1110 * The transparent property::
1111 * The color property::
1112 @end menu
1113
1114 @node The stencil property
1115 @unnumberedsubsubsec The @code{stencil} property
1116
1117 @cindex stencil property
1118
1119 This property controls the appearance of the bar lines by specifying
1120 the symbol (glyph) which should be printed.  In common
1121 with many other properties, it can be set to print nothing by
1122 setting its value to @code{#f}.  Let's try it, as before, omitting
1123 the implied Context, @code{Voice}:
1124
1125 @cindex BarLine, example of overriding
1126 @cindex stencil property, example
1127
1128 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1129 {
1130   \time 12/16
1131   \override BarLine.stencil = ##f
1132   c4 b8 c d16 c d8 |
1133   g,8 a16 b8 c d4 e16 |
1134   e8
1135 }
1136 @end lilypond
1137
1138 The bar lines are still printed.  What is wrong?  Go back to the IR
1139 and look again at the page giving the properties of BarLine.  At the
1140 top of the page it says @qq{Barline objects are created by:
1141 Bar_engraver}.  Go to the @code{Bar_engraver} page.  At the bottom it
1142 gives a list of Contexts in which the bar engraver operates.  All of
1143 them are of the type @code{Staff}, so the reason the @code{\override}
1144 command failed to work as expected is because @code{Barline} is not in
1145 the default @code{Voice} context.  If the context is specified
1146 incorrectly, the command simply does not work.  No error message is
1147 produced, and nothing is logged in the log file.  Let's try correcting
1148 it by adding the correct context:
1149
1150 @cindex BarLine, example of overriding
1151 @cindex stencil property, example
1152
1153 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1154 {
1155   \time 12/16
1156   \override Staff.BarLine.stencil = ##f
1157   c4 b8 c d16 c d8 |
1158   g,8 a16 b8 c d4 e16 |
1159   e8
1160 }
1161 @end lilypond
1162
1163 Now the bar lines have vanished.  Setting the @code{stencil}
1164 property to @code{#f} is such a frequent operation that there is a
1165 shorthand for it called @code{\omit}:
1166 @funindex \omit
1167
1168 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1169 {
1170   \time 12/16
1171   \omit Staff.BarLine
1172   c4 b8 c d16 c d8 |
1173   g,8 a16 b8 c d4 e16 |
1174   e8
1175 }
1176 @end lilypond
1177
1178 Note, though, that setting the @code{stencil} property to @code{#f}
1179 will cause errors when the dimensions of the object are required for
1180 correct processing.  For example, errors will be generated if the
1181 @code{stencil} property of the @code{NoteHead} object is set to
1182 @code{#f}.  If this is the case, you can instead use the
1183 @code{point-stencil} function, which sets the stencil to an object
1184 with zero size:
1185
1186 @lilypond[quote,verbatim,relative=2]
1187 {
1188   c4 c
1189   \once \override NoteHead.stencil = #point-stencil
1190   c4 c
1191 }
1192 @end lilypond
1193
1194 @node The break-visibility property
1195 @unnumberedsubsubsec The @code{break-visibility} property
1196
1197 @cindex break-visibility property
1198
1199 We see from the @code{BarLine} properties in the IR that the
1200 @code{break-visibility} property requires a vector of three booleans.
1201 These control respectively whether bar lines are printed at the end of
1202 a line, in the middle of lines, and at the beginning of lines.  For
1203 our example we want all bar lines to be suppressed, so the value we
1204 need is @code{#(#f #f #f)} (also available
1205 under the name @code{all-invisible}).  Let's try that, remembering to include
1206 the @code{Staff} context.  Note also that in writing this value we
1207 have @code{##} before the opening parenthesis.  One @code{#} is required
1208 as part of vector constant syntax, and the first@tie{}@code{#} is
1209 required, as always, to precede the value itself in the
1210 @code{\override} command.
1211
1212 @cindex BarLine, example of overriding
1213 @cindex break-visibility property, example
1214
1215 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1216 {
1217   \time 12/16
1218   \override Staff.BarLine.break-visibility = ##(#f #f #f)
1219   c4 b8 c d16 c d8 |
1220   g,8 a16 b8 c d4 e16 |
1221   e8
1222 }
1223 @end lilypond
1224
1225 And we see this too removes all the bar lines.
1226
1227 @node The transparent property
1228 @unnumberedsubsubsec The @code{transparent} property
1229
1230 @cindex transparent property
1231 @cindex transparency
1232
1233 We see from the properties specified in the @code{grob-interface} page
1234 in the IR that the @code{transparent} property is a boolean.  This
1235 should be set to @code{#t} to make the grob transparent.  In this next
1236 example let us make the time signature invisible rather than the bar
1237 lines.  To do this we need to find the grob name for the time
1238 signature.  Back to the @q{All layout objects} page in the IR to find
1239 the properties of the @code{TimeSignature} layout object.  This is
1240 produced by the @code{Time_signature_engraver} which you can check
1241 also lives in the @code{Staff} context and also supports the
1242 @code{grob-interface}.  So the command to make the time signature
1243 transparent is:
1244
1245 @cindex TimeSignature, example of overriding
1246 @cindex transparent property, example
1247
1248 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1249 {
1250   \time 12/16
1251   \override Staff.TimeSignature.transparent = ##t
1252   c4 b8 c d16 c d8 |
1253   g,8 a16 b8 c d4 e16 |
1254   e8
1255 }
1256 @end lilypond
1257
1258 @noindent
1259 Again, setting the @code{transparent} property is a rather
1260 frequent operation, so we have a shorthand for it called
1261 @code{\hide}:
1262 @funindex \hide
1263
1264 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1265 {
1266   \time 12/16
1267   \hide Staff.TimeSignature
1268   c4 b8 c d16 c d8 |
1269   g,8 a16 b8 c d4 e16 |
1270   e8
1271 }
1272 @end lilypond
1273
1274 @noindent
1275 In either case, the time signature is gone, but this command
1276 leaves a gap where
1277 the time signature should be.  Maybe this is what is wanted for
1278 an exercise for the student to fill it in, but in other
1279 circumstances a gap might be undesirable.  To remove it, the
1280 stencil for the time signature should be set to @code{#f}
1281 instead:
1282
1283 @cindex TimeSignature, example of overriding
1284 @cindex stencil property, example
1285
1286 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1287 {
1288   \time 12/16
1289   \omit Staff.TimeSignature
1290   c4 b8 c d16 c d8 |
1291   g,8 a16 b8 c d4 e16 |
1292   e8
1293 }
1294 @end lilypond
1295
1296 @noindent
1297 and the difference is obvious: setting the stencil to @code{#f}
1298 (possibly via @code{\omit})
1299 removes the object entirely; making the object @code{transparent}
1300 (which can be done using @code{\hide})
1301 leaves it where it is, but makes it invisible.
1302
1303 @node The color property
1304 @unnumberedsubsubsec The @code{color} property
1305
1306 @cindex color property
1307
1308 Finally let us try making the bar lines invisible by coloring
1309 them white.  (There is a difficulty with this in that the
1310 white bar line may or may not blank out the staff lines where
1311 they cross.  You may see in some of the examples below that this
1312 happens unpredictably.  The details of why this is so and how to
1313 control it are covered in @ruser{Painting objects white}.  But at
1314 the moment we are learning about color, so please just accept this
1315 limitation for now.)
1316
1317 The @code{grob-interface} specifies that the
1318 color property value is a list, but there is no
1319 explanation of what that list should be.  The list it
1320 requires is actually a list of values in internal units,
1321 but, to avoid having to know what these are, several ways
1322 are provided to specify colors.  The first way is to use one
1323 of the @q{normal} colors listed in the first table in
1324 @ruser{List of colors}.  To set the bar lines to white
1325 we write:
1326
1327 @cindex BarLine, example of overriding
1328 @cindex color property, example
1329
1330 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1331 {
1332   \time 12/16
1333   \override Staff.BarLine.color = #white
1334   c4 b8 c d16 c d8 |
1335   g,8 a16 b8 c d4 e16 |
1336   e8
1337 }
1338 @end lilypond
1339
1340 @noindent
1341 and again, we see the bar lines are not visible.  Note that
1342 @emph{white} is not preceded by an apostrophe -- it is not
1343 a symbol, but a @emph{variable}.  When evaluated, it provides
1344 the list of internal values required to set the color to
1345 white.  The other colors in the normal list are variables
1346 too.  To convince yourself this is working you might like
1347 to change the color to one of the other variables in the
1348 list.
1349
1350 @cindex color, X11
1351 @cindex X11 colors
1352
1353 @funindex x11-color
1354
1355 The second way of changing the color is to use the list of
1356 X11 color names in the second list in @ruser{List of colors}.
1357 However, these are mapped to the actual values by the function
1358 @code{x11-color} which
1359 converts X11 color symbols into the list of internal values like this:
1360
1361 @cindex BarLine, example of overriding
1362 @cindex color property, example
1363
1364 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1365 {
1366   \time 12/16
1367   \override Staff.BarLine.color = #(x11-color 'white)
1368   c4 b8 c d16 c d8 |
1369   g,8 a16 b8 c d4 e16 |
1370   e8
1371 }
1372 @end lilypond
1373
1374 @noindent
1375 Note that in this case the function @code{x11-color} takes
1376 a symbol as an argument, so the symbol must be preceded by
1377 an apostrophe to keep it from being evaluated as a variable, and
1378 the whole function call has to be enclosed in parentheses.
1379
1380 @cindex rgb colors
1381 @cindex color, rgb
1382
1383 @funindex rgb-color
1384
1385 There is another function, one which converts RGB values into
1386 internal colors -- the @code{rgb-color} function.  This takes
1387 three arguments giving the intensities of the red, green and
1388 blue colors.  These take values in the range 0 to 1.  So to
1389 set the color to red the value should be @code{(rgb-color 1 0 0)}
1390 and to white it should be @code{(rgb-color 1 1 1)}:
1391
1392 @cindex BarLine, example of overriding
1393 @cindex color property, example
1394
1395 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1396 {
1397   \time 12/16
1398   \override Staff.BarLine.color = #(rgb-color 1 1 1)
1399   c4 b8 c d16 c d8 |
1400   g,8 a16 b8 c d4 e16 |
1401   e8
1402 }
1403 @end lilypond
1404
1405 Finally, there is also a grey scale available as part of the
1406 X11 set of colors.  These range from black, @code{'grey0},
1407 to white, @code{'grey100}, in steps of 1.  Let's illustrate
1408 this by setting all the layout objects in our example to
1409 various shades of grey:
1410
1411 @cindex StaffSymbol, example of overriding
1412 @cindex TimeSignature, example of overriding
1413 @cindex Clef, example of overriding
1414 @cindex NoteHead, example of overriding
1415 @cindex Stem, example of overriding
1416 @cindex BarLine, example of overriding
1417 @cindex color property, example
1418 @cindex x11-color, example of using
1419
1420 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1421 {
1422   \time 12/16
1423   \override Staff.StaffSymbol.color = #(x11-color 'grey30)
1424   \override Staff.TimeSignature.color = #(x11-color 'grey60)
1425   \override Staff.Clef.color = #(x11-color 'grey60)
1426   \override Voice.NoteHead.color = #(x11-color 'grey85)
1427   \override Voice.Stem.color = #(x11-color 'grey85)
1428   \override Staff.BarLine.color = #(x11-color 'grey10)
1429   c4 b8 c d16 c d8 |
1430   g,8 a16 b8 c d4 e16 |
1431   e8
1432 }
1433 @end lilypond
1434
1435 @noindent
1436 Note the contexts associated with each of the layout objects.
1437 It is important to get these right, or the commands will not
1438 work!  Remember, the context is the one in which the appropriate
1439 engraver is placed.  The default context for engravers can be
1440 found by starting from the layout object, going from there to
1441 the engraver which produces it, and on the engraver page in the
1442 IR it tells you in which context the engraver will normally be
1443 found.
1444
1445
1446 @node Size of objects
1447 @subsection Size of objects
1448
1449 @cindex changing size of objects
1450 @cindex size of objects
1451 @cindex objects, size of
1452 @cindex objects, changing size of
1453
1454 Let us begin by looking again at the earlier example
1455 (see @ref{Nesting music expressions}) which showed
1456 how to introduce a new temporary staff, as in an @rglos{ossia}.
1457
1458 @cindex alignAboveContext property, example
1459 @cindex @code{\with}, example
1460
1461 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1462 \new Staff ="main" {
1463   \relative g' {
1464     r4 g8 g c4 c8 d |
1465     e4 r8
1466     <<
1467       { f8 c c }
1468       \new Staff \with {
1469         alignAboveContext = #"main" }
1470       { f8 f c }
1471     >>
1472     r4 |
1473   }
1474 }
1475 @end lilypond
1476
1477 Ossia are normally written without clef and time signature, and
1478 are usually printed slightly smaller than the main staff.  We
1479 already know now how to remove the clef and time signature --
1480 we simply set the stencil of each to @code{#f}, as follows:
1481
1482 @cindex alignAboveContext property, example
1483 @cindex @code{\with}, example
1484 @funindex \omit
1485 @cindex Clef, example of overriding
1486 @cindex TimeSignature, example of overriding
1487
1488 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1489 \new Staff ="main" {
1490   \relative g' {
1491     r4 g8 g c4 c8 d |
1492     e4 r8
1493     <<
1494       { f8 c c }
1495       \new Staff \with {
1496         alignAboveContext = #"main"
1497       }
1498       {
1499         \omit Staff.Clef
1500         \omit Staff.TimeSignature
1501         { f8 f c }
1502       }
1503     >>
1504     r4 |
1505   }
1506 }
1507 @end lilypond
1508
1509 @noindent
1510 where the extra pair of braces after the @code{\with} clause are
1511 required to ensure the enclosed overrides and music are applied
1512 to the ossia staff.
1513
1514 But what is the difference between modifying the staff context by
1515 using @code{\with} and modifying the stencils of the clef and the
1516 time signature with @code{\override}, or in this case
1517 @code{\omit}?
1518 The main difference is that
1519 changes made in a @code{\with} clause are made at the time the
1520 context is created, and remain in force as the @strong{default}
1521 values for the duration of that context, whereas
1522 @code{\set} or @code{\override} commands embedded in the
1523 music are dynamic -- they make changes synchronized with
1524 a particular point in the music.  If changes are unset or
1525 reverted using @code{\unset} or @code{\revert} they return to
1526 their default values, which will be the ones set in the
1527 @code{\with} clause, or if none have been set there, the normal
1528 default values.
1529
1530 Some context properties can be modified only in @code{\with} clauses.
1531 These are those properties which cannot sensibly be changed after the
1532 context has been created.  @code{alignAboveContext} and its partner,
1533 @code{alignBelowContext}, are two such properties -- once the staff
1534 has been created its alignment is decided and it would make no sense
1535 to try to change it later.
1536
1537 The default values of layout object properties can also be set
1538 in @code{\with} clauses.  Simply use the normal @code{\override}
1539 command leaving out the context name, since this is unambiguously
1540 defined as the context which the @code{\with} clause is modifying.
1541 If fact, an error will be generated if a context is specified
1542 in this location.
1543
1544 So we could replace the example above with
1545
1546 @cindex alignAboveContext property, example
1547 @cindex @code{\with}, example
1548 @cindex Clef, example of overriding
1549 @cindex TimeSignature, example of overriding
1550
1551 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1552 \new Staff ="main" {
1553   \relative g' {
1554     r4 g8 g c4 c8 d |
1555     e4 r8
1556     <<
1557       { f8 c c }
1558       \new Staff \with {
1559         alignAboveContext = #"main"
1560         % Don't print clefs in this staff
1561         \override Clef.stencil = ##f
1562         % Don't print time signatures in this staff
1563         \override TimeSignature.stencil = ##f
1564       }
1565       { f8 f c }
1566     >>
1567     r4 |
1568   }
1569 }
1570 @end lilypond
1571
1572 It turns out that we can also employ the shorthands @code{\hide}
1573 and @code{\omit} for setting the @code{transparent} property and
1574 clearing the @code{stencil} here, leading to the result
1575
1576 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1577 \new Staff ="main" {
1578   \relative g' {
1579     r4 g8 g c4 c8 d |
1580     e4 r8
1581     <<
1582       { f8 c c }
1583       \new Staff \with {
1584         alignAboveContext = #"main"
1585         % Don't print clefs in this staff
1586         \omit Clef
1587         % Don't print time signatures in this staff
1588         \omit TimeSignature
1589       }
1590       { f8 f c }
1591     >>
1592     r4 |
1593   }
1594 }
1595 @end lilypond
1596
1597 Finally we come to changing the size of layout objects.
1598
1599 Some layout objects are created as glyphs selected from a typeface
1600 font.  These include note heads, accidentals, markup, clefs, time
1601 signatures, dynamics and lyrics.  Their size is changed by modifying
1602 the @code{font-size} property, as we shall shortly see.  Other layout
1603 objects such as slurs and ties -- in general, spanner objects -- are
1604 drawn individually, so there is no @code{font-size} associated with
1605 them.  These objects generally derive their size from the objects to
1606 which they are attached, so usually there is no need to change their
1607 size manually.  Still other properties such as the length of stems and
1608 bar lines, thickness of beams and other lines, and the separation of
1609 staff lines all need to be modified in special ways.
1610
1611 Returning to the ossia example, let us first change the font-size.
1612 We can do this in two ways.  We can either change the size of the
1613 fonts of each object type, like @code{NoteHead}s with commands
1614 like
1615
1616 @example
1617 \override NoteHead.font-size = #-2
1618 @end example
1619
1620 or we can change the size of all fonts by setting a special
1621 property, @code{fontSize}, using @code{\set}, or by including
1622 it in a @code{\with} clause (but without the @code{\set}).
1623
1624 @example
1625 \set fontSize = #-2
1626 @end example
1627
1628 Both of these statements would cause the font size to be reduced
1629 by 2 steps from its previous value, where each
1630 step reduces or increases the size by approximately 12%.
1631
1632 Let's try it in our ossia example:
1633
1634 @cindex alignAboveContext property, example
1635 @cindex @code{\with}, example
1636 @cindex Clef, example of overriding
1637 @cindex TimeSignature, example of overriding
1638 @cindex fontSize property, example
1639
1640 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1641 \new Staff ="main" {
1642   \relative g' {
1643     r4 g8 g c4 c8 d |
1644     e4 r8
1645     <<
1646       { f8 c c }
1647       \new Staff \with {
1648         alignAboveContext = #"main"
1649         \omit Clef
1650         \omit TimeSignature
1651         % Reduce all font sizes by ~24%
1652         fontSize = #-2
1653       }
1654       { f8 f c }
1655     >>
1656     r4 |
1657   }
1658 }
1659 @end lilypond
1660
1661 This is still not quite right.  The note heads and flags are
1662 smaller, but the stems are too long in proportion and the
1663 staff lines are spaced too widely apart.  These need to be
1664 scaled down in proportion to the font reduction.  The next
1665 sub-section discusses how this is done.
1666
1667 @node Length and thickness of objects
1668 @subsection Length and thickness of objects
1669
1670 @cindex distances
1671 @cindex thickness
1672 @cindex length
1673 @cindex magstep
1674 @cindex size, changing
1675 @cindex stem length, changing
1676 @cindex staff line spacing, changing
1677
1678 Distances and lengths in LilyPond are generally measured in
1679 staff-spaces, the distance between adjacent lines in the staff,
1680 (or occasionally half staff spaces) while most @code{thickness}
1681 properties are measured in units of an internal property called
1682 @code{line-thickness.}  For example, by default, the lines of
1683 hairpins are given a thickness of 1 unit of @code{line-thickness},
1684 while the @code{thickness} of a note stem is 1.3.  Note, though,
1685 that some thickness properties are different; for example, the
1686 thickness of beams is controlled by the value of the
1687 @code{beam-thickness} property, which is measured in staff-spaces.
1688
1689 So how are lengths to be scaled in proportion to the font size?
1690 This can be done with the help of a special function called
1691 @code{magstep} provided for exactly this purpose.  It takes
1692 one argument, the change in font size (#-2 in the example above)
1693 and returns a scaling factor suitable for reducing other
1694 objects in proportion.  It is used like this:
1695
1696 @cindex alignAboveContext property, example
1697 @cindex @code{\with}, example
1698 @cindex Clef, example of overriding
1699 @cindex TimeSignature, example of overriding
1700 @cindex fontSize property, example
1701 @cindex StaffSymbol, example of overriding
1702 @cindex magstep function, example of using
1703 @cindex staff-space property, example
1704 @cindex stencil property, example
1705
1706 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1707 \new Staff ="main" {
1708   \relative g' {
1709     r4 g8 g c4 c8 d |
1710     e4 r8
1711     <<
1712       { f8 c c }
1713       \new Staff \with {
1714         alignAboveContext = #"main"
1715         \omit Clef
1716         \omit TimeSignature
1717         fontSize = #-2
1718         % Reduce stem length and line spacing to match
1719         \override StaffSymbol.staff-space = #(magstep -2)
1720       }
1721       { f8 f c }
1722     >>
1723     r4 |
1724   }
1725 }
1726 @end lilypond
1727
1728 @noindent
1729 Since the length of stems and many other length-related properties are
1730 always calculated relative to the value of the @code{staff-space}
1731 property these are automatically scaled down in length too.  Note that
1732 this affects only the vertical scale of the ossia -- the horizontal
1733 scale is determined by the layout of the main music in order to remain
1734 synchronized with it, so it is not affected by any of these changes in
1735 size.  Of course, if the scale of all the main music were changed in
1736 this way then the horizontal spacing would be affected.  This is
1737 discussed later in the layout section.
1738
1739 This, then, completes the creation of an ossia.  The sizes and
1740 lengths of all other objects may be modified in analogous ways.
1741
1742 For small changes in scale, as in the example above, the
1743 thickness of the various drawn lines such as bar lines,
1744 beams, hairpins, slurs, etc does not usually require global
1745 adjustment.  If the thickness of any particular layout object
1746 needs to be adjusted this can be best achieved by overriding its
1747 @code{thickness} property.  An example of changing the thickness
1748 of slurs was shown above in @ref{Properties of layout objects}.
1749 The thickness of all drawn objects (i.e., those not produced
1750 from a font) may be changed in the same way.
1751
1752
1753 @node Placement of objects
1754 @section Placement of objects
1755
1756 @menu
1757 * Automatic behavior::
1758 * Within-staff objects::
1759 * Outside-staff objects::
1760 @end menu
1761
1762
1763 @node Automatic behavior
1764 @subsection Automatic behavior
1765
1766 @cindex within-staff objects
1767 @cindex outside-staff objects
1768 @cindex objects, within-staff
1769 @cindex objects, outside-staff
1770
1771 There are some objects in musical notation that belong to
1772 the staff and there are other objects that should be
1773 placed outside the staff.  These are called within-staff
1774 objects and outside-staff objects respectively.
1775
1776 Within-staff objects are those that are located on the staff
1777 -- note heads, stems, accidentals, etc.  The positions of
1778 these are usually fixed by the music itself -- they are
1779 vertically positioned on specific lines of the staff or are
1780 tied to other objects that are so positioned.  Collisions of
1781 note heads, stems and accidentals in closely set chords are
1782 normally avoided automatically.  There are commands and
1783 overrides which can modify this automatic behavior, as we
1784 shall shortly see.
1785
1786 Objects belonging outside the staff include things such as
1787 rehearsal marks, text and dynamic markings.  LilyPond's rule for
1788 the vertical placement of outside-staff objects is to place them
1789 as close to the staff as possible but not so close that they
1790 collide with any other object.  LilyPond uses the
1791 @code{outside-staff-priority} property to determine the order in
1792 which the objects should be placed, as follows.
1793
1794 First, LilyPond places all the within-staff objects.
1795 Then it sorts the outside-staff objects according to their
1796 @code{outside-staff-priority}.  The outside-staff objects are
1797 taken one by one, beginning with the object with the lowest
1798 @code{outside-staff-priority}, and placed so that they do not
1799 collide with any objects that have already been placed.  That is,
1800 if two outside-staff grobs are competing for the same space, the
1801 one with the lower @code{outside-staff-priority} will be placed
1802 closer to the staff.  If two objects have the same
1803 @code{outside-staff-priority} the one encountered first will be
1804 placed closer to the staff.
1805
1806 In the following example all the markup texts have the same
1807 priority (since it is not explicitly set).  Note that @q{Text3}
1808 is automatically positioned close to the staff again, nestling
1809 under @q{Text2}.
1810
1811 @cindex markup example
1812
1813 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1814 c2^"Text1"
1815 c2^"Text2" |
1816 c2^"Text3"
1817 c2^"Text4" |
1818 @end lilypond
1819
1820 Staves are also positioned, by default, as closely together as
1821 possible (subject to a minimum separation).  If notes project
1822 a long way towards an adjacent staff they will force the
1823 staves further apart only if an overlap of the notation
1824 would otherwise occur.  The following example demonstrates
1825 this @q{nestling} of the notes on adjacent staves:
1826
1827 @lilypond[quote,ragged-right,verbatim]
1828 <<
1829   \new Staff {
1830     \relative c' { c4 a, }
1831   }
1832   \new Staff {
1833     \relative c'''' { c4 a, }
1834   }
1835 >>
1836 @end lilypond
1837
1838
1839 @node Within-staff objects
1840 @subsection Within-staff objects
1841
1842 We have already seen how the commands @code{\voiceXXX} affect the
1843 direction of slurs, ties, fingering and everything else which depends on
1844 the direction of the stems -- see @ref{Explicitly instantiating voices}.
1845 These commands are essential when writing polyphonic music to permit
1846 interweaving melodic lines to be distinguished.  But occasionally it may
1847 be necessary to override this automatic behavior.  This can be done for
1848 whole sections of music or even for an individual note.  The property
1849 which controls this behavior is the @code{direction} property of each
1850 layout object.  We first explain what this does, and then introduce a
1851 number of ready-made commands which avoid your having to code explicit
1852 overrides for the more common modifications.
1853
1854 Some layout objects like slurs and ties curve, bend or point
1855 either up or down; others like stems and flags also move to
1856 right or left when they point up or down.  This is controlled
1857 automatically when @code{direction} is set.
1858
1859 @menu
1860 * The direction property::
1861 * Fingering::
1862 @end menu
1863
1864 @node The direction property
1865 @unnumberedsubsubsec The @code{direction} property
1866
1867 @cindex down
1868 @cindex up
1869 @cindex center
1870 @cindex neutral
1871
1872 The following example shows in bar 1 the default behavior of stems,
1873 with those on high notes pointing down and those on low notes pointing
1874 up, followed by four notes with all stems forced down, four notes with
1875 all stems forced up, and finally four notes reverted back to the
1876 default behavior.
1877
1878 @cindex Stem, example of overriding
1879 @cindex direction property, example
1880
1881 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1882 a4 g c a |
1883 \override Stem.direction = #DOWN
1884 a4 g c a |
1885 \override Stem.direction = #UP
1886 a4 g c a |
1887 \revert Stem.direction
1888 a4 g c a |
1889 @end lilypond
1890
1891 Here we use the constants @code{DOWN} and @code{UP}.
1892 These have the values @w{@code{-1}} and @code{+1} respectively, and
1893 these numerical values may be used instead.  The value @code{0}
1894 may also be used in some cases.  It is simply treated as meaning
1895 @code{UP} for stems, but for some objects it means @q{center}.
1896 There is a constant, @code{CENTER} which has the value @code{0}.
1897
1898 However, these explicit overrides are not usually used, as there are
1899 simpler equivalent predefined commands available.  Here is a table of
1900 the commonest.  The meaning of each is stated where it is not obvious.
1901
1902 @multitable @columnfractions .2 .2 .25 .35
1903 @headitem Down/Left
1904   @tab Up/Right
1905   @tab Revert
1906   @tab Effect
1907 @item @code{\arpeggioArrowDown}
1908   @tab @code{\arpeggioArrowUp}
1909   @tab @code{\arpeggioNormal}
1910   @tab Arrow is at bottom, at top, or no arrow
1911 @item @code{\dotsDown}
1912   @tab @code{\dotsUp}
1913   @tab @code{\dotsNeutral}
1914   @tab Direction of movement to avoid staff lines
1915 @item @code{\dynamicDown}
1916   @tab @code{\dynamicUp}
1917   @tab @code{\dynamicNeutral}
1918   @tab
1919 @item @code{\phrasingSlurDown}
1920   @tab @code{\phrasingSlurUp}
1921   @tab @code{\phrasingSlurNeutral}
1922   @tab Note: distinct from slur commands
1923 @item @code{\slurDown}
1924   @tab @code{\slurUp}
1925   @tab @code{\slurNeutral}
1926   @tab
1927 @item @code{\stemDown}
1928   @tab @code{\stemUp}
1929   @tab @code{\stemNeutral}
1930   @tab
1931 @item @code{\textSpannerDown}
1932   @tab @code{\textSpannerUp}
1933   @tab @code{\textSpannerNeutral}
1934   @tab Text entered as spanner is below/above staff
1935 @item @code{\tieDown}
1936   @tab @code{\tieUp}
1937   @tab @code{\tieNeutral}
1938   @tab
1939 @item @code{\tupletDown}
1940   @tab @code{\tupletUp}
1941   @tab @code{\tupletNeutral}
1942   @tab Tuplets are below/above notes
1943 @end multitable
1944
1945 The neutral/normal variants of these commands are implemented
1946 using @code{\revert} and may @strong{not} be
1947 preceded by @code{\once}.  If you wish to limit the
1948 effect of the other commands (which are implemented using
1949 @code{\override}) to a single timestep, you can precede them with
1950 @code{\once} like you would do with explicit overrides.
1951
1952 @node Fingering
1953 @unnumberedsubsubsec Fingering
1954
1955 @cindex fingering, placement
1956 @cindex fingering, chords
1957
1958 The placement of fingering on single notes can also be controlled
1959 by the @code{direction} property, but changing @code{direction}
1960 has no effect on chords.  As we shall see, there are special
1961 commands which allow the fingering of individual notes
1962 of chords to be controlled, with the fingering being placed
1963 above, below, to the left or to the right of each note.
1964
1965 First, here's the effect of @code{direction} on the fingering
1966 attached to single notes.  The first bar shows the default
1967 behaviour, and the following two bars shows the effect of
1968 specifying @code{DOWN} and @code{UP}:
1969
1970 @cindex Fingering, example of overriding
1971 @cindex direction property, example
1972
1973 @lilypond[quote,verbatim,relative=2]
1974 c4-5 a-3 f-1 c'-5 |
1975 \override Fingering.direction = #DOWN
1976 c4-5 a-3 f-1 c'-5 |
1977 \override Fingering.direction = #UP
1978 c4-5 a-3 f-1 c'-5 |
1979 @end lilypond
1980
1981 However, overriding the @code{direction} property is not the
1982 easiest way of manually setting the fingering above or below
1983 the notes; using @code{_} or @code{^} instead of @code{-} before
1984 the fingering number is usually preferable.  Here is the previous
1985 example using this method:
1986
1987 @cindex fingering example
1988
1989 @lilypond[quote,verbatim,relative=2]
1990 c4-5 a-3 f-1 c'-5 |
1991 c4_5 a_3 f_1 c'_5 |
1992 c4^5 a^3 f^1 c'^5 |
1993 @end lilypond
1994
1995 The @code{direction} property is ignored for chords, but the
1996 directional prefixes, @code{_} and @code{^} do work.  By default,
1997 the fingering is automatically placed both above and below the
1998 notes of a chord, as shown:
1999
2000 @cindex fingering example
2001
2002 @lilypond[quote,verbatim,relative=2]
2003 <c-5 g-3>4
2004 <c-5 g-3 e-2>4
2005 <c-5 g-3 e-2 c-1>4
2006 @end lilypond
2007
2008 @noindent
2009 but this may be overridden to manually force all or any of the
2010 individual fingering numbers above or below:
2011
2012 @cindex fingering example
2013
2014 @lilypond[quote,verbatim,relative=2]
2015 <c-5 g-3 e-2 c-1>4
2016 <c^5 g_3 e_2 c_1>4
2017 <c^5 g^3 e^2 c_1>4
2018 @end lilypond
2019
2020 Even greater control over the placement of fingering of the
2021 individual notes in a chord is possible by using the
2022 @code{\set fingeringOrientations} command.  The format of this
2023 command is:
2024
2025 @example
2026 @code{\set fingeringOrientations = #'([up] [left/right] [down])}
2027 @end example
2028
2029 @noindent
2030 @code{\set} is used because @code{fingeringOrientations} is a
2031 property of the @code{Voice} context, created and used by the
2032 @code{New_fingering_engraver}.
2033
2034 The property may be set to a list of one to three values.
2035 It controls whether fingerings may be placed above (if
2036 @code{up} appears in the list), below (if @code{down} appears),
2037 to the left (if @code{left} appears, or to the right
2038 (if @code{right} appears).  Conversely, if a location is not
2039 listed, no fingering is placed there.  LilyPond takes these
2040 constraints and works out the best placement for the fingering
2041 of the notes of the following chords.  Note that @code{left} and
2042 @code{right} are mutually exclusive -- fingering may be placed
2043 only on one side or the other, not both.
2044
2045 @warning{To control the placement of the fingering of a single
2046 note using this command it is necessary to write it as a single
2047 note chord by placing angle brackets round it.}
2048
2049 Here are a few examples:
2050
2051 @cindex fingering example
2052 @cindex @code{\set}, example of using
2053 @cindex fingeringOrientations property, example
2054
2055 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2056 \set fingeringOrientations = #'(left)
2057 <f-2>4
2058 <c-1 e-2 g-3 b-5>4
2059 \set fingeringOrientations = #'(left)
2060 <f-2>4
2061 <c-1 e-2 g-3 b-5>4 |
2062 \set fingeringOrientations = #'(up left down)
2063 <f-2>4
2064 <c-1 e-2 g-3 b-5>4
2065 \set fingeringOrientations = #'(up left)
2066 <f-2>4
2067 <c-1 e-2 g-3 b-5>4 |
2068 \set fingeringOrientations = #'(right)
2069 <f-2>4
2070 <c-1 e-2 g-3 b-5>4
2071 @end lilypond
2072
2073 @noindent
2074 If the fingering seems a little crowded the @code{font-size}
2075 could be reduced.  The default value can be seen from the
2076 @code{Fingering} object in the IR to be @w{@code{-5}}, so let's
2077 try @w{@code{-7}}:
2078
2079 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2080 \override Fingering.font-size = #-7
2081 \set fingeringOrientations = #'(left)
2082 <f-2>4
2083 <c-1 e-2 g-3 b-5>4
2084 \set fingeringOrientations = #'(left)
2085 <f-2>4
2086 <c-1 e-2 g-3 b-5>4 |
2087 \set fingeringOrientations = #'(up left down)
2088 <f-2>4
2089 <c-1 e-2 g-3 b-5>4
2090 \set fingeringOrientations = #'(up left)
2091 <f-2>4
2092 <c-1 e-2 g-3 b-5>4 |
2093 \set fingeringOrientations = #'(right)
2094 <f-2>4
2095 <c-1 e-2 g-3 b-5>4
2096 @end lilypond
2097
2098 @node Outside-staff objects
2099 @subsection Outside-staff objects
2100
2101 Outside-staff objects are automatically placed to avoid collisions.
2102 There are several ways to override the automatic placement if the
2103 positioning is not optimum.
2104
2105 @menu
2106 * The outside-staff-priority property::
2107 * The textLengthOn command::
2108 * Dynamics placement::
2109 * Grob sizing::
2110 @end menu
2111
2112
2113 @node The outside-staff-priority property
2114 @unnumberedsubsubsec The @code{outside-staff-priority} property
2115
2116 Objects with the lower value of the @code{outside-staff-priority}
2117 property are placed nearer to the staff, and other outside-staff
2118 objects are then raised as far as necessary to avoid collisions.
2119 The @code{outside-staff-priority} is defined in the
2120 @code{grob-interface} and so is a property of all layout objects.
2121 By default it is set to @code{#f} for all within-staff objects,
2122 and to a numerical value appropriate to each outside-staff object
2123 when the object is created.  The following table shows the default
2124 numerical values for some of the commonest outside-staff objects.
2125
2126 @cindex spanners
2127
2128 Note the unusual names for some of the objects: spanner objects
2129 are automatically created to control the vertical positioning of
2130 grobs which (might) start and end at different musical moments, so
2131 changing the @code{outside-staff-priority} of the underlying grob
2132 will have no effect.  For example, changing
2133 @code{outside-staff-priority} of the @code{Hairpin} object will
2134 have no effect on the vertical positioning of hairpins -- you must
2135 change @code{outside-staff-priority} of the associated
2136 @code{DynamicLineSpanner} object instead.  This override must be
2137 placed at the start of the spanner, which might include several
2138 linked hairpins and dynamics.
2139
2140 @multitable @columnfractions .3 .3 .3
2141 @headitem Layout Object
2142   @tab Priority
2143   @tab Controls position of:
2144 @item @code{RehearsalMark}
2145   @tab @code{1500}
2146   @tab Rehearsal marks
2147 @item @code{MetronomeMark}
2148   @tab @code{1000}
2149   @tab Metronome marks
2150 @item @code{VoltaBracketSpanner}
2151   @tab @code{600}
2152   @tab Volta brackets
2153 @item @code{TextScript}
2154   @tab @code{450}
2155   @tab Markup text
2156 @item @code{MultiMeasureRestText}
2157   @tab @code{450}
2158   @tab Markup text over full-bar rests
2159 @item @code{OttavaBracket}
2160   @tab @code{400}
2161   @tab Ottava brackets
2162 @item @code{TextSpanner}
2163   @tab @code{350}
2164   @tab Text spanners
2165 @item @code{DynamicLineSpanner}
2166   @tab @code{250}
2167   @tab All dynamic markings
2168 @item @code{BarNumber}
2169   @tab @code{ 100}
2170   @tab Bar numbers
2171 @item @code{TrillSpanner}
2172   @tab @code{50}
2173   @tab Spanning trills
2174 @end multitable
2175
2176 Here is an example showing the default placement of some of
2177 these.
2178
2179 @cindex text spanner
2180 @cindex ottava bracket
2181
2182 @funindex \startTextSpan
2183 @funindex startTextSpan
2184 @funindex \stopTextSpan
2185 @funindex stopTextSpan
2186
2187 @cindex TextSpanner, example of overriding
2188 @cindex bound-details property, example
2189
2190 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2191 % Set details for later Text Spanner
2192 \override TextSpanner.bound-details.left.text
2193     = \markup { \small \bold Slower }
2194 % Place dynamics above staff
2195 \dynamicUp
2196 % Start Ottava Bracket
2197 \ottava #1
2198 c'4 \startTextSpan
2199 % Add Dynamic Text and hairpin
2200 c4\pp\<
2201 c4
2202 % Add Text Script
2203 c4^Text |
2204 c4 c
2205 % Add Dynamic Text and terminate hairpin
2206 c4\ff c \stopTextSpan |
2207 % Stop Ottava Bracket
2208 \ottava #0
2209 c,4 c c c |
2210 @end lilypond
2211
2212 This example also shows how to create Text Spanners --
2213 text with extender lines above a section of music.  The
2214 spanner extends from the @code{\startTextSpan} command to
2215 the @code{\stopTextSpan} command, and the format of the
2216 text is defined by the @code{\override TextSpanner} command.
2217 For more details see @ruser{Text spanners}.
2218
2219 It also shows how ottava brackets are created.
2220
2221 @cindex tweaking bar number placement
2222 @cindex bar numbers, tweaking placement
2223 @cindex tweaking metronome mark placement
2224 @cindex metronome mark, tweaking placement
2225 @cindex tweaking rehearsal mark placement
2226 @cindex rehearsal marks, tweaking placement
2227
2228 If the default values of @code{outside-staff-priority} do not give you
2229 the placing you want, the priority of any of the objects may be
2230 overridden.  Suppose we would like the ottava bracket to be placed
2231 below the text spanner in the example above.  All we need to do is to
2232 look up the priority of @code{OttavaBracket} in the IR or in the
2233 tables above, and reduce it to a value lower than that of a
2234 @code{TextSpanner}, remembering that @code{OttavaBracket} is created
2235 in the @code{Staff} context:
2236
2237 @cindex TextSpanner, example of overriding
2238 @cindex bound-details property, example
2239
2240 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2241 % Set details for later Text Spanner
2242 \override TextSpanner.bound-details.left.text
2243     = \markup { \small \bold Slower }
2244 % Place dynamics above staff
2245 \dynamicUp
2246 % Place following Ottava Bracket below Text Spanners
2247 \once \override Staff.OttavaBracket.outside-staff-priority = #340
2248 % Start Ottava Bracket
2249 \ottava #1
2250 c'4 \startTextSpan
2251 % Add Dynamic Text
2252 c4\pp
2253 % Add Dynamic Line Spanner
2254 c4\<
2255 % Add Text Script
2256 c4^Text |
2257 c4 c
2258 % Add Dynamic Text
2259 c4\ff c \stopTextSpan |
2260 % Stop Ottava Bracket
2261 \ottava #0
2262 c,4 c c c |
2263 @end lilypond
2264
2265 Note that some of these objects, in particular bar numbers,
2266 metronome marks and rehearsal marks, live by default in the
2267 @code{Score} context, so be sure to use the correct context
2268 when these are being overriden.
2269
2270 @cindex slurs and outside-staff-priority
2271 @cindex slurs and articulations
2272 @cindex articulations and slurs
2273
2274 Slurs by default are classed as within-staff objects, but
2275 they often appear above the staff if the notes to
2276 which they are attached are high on the staff.  This can push
2277 outside-staff objects such as articulations too high, as the slur
2278 will be placed first.  The @code{avoid-slur} property of the
2279 articulation can be set to @code{'inside} to bring the articulation
2280 inside the slur, but the @code{avoid-slur} property is effective
2281 only if the @code{outside-staff-priority} is also set to @code{#f}.
2282 Alternatively, the @code{outside-staff-priority} of the slur
2283 can be set to a numerical value to cause it to be placed along with
2284 other outside-staff objects according to that value.  Here's an
2285 example showing the effect of the two methods:
2286
2287 @lilypond[quote,verbatim,relative=2]
2288 c4( c^\markup { \tiny \sharp } d4.) c8 |
2289 c4(
2290 \once \override TextScript.avoid-slur = #'inside
2291 \once \override TextScript.outside-staff-priority = ##f
2292 c4^\markup { \tiny \sharp } d4.) c8 |
2293 \once \override Slur.outside-staff-priority = #500
2294 c4( c^\markup { \tiny \sharp } d4.) c8 |
2295 @end lilypond
2296
2297 Changing the @code{outside-staff-priority} can also be used to
2298 control the vertical placement of individual objects, although
2299 the results may not always be desirable.  Suppose we would
2300 like @qq{Text3} to be placed above @qq{Text4} in the example
2301 under Automatic behavior, above (see @ref{Automatic behavior}).
2302 All we need to do is to look up the priority of @code{TextScript}
2303 in the IR or in the tables above, and increase the priority of
2304 @qq{Text3} to a higher value:
2305
2306 @cindex TextScript, example of overriding
2307 @cindex outside-staff-priority property, example
2308
2309 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2310 c2^"Text1"
2311 c2^"Text2" |
2312 \once \override TextScript.outside-staff-priority = #500
2313 c2^"Text3"
2314 c2^"Text4" |
2315 @end lilypond
2316
2317 This certainly lifts @qq{Text3} above @qq{Text4} but it also lifts it
2318 above @qq{Text2}, and @qq{Text4} now drops down.  Perhaps this is not
2319 so good.  What we would really like to do is to position all the
2320 annotation at the same distance above the staff.  To do this, we
2321 clearly will need to space the notes out horizontally to make more
2322 room for the text.  This is done using the @code{textLengthOn}
2323 command.
2324
2325 @node The textLengthOn command
2326 @unnumberedsubsubsec The @code{@bs{}textLengthOn} command
2327
2328 @cindex notes, spreading out with text
2329
2330 @funindex \textLengthOn
2331 @funindex textLengthOn
2332 @funindex \textLengthOff
2333 @funindex textLengthOff
2334
2335 By default, text produced by markup takes up no horizontal space
2336 as far as laying out the music is concerned.  The @code{\textLengthOn}
2337 command reverses this behavior, causing the notes to be spaced
2338 out as far as is necessary to accommodate the text:
2339
2340 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2341 \textLengthOn  % Cause notes to space out to accommodate text
2342 c2^"Text1"
2343 c2^"Text2" |
2344 c2^"Text3"
2345 c2^"Text4" |
2346 @end lilypond
2347
2348 The command to revert to the default behavior is
2349 @code{\textLengthOff}.  Alternatively, @code{\once} may be used
2350 with @code{\textLengthOn} if the effect is to be limited to just a
2351 single musical moment.
2352 The corresponding spacing behavior for rehearsal marks and tempo
2353 indications is independently controlled with the commands
2354 @code{\markLengthOn} and @code{\markLengthOff}.
2355
2356 @cindex markup text, allowing collisions
2357
2358 Markup text will also avoid notes which project above the staff.
2359 If this is not desired, the automatic displacement upwards may
2360 be turned off by setting the priority to @code{#f}.  Here's an
2361 example to show how markup text interacts with such notes.
2362
2363 @cindex TextScript, example of overriding
2364 @cindex outside-staff-priority property, example
2365
2366 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2367 % This markup is short enough to fit without collision
2368 c2^"Tex" c'' |
2369 R1 |
2370
2371 % This is too long to fit, so it is displaced upwards
2372 c,,2^"Text" c'' |
2373 R1 |
2374
2375 % Turn off collision avoidance
2376 \once \override TextScript.outside-staff-priority = ##f
2377 c,,2^"Long Text   " c'' |
2378 R1 |
2379
2380 % Turn off collision avoidance
2381 \once \override TextScript.outside-staff-priority = ##f
2382 \textLengthOn        % and turn on textLengthOn
2383 c,,2^"Long Text   "  % Spaces at end are honored
2384 c''2 |
2385 @end lilypond
2386
2387 @node Dynamics placement
2388 @unnumberedsubsubsec Dynamics placement
2389
2390 @cindex tweaking dynamics placement
2391 @cindex dynamics, tweaking placement
2392
2393 Dynamic markings will normally be positioned beneath the
2394 staff, but may be positioned above with the @code{\dynamicUp}
2395 command.  They will be positioned vertically relative to the
2396 note to which they are attached, and will float below (or above)
2397 all within-staff objects such as phrasing slurs and bar numbers.
2398 This can give quite acceptable results, as this example
2399 shows:
2400
2401 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2402 \clef "bass"
2403 \key aes \major
2404 \time 9/8
2405 \dynamicUp
2406 bes4.~\f\< \( bes4 bes8 des4\ff\> c16 bes\! |
2407 ees,2.~\)\mf ees4 r8 |
2408 @end lilypond
2409
2410 However, if the notes and attached dynamics are close
2411 together the automatic placement will avoid collisions
2412 by displacing later dynamic markings further away, but this may
2413 not be the optimum placement, as this rather artificial example
2414 shows:
2415
2416 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2417 \dynamicUp
2418 a4\f b\mf a\mp b\p
2419 @end lilypond
2420
2421 @noindent
2422 Should a similar situation arise in @q{real} music, it may be
2423 preferable to space out the notes a little further, so the dynamic
2424 markings can all fit at the same vertical distance from the staff.  We
2425 were able to do this for markup text by using the @code{\textLengthOn}
2426 command, but there is no equivalent command for dynamic marks.  So we
2427 shall have to work out how to do this using @code{\override} commands.
2428
2429 @node Grob sizing
2430 @unnumberedsubsubsec Grob sizing
2431
2432 @cindex grob sizing
2433 @cindex sizing grobs
2434
2435 First we must learn how grobs are sized.  All grobs have a
2436 reference point defined within them which is used to position
2437 them relative to their parent object.  This point in the grob
2438 is then positioned at a horizontal distance, @code{X-offset},
2439 and at a vertical distance, @code{Y-offset}, from its parent.
2440 The horizontal extent of the object is given by a pair of
2441 numbers, @code{X-extent}, which say where the left and right
2442 edges are relative to the reference point.  The vertical extent
2443 is similarly defined by a pair of numbers, @code{Y-extent}.
2444 These are properties of all grobs which support the
2445 @code{grob-interface}.
2446
2447 @cindex @code{extra-spacing-width}
2448
2449 By default, outside-staff objects are given a width of zero so
2450 that they may overlap in the horizontal direction.  This is done
2451 by the trick of making the leftmost extent infinity and
2452 the rightmost extent minus infinity by setting the
2453 @code{extra-spacing-width} to @code{'(+inf.0 . -inf.0)}.  To
2454 ensure they do not overlap in the horizontal direction we
2455 must override this value of @code{extra-spacing-width} to give them
2456 a little extra spacing.  The units are the space between two staff
2457 lines, so moving the left edge half a unit to the left and the
2458 right edge half a unit to the right should do it:
2459
2460 @example
2461 \override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
2462 @end example
2463
2464 @noindent
2465 Let's see if this works in our previous example:
2466
2467 @cindex DynamicText, example of overriding
2468 @cindex extra-spacing-width property, example
2469
2470
2471 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2472 \dynamicUp
2473 % Extend width by 1 staff space
2474 \override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
2475 a4\f b\mf a\mp b\p
2476 @end lilypond
2477
2478 @noindent
2479 This looks better, but maybe we would prefer the dynamic marks
2480 to be aligned along the same baseline rather than going up and
2481 down with the notes.  The property to do this is
2482 @code{staff-padding} which is covered in the section on collisions
2483 (see @ref{Collisions of objects}).
2484
2485
2486 @node Vertical spacing
2487 @section Vertical spacing
2488
2489 As a rule, LilyPond's vertical spacing of musical objects is pretty
2490 good.  Let's see how it does with a simple song, with 2 voices and
2491 piano accompaniment:
2492
2493 @lilypond[quote,fragment,ragged-right]
2494 <<
2495   \new ChoirStaff
2496   <<
2497     \new Staff {
2498       \new Voice = "music" {
2499         b'2 c' c' c'
2500       }
2501     }
2502     \new Lyrics
2503     \lyricsto "music" {
2504       Here are some lyrics
2505     }
2506     \new Staff {
2507       \clef bass e'2 f e c
2508     }
2509   >>
2510   \new PianoStaff
2511   <<
2512     \new Staff {
2513       g''2 c'' c'' a''
2514     }
2515     \new Staff {
2516       \clef bass e2 f c e
2517     }
2518   >>
2519 >>
2520 @end lilypond
2521
2522 There's nothing wrong with the default vertical spacing.  However, let's
2523 assume that you're working with a publisher with some specific
2524 requirements for vertical spacing of staves and lyrics: they want
2525 the lyrics spaced away from any notes, they want the piano
2526 accompaniment spaced away from the vocal line and they want the two
2527 piano staves pushed together tightly.  Let's start with the lyrics.
2528
2529 Lyrics sit within a system, and therefore the commands to space them
2530 are found in @ruser{Flexible vertical spacing within systems}.  It
2531 tells us that lyrics are @code{non-staff lines} and therefore the
2532 command to change their spacing will refer to the @code{nonstaff}
2533 property.  Spacing them away from the staff to which they relate
2534 (the top line) will use the @code{relatedstaff} property.  Spacing
2535 them from the lower line will use the @code{unrelatedstaff} property.
2536 The vocal parts are part of a @code{VerticalAxisGroup}, so we need to
2537 adjust its properties.  Let's try it and see if it works.
2538
2539 @lilypond[quote,fragment,ragged-right,verbatim]
2540 <<
2541   \new ChoirStaff
2542   <<
2543     \new Staff {
2544       \new Voice = "music" {
2545         b'2 c' c' c'
2546       }
2547     }
2548     \new Lyrics \with {
2549       \override VerticalAxisGroup.
2550         nonstaff-relatedstaff-spacing.padding = #5
2551       \override VerticalAxisGroup.
2552         nonstaff-unrelatedstaff-spacing.padding = #5
2553     }
2554     \lyricsto "music" {
2555       Here are some lyrics
2556     }
2557     \new Staff {
2558       \clef bass e'2 f e c
2559     }
2560   >>
2561   \new PianoStaff
2562   <<
2563     \new Staff {
2564       g''2 c'' c'' a''
2565     }
2566     \new Staff {
2567       \clef bass e2 f c e
2568     }
2569   >>
2570 >>
2571 @end lilypond
2572
2573 Well - yes it does, but perhaps too well.  When we set the
2574 @code{padding} to 5, LilyPond adds 5 staff spaces to the distance
2575 between objects, which is too much for us here.  We'll use 2.
2576
2577 Next, let's move the piano music away from the vocal parts.  The
2578 vocal music is a @code{ChoirStaff}, so we need to increase the
2579 spacing between that group of staves and the piano staff below.
2580 We'll do this by changing the @code{basic-distance} of the
2581 @code{StaffGrouper}'s @code{staffgroup-staff-spacing}.
2582
2583 @lilypond[quote,fragment,ragged-right,verbatim]
2584 <<
2585   \new ChoirStaff \with {
2586     \override StaffGrouper.
2587       staffgroup-staff-spacing.basic-distance = #15
2588   }
2589   <<
2590     \new Staff {
2591       \new Voice = "music" {
2592         b'2 c' c' c'
2593       }
2594     }
2595     \new Lyrics \with {
2596       \override VerticalAxisGroup.
2597         nonstaff-relatedstaff-spacing.padding = #2
2598       \override VerticalAxisGroup.
2599         nonstaff-unrelatedstaff-spacing.padding = #2
2600     }
2601     \lyricsto "music" {
2602       Here are some lyrics
2603     }
2604     \new Staff {
2605       \clef bass e'2 f e c
2606     }
2607   >>
2608   \new PianoStaff
2609   <<
2610     \new Staff {
2611       g''2 c'' c'' a''
2612     }
2613     \new Staff {
2614       \clef bass e2 f c e
2615     }
2616   >>
2617 >>
2618 @end lilypond
2619
2620 Excellent.  Now just for the last requirement to make the piano staves
2621 closer together.  To do this, we again alter the properties of the
2622 @code{StaffGrouper}, but this time we're going to reduce both
2623 the @code{basic-distance} and the @code{padding}.  We can do this
2624 as shown below.
2625
2626 @lilypond[quote,fragment,ragged-right,verbatim]
2627 <<
2628   \new ChoirStaff \with {
2629     \override StaffGrouper.
2630       staffgroup-staff-spacing.basic-distance = #15
2631   }
2632   <<
2633     \new Staff {
2634       \new Voice = "music" {
2635         b'2 c' c' c'
2636       }
2637     }
2638     \new Lyrics \with {
2639       \override VerticalAxisGroup.
2640         nonstaff-relatedstaff-spacing.padding = #2
2641       \override VerticalAxisGroup.
2642         nonstaff-unrelatedstaff-spacing.padding = #2
2643     }
2644     \lyricsto "music" {
2645       Here are some lyrics
2646     }
2647     \new Staff {
2648       \clef bass e'2 f e c
2649     }
2650   >>
2651   \new PianoStaff \with {
2652     \override StaffGrouper.staff-staff-spacing = #'(
2653                             (basic-distance . 0)
2654                             (padding . 0))
2655   }
2656   <<
2657     \new Staff {
2658       g''2 c'' c'' a''
2659     }
2660     \new Staff {
2661       \clef bass e2 f c e
2662     }
2663   >>
2664 >>
2665 @end lilypond
2666
2667 That's put them really close together -- but it's what
2668 the publisher wanted.  They could be moved further
2669 apart by altering the @code{padding} or @code{basic-distance}
2670 if wanted.
2671
2672 There are many ways of altering vertical spacing.  A key point
2673 to remember is that the spacing between objects in a
2674 @code{StaffGroup} (like @code{GrandStaff} or
2675 @code{PianoStaff} groups) is controlled by the spacing variables
2676 of the @code{StaffGrouper}. Spacing from ungrouped staves
2677 (like @code{Lyrics} and @code{Staff}) is controlled by the
2678 variables of the @code{VerticalAxisGroup}.  See the
2679 @ruser{Flexible vertical spacing paper variables} and
2680 @ruser{Flexible vertical spacing within systems} for more
2681 details.
2682
2683 @node Collisions of objects
2684 @section Collisions of objects
2685
2686 @menu
2687 * Moving objects::
2688 * Fixing overlapping notation::
2689 * Real music example::
2690 @end menu
2691
2692 @node Moving objects
2693 @subsection Moving objects
2694
2695 @cindex moving overlapping objects
2696 @cindex moving colliding objects
2697 @cindex moving colliding grobs
2698 @cindex objects, moving colliding
2699 @cindex grobs, moving colliding
2700
2701 This may come as a surprise, but LilyPond is not perfect.  Some
2702 notation elements can overlap.  This is unfortunate, but in fact
2703 rather rare.  Usually the need to move objects is for clarity or
2704 aesthetic reasons -- they would look better with a little more
2705 or a little less space around them.
2706
2707 There are three main approaches to resolving overlapping
2708 notation.  They should be considered in the following order:
2709
2710 @enumerate
2711 @item
2712 The @strong{direction} of one of the overlapping objects may
2713 be changed using the predefined commands listed above for
2714 within-staff objects (see @ref{Within-staff objects}).
2715 Stems, slurs, beams, ties, dynamics, text and tuplets may be
2716 repositioned easily in this way.  The limitation is that you
2717 have a choice of only two positions, and neither may be
2718 suitable.
2719
2720 @item
2721 The @strong{object properties}, which LilyPond uses when positioning
2722 layout objects, may be modified using @code{\override}.  The
2723 advantages of making changes to this type of property are (a) that
2724 some other objects will be moved automatically if necessary to make
2725 room and (b) the single override can apply to all instances of the
2726 same type of object.  Such properties include:
2727
2728 @itemize
2729
2730 @item
2731 @code{direction}
2732
2733 This has already been covered in some detail -- see
2734 @ref{Within-staff objects}.
2735
2736 @item
2737 @code{padding}, @code{right-padding}, @code{staff-padding}
2738
2739 @cindex padding
2740 @cindex padding property
2741 @cindex right-padding property
2742 @cindex staff-padding property
2743
2744 As an object is being positioned the value of its @code{padding}
2745 property specifies the gap that must be left between itself and the
2746 nearest edge of the object against which it is being positioned.  Note
2747 that it is the @code{padding} value of the object @strong{being
2748 placed} that is used; the @code{padding} value of the object which is
2749 already placed is ignored.  Gaps specified by @code{padding} can be
2750 applied to all objects which support the
2751 @code{side-position-interface}.
2752
2753 Instead of @code{padding}, the placement of groups of accidentals
2754 is controlled by @code{right-padding}.  This property is to be found
2755 in the @code{AccidentalPlacement} object which, note, lives in the
2756 @strong{Staff} context.  In the typesetting process the note heads
2757 are typeset first and then the accidentals, if any, are added to the
2758 left of the note heads using the @code{right-padding} property to determine
2759 the separation from the note heads and between individual accidentals.
2760 So only the @code{right-padding} property of the @code{AccidentalPlacement}
2761 object has any effect on the placement of the accidentals.
2762
2763 The @code{staff-padding} property is closely related to the
2764 @code{padding} property: @code{padding} controls the minimum amount of
2765 space between any object which supports the
2766 @code{side-position-interface} and the nearest other object (generally
2767 the note or the staff lines); @code{staff-padding} applies only to
2768 those objects which are always set outside the staff -- it controls
2769 the minimum distance from the staff to the outside-staff object.
2770 Note that @code{staff-padding} has no effect on
2771 objects that are positioned relative to the note rather than the
2772 staff, even though it may be overridden without error for such objects
2773 -- it is simply ignored.
2774
2775 To discover which padding property is required for the object you wish
2776 to reposition, you need to return to the IR and look up the object's
2777 properties.  Be aware that the padding properties might not be located
2778 in the obvious object, so look in objects that appear to be related.
2779
2780 All padding values are measured in staff spaces.  For most
2781 objects, this value is set by default to be around 1.0 or less
2782 (it varies with each object).  It may be overridden if a larger
2783 (or smaller) gap is required.
2784
2785 @item
2786 @code{self-alignment-X}
2787
2788 @cindex self-alignment-X property
2789
2790 This property can be used to align the object to the left, to
2791 the right, or to center it with respect to the parent object's
2792 reference point.  It may be used with all objects which support
2793 the @code{self-alignment-interface}.  In general these are objects
2794 that contain text.  The values are @code{LEFT}, @code{RIGHT}
2795 or @code{CENTER}.  Alternatively, a numerical value between
2796 @w{@code{-1}} and @code{+1} may be specified, where @w{@code{-1}} is
2797 left-aligned, @code{+1} is right-aligned, and numbers in between
2798 move the text progressively from left-aligned to right-aligned.
2799 Numerical values greater than @code{1} may be specified to move
2800 the text even further to the left, or less than @w{@code{-1}} to
2801 move the text even further to the right.  A change of @code{1}
2802 in the value corresponds to a movement of half the text's length.
2803
2804 @item
2805 @code{extra-spacing-width}
2806
2807 @cindex extra-spacing-width property
2808
2809 This property is available for all objects which support the
2810 @code{item-interface}.  It takes two numbers, the first is added
2811 to the leftmost extent and the second is added to the rightmost
2812 extent.  Negative numbers move the edge to the left, positive to
2813 the right, so to widen an object the first number must be negative,
2814 the second positive.  Note that not all objects honor both
2815 numbers.  For example, the @code{Accidental} object only takes
2816 notice of the first (left edge) number.
2817
2818 @item
2819 @code{staff-position}
2820
2821 @cindex staff-position property
2822
2823 @code{staff-position} is a property of the
2824 @code{staff-symbol-referencer-interface}, which is supported by
2825 objects which are positioned relative to the staff.  It specifies
2826 the vertical position of the object relative to the center line
2827 of the staff in half staff-spaces.  It is useful in resolving
2828 collisions between layout objects like multi-measure rests, ties
2829 and notes in different voices.
2830
2831 @item
2832 @code{horizontal-shift}
2833
2834 @cindex horizontal-shift property
2835 @cindex note column
2836 @cindex note collisions
2837 @cindex collisions, notes
2838 @cindex shift commands
2839 @funindex \shiftOff
2840 @funindex shiftOff
2841 @funindex \shiftOn
2842 @funindex shiftOn
2843 @funindex \shiftOnn
2844 @funindex shiftOnn
2845 @funindex \shiftOnnn
2846 @funindex shiftOnnn
2847
2848 Within a voice, all the notes occuring at the same musical moment are
2849 grouped into a note column, and a @code{NoteColumn} object is created
2850 to control the horizontal positioning of that group of notes (see
2851 @qq{Note columns} in @ref{Explicitly instantiating voices}).  If
2852 @emph{and only if} two or more note columns within a single Staff
2853 context, both with stems in the same direction, occur at the same
2854 musical moment, the values of their @code{horizontal-shift} properties
2855 are used to rank them and the columns in the higher ranks are
2856 progessively offset to avoid collisions of the noteheads.  This
2857 property is set by the @code{\voiceXXX} commands and may be overridden
2858 directly with an @code{\override} command or, more usually, by the
2859 @code{\shiftOn} commands.  Note that this property is used to
2860 @emph{rank} the note columns for off-setting - it does not specify the
2861 magnitude of the offset, which is progressively increased in steps
2862 based on the note head's width for each rank.  The steps are usually
2863 of half a note head's width, but may be a full note head's width when
2864 a closely spaced group of notes is involved.
2865
2866 @item
2867 @code{force-hshift}
2868
2869 @cindex force-hshift property
2870
2871 The @code{force-hshift} property is a property of a @code{NoteColumn}
2872 (actually of the @code{note-column-interface}).  Changing it permits a
2873 note column to be moved in situations where the note columns overlap.
2874 Note that it has no effect on note columns that do not overlap.
2875 It is specified in units appropriate to a note column, viz. the note
2876 head width of the first voice note.  It should be used in complex
2877 situations where the normal @code{\shiftOn} commands (see
2878 @ref{Explicitly instantiating voices}) do not resolve the note
2879 conflict satisfactorily.  It is preferable to the @code{extra-offset}
2880 property for this purpose as there is no need to work out the distance
2881 in staff-spaces, and moving the notes into or out of a
2882 @code{NoteColumn} affects other actions such as merging note heads.
2883
2884 @end itemize
2885
2886 @item
2887 Finally, when all else fails, objects may be manually repositioned
2888 relative to the staff center line vertically, or by displacing them by
2889 any distance to a new position.  The disadvantages are that the
2890 correct values for the repositioning have to be worked out, often by
2891 trial and error, for every object individually, and, because the
2892 movement is done after LilyPond has placed all other objects, the user
2893 is responsible for avoiding any collisions that might ensue.  But the
2894 main difficulty with this approach is that the repositioning values
2895 may need to be reworked if the music is later modified.  The
2896 properties that can be used for this type of manual repositioning are:
2897
2898 @table @code
2899 @item extra-offset
2900
2901 @cindex extra-offset property
2902
2903 This property applies to any layout object supporting the
2904 @code{grob-interface}.  It takes a pair of numbers which specify the
2905 extra displacement in the horizontal and vertical directions.
2906 Negative numbers move the object to the left or down.  The units are
2907 staff-spaces.  The extra displacement is made after the typesetting of
2908 objects is finished, so an object may be repositioned anywhere without
2909 affecting anything else.
2910
2911 @item positions
2912
2913 @cindex positions property
2914
2915 This is most useful for manually adjusting the slope and height
2916 of beams, slurs, and tuplets.  It takes a pair of numbers
2917 giving the position of the left and right ends of the beam, slur,
2918 etc. relative to the center line of the staff.  Units are
2919 staff-spaces.  Note, though, that slurs and phrasing slurs cannot
2920 be repositioned by arbitrarily large amounts.  LilyPond first
2921 generates a list of possible positions for the slur and by default
2922 finds the slur that @qq{looks best}.  If the @code{positions}
2923 property has been overridden the slur that is closest to the
2924 requested positions is selected from the list.
2925 @end table
2926
2927 @end enumerate
2928
2929 A particular object may not have all of these properties.
2930 It is necessary to go to the IR to look up which properties
2931 are available for the object in question.
2932
2933 Here is a list of the objects which are most likely to be
2934 involved in collisions, together with the name of the object which
2935 should be looked up in the IR in order to discover which properties
2936 should be used to move them.
2937
2938 @multitable @columnfractions .5 .5
2939 @headitem Object type           @tab Object name
2940 @item Articulations             @tab @code{Script}
2941 @item Beams                     @tab @code{Beam}
2942 @item Dynamics (vertically)     @tab @code{DynamicLineSpanner}
2943 @item Dynamics (horizontally)   @tab @code{DynamicText}
2944 @item Fingerings                @tab @code{Fingering}
2945 @item Rehearsal / Text marks    @tab @code{RehearsalMark}
2946 @item Slurs                     @tab @code{Slur}
2947 @item Text e.g. @code{^"text"}  @tab @code{TextScript}
2948 @item Ties                      @tab @code{Tie}
2949 @item Tuplets                   @tab @code{TupletBracket}
2950 @end multitable
2951
2952
2953 @node Fixing overlapping notation
2954 @subsection Fixing overlapping notation
2955
2956 Let's now see how the properties in the previous section can
2957 help to resolve overlapping notation.
2958
2959 @menu
2960 * The padding property::
2961 * The right-padding property::
2962 * The staff-padding property::
2963 * The self-alignment-X property::
2964 * The staff-position property::
2965 * The extra-offset property::
2966 * The positions property::
2967 * The force-hshift property::
2968 @end menu
2969
2970 @node The padding property
2971 @unnumberedsubsubsec The @code{padding} property
2972
2973 @cindex padding
2974 @cindex fixing overlapping notation
2975 @cindex overlapping notation
2976
2977 The @code{padding} property can be set to increase
2978 (or decrease) the distance between symbols that are printed
2979 above or below notes.
2980
2981 @cindex Script, example of overriding
2982 @cindex padding property, example
2983
2984 @lilypond[quote,fragment,relative=1,verbatim]
2985 c2\fermata
2986 \override Script.padding = #3
2987 b2\fermata
2988 @end lilypond
2989
2990 @cindex MetronomeMark, example of overriding
2991 @cindex padding property, example
2992
2993 @lilypond[quote,fragment,relative=1,verbatim]
2994 % This will not work, see below
2995 \override MetronomeMark.padding = #3
2996 \tempo 4 = 120
2997 c1 |
2998 % This works
2999 \override Score.MetronomeMark.padding = #3
3000 \tempo 4 = 80
3001 d1 |
3002 @end lilypond
3003
3004 Note in the second example how important it is to figure out what
3005 context handles a certain object.  Since the @code{MetronomeMark}
3006 object is handled in the @code{Score} context, property changes in the
3007 @code{Voice} context will not be noticed.  For more details, see
3008 @ruser{Modifying properties}.
3009
3010 If the @code{padding} property of an object is increased when that
3011 object is in a stack of objects being positioned according to
3012 their @code{outside-staff-priority}, then that object and all
3013 objects outside it are moved.
3014
3015
3016 @node The right-padding property
3017 @unnumberedsubsubsec The @code{right-padding} property
3018
3019 @cindex right-padding property
3020
3021 The @code{right-padding} property affects the spacing between the
3022 accidental and the note to which it applies.  It is not often
3023 required, but the default spacing may be wrong for certain special
3024 accidental glyphs or combination of glyphs used in some microtonal
3025 music.  These have to be entered by overriding the accidental
3026 stencil with a markup containing the desired symbol(s), like this:
3027
3028 @cindex Accidental, example of overriding
3029 @cindex text property, example
3030 @cindex stencil property, example
3031 @cindex AccidentalPlacement, example of overriding
3032 @cindex right-padding property, example
3033
3034 @lilypond[quote,ragged-right,verbatim]
3035 sesquisharp = \markup { \sesquisharp }
3036 \relative c'' {
3037   c4
3038   % This prints a sesquisharp but the spacing is too small
3039   \once \override Accidental.stencil = #ly:text-interface::print
3040   \once \override Accidental.text = #sesquisharp
3041   cis4 c
3042   % This improves the spacing
3043   \once \override Score.AccidentalPlacement.right-padding = #0.6
3044   \once \override Accidental.stencil = #ly:text-interface::print
3045   \once \override Accidental.text = #sesquisharp
3046   cis4 |
3047 }
3048 @end lilypond
3049
3050 @noindent
3051 This necessarily uses an override for the accidental stencil which
3052 will not be covered until later.  The stencil type must be a
3053 procedure, here changed to print the contents of the @code{text}
3054 property of @code{Accidental}, which itself is set to be a
3055 sesquisharp sign.  This sign is then moved further away from the
3056 note head by overriding @code{right-padding}.
3057
3058 @noindent
3059
3060 @node The staff-padding property
3061 @unnumberedsubsubsec The @code{staff-padding} property
3062
3063 @cindex aligning objects on a baseline
3064 @cindex objects, aligning on a baseline
3065
3066 @code{staff-padding} can be used to align objects such as dynamics
3067 along a baseline at a fixed distance from the staff, when no other
3068 notation forces them further from the staff.
3069 It is not a property of @code{DynamicText} but of
3070 @code{DynamicLineSpanner}.  This is because the baseline should apply
3071 equally to @strong{all} dynamics, including those created as extended
3072 spanners.  So this is the way to align the dynamic marks in the
3073 example taken from the previous section:
3074
3075 @cindex DynamicText, example of overriding
3076 @cindex extra-spacing-width property, example
3077 @cindex DynamicLineSpanner, example of overriding
3078 @cindex staff-padding property, example
3079
3080 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
3081 \override DynamicLineSpanner.staff-padding = #3
3082 a4\f b\mf a\p b\mp
3083 @end lilypond
3084
3085
3086 @node The self-alignment-X property
3087 @unnumberedsubsubsec The @code{self-alignment-X} property
3088
3089 The following example shows how to adjust the position
3090 of a string fingering object relative to a note's stem by aligning the
3091 right edge with the reference point of the parent note:
3092
3093 @cindex StringNumber, example of overriding
3094 @cindex self-alignment-X property, example
3095
3096 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
3097 \voiceOne
3098 <a\2>
3099 \once \override StringNumber.self-alignment-X = #RIGHT
3100 <a\2>
3101 @end lilypond
3102
3103 @node The staff-position property
3104 @unnumberedsubsubsec The @code{staff-position} property
3105
3106 @cindex object collision within a staff
3107
3108 Multimeasure rests in one voice can collide with notes in another.
3109 Since these rests are typeset centered between the bar lines, it
3110 would require significant effort for LilyPond to figure out which
3111 other notes might collide with it, since all the current collision
3112 handling between notes and between notes and rests is done only
3113 for notes and rests that occur at the same time.  Here's an
3114 example of a collision of this type:
3115
3116 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
3117 << { c4 c c c } \\ { R1 } >>
3118 @end lilypond
3119
3120 The best solution here is to move the multimeasure rest down, since the
3121 rest is in voice two. The default in @code{\voiceTwo} (i.e. in the
3122 second voice of a @code{<<@{@dots{}@} \\ @{@dots{}@}>>} construct) is
3123 that @code{staff-position} is set to -4 for MultiMeasureRest, so we need
3124 to move it, say, four half-staff spaces down to @w{@code{-8}}.
3125
3126 @cindex MultiMeasureRest, example of overriding
3127 @cindex staff-position property, example
3128
3129 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
3130 <<
3131   { c4 c c c }
3132   \\
3133   \override MultiMeasureRest.staff-position = #-8
3134   { R1 }
3135 >>
3136 @end lilypond
3137
3138 This is better than using, for example, @code{extra-offset},
3139 because the ledger line above the rest is inserted automatically.
3140
3141 @node The extra-offset property
3142 @unnumberedsubsubsec The @code{extra-offset} property
3143
3144 @cindex positioning objects
3145 @cindex positioning grobs
3146 @cindex objects, positioning
3147 @cindex grobs, positioning
3148
3149 The @code{extra-offset} property provides complete control over the
3150 positioning of an object both horizontally and vertically.
3151
3152 In the following example, the second fingering is moved a little to
3153 the left, and 1.8 staff space downwards:
3154
3155 @cindex Fingering, example of overriding
3156 @cindex extra-offset property, example
3157
3158 @lilypond[quote,fragment,relative=1,verbatim]
3159 \stemUp
3160 f4-5
3161 \once \override Fingering.extra-offset = #'(-0.3 . -1.8)
3162 f4-5
3163 @end lilypond
3164
3165
3166 @node The positions property
3167 @unnumberedsubsubsec The @code{positions} property
3168
3169 @cindex controlling tuplets, slurs, phrasing slurs, and beams manually
3170 @cindex manually controlling tuplets, slurs, phrasing slurs, and beams
3171 @cindex tuplet beams, controlling manually
3172 @cindex slurs, controlling manually
3173 @cindex phrasing slurs, controlling manually
3174 @cindex beams, controlling manually
3175
3176 The @code{positions} property allows the vertical position and hence
3177 the slope of tuplets, slurs, phrasing slurs and beams to be controlled
3178 manually.
3179
3180 Here's an example in which the phrasing slur and slur collide:
3181
3182 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
3183 a8 \( ( a'16 ) a \)
3184 @end lilypond
3185
3186 @cindex PhrasingSlur, example of overriding
3187 @cindex positions property, example
3188
3189 @noindent
3190 One possibility would be to move the two ends of the phrasing slur
3191 higher.  We can try setting the left end to 2.5 staff-spaces above the
3192 centre line and the right end to 4.5 above, and LilyPond will
3193 select the phrasing slur from the candidates it has found with its
3194 end points closest to these:
3195
3196 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
3197 \once \override PhrasingSlur.positions = #'(2.5 . 4.5)
3198 a8 \( ( a'16 ) a \)
3199 @end lilypond
3200
3201 This is an improvement, but why not lower the right end of the slur
3202 a little?  If you try it you'll find it can't be done in this way.
3203 That's because there are no candidate slurs lower than the one
3204 already selected, and in this case the @code{positions} property has
3205 no effect.  However, ties, slurs and phrasing slurs @emph{can} be
3206 positioned and shaped very precisely when necessary.  To learn how to
3207 do this, see @ruser{Modifying ties and slurs}.
3208
3209 Here's a further example.  We see that the beams
3210 collide with the ties:
3211
3212 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
3213 {
3214   \time 4/2
3215   <<
3216     { c1~ 2. e8 f }
3217     \\
3218     {
3219       e'8 e e e
3220       e e e e
3221       f2 g
3222     }
3223   >>
3224   <<
3225     { c,,1~ 2. e8 f }
3226     \\
3227     {
3228       e'8 e e e
3229       e e e e
3230       f2 g
3231     }
3232   >>
3233 }
3234 @end lilypond
3235
3236 @noindent
3237 This can be resolved by manually moving both ends of the beam
3238 up from their position at 1.81 staff-spaces below the center line to,
3239 say, 1:
3240
3241 @cindex Beam, example of overriding
3242 @cindex positions property, example
3243
3244 @lilypond[quote,verbatim,ragged-right,relative=1]
3245 {
3246   \time 4/2
3247   <<
3248     { c1~ 2. e8 f }
3249     \\
3250     {
3251       \override Beam.positions = #'(-1 . -1)
3252       e'8 e e e
3253       e e e e
3254       f2 g
3255     }
3256   >>
3257   <<
3258     { c,,1~ 2. e8 f }
3259     \\
3260     {
3261       e'8 e e e
3262       e e e e
3263       f2 g
3264       \revert Beam.positions
3265     }
3266   >>
3267 }
3268 @end lilypond
3269
3270 @noindent
3271 Note that the override continues to apply in the second voice of
3272 the second measure of eighth notes, but not to any of the beams in the
3273 first voice, even those in the later second measure.  As soon as the
3274 override should no longer apply it should be reverted, as shown.
3275
3276 @node The force-hshift property
3277 @unnumberedsubsubsec The @code{force-hshift} property
3278
3279 We can now see how to apply the final corrections to the Chopin
3280 example introduced at the end of @ref{I'm hearing Voices}, which
3281 was left looking like this:
3282
3283 @lilypond[quote,verbatim,fragment,ragged-right]
3284 \new Staff \relative c'' {
3285   \key aes \major
3286   <<
3287     { c2 aes4. bes8 }
3288     \\
3289     { <ees, c>2 des }
3290     \\
3291     \\
3292     { aes'2 f4 fes }
3293   >> |
3294   <c ees aes c>1 |
3295 }
3296 @end lilypond
3297
3298 @noindent
3299 The inner note of the first chord (i.e. the A-flat in the fourth
3300 Voice) need not be shifted away from the note column of the higher
3301 note, so we use @code{\shiftOff}.
3302
3303 In the second chord we prefer the F to line up with the A-flat and
3304 the lowest note to be positioned slightly right to avoid a collision
3305 of stems.  We achieve this by setting @code{force-hshift} in the
3306 @code{NoteColumn} of the low D-flat to move it to the right by half
3307 a staff-space, and setting @code{force-hshift} for the F to zero.
3308 Note that we use @code{\once} to avoid the settings propagating
3309 beyond the immediate musical moment, although in this small example
3310 the @code{\once} and the second @code{\override} in Voice four could
3311 be omitted.  This would not be good practice.
3312
3313 Here's the final result:
3314
3315 @cindex NoteColumn, example of overriding
3316 @cindex force-hshift property, example
3317
3318 @lilypond[quote,verbatim,fragment,ragged-right]
3319 \new Staff \relative c'' {
3320   \key aes \major
3321   <<
3322     { c2 aes4. bes8 }
3323     \\
3324     { <ees, c>2 \once \override NoteColumn.force-hshift = 0.5 des }
3325     \\
3326     \\
3327     { \once \shiftOff aes'2 \once \shiftOff f4 fes }
3328   >> |
3329   <c ees aes c>1 |
3330 }
3331 @end lilypond
3332
3333
3334 @node Real music example
3335 @subsection Real music example
3336
3337 We end this section on Tweaks by showing the steps to be taken to
3338 deal with a tricky example which needs several tweaks to produce
3339 the desired output.  The example has been deliberately chosen to
3340 illustrate the use of the Notation Reference to resolve unusual
3341 problems with notation.  It is not representative of the more usual
3342 engraving process, so please do not let these difficulties put
3343 you off!  Fortunately, difficulties like these are not very common!
3344
3345 The example is from Chopin's Première Ballade, Op. 23, bars 6 to
3346 9, the transition from the opening Lento to Moderato.
3347 Here, first, is what we want the output to look like, but to avoid
3348 over-complicating the example too much we have left out the
3349 dynamics, fingering and pedalling.
3350
3351 @c The following should appear as music without code
3352 @c This example should not be indexed
3353 @c line-width ensures no break
3354 @lilypond[quote,ragged-right,line-width=6\in]
3355 rhMusic = \relative c'' {
3356   \new Voice {
3357     r2 c4.\( g8 |
3358     \once \override Tie.staff-position = #3.5
3359     bes1~ |
3360     \bar "||"
3361     \time 6/4
3362     \mergeDifferentlyHeadedOn
3363     \mergeDifferentlyDottedOn
3364     bes2.\tempo "Moderato" r8
3365     <<
3366       { c,8 d fis bes a }
3367       \new Voice {
3368         \voiceTwo
3369         c,8~
3370         % Reposition the c2 to the right of the merged note
3371         \once \override NoteColumn.force-hshift = #1.0
3372         % Move the c2 out of the main note column
3373         % so the merge will work
3374         \shiftOnn
3375         c2
3376       }
3377       \new Voice {
3378         \voiceThree
3379         s8
3380         % Stem on the d2 must be down to permit merging
3381         \stemDown
3382         % Stem on the d2 should be invisible
3383         \tweak Stem.transparent ##t
3384         d2
3385       }
3386       \new Voice {
3387         \voiceFour
3388         s4 fis4.
3389       }
3390     >> |
3391     \mergeDifferentlyHeadedOff
3392     \mergeDifferentlyDottedOff
3393     g2.\)
3394   }
3395 }
3396
3397 lhMusic = \relative c' {
3398   r2 <c g ees>2( |
3399   <d g, d>1)\arpeggio |
3400   r2. d,,4 r4 r |
3401   r4
3402 }
3403
3404 \score {
3405   \new PianoStaff <<
3406     \new Staff = "RH"  <<
3407       \key g \minor
3408       \rhMusic
3409     >>
3410     \new Staff = "LH" <<
3411       \key g \minor
3412       \clef "bass"
3413       \lhMusic
3414     >>
3415   >>
3416 }
3417 @end lilypond
3418
3419 We note first that the right hand part in the third bar
3420 requires four voices.  These are the five beamed eighth notes,
3421 the tied C, the half-note D which is merged with the eighth note
3422 D, and the dotted quarter note F-sharp, which is also merged with
3423 the eighth note at the same pitch.  Everything else is in a single
3424 voice, so the easiest way is to introduce these extra three voices
3425 temporarily at the time they are needed.  If you have forgotten
3426 how to do this, look at @ref{I'm hearing Voices} and @ref{Explicitly
3427 instantiating voices}.  Here we choose to use explicitly instantiated
3428 voices for the polyphonic passage, as LilyPond is better able to
3429 avoid collisions if all voices are instantiated explicitly in this
3430 way.
3431
3432 So let us begin by entering the notes as two variables, setting up
3433 the staff structure in a score block, and seeing what LilyPond
3434 produces by default:
3435
3436 @c line-width ensures no break
3437 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3438 rhMusic = \relative c'' {
3439   \new Voice {
3440     r2 c4. g8 |
3441     bes1~ |
3442     \time 6/4
3443     bes2. r8
3444     % Start polyphonic section of four voices
3445     <<
3446       { c,8 d fis bes a }  % continuation of main voice
3447       \new Voice {
3448         \voiceTwo
3449         c,8~ 2
3450       }
3451       \new Voice {
3452         \voiceThree
3453         s8 d2
3454       }
3455       \new Voice {
3456         \voiceFour
3457         s4 fis4.
3458       }
3459     >> |
3460     g2.  % continuation of main voice
3461   }
3462 }
3463
3464 lhMusic = \relative c' {
3465   r2 <c g ees>2 |
3466   <d g, d>1 |
3467   r2. d,,4 r4 r |
3468   r4
3469 }
3470
3471 \score {
3472   \new PianoStaff <<
3473     \new Staff = "RH"  <<
3474       \key g \minor
3475       \rhMusic
3476     >>
3477     \new Staff = "LH" <<
3478       \key g \minor
3479       \clef "bass"
3480       \lhMusic
3481     >>
3482   >>
3483 }
3484 @end lilypond
3485
3486 All the notes are right, but the appearance is far from
3487 satisfactory.  The tie collides with the change in time signature,
3488 some notes are not merged together, and several notation elements
3489 are missing.  Let's first deal with the easier things.  We can
3490 easily add the left hand slur and the right hand phrasing slur,
3491 since these were all covered in the Tutorial.  Doing this gives:
3492
3493 @c line-width ensures no break
3494 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3495 rhMusic = \relative c'' {
3496   \new Voice {
3497     r2 c4.\( g8 |
3498     bes1~ |
3499     \time 6/4
3500     bes2. r8
3501     % Start polyphonic section of four voices
3502     <<
3503       { c,8 d fis bes a }  % continuation of main voice
3504       \new Voice {
3505         \voiceTwo
3506         c,8~ 2
3507       }
3508       \new Voice {
3509         \voiceThree
3510         s8 d2
3511       }
3512       \new Voice {
3513         \voiceFour
3514         s4 fis4.
3515       }
3516     >> |
3517     g2.\)  % continuation of main voice
3518   }
3519 }
3520
3521 lhMusic = \relative c' {
3522   r2 <c g ees>2( |
3523   <d g, d>1) |
3524   r2. d,,4 r4 r |
3525   r4
3526 }
3527
3528 \score {
3529   \new PianoStaff <<
3530     \new Staff = "RH"  <<
3531       \key g \minor
3532       \rhMusic
3533     >>
3534     \new Staff = "LH" <<
3535       \key g \minor
3536       \clef "bass"
3537       \lhMusic
3538     >>
3539   >>
3540 }
3541 @end lilypond
3542
3543 The first bar is now correct.  The second bar contains an arpeggio and
3544 is terminated by a double bar line.  How do we do these, as they have
3545 not been mentioned in this Learning Manual?  This is where we need to
3546 turn to the Notation Reference.  Looking up @q{arpeggio} and @q{bar
3547 line} in the index quickly shows us that an arpeggio is produced by
3548 appending @code{\arpeggio} to a chord, and a double bar line is
3549 produced by the @code{\bar "||"} command.  That's easily done.  We
3550 next need to correct the collision of the tie with the time signature.
3551 This is best done by moving the tie upwards.  Moving objects was
3552 covered earlier in @ref{Moving objects}, which says that objects
3553 positioned relative to the staff can be moved vertically by overriding
3554 their @code{staff-position} property, which is specified in half staff
3555 spaces relative to the center line of the staff.  So the following
3556 override placed just before the first tied note would move the tie up
3557 to 3.5 half staff spaces above the center line:
3558
3559 @code{\once \override Tie.staff-position = #3.5}
3560
3561 This completes bar two, giving:
3562
3563 @c line-width ensures no break
3564 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3565 rhMusic = \relative c'' {
3566   \new Voice {
3567     r2 c4.\( g8 |
3568     \once \override Tie.staff-position = #3.5
3569     bes1~ |
3570     \bar "||"
3571     \time 6/4
3572     bes2. r8
3573     % Start polyphonic section of four voices
3574     <<
3575       { c,8 d fis bes a }  % continuation of main voice
3576       \new Voice {
3577         \voiceTwo
3578         c,8~ 2
3579       }
3580       \new Voice {
3581         \voiceThree
3582         s8 d2
3583       }
3584       \new Voice {
3585         \voiceFour
3586         s4 fis4.
3587       }
3588     >> |
3589     g2.\)  % continuation of main voice
3590   }
3591 }
3592
3593 lhMusic = \relative c' {
3594   r2 <c g ees>2( |
3595   <d g, d>1)\arpeggio |
3596   r2. d,,4 r4 r |
3597   r4
3598 }
3599
3600 \score {
3601   \new PianoStaff <<
3602     \new Staff = "RH"  <<
3603       \key g \minor
3604       \rhMusic
3605     >>
3606     \new Staff = "LH" <<
3607       \key g \minor
3608       \clef "bass"
3609       \lhMusic
3610     >>
3611   >>
3612 }
3613 @end lilypond
3614
3615 On to bar three and the start of the Moderato section.  The tutorial
3616 showed how to add a tempo indication with the @code{\tempo} command, so
3617 adding @qq{Moderato} is easy.  But how do we merge notes in
3618 different voices together?  This is where we need to turn again to
3619 the Notation Reference for help.  A search for @qq{merge} in the
3620 Notation Reference index quickly leads us to the commands for merging
3621 differently headed and differently dotted notes in
3622 @ruser{Collision resolution}.  In our example we need to merge both
3623 types of note for the duration of the polyphonic section in bar 3,
3624 so using the information we find in the Notation Reference we add
3625
3626 @example
3627 \mergeDifferentlyHeadedOn
3628 \mergeDifferentlyDottedOn
3629 @end example
3630
3631 @noindent
3632 to the start of that section and
3633
3634 @example
3635 \mergeDifferentlyHeadedOff
3636 \mergeDifferentlyDottedOff
3637 @end example
3638
3639 @noindent
3640 to the end, giving:
3641
3642 @c line-width ensures no break
3643 @lilypond[quote,ragged-right,line-width=6\in]
3644 rhMusic = \relative c'' {
3645   \new Voice {
3646     r2 c4.\( g8 |
3647     \once \override Tie.staff-position = #3.5
3648     bes1~ |
3649     \bar "||"
3650     \time 6/4
3651     bes2.\tempo "Moderato" r8
3652     \mergeDifferentlyHeadedOn
3653     \mergeDifferentlyDottedOn
3654     % Start polyphonic section of four voices
3655     <<
3656       { c,8 d fis bes a }  % continuation of main voice
3657       \new Voice {
3658         \voiceTwo
3659         c,8~ 2
3660       }
3661       \new Voice {
3662         \voiceThree
3663         s8 d2
3664       }
3665       \new Voice {
3666         \voiceFour
3667         s4 fis4.
3668       }
3669     >> |
3670     \mergeDifferentlyHeadedOff
3671     \mergeDifferentlyDottedOff
3672     g2.\)  % continuation of main voice
3673   }
3674 }
3675
3676 lhMusic = \relative c' {
3677   r2 <c g ees>2( |
3678   <d g, d>1)\arpeggio |
3679   r2. d,,4 r4 r |
3680   r4
3681 }
3682
3683 \score {
3684   \new PianoStaff <<
3685     \new Staff = "RH"  <<
3686       \key g \minor
3687       \rhMusic
3688     >>
3689     \new Staff = "LH" <<
3690       \key g \minor
3691       \clef "bass"
3692       \lhMusic
3693     >>
3694   >>
3695 }
3696 @end lilypond
3697
3698 These overrides have merged the two F-sharp notes, but not the two
3699 on D.  Why not?  The answer is there in the same section in the
3700 Notation Reference -- notes being merged must have stems in
3701 opposite directions and two notes cannot be merged successfully if
3702 there is a third note in the same note column.  Here the two D's
3703 both have upward stems and there is a third note -- the C.  We know
3704 how to change the stem direction using @code{\stemDown}, and
3705 the Notation Reference also says how to move the C -- apply a shift
3706 using one of the @code{\shift} commands.  But which one?
3707 The C is in voice two which has shift off, and the two D's are in
3708 voices one and three, which have shift off and shift on,
3709 respectively.  So we have to shift the C a further level still
3710 using @code{\shiftOnn} to avoid it interfering with the two D's.
3711 Applying these changes gives:
3712
3713 @cindex Tie, example of overriding
3714 @cindex staff-position property, example
3715
3716 @c line-width ensures no break
3717 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3718 rhMusic = \relative c'' {
3719   \new Voice {
3720     r2 c4.\( g8 |
3721     \once \override Tie.staff-position = #3.5
3722     bes1~ |
3723     \bar "||"
3724     \time 6/4
3725     bes2.\tempo "Moderato" r8
3726     \mergeDifferentlyHeadedOn
3727     \mergeDifferentlyDottedOn
3728     % Start polyphonic section of four voices
3729     <<
3730       { c,8 d fis bes a }  % continuation of main voice
3731       \new Voice {
3732         \voiceTwo
3733         % Move the c2 out of the main note column
3734         % so the merge will work
3735         c,8~ \shiftOnn c2
3736       }
3737       \new Voice {
3738         \voiceThree
3739         % Stem on the d2 must be down to permit merging
3740         s8 \stemDown d2
3741       }
3742       \new Voice {
3743         \voiceFour
3744         s4 fis4.
3745       }
3746     >> |
3747     \mergeDifferentlyHeadedOff
3748     \mergeDifferentlyDottedOff
3749     g2.\)  % continuation of main voice
3750   }
3751 }
3752
3753 lhMusic = \relative c' {
3754   r2 <c g ees>2( |
3755   <d g, d>1)\arpeggio |
3756   r2. d,,4 r4 r |
3757   r4
3758 }
3759
3760 \score {
3761   \new PianoStaff <<
3762     \new Staff = "RH"  <<
3763       \key g \minor
3764       \rhMusic
3765     >>
3766     \new Staff = "LH" <<
3767       \key g \minor
3768       \clef "bass"
3769       \lhMusic
3770     >>
3771   >>
3772 }
3773 @end lilypond
3774
3775 Nearly there.  Only two problems remain: The downward stem on the
3776 merged D should not be there, and the C would be better positioned
3777 to the right of the D's.  We know how to do both of these from the
3778 earlier tweaks: we make the stem transparent, and move the C with
3779 the @code{force-hshift} property.  Here's the final result:
3780
3781 @cindex NoteColumn, example of overriding
3782 @cindex force-hshift property, example
3783 @cindex Stem, example of overriding
3784 @cindex transparent property, example
3785
3786 @c line-width ensures no break
3787 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3788 rhMusic = \relative c'' {
3789   \new Voice {
3790     r2 c4.\( g8 |
3791     \once \override Tie.staff-position = #3.5
3792     bes1~ |
3793     \bar "||"
3794     \time 6/4
3795     bes2.\tempo "Moderato" r8
3796     \mergeDifferentlyHeadedOn
3797     \mergeDifferentlyDottedOn
3798     % Start polyphonic section of four voices
3799     <<
3800       { c,8 d fis bes a }  % continuation of main voice
3801       \new Voice {
3802         \voiceTwo
3803         c,8~
3804         % Reposition the c2 to the right of the merged note
3805         \once \override NoteColumn.force-hshift = #1.0
3806         % Move the c2 out of the main note column
3807         % so the merge will work
3808         \shiftOnn
3809         c2
3810       }
3811       \new Voice {
3812         \voiceThree
3813         s8
3814         % Stem on the d2 must be down to permit merging
3815         \stemDown
3816         % Stem on the d2 should be invisible
3817         \tweak Stem.transparent ##t
3818         d2
3819       }
3820       \new Voice {
3821         \voiceFour
3822         s4 fis4.
3823       }
3824     >> |
3825     \mergeDifferentlyHeadedOff
3826     \mergeDifferentlyDottedOff
3827     g2.\)  % continuation of main voice
3828   }
3829 }
3830
3831 lhMusic = \relative c' {
3832   r2 <c g ees>2( |
3833   <d g, d>1)\arpeggio |
3834   r2. d,,4 r4 r |
3835   r4
3836 }
3837
3838 \score {
3839   \new PianoStaff <<
3840     \new Staff = "RH"  <<
3841       \key g \minor
3842       \rhMusic
3843     >>
3844     \new Staff = "LH" <<
3845       \key g \minor
3846       \clef "bass"
3847       \lhMusic
3848     >>
3849   >>
3850 }
3851 @end lilypond
3852
3853
3854 @node Further tweaking
3855 @section Further tweaking
3856
3857 @menu
3858 * Other uses for tweaks::
3859 * Using variables for layout adjustments::
3860 * Style sheets::
3861 * Other sources of information::
3862 * Advanced tweaks with Scheme::
3863 @end menu
3864
3865 @node Other uses for tweaks
3866 @subsection Other uses for tweaks
3867
3868 @menu
3869 * Tying notes across voices::
3870 * Simulating a fermata in MIDI::
3871 @end menu
3872
3873 @cindex removing objects
3874 @cindex objects, removing
3875
3876 @node Tying notes across voices
3877 @unnumberedsubsubsec Tying notes across voices
3878
3879 @cindex tying notes across voices
3880
3881 The following example demonstrates how to connect notes in different
3882 voices using ties.  Normally, only notes in the same voice can be
3883 connected with ties.  By using two voices, with the tied notes in one
3884 of them
3885
3886 @lilypond[quote,fragment,relative=2]
3887 << { b8~ 8\noBeam } \\ { b8[ g] } >>
3888 @end lilypond
3889
3890 @noindent
3891 and removing the first up-stem and its flag in that voice, the tie
3892 appears to cross voices:
3893
3894 @funindex \omit
3895 @cindex Stem, example of removing
3896 @cindex Flag, example of removing
3897 @cindex @code{\omit}, example
3898 @cindex example of @code{\omit}
3899
3900 @lilypond[quote,fragment,relative=2,verbatim]
3901 <<
3902   {
3903     \once \omit Stem
3904     \once \omit Flag
3905     b8~ 8\noBeam
3906   }
3907 \\
3908   { b8[ g] }
3909 >>
3910 @end lilypond
3911
3912 @seealso
3913 Learning Manual:
3914 @ref{The once prefix,,The @code{@bs{}once} prefix},
3915 @ref{The stencil property}.
3916
3917
3918 @node Simulating a fermata in MIDI
3919 @unnumberedsubsubsec Simulating a fermata in MIDI
3920
3921 @cindex stencil property, use of
3922 @cindex fermata, implementing in MIDI
3923
3924 For outside-staff objects it is usually better to override the
3925 object's @code{stencil} property rather than its @code{transparent}
3926 property when you wish to remove it from the printed output.
3927 Setting the @code{stencil} property of an object to @code{#f} will
3928 remove that object entirely from the printed output.  This means it
3929 has no effect on the placement of other objects placed relative to
3930 it.
3931
3932 For example, if we wished to change the metronome setting in order
3933 to simulate a fermata in the MIDI output we would not want the
3934 metronome markings to appear in the printed output, and we would
3935 not want it to influence the spacing between the two systems or
3936 the positions of adjacent annotations on the staff.  So setting
3937 its @code{stencil} property to @code{#f} would be the best way.
3938 We show here the effect of the two methods:
3939
3940 @cindex MetronomeMark, example of overriding
3941 @cindex transparent property, example
3942
3943 @lilypond[quote,verbatim,ragged-right]
3944 \score {
3945   \relative c'' {
3946     % Visible tempo marking
3947     \tempo 4=120
3948     a4 a a
3949     \once \hide Score.MetronomeMark
3950     % Invisible tempo marking to lengthen fermata in MIDI
3951     \tempo 4=80
3952     a4\fermata |
3953     % New tempo for next section
3954     \tempo 4=100
3955     a4 a a a |
3956   }
3957   \layout { }
3958   \midi { }
3959 }
3960 @end lilypond
3961
3962 @cindex MetronomeMark, example of overriding
3963 @cindex stencil property, example
3964
3965 @lilypond[quote,verbatim,ragged-right]
3966 \score {
3967   \relative c'' {
3968     % Visible tempo marking
3969     \tempo 4=120
3970     a4 a a
3971     \once \omit Score.MetronomeMark
3972     % Invisible tempo marking to lengthen fermata in MIDI
3973     \tempo 4=80
3974     a4\fermata |
3975     % New tempo for next section
3976     \tempo 4=100
3977     a4 a a a |
3978   }
3979   \layout { }
3980   \midi { }
3981 }
3982 @end lilypond
3983
3984 @noindent
3985 Both methods remove the metronome mark which lengthens the fermata
3986 from the printed output, and both affect the MIDI timing as
3987 required, but the transparent metronome mark in the first line
3988 forces the following tempo indication too high while the
3989 second (with the stencil removed) does not.
3990
3991 @seealso
3992 Music Glossary:
3993 @rglos{system}.
3994
3995 @node Using variables for layout adjustments
3996 @subsection Using variables for layout adjustments
3997
3998 @cindex variables, using for overrides
3999 @cindex overrides, using variables for
4000 @cindex adjustments, using variables for
4001 @cindex layout adjustments, using variables for
4002
4003 Override commands are often long and tedious to type, and they
4004 have to be absolutely correct.  If the same overrides are to be
4005 used many times it may be worth defining variables to hold them.
4006
4007 Suppose we wish to emphasize certain words in lyrics by printing
4008 them in bold italics.  The @code{\italic} and @code{\bold}
4009 commands only work within lyrics if they are embedded, together with
4010 the word or words to be modified, within a @code{\markup} block,
4011 which makes them tedious to enter.  The need to embed the words
4012 themselves prevents their use in simple variables.  As an
4013 alternative can we use @code{\override} and @code{\revert} commands?
4014
4015 @example
4016 @code{\override Lyrics.LyricText.font-shape = #'italic}
4017 @code{\override Lyrics.LyricText.font-series = #'bold}
4018
4019 @code{\revert Lyrics.LyricText.font-shape}
4020 @code{\revert Lyrics.LyricText.font-series}
4021 @end example
4022
4023 These would also be extremely tedious to enter if there were many
4024 words requiring emphasis.  But we @emph{can} define these as two
4025 variables and use those to bracket the words to be emphasized.
4026 Another advantage of using variables for these overrides is that
4027 the spaces around the dot are not necessary, since they are not
4028 being interpreted in @code{\lyricmode} directly.  Here's an example
4029 of this, although in practice  we would choose shorter names
4030 for the variables to make them quicker to type:
4031
4032 @cindex LyricText, example of overriding
4033 @cindex font-shape property, example
4034 @cindex font-series property, example
4035
4036 @lilypond[quote,verbatim]
4037 emphasize = {
4038   \override Lyrics.LyricText.font-shape = #'italic
4039   \override Lyrics.LyricText.font-series = #'bold
4040 }
4041
4042 normal = {
4043   \revert Lyrics.LyricText.font-shape
4044   \revert Lyrics.LyricText.font-series
4045 }
4046
4047 global = { \key c \major \time 4/4 \partial 4 }
4048
4049 SopranoMusic = \relative c' { c4 | e4. e8 g4 g    | a4   a   g  }
4050 AltoMusic    = \relative c' { c4 | c4. c8 e4 e    | f4   f   e  }
4051 TenorMusic   = \relative c  { e4 | g4. g8 c4.  b8 | a8 b c d e4 }
4052 BassMusic    = \relative c  { c4 | c4. c8 c4 c    | f8 g a b c4 }
4053
4054 VerseOne = \lyrics {
4055   E -- | ter -- nal \emphasize Fa -- ther, | \normal strong to save,
4056 }
4057
4058 VerseTwo = \lyricmode {
4059   O | \once \emphasize Christ, whose voice the | wa -- ters heard,
4060 }
4061
4062 VerseThree = \lyricmode {
4063   O | \emphasize Ho -- ly Spi -- rit, | \normal who didst brood
4064 }
4065
4066 VerseFour = \lyricmode {
4067   O | \emphasize Tri -- ni -- ty \normal of | love and pow'r
4068 }
4069
4070 \score {
4071   \new ChoirStaff <<
4072     \new Staff <<
4073       \clef "treble"
4074       \new Voice = "Soprano"  { \voiceOne \global \SopranoMusic }
4075       \new Voice = "Alto" { \voiceTwo \AltoMusic }
4076       \new Lyrics \lyricsto "Soprano" { \VerseOne }
4077       \new Lyrics \lyricsto "Soprano" { \VerseTwo }
4078       \new Lyrics \lyricsto "Soprano" { \VerseThree }
4079       \new Lyrics \lyricsto "Soprano" { \VerseFour }
4080     >>
4081     \new Staff <<
4082       \clef "bass"
4083       \new Voice = "Tenor" { \voiceOne \TenorMusic }
4084       \new Voice = "Bass"  { \voiceTwo \BassMusic }
4085     >>
4086   >>
4087 }
4088 @end lilypond
4089
4090
4091 @node Style sheets
4092 @subsection Style sheets
4093
4094 The output that LilyPond produces can be heavily modified; see
4095 @ref{Tweaking output}, for details.  But what if you have many
4096 input files that you want to apply your tweaks to?  Or what if you
4097 simply want to separate your tweaks from the actual music?  This
4098 is quite easy to do.
4099
4100 Let's look at an example.  Don't worry if you don't understand
4101 the parts with all the @code{#()}.  This is explained in
4102 @ref{Advanced tweaks with Scheme}.
4103
4104 @lilypond[quote,verbatim,ragged-right]
4105 mpdolce =
4106   \tweak self-alignment-X #-0.6
4107   #(make-dynamic-script
4108     #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4109
4110 inst =
4111 #(define-music-function
4112      (parser location string)
4113      (string?)
4114    #{ <>^\markup \bold \box #string #})
4115
4116 \relative c'' {
4117   \tempo 4=50
4118   a4.\mpdolce d8 cis4--\glissando a |
4119   b4 bes a2 |
4120   \inst "Clarinet"
4121   cis4.\< d8 e4 fis |
4122   g8(\! fis)-. e( d)-. cis2 |
4123 }
4124 @end lilypond
4125
4126 Let's do something about the @code{mpdolce} and @code{inst} definitions.
4127 They produce the output we desire, but we might want to use them in
4128 another piece.  We could simply copy-and-paste them at the top of every
4129 file, but that's an annoyance.  It also leaves those definitions in our
4130 input files, and I personally find all the @code{#()} somewhat ugly.
4131 Let's hide them in another file:
4132
4133 @example
4134 %%% save this to a file called "definitions.ily"
4135 mpdolce =
4136   \tweak self-alignment-X #-0.6
4137   #(make-dynamic-script
4138     #@{ \markup @{ \dynamic mp \normal-text \italic \bold dolce @} #@})
4139
4140 inst =
4141 #(define-music-function
4142      (parser location string)
4143      (string?)
4144    #@{ <>^\markup \bold \box #string #@})
4145 @end example
4146
4147 We will refer to this file using the @code{\include} command near
4148 the top of the music file.  (The extension @file{.ily} is used to
4149 distinguish this included file, which is not meant to be compiled
4150 on its own, from the main file.)
4151 Now let's modify our music (let's save this file as @file{music.ly}).
4152
4153 @c  We have to do this awkward example/lilypond-non-verbatim
4154 @c  because we can't do the \include stuff in the manual.
4155
4156 @example
4157 \include "definitions.ily"
4158
4159 \relative c'' @{
4160   \tempo 4=50
4161   a4.\mpdolce d8 cis4--\glissando a |
4162   b4 bes a2 |
4163   \inst "Clarinet"
4164   cis4.\< d8 e4 fis |
4165   g8(\! fis)-. e( d)-. cis2 |
4166 @}
4167 @end example
4168
4169 @lilypond[quote,ragged-right]
4170 mpdolce =
4171   \tweak self-alignment-X #-0.6
4172   #(make-dynamic-script
4173     #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4174
4175 inst =
4176 #(define-music-function
4177      (parser location string)
4178      (string?)
4179    #{ <>^\markup \bold \box #string #})
4180
4181 \relative c'' {
4182   \tempo 4=50
4183   a4.\mpdolce d8 cis4--\glissando a |
4184   b4 bes a2 |
4185   \inst "Clarinet"
4186   cis4.\< d8 e4 fis |
4187   g8(\! fis)-. e( d)-. cis2 |
4188 }
4189 @end lilypond
4190
4191 That looks better, but let's make a few changes.  The glissando is hard
4192 to see, so let's make it thicker and closer to the note heads.  Let's
4193 put the metronome marking above the clef, instead of over the first
4194 note.  And finally, my composition professor hates @q{C} time signatures,
4195 so we'd better make that @q{4/4} instead.
4196
4197 Don't change @file{music.ly}, though.  Replace our @file{definitions.ily}
4198 with this:
4199
4200 @example
4201 %%%  definitions.ily
4202 mpdolce =
4203   \tweak self-alignment-X #-0.6
4204   #(make-dynamic-script
4205     #@{ \markup @{ \dynamic mp \normal-text \italic \bold dolce @} #@})
4206
4207 inst =
4208 #(define-music-function
4209      (parser location string)
4210      (string?)
4211    #@{ <>^\markup \bold \box #string #@})
4212
4213 \layout@{
4214   \context @{
4215     \Score
4216     \override MetronomeMark.extra-offset = #'(-5 . 0)
4217     \override MetronomeMark.padding = #'3
4218   @}
4219   \context @{
4220     \Staff
4221     \override TimeSignature.style = #'numbered
4222   @}
4223   \context @{
4224     \Voice
4225     \override Glissando.thickness = #3
4226     \override Glissando.gap = #0.1
4227   @}
4228 @}
4229 @end example
4230
4231 @lilypond[quote,ragged-right]
4232 mpdolce =
4233   \tweak self-alignment-X #-0.6
4234   #(make-dynamic-script
4235     #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4236
4237 inst =
4238 #(define-music-function
4239      (parser location string)
4240      (string?)
4241    #{ <>^\markup \bold \box #string #})
4242
4243 \layout{
4244   \context {
4245     \Score
4246     \override MetronomeMark.extra-offset = #'(-5 . 0)
4247     \override MetronomeMark.padding = #'3
4248   }
4249   \context {
4250     \Staff
4251     \override TimeSignature.style = #'numbered
4252   }
4253   \context {
4254     \Voice
4255     \override Glissando.thickness = #3
4256     \override Glissando.gap = #0.1
4257   }
4258 }
4259
4260 \relative c'' {
4261   \tempo 4=50
4262   a4.\mpdolce d8 cis4--\glissando a |
4263   b4 bes a2 |
4264   \inst "Clarinet"
4265   cis4.\< d8 e4 fis |
4266   g8(\! fis)-. e( d)-. cis2 |
4267 }
4268 @end lilypond
4269
4270 That looks nicer!  But now suppose that I want to publish this
4271 piece.  My composition professor doesn't like @q{C} time
4272 signatures, but I'm somewhat fond of them.  Let's copy the
4273 current @file{definitions.ily} to @file{web-publish.ily} and
4274 modify that.  Since this music is aimed at producing a pdf which
4275 will be displayed on the screen, we'll also increase the
4276 overall size of the output.
4277
4278 @example
4279 %%%  web-publish.ily
4280 mpdolce =
4281   \tweak self-alignment-X #-0.6
4282   #(make-dynamic-script
4283     #@{ \markup @{ \dynamic mp \normal-text \italic \bold dolce @} #@})
4284
4285 inst =
4286 #(define-music-function
4287      (parser location string)
4288      (string?)
4289    #@{ <>^\markup \bold \box #string #@})
4290
4291 #(set-global-staff-size 23)
4292
4293 \layout@{
4294   \context @{
4295     \Score
4296     \override MetronomeMark.extra-offset = #'(-5 . 0)
4297     \override MetronomeMark.padding = #'3
4298   @}
4299   \context @{
4300     \Staff
4301   @}
4302   \context @{
4303     \Voice
4304     \override Glissando.thickness = #3
4305     \override Glissando.gap = #0.1
4306   @}
4307 @}
4308 @end example
4309
4310 @lilypond[quote,ragged-right]
4311 mpdolce =
4312   \tweak self-alignment-X #-0.6
4313   #(make-dynamic-script
4314     #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4315
4316 inst =
4317 #(define-music-function
4318      (parser location string)
4319      (string?)
4320    #{ <>^\markup \bold \box #string #})
4321
4322 #(set-global-staff-size 23)
4323
4324 \layout{
4325   \context { \Score
4326     \override MetronomeMark.extra-offset = #'(-5 . 0)
4327     \override MetronomeMark.padding = #'3
4328   }
4329   \context { \Voice
4330     \override Glissando.thickness = #3
4331     \override Glissando.gap = #0.1
4332   }
4333 }
4334
4335 \relative c'' {
4336   \tempo 4=50
4337   a4.\mpdolce d8 cis4--\glissando a |
4338   b4 bes a2 |
4339   \inst "Clarinet"
4340   cis4.\< d8 e4 fis |
4341   g8(\! fis)-. e( d)-. cis2 |
4342 }
4343 @end lilypond
4344
4345 Now in our music, I simply replace
4346 @code{\include "definitions.ily"} with
4347 @code{\include "web-publish.ily"}.  Of course, we could make this
4348 even more convenient.  We could make a @file{definitions.ily} file which
4349 contains only the definitions of @code{mpdolce} and @code{inst}, a
4350 @file{web-publish.ily} file which contains only the @code{\layout}
4351 section listed above, and a @file{university.ily} file which
4352 contains only the tweaks to produce the output that my professor
4353 prefers.  The top of @file{music.ly} would then look like this:
4354
4355 @example
4356 \include "definitions.ily"
4357
4358 %%%  Only uncomment one of these two lines!
4359 \include "web-publish.ily"
4360 %\include "university.ily"
4361 @end example
4362
4363 This approach can be useful even if you are only producing
4364 one set of parts.  I use half a dozen different
4365 @q{style sheet} files for my projects.  I begin every music
4366 file with @code{\include "../global.ily"}, which contains
4367
4368 @example
4369 %%%   global.ily
4370 \version @w{"@version{}"}
4371
4372 #(ly:set-option 'point-and-click #f)
4373
4374 \include "../init/init-defs.ly"
4375 \include "../init/init-layout.ly"
4376 \include "../init/init-headers.ly"
4377 \include "../init/init-paper.ly"
4378 @end example
4379
4380
4381 @node Other sources of information
4382 @subsection Other sources of information
4383
4384 The Internals Reference documentation contains a lot of information
4385 about LilyPond, but even more information can be gathered by
4386 looking at the internal LilyPond files.  To explore these, you must
4387 first find the directory appropriate to your system.  The location
4388 of this directory depends (a) on whether you obtained LilyPond
4389 by downloading a precompiled binary from lilypond.org
4390 or whether you installed it from a package manager (i.e.
4391 distributed with GNU/Linux, or installed under fink or cygwin) or
4392 compiled it from source, and (b) on which operating system it is
4393 being used:
4394
4395 @subsubsubheading Downloaded from lilypond.org
4396
4397 @itemize @bullet
4398 @item GNU/Linux
4399
4400 Navigate to
4401 @example
4402 @file{@var{INSTALLDIR}/lilypond/usr/@/share/lilypond/current/}
4403 @end example
4404
4405 @item MacOS X
4406
4407 Navigate to
4408 @example
4409 @file{@var{INSTALLDIR}/LilyPond.app/Contents/@/Resources/share/lilypond/current/}
4410 @end example
4411
4412 by either @code{cd}-ing into this directory from the
4413 Terminal, or control-clicking on the LilyPond application and
4414 selecting @q{Show Package Contents}.
4415
4416 @item Windows
4417
4418 Using Windows Explorer, navigate to
4419 @example
4420 @file{@var{INSTALLDIR}/LilyPond/usr/@/share/lilypond/current/}
4421 @end example
4422
4423 @end itemize
4424
4425 @subsubsubheading Installed from a package manager or compiled from source
4426
4427 Navigate to
4428 @file{@var{PREFIX}/share/lilypond/@var{X.Y.Z}/}, where
4429 @var{PREFIX} is set by your package manager or @code{configure}
4430 script, and @var{X.Y.Z} is the LilyPond version number.
4431
4432 @smallspace
4433
4434 Within this directory the two interesting subdirectories are
4435
4436 @itemize
4437 @item @file{ly/} - contains files in LilyPond format
4438 @item @file{scm/} - contains files in Scheme format
4439 @end itemize
4440
4441 Let's begin by looking at some files in @file{ly/}.
4442 Open @file{ly/property-init.ly} in a text editor.  The one
4443 you normally use for @code{.ly} files will be fine.  This file
4444 contains the definitions of all the standard LilyPond predefined
4445 commands, such as @code{\stemUp} and @code{\slurDotted}.  You will
4446 see that these are nothing more than definitions of variables
4447 containing one or a group of @code{\override} commands.  For
4448 example, @code{/tieDotted} is defined to be:
4449
4450 @example
4451 tieDotted = @{
4452   \override Tie.dash-period = #0.75
4453   \override Tie.dash-fraction = #0.1
4454 @}
4455 @end example
4456
4457 If you do not like the default values these predefined commands can
4458 be redefined easily, just like any other variable, at the
4459 head of your input file.
4460
4461 The following are the most useful files to be found in
4462 @file{ly/}:
4463
4464 @multitable @columnfractions .4 .6
4465 @headitem Filename
4466   @tab Contents
4467 @item @file{ly/engraver-init.ly}
4468   @tab Definitions of engraver Contexts
4469 @item @file{ly/paper-defaults-init.ly}
4470   @tab Specifications of paper-related defaults
4471 @item @file{ly/performer-init.ly}
4472   @tab Definitions of performer Contexts
4473 @item @file{ly/property-init.ly}
4474   @tab Definitions of all common predefined commands
4475 @item @file{ly/spanner-init.ly}
4476   @tab Definitions of spanner-related predefined commands
4477 @end multitable
4478
4479 Other settings (such as the definitions of markup commands) are
4480 stored as @file{.scm} (Scheme) files.  The Scheme programming
4481 language is used to provide a programmable interface into
4482 LilyPond internal operation.  Further explanation of these files
4483 is currently outside the scope of this manual, as a knowledge of
4484 the Scheme language is required.  Users should be warned that
4485 a substantial amount of technical knowledge or time is required
4486 to understand Scheme and these files (see @rextend{Scheme tutorial}).
4487
4488 If you have this knowledge, the Scheme files which may be of
4489 interest are:
4490
4491 @multitable @columnfractions .4 .6
4492 @headitem Filename
4493   @tab Contents
4494 @item @file{scm/auto-beam.scm}
4495   @tab Sub-beaming defaults
4496 @item @file{scm/define-grobs.scm}
4497   @tab Default settings for grob properties
4498 @item @file{scm/define-markup-commands.scm}
4499   @tab Specify all markup commands
4500 @item @file{scm/midi.scm}
4501   @tab Default settings for MIDI output
4502 @item @file{scm/output-lib.scm}
4503   @tab Settings that affect appearance of frets, colors,
4504        accidentals, bar lines, etc
4505 @item @file{scm/parser-clef.scm}
4506   @tab Definitions of supported clefs
4507 @item @file{scm/script.scm}
4508   @tab Default settings for articulations
4509 @end multitable
4510
4511
4512 @node Advanced tweaks with Scheme
4513 @subsection Advanced tweaks with Scheme
4514
4515 Although many things are possible with the @code{\override} and
4516 @code{\tweak} commands, an even more powerful way of modifying
4517 the action of LilyPond is available through a programmable
4518 interface to the LilyPond internal operation.  Code written in
4519 the Scheme programming language can be incorporated directly in
4520 the internal operation of LilyPond.  Of course, at least a basic
4521 knowledge of programming in Scheme is required to do this, and an
4522 introduction is provided in the @rextend{Scheme tutorial}.
4523
4524 As an illustration of one of the many possibilities, instead of
4525 setting a property to a constant it can be set to a Scheme
4526 procedure which is then called whenever that property is accessed
4527 by LilyPond.  The property can then be set dynamically to a value
4528 determined by the procedure at the time it is called.  In this
4529 example we color the note head in accordance with its position on
4530 the staff.
4531
4532 @cindex x11-color function, example of using
4533 @cindex NoteHead, example of overriding
4534 @cindex color property, setting to Scheme procedure
4535
4536 @lilypond[quote,verbatim,ragged-right]
4537 #(define (color-notehead grob)
4538    "Color the notehead according to its position on the staff."
4539    (let ((mod-position (modulo (ly:grob-property grob 'staff-position)
4540                                7)))
4541      (case mod-position
4542        ;;   Return rainbow colors
4543        ((1) (x11-color 'red    ))  ; for C
4544        ((2) (x11-color 'orange ))  ; for D
4545        ((3) (x11-color 'yellow ))  ; for E
4546        ((4) (x11-color 'green  ))  ; for F
4547        ((5) (x11-color 'blue   ))  ; for G
4548        ((6) (x11-color 'purple ))  ; for A
4549        ((0) (x11-color 'violet ))  ; for B
4550        )))
4551
4552 \relative c' {
4553   % Arrange to obtain color from color-notehead procedure
4554   \override NoteHead.color = #color-notehead
4555   a2 b | c2 d | e2 f | g2 a |
4556 }
4557 @end lilypond
4558
4559 Further examples showing the use of these programmable interfaces
4560 can be found in @rextend{Callback functions}.
4561
4562
4563