lilypond-user
[Top][All Lists]
Advanced

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

How to align a new MultiMeasureRest-stencil?


From: Thomas Morley
Subject: How to align a new MultiMeasureRest-stencil?
Date: Fri, 15 Mar 2013 21:18:39 +0100

Hi,

I'm trying to set a new MultiMeasureRest-stencil.

Therefore I read out the left- and right-bound: NonMusicalPaperColumn,
their X-coordinate and the interval-length of their grob-extent.
These values are used to do some calculations to center the new
MMR-stencil in the measure.
Intented is to do exactly the same as it is done for the original stencil.

Well, it doesn't work as expected.

The alignment of the new stencil differs, depending on changes of
key/time/clef or
if the MMR is at line-begin, line-end or in the middle of a line.
Even if the MMR is in the first or the second system makes a difference.
Setting the BarNumber-stencil #f makes a difference.

Meanwhile I tried all I could think off, without success.
Below a basic code demonstrating the problem.


\version "2.17.12"

#(define (new-centered-mmr-stencil grob)
     (let* ((sys (ly:grob-system grob))
            (X-extent (lambda (q) (ly:grob-extent q sys X)))
            (left-bound (ly:spanner-bound grob LEFT))
            (left-bound-X-length (interval-length (X-extent left-bound)))
            (left-bound-coord (ly:grob-relative-coordinate left-bound sys X))
            (right-bound (ly:spanner-bound grob RIGHT))
            (right-bound-X-length (interval-length (X-extent right-bound)))
            (right-bound-coord (ly:grob-relative-coordinate right-bound sys X))
            (new-stil
               (grob-interpret-markup grob
                 (markup "X↑X")))
            (new-stil-X-length (interval-length (ly:stencil-extent new-stil X)))

            (translate-value (- (+ (/ (- right-bound-coord left-bound-coord) 2)
                                   (/ left-bound-X-length 2))
                                (/ new-stil-X-length 2)
                                (/ right-bound-X-length 2)))
           ) ;; End of Defs in let*

   ;;(display "\n\tleftbound:\t")(write left-bound)
   ;;(display "\n\trightbound:\t")(write right-bound)
   ;;(newline)

   (ly:grob-set-property! grob 'stencil
     (ly:stencil-translate-axis
       new-stil
       translate-value
       X))))

replaceMMRStencil =
  \override MultiMeasureRest #'after-line-breaking =
     #new-centered-mmr-stencil

%------------ Test

\paper {
        %line-width = 30
        indent = 0
        short-indent = 0
        ragged-right = ##f
}

\layout {
        \context {
                \Staff
                \override TimeSignature #'stencil = ##f
        }
        \context {
                \Score
                %% uncommenting this _makes_ a difference, why?
                %\override BarNumber #'stencil = ##f
        }
}

% The appearance of the new MMR-stencil (i.e. the visible offset) differs
% in the first and second system

music =  {
        \key b\major
        \compressFullBarRests
        R1*4
        %%{
        \clef alto
        \time 8/8
        \key d\major
        %}
        \break
        R1*4
        %{
        \clef bass
        \time 2/2
        \key ees\major
        %}
}

<<
\new Staff \with {  \replaceMMRStencil } \music
\new Staff \music
>>



What am I missing?
Any hint would be great.

Regards,
  Harm



reply via email to

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