[ << Tweaking output ] | [Top][Contents][Index][ ? ] | [ Working on LilyPond projects >> ] | ||
[ < Naming conventions of objects and properties ] | [ Up : Tweaking basics ] | [ The Internals Reference manual > ] |
4.1.4 Tweaking methods
\override command
We have already met the commands \set
and \with
, used to
change the properties of contexts and to remove and add
engravers, in Modifying context properties, and
Adding and removing engravers. We now must meet some more
important commands.
The command to change the properties of layout objects is
\override
. Because this command has to modify
internal properties deep within LilyPond its syntax is not
as simple as the commands you have met so far. It needs to
know precisely which property of which object in which context
has to be modified, and what its new value is to be. Let’s see
how this is done.
The general syntax of this command is:
\override Context.LayoutObject #'layout-property = #value
This will set the property with the name layout-property of the layout object with the name LayoutObject, which is a member of the Context context, to the value value.
The Context can be omitted (and usually is) when the
required context is unambiguously implied and is one of lowest
level contexts, i.e., Voice
, ChordNames
or
Lyrics
, and we shall omit it in many of the following
examples. We shall see later when it must be specified.
Later sections deal comprehensively with properties and their values, but to illustrate the format and use of these commands we shall use just a few simple properties and values which are easily understood.
For now, don’t worry about the #'
, which must precede the
layout property, and the #
, which must precede the value.
These must always be present in exactly this form. This is the
most common command used in tweaking, and most of the rest of
this chapter will be directed to presenting examples of how it is
used. Here is a simple example to change the color of the
note head:
c d \override NoteHead #'color = #red e f g \override NoteHead #'color = #green a b c
\revert command
Once overridden, the property retains its new value until it is
overridden again or a \revert
command is encountered.
The \revert
command has the following syntax and causes
the value of the property to revert to its original default
value; note, not its previous value if several \override
commands have been issued.
\revert Context.LayoutObject #'layout-property
Again, just like Context in the \override
command,
Context is often not needed. It will be omitted
in many of the following examples. Here we revert the color
of the note head to the default value for the final two notes:
c d \override NoteHead #'color = #red e f g \override NoteHead #'color = #green a \revert NoteHead #'color b c
\once prefix
Both the \override
and the \set
commands may be
prefixed by \once
. This causes the following
\override
or \set
command to be effective only
during the current musical moment before the property reverts
back to its default value. Using the same example, we can
change the color of a single note like this:
c d \once \override NoteHead #'color = #red e f g \once \override NoteHead #'color = #green a b c
\overrideProperty command
There is another form of the override command,
\overrideProperty
, which is occasionally required.
We mention it here for completeness, but for details see
Difficult tweaks.
\tweak command
The final tweaking command which is available is \tweak
.
This should be used to change the properties of objects which
occur at the same musical moment, such as the notes within a
chord. Using \override
would affect all the notes
within a chord, whereas \tweak
affects just the following
item in the input stream.
Here’s an example. Suppose we wish to change the size of the
middle note head (the E) in a C major chord. Let’s first see what
\once \override
would do:
<c e g>4 \once \override NoteHead #'font-size = #-3 <c e g> <c e g>
We see the override affects all the note heads in the chord.
This is because all the notes of a chord occur at the same
musical moment, and the action of \once
is to
apply the override to all layout objects of the type specified
which occur at the same musical moment as the \override
command itself.
The \tweak
command operates in a different way. It acts
on the immediately following item in the input stream. However,
it is effective only on objects which are created directly from
the input stream, essentially note heads and articulations;
objects such as stems and accidentals are created later and
cannot be tweaked in this way. Furthermore, when it is applied
to note heads these must be within a chord, i.e., within
single angle brackets, so to tweak a single note the \tweak
command must be placed inside single angle brackets with the
note.
So to return to our example, the size of the middle note of a chord would be changed in this way:
<c e g>4 <c \tweak #'font-size #-3 e g>4
Note that the syntax of \tweak
is different from that
of the \override
command. Neither the context nor the
layout object should be specified; in fact, it would generate
an error to do so. These are both implied by the following
item in the input stream. Note also that an equals sign should
not be present. So the general syntax of the
\tweak
command is simply
\tweak #'layout-property #value
A \tweak
command can also be used to modify just one in
a series of articulations, as shown here:
a ^Black -\tweak #'color #red ^Red -\tweak #'color #green _Green
Note that the \tweak
command must be preceded by an
articulation mark as if it were an articulation itself.
The \tweak
command must also be used to change the
appearance of one of a set of nested tuplets which begin at the
same musical moment. In the following example, the long tuplet
bracket and the first of the three short brackets begin at the
same musical moment, so any \override
command would apply
to both of them. In the example, \tweak
is used to
distinguish between them. The first \tweak
command
specifies that the long tuplet bracket is to be placed above the
notes and the second one specifies that the tuplet number is to be
printed in red on the first short tuplet bracket.
\tweak #'direction #up \times 4/3 { \tweak #'color #red \times 2/3 { c8[ c8 c8] } \times 2/3 { c8[ c8 c8] } \times 2/3 { c8[ c8 c8] } }
If nested tuplets do not begin at the same moment, their
appearance may be modified in the usual way with
\override
commands:
\times 2/3 { c8[ c c]} \once \override TupletNumber #'text = #tuplet-number::calc-fraction-text \times 2/3 { c[ c] c[ c] \once \override TupletNumber #'transparent = ##t \times 2/3 { c8[ c c] } \times 2/3 { c8[ c c]} }
See also
Notation Reference: The tweak command.
[ << Tweaking output ] | [Top][Contents][Index][ ? ] | [ Working on LilyPond projects >> ] | ||
[ < Naming conventions of objects and properties ] | [ Up : Tweaking basics ] | [ The Internals Reference manual > ] |