4.4.3 Outside-staff objects

Outside-staff objects are automatically placed to avoid collisions. Objects with the lower value of the outside-staff-priority property are placed nearer to the staff, and other outside-staff objects are then raised as far as necessary to avoid collisions. The outside-staff-priority is defined in the grob-interface and so is a property of all layout objects. By default it is set to #f for all within-staff objects, and to a numerical value appropriate to each outside-staff object when the object is created. The following table shows the default numerical values for some of the commonest outside-staff objects which are, by default, placed in the Staff or Voice contexts.

Layout Object

Priority

Controls position of:

MultiMeasureRestText

450

Text over full-bar rests

TextScript

450

Markup text

OttavaBracket

400

Ottava brackets

TextSpanner

350

Text spanners

DynamicLineSpanner

250

All dynamic markings

VoltaBracketSpanner

100

Volta brackets

TrillSpanner

50

Spanning trills

Here is an example showing the default placement of some of these.

% Set details for later Text Spanner
\override TextSpanner #'(bound-details left text)
    = \markup { \small \bold Slower }
% Place dynamics above staff
\dynamicUp
% Start Ottava Bracket
\ottava #1
c' \startTextSpan
% Add Dynamic Text
c\pp
% Add Dynamic Line Spanner
c\<
% Add Text Script
c^Text
c c
% Add Dynamic Text
c\ff c \stopTextSpan
% Stop Ottava Bracket
\ottava #0
c, c c c

[image of music]

This example also shows how to create Text Spanners – text with extender lines above a section of music. The spanner extends from the \startTextSpan command to the \stopTextSpan command, and the format of the text is defined by the \override TextSpanner command. For more details see Text spanners.

It also shows how ottava brackets are created.

Note that bar numbers, metronome marks and rehearsal marks are not shown. By default these are created in the Score context and their outside-staff-priority is ignored relative to the layout objects which are created in the Staff context. If you wish to place bar numbers, metronome marks or rehearsal marks in accordance with the value of their outside-staff-priority the Bar_number_engraver, Metronome_mark_engraver or Mark_engraver respectively should be removed from the Score context and placed in the top Staff context. If this is done, these marks will be given the following default outside-staff-priority values:

Layout Object

Priority

RehearsalMark

1500

MetronomeMark

1000

BarNumber

100

If the default values of outside-staff-priority do not give you the placing you want, the priority of any of the objects may be overridden. Suppose we would like the ottava bracket to be placed below the text spanner in the example above. All we need to do is to look up the priority of OttavaBracket in the IR or in the tables above, and reduce it to a value lower than that of a TextSpanner, remembering that OttavaBracket is created in the Staff context:

% Set details for later Text Spanner
\override TextSpanner #'(bound-details left text)
    = \markup { \small \bold Slower }
% Place dynamics above staff
\dynamicUp
%Place following Ottava Bracket below Text Spanners
\once \override Staff.OttavaBracket #'outside-staff-priority = #340
% Start Ottava Bracket
\ottava #1
c' \startTextSpan
% Add Dynamic Text
c\pp
% Add Dynamic Line Spanner
c\<
% Add Text Script
c^Text
c c
% Add Dynamic Text
c\ff c \stopTextSpan
% Stop Ottava Bracket
\ottava #0
c, c c c

[image of music]

Slurs by default are classed as within-staff objects, but they often appear above the staff if the notes to which they are attached are high on the staff. This can push outside-staff objects such as articulations too high, as the slur will be placed first. The avoid-slur property of the articulation can be set to 'inside to bring the articulation inside the slur, but the avoid-slur property is effective only if the outside-staff-priority is also set to #f. Alternatively, the outside-staff-priority of the slur can be set to a numerical value to cause it to be placed along with other outside-staff objects according to that value. Here’s an example showing the effect of the two methods:

c4( c^\markup\tiny\sharp d4.) c8
c4(
\once \override TextScript #'avoid-slur = #'inside
\once \override TextScript #'outside-staff-priority = ##f
c^\markup\tiny\sharp d4.) c8
\once \override Slur #'outside-staff-priority = #500
c4( c^\markup\tiny\sharp d4.) c8

[image of music]

Changing the outside-staff-priority can also be used to control the vertical placement of individual objects, although the results may not always be desirable. Suppose we would like “Text3” to be placed above “Text4” in the example under Automatic behavior, above (see Automatic behavior). All we need to do is to look up the priority of TextScript in the IR or in the tables above, and increase the priority of “Text3” to a higher value:

