| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 5.3.1 Overview of modifying properties | ||
5.3.2 The \set command | ||
5.3.3 The \override command | ||
5.3.4 The \tweak command | ||
5.3.5 \set vs. \override | ||
5.3.6 The \offset command | ||
| 5.3.7 Modifying alists |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Each context is responsible for creating certain types of graphical objects. The settings used for printing these objects are also stored by context. By changing these settings, the appearance of objects can be altered.
There are two different kinds of properties stored in contexts: context properties and grob properties. Context properties are properties that apply to the context as a whole and control how the context itself is displayed. In contrast, grob properties apply to specific grob types that will be displayed in the context.
The \set and \unset commands are used to change values
for context properties. The \override and \revert
commands are used to change values for grob properties.
Internals Reference: (internals)Backend section ‘Backend’ in Internals Reference, (internals)All layout objects section ‘All layout objects’ in Internals Reference, (internals)OverrideProperty section ‘OverrideProperty’ in Internals Reference, (internals)RevertProperty section ‘RevertProperty’ in Internals Reference, (internals)PropertySet section ‘PropertySet’ in Internals Reference.
The back-end is not very strict in type-checking object properties. Cyclic references in Scheme values for properties can cause hangs or crashes, or both.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
\set commandEach context has a set of properties, variables contained
in that context. Context properties are changed with the \set
command, which has the following syntax:
\set context.property = #value |
value is a Scheme object, which is why it must be preceded by
the # character.
Contexts properties are usually named in
studlyCaps. They mostly control the translation from
music to notation, e.g., localAlterations (for determining
whether to print accidentals), or measurePosition (for
determining when to print a bar line). Context properties can
change value over time while interpreting a piece of music;
measurePosition is an obvious example of
this. Context properties are modified with \set.
For example, multimeasure rests will be combined into a single bar
(as explained in Compressing empty measures)
if the context property skipBars is set to #t:
R1*2 \set Score.skipBars = ##t R1*2
If the context argument is left out, then the property will be
set in the current bottom context (typically ChordNames,
Voice, TabVoice, or Lyrics).
\set Score.autoBeaming = ##f \relative { e''8 e e e \set autoBeaming = ##t e8 e e e } \\ \relative { c''8 c c c c8 c c c }
The change is applied ‘on-the-fly’, during the music, so that the setting only affects the second group of eighth notes.
Note that the bottom-most context does not always contain the property
that you wish to change – for example, attempting to set the
skipBars property of the default bottom context, in this case
Voice, will have no effect, because skipBars is a property of
the Score context.
R1*2 \set skipBars = ##t R1*2
Contexts are hierarchical, so if an enclosing context was specified, for
example Staff, then the change would also apply to all
Voices in the current staff.
The \unset command:
\unset context.property |
is used to remove the definition of property from context. This command removes the definition only if it is set in context. Properties that have been set in enclosing contexts will not be altered by an unset in an enclosed context:
\set Score.autoBeaming = ##t \relative { \unset autoBeaming e''8 e e e \unset Score.autoBeaming e8 e e e } \\ \relative { c''8 c c c c8 c c c }
Like \set, the context argument does not have to be
specified for a bottom context, so the two statements
\set Voice.autoBeaming = ##t \set autoBeaming = ##t |
are equivalent if the current bottom context is Voice.
Preceding a \set or \unset command by \once
makes the setting apply to only a single time-step:
c''4 \once \set fontSize = #4.7 c''4 c''4
A full description of all available context properties is in the internals reference, see (internals)Tunable context properties section ‘Tunable context properties’ in Internals Reference.
Internals Reference: (internals)Tunable context properties section ‘Tunable context properties’ in Internals Reference.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
\override commandThere is a special type of context property: the grob
description. Grob descriptions are named in StudlyCaps
(starting with capital letters). They contain the
‘default settings’ for a particular kind of grob as an
association list. See ‘scm/define-grobs.scm’
to see the settings for each grob description. Grob descriptions
are modified with \override.
The syntax for the \override command is
\override [context.]GrobName.property = #value |
For example, we can increase the thickness of a note stem by
overriding the thickness property of the Stem
object:
c''4 c'' \override Voice.Stem.thickness = #3.0 c''4 c''
If no context is specified in an \override, the bottom
context is used:
\override Staff.Stem.thickness = #3.0 << \relative { e''4 e \override Stem.thickness = #0.5 e4 e } \\ \relative { c''4 c c c } >>
Some tweakable options are called ‘subproperties’ and reside inside properties. To tweak those, use commands in the form
\override Stem.details.beamed-lengths = #'(4 4 3) |
or to modify the ends of spanners, use a form like these
\override TextSpanner.bound-details.left.text = "left text" \override TextSpanner.bound-details.right.text = "right text" |
The effects of \override can be undone by \revert.
The syntax for the \revert command is
\revert [context.]GrobName.property |
For example,
\relative { c''4 \override Voice.Stem.thickness = #3.0 c4 c \revert Voice.Stem.thickness c4 }
The effects of \override and \revert apply to all
grobs in the affected context from the current time forward:
<< \relative { e''4 \override Staff.Stem.thickness = #3.0 e4 e e } \\ \relative { c''4 c c \revert Staff.Stem.thickness c4 } >>
\once can be used with \override or \revert
to affect only the current time step:
<< \relative c { \override Stem.thickness = #3.0 e''4 e e e } \\ \relative { c''4 \once \override Stem.thickness = #3.0 c4 c c } >>
Internals Reference: (internals)Backend section ‘Backend’ in Internals Reference
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
\tweak commandChanging grob properties
with \override causes the changes to apply to all of the
given grobs in the context at the moment the change applies.
Sometimes, however, it is desirable to have changes apply to just
one grob, rather than to all grobs in the affected context. This is
accomplished with the \tweak command, which has the following
syntax:
\tweak [layout-object.]grob-property value |
Specifying layout-object is optional.
The \tweak command applies to the music object that immediately
follows value in the music stream.
For an introduction to the syntax and uses of the tweak command see (learning)Tweaking methods section ‘Tweaking methods’ in Learning Manual.
When several similar items are placed at the same musical moment,
the \override command cannot be used to modify just one of
them – this is where the \tweak command must be used.
Items which may appear more than once at the same musical moment
include the following:
In this example, the color of one note head and the type of another note head are modified within a single chord:
< c'' \tweak color #red d'' g'' \tweak duration-log #1 a'' > 4
\tweak can be used to modify slurs:
\relative { c'-\tweak thickness #5 ( d e f) }
For the \tweak command to work, it must
remain immediately adjacent to the object to which it is
to apply after the input file has been converted to a music stream.
Tweaking a whole chord does not do anything since its music event
only acts as a container, and all layout objects are created from events
inside of the EventChord:
\tweak color #red c''4 \tweak color #red <c'' e''>4 <\tweak color #red c'' e''>4
The simple \tweak command cannot be used to modify any object
that is not directly created from the input. In particular
it will not affect stems, automatic
beams or accidentals, since these are generated later by
NoteHead layout objects rather than by music elements in the
input stream.
Such indirectly created layout objects can be tweaked using the form
of the \tweak command in which the grob name is specified
explicitly:
\tweak Stem.color #red \tweak Beam.color #green c''8 e'' <c'' e'' \tweak Accidental.font-size #-3 ges''>4
\tweak cannot be used to modify clefs or time
signatures, since these become separated from any preceding
\tweak command in the input stream by the automatic
insertion of extra elements required to specify the context.
Several \tweak commands may be placed before a
notational element – all affect it:
c' -\tweak style #'dashed-line -\tweak dash-fraction #0.2 -\tweak thickness #3 -\tweak color #red \glissando f''
The music stream which is generated from a section of an input file,
including any automatically inserted elements, may be examined,
see
(extending)Displaying music expressions section ‘Displaying music expressions’ in Extending. This may be helpful in
determining what may be modified by a \tweak command, or
in determining how to adjust the input to make a \tweak
apply.
Learning Manual: (learning)Tweaking methods section ‘Tweaking methods’ in Learning Manual.
Extending LilyPond: (extending)Displaying music expressions section ‘Displaying music expressions’ in Extending.
The \tweak command cannot be used to modify the control
points of just one of several ties in a chord, other than the first
one encountered in the input file.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
\set vs. \overrideThe \set and \override commands manipulate properties
associated with contexts. In both cases, the properties follow a
hierarchy of contexts; properties that are not set themselves in
a context will still show the values of their respective parent’s
context.
The lifetime and value of a context property is dynamic and only available when music is being interpreted (i.e., ‘iterated’). At the time of the context’s creation, properties are initialized from its corresponding definitions (along with any other modifications) of that context. Any subsequent changes are achieved with any ‘property-setting’ commands that are within the music itself.
Graphical Object (or “grob”) definitions are a special category of context properties as their structure and use is different from that of normal context properties. Unlike normal context properties, grob definitions are subdivided into grob properties.
Also, in contrast to normal context properties, grob definitions have their own internal ‘bookkeeping’ used to keep track of their own individual grob properties and any sub-properties. This means that it is possible to define those parts within different contexts and yet still have the overall grob definition at the time of grob creation from all the pieces provided amongst the current context and its parent(s).
A grob is usually created by an engraver at the time of interpreting a music expression and receives its initial properties from the current grob definition of the engraver’s context. The engraver (or other ‘backend’ parts of LilyPond) can then change (or add to) the grob’s initial properties. However, this does not affect the context’s own grob definition.
What LilyPond calls grob properties in the context of ‘user-level’ tweaks are really the properties of a context’s own grob definition.
Grob definitions are accessed with a different set of commands and are
manipulated using \override and \revert and have a name
starting with a capital letter (e.g., ‘NoteHead’); whereas normal
context properties are manipulated using \set and \unset
and are named starting with a lowercase letter.
The commands \tweak and \overrideProperty change grob
properties by bypassing all context properties completely and, instead,
catch grobs as they are being created, setting properties on them for
a music event (\tweak) or, in the case of
\overrideProperty for a specific override.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
\offset commandWhile it is possible to set grob properties to new values with the
\override, \tweak, and \overrideProperty commands,
it is often more convenient to modify such properties relative to a
default value. The \offset command is available for this
purpose.
The syntax for \offset is
[-]\offset property offsets item |
The command works by adding the contents of offsets to the default setting of the property property of the grob indicated by item.
Depending on the formulation of the command, \offset may act
as either a \tweak or \override. The variations in
usage are discussed after consideration is given to grob properties
that may be used with \offset.
Many, but not all, grob properties may be offset. If property
cannot be offset, the object will remain unchanged and a warning will
be issued. In such cases, \override or \tweak should be
used to modify the object instead.
One can work by trial and error and let the warnings be the guide to what may or may not be offset. A more systematic approach is possible, however.
The following criteria determine whether a property can be modified with
\offset:
number, list of numbers, number-pair, and
number-pair-list. The pages at
(internals)All layout objects section ‘All layout objects’ in Internals Reference
list the type of data characteristic to each property. It is immaterial
whether the default setting is a function.
The following examples consider several grob properties against the criteria outlined above.
Hairpin.heightThis property is not a subproperty, and it is listed at
(internals)Hairpin section ‘Hairpin’ in Internals Reference. For a value, it takes ‘dimension, in staff
space’ set to 0.6666—clearly a non-infinite number.
Arpeggio.positionsThe page
(internals)Arpeggio section ‘Arpeggio’ in Internals Reference lists a positions property which
accepts a ‘pair of numbers’. It defaults to
ly:arpeggio::positions—a callback which will be evaluated
during the typesetting phase to yield a pair of numbers for any given
Arpeggio object.
Hairpin.colorThere is no listing for color at
(internals)Hairpin section ‘Hairpin’ in Internals Reference.
Hairpin.circled-tipThe listing for Hairpin.circled-tip at
(internals)Hairpin section ‘Hairpin’ in Internals Reference shows
that it takes a boolean value. Booleans are non-numerical.
Stem.details.lengthsThough listed at
(internals)Stem section ‘Stem’ in Internals Reference and defaulting to a list of
numbers, this is a ‘subproperty’. There is currently no
support for ‘nested properties’.
If item is a grob name like Arpeggio or
Staff.OttavaBracket, the result is an \override of the
specified grob-type.
\offset property offsets [context.]GrobName |
Note that the leading hyphen is never used with the ‘override’
form, just as it is never used with the \override command itself.
The following example uses the ‘override’ form to lengthen the
default arpeggios shown in the first measure to cover the extent of
the chords more fully. The arpeggios are stretched by a half
staff-space to top and bottom. Also shown is the same operation done on
the first chord with an ordinary override of the positions
property. This method is not at all expressive of the task of
‘stretching by a half staff-space’, as the endpoints must be specified
with absolute rather than relative coordinates. Furthermore, individual
overrides would be needed for the other chords, as they vary in size and
position.
arpeggioMusic = { <c' e' g'>\arpeggio <a' c'' e''>\arpeggio <d' f' a' c''>\arpeggio <c' e' g' b' d'' f'' a''>\arpeggio } { \arpeggioMusic \bar "||" \offset positions #'(-0.5 . 0.5) Arpeggio \arpeggioMusic \bar "||" \once \override Arpeggio.positions = #'(-3.5 . -0.5) <c' e' g'>1\arpeggio \bar "||" }
In its ‘override’ usage, \offset may be prefaced with
\once or \temporary and reverted using \revert
with property (see
functions
(extending)Intermediate substitution functions section ‘Intermediate substitution functions’ in Extending). This follows from the fact that \offset
actually creates an \override of property.
music = { c'8\< d' e' f'\! } { \music \offset height 1 Hairpin \music \music \revert Hairpin.height \music \bar "||" \once \offset height 1 Hairpin \music \music \bar "||" \override Hairpin.height = 0.2 \music \temporary \offset height 2 Hairpin \music \music \revert Hairpin.height \music \bar "||" }
Also like \override, the ‘override’ form of \offset may
be used with \undo and \single.
longStem = \offset length 6 Stem { \longStem c'4 c''' c' c'' \bar "||" \undo \longStem c'4 c''' c' c'' \bar "||" \single \longStem c'4 c''' c' c'' \bar "||" }
If item is a music expression such as ( or
\arpeggio, the result is the same music expression with a tweak
applied.
[-]\offset [GrobName.]property offsets music-expression |
The syntax of \offset in its ‘tweak’ form is analogous to the
\tweak command itself, both in ordering and in the presence or
absence of the leading hyphen.
The following example uses the ‘tweak’ form to adjust the vertical
position of the BreathingSign object. Compare this with the
ordinary \tweak command also demonstrated. The syntax is
equivalent; however, the output of \tweak is less intuitive,
since BreathingSign.Y-offset is calculated from the middle
staff-line. It is not necessary to know how Y-offset is
calculated when using \offset.
{ c''4 \breathe c''4 \offset Y-offset 2 \breathe c''2 \tweak Y-offset 3 \breathe }
In the previous example, the tweaked objects were created directly from
the user input: the \breathe command was an explicit instruction
to return a BreathingSign object. Since the focus of the command
was unambiguous, there was no need to specify the object’s name. When
an object is indirectly created, however, it is necessary to
include the grob’s name. This is the same as for the \tweak
command.
In the following example, the Beam object is lowered two
staff-spaces by applying \offset to the positions
property.
The first application of \offset requires that the grob’s name
be included, because nothing in the input explicitly creates the
beam. In the second application, the beam is created manually with the
music expression [; therefore, the grob’s name is not needed.
(Also illustrated is a shorthand: a single number will be applied
to both members of a number-pair.)
{ c''8 g'' e'' d'' \offset Beam.positions #'(-2 . -2) c''8 g'' e'' d'' c''8 g'' e'' d'' c''8-\offset positions #-2 [ g'' e'' d''] }
Independently modifying segments of a spanner extending over a line break or breaks is also possible. In this case, offsets takes a list of values of the property’s required data type.
The \offset command used in this manner is similar to the
\alterBroken command. (See Modifying broken spanners.)
In contrast with \alterBroken, however, the values given to
\offset are relative, not absolute.
The following example displaces the ‘broken’ OttavaBracket
object through its staff-padding property. Since the property
takes a number, offsets is provided with a list of
numbers to account for the two segments created by the line
break. The bracket piece on the first line is effectively untouched
since 0 is added to its default value of staff-padding.
The segment on the second line is raised three staff-spaces from its
default height. The default height happens to be 2, though it is
not necessary to know this to achieve the desired positioning.
{ \offset staff-padding #'(0 3) Staff.OttavaBracket \ottava #1 c'''2 c''' \break c'''2 c''' }
The following example mimics the effect of the \shape command by
offsetting the control-points property of the Slur object.
Here, offsets is a list of number-pair-lists, one for each
slur segment. This example achieves a result identical to the
corresponding illustration at Modifying shapes.
{ c'4-\offset control-points #'( ((0 . 0) (0 . 0) (0 . 0) (0 . 1)) ((0.5 . 1.5) (1 . 0) (0 . 0) (0 . -1.5)) ) ( f'4 g' c'' \break d'4 c'' f' c') }
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Some user-configurable properties are internally represented as alists (association lists), which store pairs of keys and values. The structure of an alist is:
'((key1 . value1) (key2 . value2) (key3 . value3) …) |
If an alist is a grob property or \paper variable, its keys
can be modified individually without affecting other keys.
For example, to reduce the space between adjacent staves in a
staff-group, use the staff-staff-spacing property of the
StaffGrouper grob. The property is an alist with four
keys: basic-distance, minimum-distance,
padding, and stretchability. The standard settings
for this property are listed in the “Backend” section of the
Internals Reference (see
(internals)StaffGrouper section ‘StaffGrouper’ in Internals Reference):
'((basic-distance . 9) (minimum-distance . 7) (padding . 1) (stretchability . 5)) |
One way to bring the staves closer together is by reducing the
value of the basic-distance key (9) to match the
value of minimum-distance (7). To modify a single
key individually, use a nested declaration:
% default space between staves \new PianoStaff << \new Staff { \clef treble c''1 } \new Staff { \clef bass c1 } >> % reduced space between staves \new PianoStaff \with { % this is the nested declaration \override StaffGrouper.staff-staff-spacing.basic-distance = #7 } << \new Staff { \clef treble c''1 } \new Staff { \clef bass c1 } >>
Using a nested declaration will update the specified key (such as
basic-distance in the above example) without altering any
other keys already set for the same property.
Now suppose we want the staves to be as close as possible without overlapping. The simplest way to do this is to set all four alist keys to zero. However, it is not necessary to enter four nested declarations, one for each key. Instead, the property can be completely re-defined with one declaration, as an alist:
\new PianoStaff \with { \override StaffGrouper.staff-staff-spacing = #'((basic-distance . 0) (minimum-distance . 0) (padding . 0) (stretchability . 0)) } << \new Staff { \clef treble c''1 } \new Staff { \clef bass c1 } >>
Note that any keys not explicitly listed in the alist definition
will be reset to their default-when-unset values. In the
case of staff-staff-spacing, any unset key-values would be
reset to zero (except stretchability, which takes the value
of basic-distance when unset). Thus the following two
declarations are equivalent:
\override StaffGrouper.staff-staff-spacing =
#'((basic-distance . 7))
\override StaffGrouper.staff-staff-spacing =
#'((basic-distance . 7)
(minimum-distance . 0)
(padding . 0)
(stretchability . 7))
|
One (possibly unintended) consequence of this is the removal of
any standard settings that are set in an initialization file and
loaded each time an input file is compiled. In the above example,
the standard settings for padding and
minimum-distance (defined in ‘scm/define-grobs.scm’)
are reset to their default-when-unset values (zero for both keys).
Defining a property or variable as an alist (of any size) will
always reset all unset key-values to their default-when-unset
values. Unless this is the intended result, it is safer to update
key-values individually with a nested declaration.
Note: Nested declarations will not work for context property
alists (such as beamExceptions, keyAlterations,
timeSignatureSettings, etc.). These properties can only be
modified by completely re-defining them as alists.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated by gub on July 13, 2020 using texi2html 1.82.
Más nyelvek: català, deutsch, español, français, italiano, 日本語.
Az automatikus nyelvválasztásról.