lilypond-user
[Top][All Lists]
Advanced

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

RE: Re: Small note between staves as time signature


From: juergen . gruen
Subject: RE: Re: Small note between staves as time signature
Date: Fri, 12 May 2023 08:25:04 GMT
User-agent: freenet-api2

Hello Jakob,

thank you, but I would never have figured out the use of GridLine for this purpose on my own also ;-)

I added calculation of the x-Position, so the first notehead is centered over the dots of the bass clef automatically. The parameter x-off is optional now.
You can call the music function in front of the staff definitions. In addition with the removal of the time-signature-engraver in the layout-block, everything is clearer and better readable, I think.

Juergen.

%%%%%%%%%%%%%%%%%%%%%%%%%%
\version "2.24.0"

\language "deutsch"

%% based on https://www.mail-archive.com/lilypond-user@gnu.org/msg119983.html
positionTimeSignature =
#(define-music-function (x-off arg) ((number? -0.75) markup?)
   "Create a markup from @var{arg}. Center the markup vertically between two staves.
    Horizontally aligned to the end of the clefs; can be optionally adjusted with @var{x-off}."
   #{
     \once \override Score.GridLine.stencil =
     #(lambda (grob)
        (let* (
                ; create grid-line stencil for calculations
                (stil (ly:grid-line-interface::print grob))
                (stil-y-ext (ly:stencil-extent stil Y))
                (center ( / (+ (car stil-y-ext) (cdr stil-y-ext)) 2))


                ; calculate widest x-extent of clefs relative to system
                (refp (ly:grob-system grob))
                (all-elts (ly:grob-array->list (ly:grob-object refp 'all-elements)))
                (clefs (filter (lambda (elt)
                                 (grob::has-interface elt 'clef-interface))
                               all-elts))

                (max-x (apply max (map (lambda (clef)
                                         (max (+ (ly:grob-relative-coordinate clef refp X)
                                                (car (ly:grob-property clef 'X-extent)))
                                           (+ (ly:grob-relative-coordinate clef refp X)
                                             (cdr(ly:grob-property clef 'X-extent)))))
                                    clefs)))

                ; create time-signature markup
                (note
                 (interpret-markup
                  (ly:grob-layout grob)
                  (ly:grob-alist-chain grob
                    (ly:output-def-lookup (ly:grob-layout grob) 'text-font-defaults))
                  arg))

                ; calculate offsets for translation
                (note-y-ext (ly:stencil-extent note Y))
                (height (interval-length (ly:stencil-extent note Y)))
                (calc-y (- (- center (car note-y-ext)) ( / height 2)))
                (calc-x (+ (- max-x (ly:grob-relative-coordinate grob refp X)) x-off)))

          ;return translated stencil
          (ly:stencil-translate note (cons calc-x  calc-y))))
   #})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% definiton of custom time signature as markup
sig = \markup { \teeny \line { \note {2} #1 \note {4} #UP } }

\score {
  \new PianoStaff <<
    % no need to put inside voice context
    \positionTimeSignature \sig
    \new Staff <<
      \key d \major
      \new Voice {  \voiceOne d'4 \bar "|" }
      \new Voice { \voiceTwo a4 }
    >>
    \new Staff <<
      \clef bass \key d \major
      \new Voice { \voiceOne fis4 }
      \new Voice { \voiceTwo d4 }
    >>
  >>
}

\layout {
  \context {
    \Score
    \consists "Grid_line_span_engraver"
    \override GridLine.stencil = ##f

  }
  \context {
    \Staff
    \consists "Grid_point_engraver"
    %% adjust the value if needed
    gridInterval = #(ly:make-moment 1/64)
    % remove for all staves
    \remove "Time_signature_engraver"
  }
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


reply via email to

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