Changing context properties on the fly - GNU LilyPond
Description: GNU LilyPond

Next: Modifying context plug-ins, Previous: Creating contexts, Up: Interpretation contexts

#### 9.2.2 Changing context properties on the fly

Each context can have different properties, variables contained in that context. They can be changed during the interpretation step. This is achieved by inserting the `\set` command in the music,

    \set context.prop = #value

For example,

>          R1*2
>          \set Score.skipBars = ##t
>          R1*2

This command skips measures that have no notes. The result is that multi-rests are condensed. The value assigned is a Scheme object. In this case, it is `#t`, the boolean True value.

If the context argument is left out, then the current bottom-most context (typically `ChordNames` , `Voice` , or `Lyrics` ) is used. In this example,

>          c8 c c c
>          \set autoBeaming = ##f
>          c8 c c c

the context argument to `\set` is left out, so automatic beaming is switched off in the current Voice. 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 bottom-most context, in this case `Voice`) will have no effect.

>          R1*2
>          \set skipBars = ##t
>          R1*2

Contexts are hierarchical, so if a bigger context was specified, for example `Staff` , then the change would also apply to all `Voice` s in the current stave. The change is applied `on-the-fly', during the music, so that the setting only affects the second group of eighth notes.

There is also an `\unset` command,

    \unset context.prop

which removes the definition of prop. This command removes the definition only if it is set in context, so

    \set Staff.autoBeaming = ##f

introduces a property setting at `Staff` level. The setting also applies to the current `Voice`. However,

    \unset Voice.autoBeaming

does not have any effect. To cancel this setting, the `\unset` must be specified on the same level as the original `\set`. In other words, undoing the effect of `Staff.autoBeaming = ##f` requires

    \unset Staff.autoBeaming

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.

Settings that should only apply to a single time-step can be entered with `\once`, for example in

>          c4
>          \once \set fontSize = #4.7
>          c4
>          c4

the property `fontSize` is unset automatically after the second note.

A full description of all available context properties is in the program reference, see Tunable context properties.

This page is for LilyPond-2.8.8 (stable-branch).

Other languages: English.
Using automatic language selection.