Jump to content

Cross-staff chords – beaming problems workaround: Difference between revisions

From LilyPond wiki
m Replace version="2.24.0" with version="2.24" now that the LilyWiki extension supports auto-selecting the latest release in a stable series
mNo edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
Sometimes it is better to use stems from the upper staff for creating cross-staff chords, because no problems with automatic beam collision avoidance then arise. If the stems from the lower staff were used in the following example, it would be necessary to change the automatic beam collision avoidance settings so that it doesn't detect collisions between staves using <code>\override Staff.Beam.collision-voice-only = ##t</code>
Sometimes it is better to use stems from the ‘other’ staff for creating cross-staff chords to trick LilyPond's beam collision detector. In the following snippet, if the stems from the lower staff were used instead, it would be necessary to explicitly use
 
\override Staff.Beam.collision-voice-only = ##t
 
so that LilyPond doesn't move the beams.


<lilypond version="2.24">
<lilypond version="2.24">
\new PianoStaff <<
\new PianoStaff <<
   \new Staff = up
   \new Staff = up \relative c' <<
    \relative c' {
    { r4
      <<
      \override Stem.cross-staff = ##t
        { r4
      \override Stem.length = #19 % this is in half-spaces,
          \override Stem.cross-staff = ##t
          % so it makes stems 9.5 staffspaces long
          \override Stem.length = #19 % this is in half-spaces,
      \override Stem.Y-offset = #-6 % stems are normally lengthened
              % so it makes stems 9.5 staffspaces long
          % upwards, so here we must lower the stem by the amount
          \override Stem.Y-offset = #-6 % stems are normally lengthened
          % equal to the lengthening - in this case (19 - 7) / 2
              % upwards, so here we must lower the stem by the amount
          % (7 is default stem length)
              % equal to the lengthening - in this case (19 - 7) / 2
      e e e }
              % (7 is default stem length)
    { s4
          e e e }
      \change Staff = "bottom"
        { s4
      \override NoteColumn.ignore-collision = ##t
          \change Staff = "bottom"
      c, c c
          \override NoteColumn.ignore-collision = ##t
          c, c c
        }
      >>
    }
  \new Staff = bottom
    \relative c' {
      \clef bass
      \voiceOne
      g8 a g a g a g a
     }
     }
  >>
  \new Staff = bottom \relative c' {
    \clef bass
    \voiceOne
    g8 a g a g a g a
  }
>>
>>
</lilypond>
</lilypond>


[[Category:Chords]]
[[Category:Chords]]
[[Category:Included in the official documentation]]
[[Category:Keyboards]]
[[Category:Tweaks and overrides]]
[[Category:Tweaks and overrides]]
[[Category:Chords]]
[[Category:Keyboards]]
[[Category:Workaround]]
[[Category:Workaround]]
[[Category:Included in the official documentation]]
[[Category:Snippet]]

Latest revision as of 06:01, 14 December 2025

Sometimes it is better to use stems from the ‘other’ staff for creating cross-staff chords to trick LilyPond's beam collision detector. In the following snippet, if the stems from the lower staff were used instead, it would be necessary to explicitly use

\override Staff.Beam.collision-voice-only = ##t

so that LilyPond doesn't move the beams.

\version "2.24"

\new PianoStaff <<
  \new Staff = up \relative c' <<
    { r4
      \override Stem.cross-staff = ##t
      \override Stem.length = #19 % this is in half-spaces,
          % so it makes stems 9.5 staffspaces long
      \override Stem.Y-offset = #-6 % stems are normally lengthened
          % upwards, so here we must lower the stem by the amount
          % equal to the lengthening - in this case (19 - 7) / 2
          % (7 is default stem length)
      e e e }
    { s4
      \change Staff = "bottom"
      \override NoteColumn.ignore-collision = ##t
      c, c c
    }
  >>

  \new Staff = bottom \relative c' {
    \clef bass
    \voiceOne
    g8 a g a g a g a
  }
>>