For scores with only one voice and one staff, correct contexts are created automatically. For more complex scores, it is necessary to create them by hand. There are three commands which do this.
The easiest command is \new
, and it also the quickest to type.
It is prepended to a music expression, for example
\new type music expression
where type is a context name (like Staff
or
Voice
). This command creates a new context, and starts
interpreting music expression with that.
A practical application of \new
is a score with many
staves. Each part that should be on its own staff, is preceded with
\new Staff
.
<< \new Staff { c4 c } \new Staff { d4 d } >>
Like \new
, the \context
command also directs a music
expression to a context object, but gives the context an extra name. The
syntax is
\context type = id music
This form will search for an existing context of type type called id. If that context does not exist yet, it is created. This is useful if the context is referred to later on. For example, when setting lyrics the melody is in a named context
\context Voice = "tenor" music
so the texts can be properly aligned to its notes,
\new Lyrics \lyricsto "tenor" lyrics
Another possibility is funneling two different music expressions into one context. In the following example, articulations and notes are entered separately,
music = \notes { c4 c4 } arts = \notes { s4-. s4-> }
They are combined by sending both to the same Voice
context,
<< \new Staff \context Voice = "A" \music \context Voice = "A" \arts >>
The third command for creating contexts is
\context type music
This is similar to \context
with =
id, but matches
any context of type type, regardless of its given name.
This variant is used with music expressions that can be interpreted at
several levels. For example, the \applyoutput
command (see
Running a function on all layout objects). Without an explicit
\context
, it is usually is applied to Voice
\applyoutput #function % apply to Voice
To have it interpreted at the Score
or Staff
level use
these forms
\context Score \applyoutput #function \context Staff \applyoutput #function
Read comments on this page, or
add one.
This page is for LilyPond-2.2.6 (stable-branch). |