lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Positioning layout object between staves


From: Kyle Baldwin
Subject: Re: Positioning layout object between staves
Date: Wed, 18 Jun 2025 10:52:31 -0700

Thank you both. Here is a MWE: 

%%% Begin Snippet 
\layout {
  \context {
    \StaffGroup
    \name customStaffGroup

    % Set brace to correct type
    systemStartDelimiterHierarchy = #'(SystemStartBrace a b)

    % allow commands that work in StaffGroup to work in this context
    \alias StaffGroup
  }

  % Allow score and staffgroup to accept
  \context {
    \Score
    \accepts customStaffGroup
  }
  \context {
    \StaffGroup
    \accepts customStaffGroup
  }

  \inherit-acceptability "customStaffGroup" "StaffGroup"
  \context {
    \Staff
    \name customStaffUp
    \accidentalStyle piano

    % This is for the MM rest formatting. This removes the numbers
    % by default
    \override MultiMeasureRestNumber.stencil = #point-stencil
    \override MultiMeasureRest.expand-limit = #1

    \alias Staff
  }

  \inherit-acceptability "customStaffUp" "Staff"
  \context {
    \Dynamics
    \name customStaffDynamics

    \consists Multi_measure_rest_engraver
    \override MultiMeasureRest.expand-limit = #1
    \override MultiMeasureRest.transparent = ##t
    \override MultiMeasureRestNumber.Y-offset =
    #ly:self-alignment-interface::y-aligned-on-self
    \override MultiMeasureRestNumber.self-alignment-Y = #CENTER
    \override MultiMeasureRestNumber.font-size = #2.0

    % Give dynamics a little more breathing room
    \override VerticalAxisGroup.nonstaff-relatedstaff-spacing.padding = 1.3
    \alias Dynamics
  }

  \inherit-acceptability "customStaffDynamics" "Dynamics"
  \context {
    \Staff
    \name customStaffDown
    \accidentalStyle piano

    % This is for the MM rest formatting
    \override MultiMeasureRestNumber.stencil = #point-stencil
    \override MultiMeasureRest.expand-limit = #1

    \alias Staff
  }

  \inherit-acceptability "customStaffDown" "Staff"
}

pianoLayout = \layout {
  #(layout-set-staff-size 18.5)
}

% Begin Score Output
\score {
  \new customStaffGroup <<
    \new customStaffUp = "up" \relative c'' {
      \clef treble \key a \major \time 6/8
      r8 r8 <e e'> r8 r8 <e e'> |
      r8 r8 <e e'> r8 r8 <e e'> |
      R2.*2 |
      r8 r8 <g g'> r8 r8 <g g'> |
      r8 r8 <g g'> r8 r8 <g g'> |
    }
    \new customStaffDynamics {
      s2.*2 | \compressMMRests {R2.*2} | s8 s8 s8\ff s4. | s2.
    }
    \new customStaffDown = "down" \relative c {
      \clef bass \key a \major \time 6/8
      r8 r8 <e e'> r8 r8 <e e'> |
      r8 r8 <e e'> r8 r8 <e e'> |
      R2.*2 |
      r8 r8 <g g'> r8 r8 <g g'> |
      r8 r8 <g g'> r8 r8 <g g'> |
    }
  >>
  \layout {
    \pianoLayout
  }
}

\version "2.24.4"

%% End Snippet 

I tried including the method that Knute sent that was previously submitted by 
you and got this: 

