# LilyPond: Combine parts when identical, but split into staves when different

I'm arranging the second movement of Ravel's Ma mere l'Oye for recorder ensemble. There are two parts for tenor recorder, and I'd like to combine them into one written part. Sometimes, the two parts are identical, and sometimes, they're different enough that it would be awkward to put them on one staff. However, they won't fit on a single page if I use two staves throughout.

Is there a way to combine the parts so that they will share a single staff when the parts are identical, but use separate staves when the parts differ?

The LilyPond installation contains a file input/regression/divisi-staves.ly that shows an example of how to achieve Divisi staves that will split more complex music into multiple systems temporarily while extending the split to the line breaks.

Documentation of that feature is unfortunately awfully lacking, so you need to go by example.

\version "2.19.13"

texidoc = "The @code{VerticalAxisGroup.remove-layer}
property can be used for typesetting temporary divisi staves where
the switch to split staves is done only at line breaks such that all
complex passages are rendered in separate staves."
}

boring = \set Staff.keepAliveInterfaces = #'()
tricky = \unset Staff.keepAliveInterfaces

violI=\relative d' {
\boring \repeat unfold 100 d4
\tricky <d g'>2
\boring \repeat unfold 98 d4
\bar "|."
}

violII=\relative g {
\boring \repeat unfold 100 g4
\tricky <g d'>2
\boring \repeat unfold 98 g4
\bar "|."
}

\score {
\new StaffGroup \with { \consists "Keep_alive_together_engraver" }
<<
\new Staff \with { instrumentName = "Violin I"
shortInstrumentName = "V I"
\override VerticalAxisGroup.remove-empty = ##t
\override VerticalAxisGroup.remove-first = ##t
\override VerticalAxisGroup.remove-layer = 1
}
\violI
\new Staff \with { instrumentName = "Violin II"
shortInstrumentName = "V II"
\override VerticalAxisGroup.remove-empty = ##t
\override VerticalAxisGroup.remove-first = ##t
\override VerticalAxisGroup.remove-layer = 1
}
\violII
\new Staff \with { instrumentName = "Violins"
shortInstrumentName = "V I&II"
\override VerticalAxisGroup.remove-layer = 2
}
<<  \violI \\ \violII  >>
>>
\layout {
short-indent = 2\cm
indent = 3\cm
}
}


Try writing three staves, one for the part in unison, and one for each of the parts when they are different. Put full bar rests where the the other stave should be read.

Something like this:

Then use \RemoveAllEmptyStaves to french the score.

To get something like this:

See the following code:

\version "2.19.83"

\paper {
left-margin = 15
}

%% Recorders One and Two
recorderOneTwo = {
\new Staff \with {
instrumentName = \markup { \center-column {" " "Recorders" " "}
\center-column { 1 " " 2 } }
shortInstrumentName = \markup { \center-column {" " "Rec" " "}
\center-column { 1 " " 2 } } } {

c'4 4 4 4 |
c'4 4 4 4 |
c'4 4 4 4 |
c'4 4 4 4 |
\break

R1*4 |
}
}

%% Recorder One
recorderOne = {
\new Staff \with {
instrumentName = \markup { Recorder 1 }
shortInstrumentName = "Rec 1" } {

R1*4 |

e'4 4 4 4 |
e'4 4 4 4 |
e'4 4 4 4 |
e'4 4 4 4 |
}
}

%% Recorder Two
recorderTwo = {
\new Staff \with {
instrumentName = \markup { Recorder 2 }
shortInstrumentName = "Rec 2" } {

R1*4 |

c'4 4 4 4 |
c'4 4 4 4 |
c'4 4 4 4 |
c'4 4 4 4 |
}
}

%% CONTENTS
contents = {
\new StaffGroup
<<
\recorderOneTwo
\recorderOne
\recorderTwo
>>
}

%% PDF
\score {
\contents
\layout {
\context {
\Staff \RemoveAllEmptyStaves
}
}
}

• What will be the result if a bar with notes in the top stave shares a system with a bar with notes in the bottom two staves? Will we get three staves on that system? – Rosie F Feb 5 '20 at 7:22
• @RosieF: Yes, you will get three, with some of them having only rests. Because of that, I would advise to make only two staves, one for the first recorder and one for the second recorder in places where it differs from the first one. (You can still get weird results if, for instance, the second part differs from the first only in every other bar --- but that will be easier to cope with manually.) – Ramillies Feb 5 '20 at 10:16