Thursday, May 12, 2011

Accidentally creating a new context

Consider the following layout block:

\layout {
\context {
\type "Engraver_group"
\consists "Time_signature_engraver"
\consists "Axis_group_engraver"
\name "TimeSig"
\override TimeSignature #'font-size = #3
\override TimeSignature #'break-align-symbol = ##f
\override TimeSignature #'X-offset =
#ly:self-alignment-interface::x-aligned-on-self
\override TimeSignature #'self-alignment-X = #CENTER
\override TimeSignature #'after-line-breaking =
#shift-right-at-line-begin
}
\context {
\Score
\accepts TimeSig
}
\context {
\Staff
\remove "Time_signature_engraver"
}
}

The layout comes from the LilyPond snippet repository and allows for time signatures above staves:

\new Score <<
\new TimeSig {
\time 2/4 s2
\time 3/4 s2.
}
\new StaffGroup <<
\new Staff { c'4 c'4 c'4 c'4 c'4 }
\new Staff { c'4 c'4 c'4 c'4 c'4 }
>>
>>


But this can get messed up:

\new Score <<
\new TimeSig {
#(set-accidental-style 'forget)
\time 2/4 s2
\time 3/4 s2.
}
\new StaffGroup <<
\new Staff { c'4 c'4 c'4 c'4 c'4 }
\new Staff { c'4 c'4 c'4 c'4 c'4 }
>>
>>


The accidental style setting causes an unwanted new staff to be instantiated.

Make sure to keep Scheme commands out of nonsemantic contexts to avoid this behavior.