| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section discusses various approaches to fine tuning the appearance of the printed score.
| 5.5.1 Aligning objects | ||
| 5.5.2 Vertical grouping of grobs | ||
| 5.5.3 Modifying stencils | ||
| 5.5.4 Modifying shapes | ||
| 5.5.5 Modifying broken spanners | ||
| 5.5.6 Unpure-pure containers |
Learning Manual: (learning)Tweaking output section ‘Tweaking output’ in Learning Manual, (learning)Other sources of information section ‘Other sources of information’ in Learning Manual.
Notation Reference: Explaining the Internals Reference, Modifying properties.
Extending LilyPond: (extending)Interfaces for programmers section ‘Interfaces for programmers’ in Extending.
Installed Files: ‘scm/define-grobs.scm’.
Snippets: (snippets)Tweaks and overrides section ‘Tweaks and overrides’ in Snippets.
Internals Reference: (internals)All layout objects section ‘All layout objects’ in Internals Reference.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Graphical objects which support the self-alignment-interface
and/or the side-position-interface can be aligned to a previously
placed object in a variety of ways. For a list of these objects, see
(internals)self-alignment-interface section ‘self-alignment-interface’ in Internals Reference and
(internals)side-position-interface section ‘side-position-interface’ in Internals Reference.
All graphical objects have a reference point, a horizontal extent and a vertical extent. The horizontal extent is a pair of numbers giving the displacements from the reference point of the left and right edges, displacements to the left being negative. The vertical extent is a pair of numbers giving the displacement from the reference point to the bottom and top edges, displacements down being negative.
An object’s position on a staff is given by the values of the
X-offset and Y-offset properties. The value of
X-offset gives the displacement from the X coordinate of
the reference point of the parent object, and the value of
Y-offset gives the displacement from the center line of the
staff. The values of X-offset and Y-offset may
be set directly or may be set to be calculated by procedures in order
to achieve alignment with the parent object.
Note: Many objects have special positioning considerations which
cause any setting of X-offset or Y-offset to be
ignored or modified, even though the object supports the
self-alignment-interface. Overriding the X-offset
or Y-offset properties to a fixed value causes the respective
self-alignment property to be disregarded.
For example, an accidental can be repositioned vertically by setting
Y-offset but any changes to X-offset have no effect.
Rehearsal marks may be aligned with breakable objects such as bar
lines, clef symbols, time signature symbols and key signatures. There
are special properties to be found in the break-aligned-interface
for positioning rehearsal marks on such objects.
Notation Reference:
Using the break-alignable-interface.
Extending LilyPond: (extending)Callback functions section ‘Callback functions’ in Extending.
Setting X-offset and Y-offset directly | ||
Using the side-position-interface | ||
Using the self-alignment-interface | ||
Using the break-alignable-interface |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
X-offset and Y-offset directlyNumerical values may be given to the X-offset and Y-offset
properties of many objects. The following example shows three
notes with the default fingering position and the positions with X-offset
and Y-offset modified.
a'-3 a' -\tweak X-offset #0 -\tweak Y-offset #0 -3 a' -\tweak X-offset #-1 -\tweak Y-offset #1 -3
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
side-position-interfaceAn object which supports the side-position-interface can be
placed next to its parent object so that
the specified edges of the two objects touch. The object may be
placed above, below, to the right or to the left of the parent.
The parent cannot be specified; it is determined by the order of
elements in the input stream. Most objects have the associated
note head as their parent.
The values of the side-axis and direction properties
determine where the object is to be placed, as follows:
side-axis | direction | |
|---|---|---|
| property | property | Placement |
0 | -1 | left |
0 | 1 | right |
1 | -1 | below |
1 | 1 | above |
When side-axis is 0, X-offset should be set to
the procedure ly:side-position-interface::x-aligned-side.
This procedure will return the correct value of X-offset to
place the object to the left or right side of the parent according
to value of direction.
When side-axis is 1, Y-offset should be set to
the procedure ly:side-position-interface::y-aligned-side.
This procedure will return the correct value of Y-offset to
place the object to the top or bottom of the parent according
to value of direction.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
self-alignment-interfaceThe horizontal alignment of an object which supports the
self-alignment-interface is controlled by the value of
the self-alignment-X property, provided the object’s
X-offset property is set to
ly:self-alignment-interface::x-aligned-on-self.
self-alignment-X may be given any
real value, in units of half the total X extent of the
object. Negative values move the object to the right, positive
to the left. A value of 0 centers the object on the
reference point of its parent, a value of -1 aligns the
left edge of the object on the reference point of its parent,
and a value of 1 aligns the right edge of the object on the
reference point of its parent. The symbols LEFT,
CENTER, and RIGHT may be used instead of the values
-1, 0, and 1, respectively.
Normally the \override command would be used to modify the
value of self-alignment-X, but the \tweak command
can be used to separately align several annotations on a single
note:
a' -\tweak self-alignment-X #-1 ^"left-aligned" -\tweak self-alignment-X #0 ^"center-aligned" -\tweak self-alignment-X #RIGHT ^"right-aligned" -\tweak self-alignment-X #-2.5 ^"aligned further to the right"
Objects may be aligned vertically in an analogous way to aligning
them horizontally if the Y-offset property is set to
ly:self-alignment-interface::y-aligned-on-self. However,
other mechanisms are often involved in vertical alignment: the
value of Y-offset is just one variable taken into account.
This may make adjusting the value of some objects tricky.
The units are just half the vertical extent of the object, which
is usually quite small, so quite large numbers may be required.
A value of -1 aligns the lower edge of the object with
the reference point of the parent object, a value of 0
aligns the center of the object with the reference point of the
parent, and a value of 1 aligns the top edge of the object
with the reference point of the parent. The symbols DOWN,
CENTER, and UP may be substituted for -1,
0, and 1, respectively.
By setting both X-offset and Y-offset, an object may
be aligned in both directions simultaneously.
The following example shows how to adjust a fingering mark so that it nestles close to the note head.
a' -\tweak self-alignment-X #0.5 % move horizontally left -\tweak Y-offset #ly:self-alignment-interface::y-aligned-on-self -\tweak self-alignment-Y #-1 % move vertically up -3 % third finger
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
break-alignable-interfaceRehearsal marks and bar numbers may be aligned with notation
objects other than bar lines. These objects include ambitus,
breathing-sign, clef, custos, staff-bar,
left-edge, key-cancellation, key-signature, and
time-signature.
Each type of object has its own default reference point, to which rehearsal marks are aligned:
% The rehearsal mark will be aligned to the right edge of the Clef \override Score.RehearsalMark.break-align-symbols = #'(clef) \key a \major \clef treble \mark "↓" e'1 % The rehearsal mark will be aligned to the left edge of the Time Signature \override Score.RehearsalMark.break-align-symbols = #'(time-signature) \key a \major \clef treble \time 3/4 \mark "↓" e'2. % The rehearsal mark will be centered above the Breath Mark \override Score.RehearsalMark.break-align-symbols = #'(breathing-sign) \key a \major \clef treble \time 4/4 e'1 \breathe \mark "↓"
A list of possible target alignment objects may be specified. If
some of the objects are invisible at that point due to the setting
of break-visibility or the explicit visibility settings for
keys and clefs, the rehearsal mark or bar number is aligned to the
first object in the list which is visible. If no objects in the
list are visible the object is aligned to the bar line. If the bar
line is invisible the object is aligned to the place where the bar
line would be.
% The rehearsal mark will be aligned to the right edge of the Key Signature \override Score.RehearsalMark.break-align-symbols = #'(key-signature clef) \key a \major \clef treble \mark "↓" e'1 % The rehearsal mark will be aligned to the right edge of the Clef \set Staff.explicitKeySignatureVisibility = #all-invisible \override Score.RehearsalMark.break-align-symbols = #'(key-signature clef) \key a \major \clef bass \mark "↓" gis,1 % The rehearsal mark will be centered above the Bar Line \set Staff.explicitKeySignatureVisibility = #all-invisible \set Staff.explicitClefVisibility = #all-invisible \override Score.RehearsalMark.break-align-symbols = #'(key-signature clef) \key a \major \clef treble \mark "↓" e'1
The alignment of the rehearsal mark relative to the notation object can be changed, as shown in the following example. In a score with multiple staves, this setting should be done for all the staves.
% The RehearsalMark will be aligned with the right edge of the Key Signature \override Score.RehearsalMark.break-align-symbols = #'(key-signature) \key a \major \clef treble \time 4/4 \mark "↓" e'1 % The RehearsalMark will be centered above the Key Signature \once \override Score.KeySignature.break-align-anchor-alignment = #CENTER \mark "↓" \key a \major e'1 % The RehearsalMark will be aligned with the left edge of the Key Signature \once \override Score.KeySignature.break-align-anchor-alignment = #LEFT \key a \major \mark "↓" e'1
The rehearsal mark can also be offset to the right or left of the left edge by an arbitrary amount. The units are staff-spaces:
% The RehearsalMark will be aligned with the left edge of the Key Signature % and then shifted right by 3.5 staff-spaces \override Score.RehearsalMark.break-align-symbols = #'(key-signature) \once \override Score.KeySignature.break-align-anchor = #3.5 \key a \major \mark "↓" e'1 % The RehearsalMark will be aligned with the left edge of the Key Signature % and then shifted left by 2 staff-spaces \once \override Score.KeySignature.break-align-anchor = #-2 \key a \major \mark "↓" e'1
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The VerticalAlignment and VerticalAxisGroup grobs work together. VerticalAxisGroup groups together different grobs like Staff, Lyrics, etc. VerticalAlignment then vertically aligns the different grobs grouped together by VerticalAxisGroup. There is usually only one VerticalAlignment per score but every Staff, Lyrics, etc., has its own VerticalAxisGroup.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
All layout objects have a stencil property which is part of
the grob-interface. By default, this property is usually
set to a function specific to the object that is tailor-made to
render the symbol which represents it in the output. For example,
the standard setting for the stencil property of the
MultiMeasureRest object is ly:multi-measure-rest::print.
The standard symbol for any object can be replaced by modifying the
stencil property to reference a different, specially-written,
procedure. This requires a high level of knowledge of the internal
workings of LilyPond, but there is an easier way which can often
produce adequate results.
This is to set the stencil property to the procedure which
prints text – ly:text-interface::print – and to add a
text property to the object which is set to contain the
markup text which produces the required symbol. Due to the
flexibility of markup, much can be achieved – see in particular
Graphic notation inside markup.
The following example demonstrates this by changing the note head symbol to a cross within a circle.
XinO = { \once \override NoteHead.stencil = #ly:text-interface::print \once \override NoteHead.text = \markup { \combine \halign #-0.7 \draw-circle #0.85 #0.2 ##f \musicglyph "noteheads.s2cross" } } \relative { a' a \XinO a a }
Any of the Feta glyphs used in the Emmentaler font can be
supplied to the \musicglyph markup command – see
The Emmentaler font.
‘EPS’ files and Postscript commands can both be inserted inline
using the \epsfile and \postscript markup commands
respectively – see Graphic.
Notation Reference: Graphic notation inside markup, Formatting text, Text markup commands, The Emmentaler font, Graphic.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| Modifying ties and slurs |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Ties, Slurs, PhrasingSlurs,
LaissezVibrerTies and RepeatTies are all drawn as
third-order Bézier curves. If the shape of the tie or slur which
is calculated automatically is not optimum, the shape may be
modified manually in two ways:
Both methods are explained below. The first method is more suitable if only slight adjustments to the curve are required; the second may be better for creating curves which are related to just a single note.
Third-order or cubic Bézier curves are defined by four control points. The first and fourth control points are precisely the starting and ending points of the curve. The intermediate two control points define the shape. Animations showing how the curve is drawn can be found on the web, but the following description may be helpful. The curve starts from the first control point heading directly towards the second, gradually bending over to head towards the third and continuing to bend over to head towards the fourth, arriving there travelling directly from the third control point. The curve is entirely contained in the quadrilateral defined by the four control points. Translations, rotations and scaling of the control points all result in exactly the same operations on the curve.
In this example the automatic placement of the tie is not optimum,
and \tieDown would not help.
<< { e'1~ 1 } \\ \relative { r4 <g' c,> <g c,> <g c,> } >>
Adjusting the control points of the tie with \shape allows
the collisions to be avoided.
The syntax of \shape is
[-]\shape displacements item |
This will reposition the control-points of item by the amounts
given by displacements. The displacements argument is a
list of number pairs or a list of such lists. Each element of a pair
represents the displacement of one of the coordinates of a
control-point. If item is a string, the result is
\once\override for the specified grob type. If item is
a music expression, the result is the same music expression with an
appropriate tweak applied.
In other words, the \shape function can act as either a
\once\override command or a \tweak command depending
on whether the item argument is a grob name, like “Slur”,
or a music expression, like “(”. The displacements argument
specifies the displacements of the four control points as a list of
four pairs of (dx . dy) values in units of staff-spaces (or a list
of such lists if the curve has more than one segment).
The leading hyphen is required if and only if the \tweak form
is being used.
So, using the same example as above and the \once\override
form of \shape, this will raise the tie by half a staff-space:
<< { \shape #'((0 . 0.5) (0 . 0.5) (0 . 0.5) (0 . 0.5)) Tie e'1~ 1 } \\ \relative { r4 <g' c,> <g c,> <g c,> } >>
This positioning of the tie is better, but maybe it should be raised
more in the center. The following example does this, this time using
the alternative \tweak form:
<< { e'1-\shape #'((0 . 0.5) (0 . 1) (0 . 1) (0 . 0.5)) ~ e' } \\ \relative { r4 <g' c,> <g c,> <g c,> } >>
Changes to the horizontal positions of the control points may be made in the same way, and two different curves starting at the same musical moment may also be shaped:
\relative { c''8(\( a) a'4 e c\) \shape #'((0.7 . -0.4) (0.5 . -0.4) (0.3 . -0.3) (0 . -0.2)) Slur \shape #'((0 . 0) (0 . 0.5) (0 . 0.5) (0 . 0)) PhrasingSlur c8(\( a) a'4 e c\) }
The \shape function can also displace the control points of
curves which stretch across line breaks. Each piece of the broken
curve can be given its own list of offsets. If changes to a
particular segment are not needed, the empty list can serve as a
placeholder. In this example the line break makes the single slur
look like two:
\relative { c'4( f g c \break d,4 c' f, c) }
Changing the shapes of the two halves of the slur makes it clearer that the slur continues over the line break:
% () may be used as a shorthand for ((0 . 0) (0 . 0) (0 . 0) (0 . 0)) % if any of the segments does not need to be changed \relative c' { \shape #'( (( 0 . 0) (0 . 0) (0 . 0) (0 . 1)) ((0.5 . 1.5) (1 . 0) (0 . 0) (0 . -1.5)) ) Slur c4( f g c \break d,4 c' f, c) }
If an S-shaped curve is required the control points must always be adjusted manually — LilyPond will never select such shapes automatically.
\relative c'' { c8( e b-> f d' a e-> g) \shape #'((0 . -1) (5.5 . -0.5) (-5.5 . -10.5) (0 . -5.5)) PhrasingSlur c8\( e b-> f d' a e-> g\) }
The coordinates of the Bézier control points are specified in units of staff-spaces. The X coordinate is relative to the reference point of the note to which the tie or slur is attached, and the Y coordinate is relative to the staff center line. The coordinates are specified as a list of four pairs of decimal numbers (reals). One approach is to estimate the coordinates of the two end points, and then guess the two intermediate points. The optimum values are then found by trial and error. Be aware that these values may need to be manually adjusted if any further changes are made to the music or the layout.
One situation where specifying the control points explicitly is preferable to specifying displacements is when they need to be specified relative to a single note. Here is an example of this. It shows one way of indicating a slur extending into alternative sections of a volta repeat.
\relative { c''1 \repeat volta 3 { c4 d( e f } \alternative { { g2) d } { g2 % create a slur and move it to a new position % the <> is just an empty chord to carry the slur termination -\tweak control-points #'((-2 . 3.8) (-1 . 3.9) (0 . 4) (1 . 3.4)) ( <> ) f, } { e'2 % create a slur and move it to a new position -\tweak control-points #'((-2 . 3) (-1 . 3.1) (0 . 3.2) (1 . 2.4)) ( <> ) f, } } }
It is not possible to modify shapes of ties or slurs by changing
the control-points property if there are multiple ties or slurs
at the same musical moment – the \tweak command will also not
work in this case. However, the tie-configuration property of
TieColumn can be overridden to set start line and direction as
required.
Internals Reference: (internals)TieColumn section ‘TieColumn’ in Internals Reference.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Using \alterBroken |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
\alterBrokenWhen a spanner crosses a line break or breaks, each piece
inherits the attributes of the original spanner. Thus, ordinary
tweaking of a broken spanner applies the same modifications to
each of its segments. In the example below, overriding
thickness affects the slur on either side of the line
break.
\relative c'' { r2 \once\override Slur.thickness = 10 c8( d e f \break g8 f e d) r2 }
Independently modifying the appearance of individual pieces
of a broken spanner is possible with the \alterBroken
command. This command can produce either an \override
or a \tweak of a spanner property.
The syntax for \alterBroken is
[-]\alterBroken property values item |
The argument values is a list of values, one for each
broken piece. If item is a grob name like Slur or
Staff.PianoPedalBracket, the result is an \override
of the specified grob type. If item is a music expression
such as “(” or “[” the result is the same music expression
with an appropriate tweak applied.
The leading hyphen must be used with the \tweak form. Do
not add it when \alterBroken is used as an
\override.
In its \override usage, \alterBroken may be prefaced
by \once or \temporary and reverted by using
\revert with property (see
substitution functions
(extending)Intermediate substitution functions section ‘Intermediate substitution functions’ in Extending).
The following code applies an independent \override to
each of the slur segments in the previous example:
\relative c'' { r2 \alterBroken thickness #'(10 1) Slur c8( d e f \break g8 f e d) r2 }
The \alterBroken command may be used with any spanner
object, including Tie, PhrasingSlur, Beam
and TextSpanner. For example, an editor preparing a
scholarly edition may wish to indicate the absence of part of a
phrasing slur in a source by dashing only the segment which has
been added. The following example illustrates how this can be
done, in this case using the \tweak form of the command:
% The empty list is conveniently used below, because it is the % default setting of dash-definition, resulting in a solid curve. \relative { c''2-\alterBroken dash-definition #'(() ((0 1.0 0.4 0.75))) \(e \break g2 e\) }
It is important to understand that \alterBroken will set
each piece of a broken spanner to the corresponding value in
values. When there are fewer values than pieces, any
additional piece will be assigned the empty list. This may lead
to undesired results if the layout property is not set to the
empty list by default. In such cases, each segment should be
assigned an appropriate value.
Line breaks may occur in different places following changes in
layout. Settings chosen for \alterBroken may be unsuitable
for a spanner that is no longer broken or is split into more
segments than before. Explicit use of \break can guard
against this situation.
The \alterBroken command is ineffective for spanner
properties accessed before line-breaking such as
direction.
Extending LilyPond: (extending)Difficult tweaks section ‘Difficult tweaks’ in Extending.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Unpure-pure containers are useful for overriding Y-axis spacing
calculations - specifically Y-offset and Y-extent - with a
Scheme function instead of a literal (i.e., a number or pair).
For certain grobs, the Y-extent is based on the stencil
property, overriding the stencil property of one of these will
require an additional Y-extent override with an unpure-pure
container. When a function overrides a Y-offset and/or
Y-extent it is assumed that this will trigger line breaking
calculations too early during compilation. So the function is not
evaluated at all (usually returning a value of ‘0’ or
‘'(0 . 0)’) which can result in collisions. A ‘pure’ function
will not affect properties, objects or grob suicides and therefore will
always have its Y-axis-related evaluated correctly.
Currently, there are about thirty functions that are already considered ‘pure’ and Unpure-pure containers are a way to set functions not on this list as ‘pure’. The ‘pure’ function is evaluated before any line-breaking and so the horizontal spacing can be adjusted ‘in time’. The ‘unpure’ function is then evaluated after line breaking.
Note: As it is difficult to always know which functions are on this
list we recommend that any ‘pure’ functions you create do not use
Beam or VerticalAlignment grobs.
An unpure-pure container is constructed as follows;
(ly:make-unpure-pure-container f0 f1)
where f0 is a function taking n arguments (n >= 1)
and the first argument must always be the grob. This is the function
that gives the actual result. f1 is the function being labeled
as ‘pure’ that takes n + 2 arguments. Again, the first argument
must always still be the grob but the second and third are ‘start’
and ‘end’ arguments.
start and end are, for all intents and purposes, dummy
values that only matter for Spanners (i.e Hairpin or
Beam), that can return different height estimations based on a
starting and ending column.
The rest are the other arguments to the first function (which may be none if n = 1).
The results of the second function are used as an approximation of the value needed which is then used by the first function to get the real value which is then used for fine-tuning much later during the spacing process.
#(define (square-line-circle-space grob) (let* ((pitch (ly:event-property (ly:grob-property grob 'cause) 'pitch)) (notename (ly:pitch-notename pitch))) (if (= 0 (modulo notename 2)) (make-circle-stencil 0.5 0.0 #t) (make-filled-box-stencil '(0 . 1.0) '(-0.5 . 0.5))))) squareLineCircleSpace = { \override NoteHead.stencil = #square-line-circle-space } smartSquareLineCircleSpace = { \squareLineCircleSpace \override NoteHead.Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height (lambda (grob start end) (ly:grob::stencil-height grob))) } \new Voice \with { \remove "Stem_engraver" } \relative c'' { \squareLineCircleSpace cis4 ces disis d \smartSquareLineCircleSpace cis4 ces disis d }
In the first measure, without the unpure-pure container, the spacing engine does not know the width of the note head and lets it collide with the accidentals. In the second measure, with unpure-pure containers, the spacing engine knows the width of the note heads and avoids the collision by lengthening the line accordingly.
Usually for simple calculations nearly-identical functions for
both the ‘unpure’ and ‘pure’ parts can be used, by only
changing the number of arguments passed to, and the scope of, the
function. This use case is frequent enough that
ly:make-unpure-pure-container constructs such a second
function by default when called with only one function argument.
Note: If a function is labeled as ‘pure’ and it turns out not to be, the results can be unexpected.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated by gub on July 13, 2020 using texi2html 1.82.
Andere talen: català, deutsch, español, français, italiano, 日本語.
Gebruik van automatische taalkeuze.