Next: , Previous: Creating contexts, Up: Interpretation contexts



4.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

[image of music]

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

[image of music]

the context argument to \set is left out, and the current Voice is used.

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,

\set context.prop

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

       \set Staff.autoBeaming = ##f
       \unset Voice.autoBeaming

the current Voice does not have the property, and the definition at Staff level remains intact. Like \set, the context argument does not have to be specified for a bottom context.

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

  c4
  \once \set fontSize = #4.7
  c4
  c4

[image of music]

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.

Read comments on this page, or add one.

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

Report errors to <bug-lilypond@gnu.org>.