c2^"Text1"
c^"Text2"
\once \override TextScript #'outside-staff-priority = #500
c^"Text3"
c^"Text4"

[image of music]

This certainly lifts “Text3” above “Text4” but it also lifts it above “Text2”, and “Text4” now drops down. Perhaps this is not so good. What we would really like to do is to position all the annotation at the same distance above the staff. To do this, we clearly will need to space the notes out horizontally to make more room for the text. This is done using the textLengthOn command.

\textLengthOn

By default, text produced by markup takes up no horizontal space as far as laying out the music is concerned. The \textLengthOn command reverses this behavior, causing the notes to be spaced out as far as is necessary to accommodate the text:

\textLengthOn  % Cause notes to space out to accommodate text
c2^"Text1"
c^"Text2"
c^"Text3"
c^"Text4"

[image of music]

The command to revert to the default behavior is \textLengthOff. Remember \once only works with \override, \set, \revert or unset, so cannot be used with \textLengthOn.

Markup text will also avoid notes which project above the staff. If this is not desired, the automatic displacement upwards may be turned off by setting the priority to #f. Here’s an example to show how markup text interacts with such notes.

% This markup is short enough to fit without collision
c2^"Tex"
c''2
R1
% This is too long to fit, so it is displaced upwards
c,,2^"Text"
c''2
R1
% Turn off collision avoidance
\once \override TextScript #'outside-staff-priority = ##f
c,,2^"Long Text   "
c''2
R1
% Turn off collision avoidance
\once \override TextScript #'outside-staff-priority = ##f
\textLengthOn  % and turn on textLengthOn
c,,2^"Long Text   "  % Spaces at end are honored
c''2

[image of music]

Dynamics

Dynamic markings will normally be positioned beneath the staff, but may be positioned above with the dynamicUp command. They will be positioned vertically relative to the note to which they are attached, and will float below (or above) all within-staff objects such as phrasing slurs and bar numbers. This can give quite acceptable results, as this example shows:

\clef "bass"
\key aes \major
\time 9/8
\dynamicUp
bes4.~\f\< \( bes4 bes8 des4\ff\> c16 bes\! |
ees,2.~\)\mf ees4 r8 |

[image of music]

However, if the notes and attached dynamics are close together the automatic placement will avoid collisions by displacing later dynamic markings further away, but this may not be the optimum placement, as this rather artificial example shows:

\dynamicUp
a4\f b\mf c\mp b\p

[image of music]

Should a similar situation arise in ‘real’ music, it may be preferable to space out the notes a little further, so the dynamic markings can all fit at the same vertical distance from the staff. We were able to do this for markup text by using the \textLengthOn command, but there is no equivalent command for dynamic marks. So we shall have to work out how to do this using \override commands.

Grob sizing

First we must learn how grobs are sized. All grobs have a reference point defined within them which is used to position them relative to their parent object. This point in the grob is then positioned at a horizontal distance, X-offset, and at a vertical distance, Y-offset, from its parent. The horizontal extent of the object is given by a pair of numbers, X-extent, which say where the left and right edges are relative to the reference point. The vertical extent is similarly defined by a pair of numbers, Y-extent. These are properties of all grobs which support the grob-interface.

By default, outside-staff objects are given a width of zero so that they may overlap in the horizontal direction. This is done by the trick of adding infinity to the leftmost extent and minus infinity to the rightmost extent by setting the extra-spacing-width to '(+inf.0 . -inf.0). So to ensure they do not overlap in the horizontal direction we must override this value of extra-spacing-width to '(0 . 0) so the true width shines through. This is the command to do this for dynamic text:

\override DynamicText #'extra-spacing-width = #'(0 . 0)

Let’s see if this works in our previous example:

\dynamicUp
\override DynamicText #'extra-spacing-width = #'(0 . 0)
a4\f b\mf c\mp b\p

[image of music]

Well, it has certainly stopped the dynamic marks being displaced, but two problems remain. The marks should be spaced a little further apart and it would be better if they were all the same distance from the staff. We can solve the first problem easily. Instead of making the extra-spacing-width zero we could add a little more to it. The units are the space between two staff lines, so moving the left edge half a unit to the left and the right edge half a unit to the right should do it:

\dynamicUp
% Extend width by 1 staff space
\override DynamicText #'extra-spacing-width = #'(-0.5 . 0.5)
a4\f b\mf c\mp b\p

[image of music]

This looks better, but maybe we would prefer the dynamic marks to be aligned along the same baseline rather than going up and down with the notes. The property to do this is staff-padding which is covered in the following section.


Other languages: espaƱol, deutsch.

Learning Manual