%% Begin snippet 
\layout {
  \context {
    \StaffGroup
    \name customStaffGroup

    % Set brace to correct type
    systemStartDelimiterHierarchy = #'(SystemStartBrace a b)

    % allow commands that work in StaffGroup to work in this context
    \alias StaffGroup
  }

  % Allow score and staffgroup to accept
  \context {
    \Score
    \accepts customStaffGroup
  }
  \context {
    \StaffGroup
    \accepts customStaffGroup
  }

  \inherit-acceptability "customStaffGroup" "StaffGroup"
  \context {
    \Staff
    \name customStaffUp
    \accidentalStyle piano

    % This is for the MM rest formatting. This removes the numbers
    % by default
    \override MultiMeasureRestNumber.stencil = #point-stencil
    \override MultiMeasureRest.expand-limit = #1

    \alias Staff
  }

  \inherit-acceptability "customStaffUp" "Staff"
  \context {
    \Dynamics
    \name customStaffDynamics

    \consists Multi_measure_rest_engraver
    \override MultiMeasureRest.expand-limit = #1
    \override MultiMeasureRest.transparent = ##t
    \override MultiMeasureRestNumber.Y-offset =
    #ly:self-alignment-interface::y-aligned-on-self
    \override MultiMeasureRestNumber.self-alignment-Y = #CENTER
    \override MultiMeasureRestNumber.font-size = #2.0

    % Give dynamics a little more breathing room
    \override VerticalAxisGroup.nonstaff-relatedstaff-spacing.padding = 1.3
    \alias Dynamics
  }

  \inherit-acceptability "customStaffDynamics" "Dynamics"
  \context {
    \Staff
    \name customStaffDown
    \accidentalStyle piano

    % This is for the MM rest formatting
    \override MultiMeasureRestNumber.stencil = #point-stencil
    \override MultiMeasureRest.expand-limit = #1

    \alias Staff
  }

  \inherit-acceptability "customStaffDown" "Staff"
  
  \context {
    \name PianoMMR
    \type "Engraver_group"
    \inherit-acceptability PianoMMR Dynamics
    \consists "Axis_group_engraver"
    \override VerticalAxisGroup.staff-affinity = #CENTER
    \override VerticalAxisGroup.nonstaff-relatedstaff-spacing =
      #'((basic-distance . 1) (minimum-distance . 1) (padding . 0.5) 
(stretchability . 1))
    \consists "Multi_measure_rest_engraver"
    \hide MultiMeasureRest
    \override MultiMeasureRest.Y-extent = #empty-interval
    \override MultiMeasureRestNumber.Y-offset = #-1
  }
  \context {
    \PianoStaff
    \accepts PianoMMR
    \override VerticalAxisGroup.staff-staff-spacing.padding = #14
  }
}

pianoLayout = \layout {
  #(layout-set-staff-size 18.5)
}

% Begin Score Output
\score {
  \new customStaffGroup <<
    \new customStaffUp = "up" \relative c'' {
      \clef treble \key a \major \time 6/8
      r8 r8 <e e'> r8 r8 <e e'> |
      r8 r8 <e e'> r8 r8 <e e'> |
      R2.*2 |
      r8 r8 <g g'> r8 r8 <g g'> |
      r8 r8 <g g'> r8 r8 <g g'> |
    }
    \new PianoMMR {
      s2.*2 | \compressMMRests { R2.*2 } | s8 s8 s8\ff s4. | s2.
    }
    \new customStaffDynamics {
      s2.*2 | s2.*2 | s8 s8 s8\ff s4. | s2.
    }
    \new customStaffDown = "down" \relative c {
      \clef bass \key a \major \time 6/8
      r8 r8 <e e'> r8 r8 <e e'> |
      r8 r8 <e e'> r8 r8 <e e'> |
      R2.*2 |
      r8 r8 <g g'> r8 r8 <g g'> |
      r8 r8 <g g'> r8 r8 <g g'> |
    }
  >>
  \layout {
    \pianoLayout
  }
}

\version "2.24.4"

%% End snippet 

The problem I am running into is that the notes in the upper or lower voices 
offset the middle contexts. 

-kwb 


> On Jun 17, 2025, at 5:04 PM, Kieren MacMillan <kieren@kierenmacmillan.info> 
> wrote:
> 
> Hi Kyle,
> 
> If you included an MWE, it would be a lot easier for people to try to help…
> 
> Cheers,
> Kieren.
> 
>> On Jun 17, 2025, at 7:58 PM, Kyle Baldwin <g.pit.kyle@gmail.com> wrote:
>> 
>> Hi all - 
>> 
>> I'm looking at improving my centering of MM rest numbers between staves. I 
>> have come across solutions like this: 
>> https://lists.gnu.org/archive/html/lilypond-user/2012-10/msg00293.html but 
>> the problem seems to be that it will always find the center of the Dynamics 
>> context which, if notes whatever are between the staves, un-centers the MM 
>> rest numbers. 
>> 
>> This is my current thought process. 
>> 
>> - Create an engraver that lives on the piano staff that records the position 
>> of my up and down staves and record Y pos in a context property.
>> - Set the MM rest number to transparent so that it is not recorded as taking 
>> up space
>> - Set the MM rest 'after-line-breaking' to read the context property of the 
>> parents and set the numbers centered between the bars. 
>> 
>> Does this sound feasible? Is there an easier way? I remember seeing 
>> something about looking at the gridlines for height, but not 100% sure it 
>> would work for my purposes: 
>> https://lists.gnu.org/archive/html/lilypond-user/2023-05/msg00139.html 
>> Thanks! 
>> 
>> -Kyle




reply via email to

[Prev in Thread] Current Thread [Next in Thread]