3

Here is a demonstration of what I want to achieve. A single staff for a few measures, then additional staves joining to form a staff group:

Desired output without key signature

However, with a key signature, I get an additional fragment of a bar before the line break at the transition to the staff group:

Undesired output

How can I get rid of that?

Here is my sample code:

\version "2.22.1"

\score {
           << 
              \new ChordNames \chordmode { g1 c1 g1 c1 }
              \new StaffGroup {<<
                \new Staff { 
                  a2 a a a \break
                  <<
                               { b2 b b b }
                    \new Staff { c'2 c' c' c' } 
                    \new Staff { d'2 d' d' d' }
                  >>
                  }
              >>}
           >>
}


\score {
           << 
              \new ChordNames \chordmode { g1 c1 g1 c1 }
              \new StaffGroup {<<
                \new Staff { 
                  \key g \major 
                  a2 a a a \break
                  <<
                               {  b2 b b b }
                    \new Staff { \key g \major c'2 c' c' c' } 
                    \new Staff { \key g \major d'2 d' d' d' }
                  >>
                  }
              >>}
           >>
}

2 Answers 2

2

That fragment of a bar is there because LilyPond is leaving room for cancelling an old key signature before instantiating the new key signature.

So, right after setting the key signature of both of the new staves, place:

\once \set Staff.explicitKeySignatureVisibility = ##(#f #t #t)

to stop the visibility of the key signature before the break.


You may also want to place:

\once \omit Score.TimeSignature

to get rid of the extra time signatures.


N.B. Set the key sig. at the at staff level of each new staff, but set the time sig. only once at the score level. This is much more practical, because the new staves could possibly be in different (written) key sig. (if you have transposing instruments), where as you are most likely to be using just one time sig. at a time (unless you're using a polymeter).


...
\new Staff { 
    \key g \major 
    a2 a a a \break               
    \once \omit Score.TimeSignature % NEW
    <<
        { 
            b2 b b b 
        }
        \new Staff { 
            \key g \major 
            \once \set Staff.explicitKeySignatureVisibility = ##(#f #t #t) % NEW
            c'2 c' c' c' 
        } 
        \new Staff { 
            \key g \major 
            \once \set Staff.explicitKeySignatureVisibility = ##(#f #t #t) % NEW
            d'2 d' d' d'
        }
    >>
}
...
0

Add \RemoveAllEmptyStaves to the \StaffGroup \layout context. (See Hiding Staves in the LilyPond Manual.)

\layout {
  \context {
    \StaffGroup
    \RemoveAllEmptyStaves
  }
}

This will allow for some cleanup of your existing code, but with the addition of specifying rests for the staves to be hidden. For example:

\score {
    \new StaffGroup {<<
        \new ChordNames \chordmode { g1 c1 g1 c1 }
        \new Staff { a2 a a a \break b2 b b b }
        \new Staff { R1 R1 \break c'2 c' c' c' } 
        \new Staff { R1 R1 \break d'2 d' d' d' }
    >>}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.