4

I'm quite new to Lilypond, and have been trying to produce something like in the attached picture: broken line connecting staffs

Here's a minimal example of what I tried, which doesn't work. How do I prevent the note in the upper staff to be shifted so much to the right? Should I use an entirely different approach?

Would be very grateful for any help!

\version "2.20.0"  % necessary for upgrading to future LilyPond versions.

upper = \relative c' {
  \clef treble
  \key c \major
  \time 4/4
<<f4 a>> <<f a>> <<f a>> <<e g>> |

}

lower = \relative c' {
  \clef bass
  \key c \major
  \time 4/4


<< f, a {\(c \change Staff = "upper" c \)}>>\change Staff = "lower"
<< f, a {\(c \change Staff = "upper" c\)} >>\change Staff = "lower"
<< f, a {\(c \change Staff = "upper" c\)} >>\change Staff = "lower"
<< c, g'{\(c \change Staff = "upper" c\)} >>\change Staff = "lower"
 
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\score {
  \new PianoStaff  

  <<
    \new Staff = "upper" \upper
    \new Staff = "lower" \lower
  >>
\layout {}
  \midi { }
}
2
  • 2
    The lilypond community usually calls this "cross-staff beaming", and you can find a lot of information in the docs and the forums under that name. Commented Jan 29, 2022 at 21:34
  • Thanks! There's a lot of terminology to learn here
    – Tali
    Commented Jan 30, 2022 at 6:09

2 Answers 2

4

You need to use multiple voices for the bass notes and the changing 8th notes and then have them be 8th notes instead of quarters. Here is a fixed version of your code:

\version "2.20.0"  % necessary for upgrading to future LilyPond versions.

upper = \relative c' {
  \clef treble
  \key c \major
  \time 4/4
<f a>4 <f a> <f a> <e g> |

}

lower = \relative c' {
  \clef bass
  \key c \major
  \time 4/4


<< 
  \new Voice { \repeat unfold 4 {
    <>^\markup\with-dimensions #'(-0.1 . 0.1) #'(-2.55 . 0) " " %%% This hack serves as little spacer to increase the distance to the top staff
    \override Stem.length-fraction = #0.7 %%% make stems a bit shorter
    \voiceOne c8[ \change Staff = "upper" \voiceTwo c] \change Staff = "lower"
  } }
  { \voiceTwo <f, a>4 <f a> <f a> <c g'> }
>>
 
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\score {
  \new PianoStaff  

  <<
    \new Staff = "upper" \upper
    \new Staff = "lower" \lower
  >>
\layout {}
  \midi { }
}

Edit: You might also want to check out this part of the manual: https://lilypond.org/doc/v2.22/Documentation/notation/multiple-voices

2

Like Lazy, I've also had a go at fixing your code. It looks like our codes are actually quite similar, but I thought I'd post my code anyway.

A first point I would make is that chords should be written within a single pair of chevrons, with the duration on the outside, i.e. <f a>4 rather that <<f4 a>>.

The main problem with your attempt is that you need to write the quavers that change staff as a seperate voice from the chords. These will be in \voiceOne when in lower staff, but become \voiceTwo when we change to the upper staff.

I don't know why you've got phrasing slurs.

The main difference between my code and Lazy's is that I've use a beam position override to get flat horizontal beams.

PS: I haven't used \relative, because it's gross.

\version "2.20.0"

upper = {
    \clef treble
    \key c \major
    \omit\time 4/4
        \once\override DynamicText.self-alignment-X = #1.25
        <f' a'>4\mp^- 4^- 4^- <e' g'!> |
}

lower = {
    \clef bass
    \key c \major
    \omit\time 4/4      
        << 
            {
                \repeat unfold 4 {
                    \voiceOne
                    \once\override Beam.positions = #'( 4.5 . 4.5)
                        c'8[
                    \change Staff = "upper"
                    \voiceTwo
                            c']
                    \change Staff = "lower"
                } |
            } \\
            {
                <f a>4 4 4 <c g!> |
            }
        >>
}

\score {
    \new PianoStaff
        <<
            \new Staff = "upper" \upper
            \new Staff = "lower" \lower
        >>
    \layout {}
    \midi {}
}

result of above code

1
  • Using << ... >> to get chords is a valid way to do it. Basically if multiple simultaneous notes are entered at the same time they are combined into a chord under circumstances. Basically implicitely generated contexts will fuge this up if you do not have music before, as it will then implicitely create two voices. So to be secure one should do a \new Staff \new Voice ... . This feature is very useful if we have long passages of chords of fixed number of voices. For example instead of <c e> <d f> <e g> <d f> <c e> we can do << {c d e d c} {e f g f e} >>.
    – Lazy
    Commented Jan 30, 2022 at 0:14

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.