lilypond-user
[Top][All Lists]
Advanced

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

Re: Alignment issues of Time signature above the staff


From: Aaron Hill
Subject: Re: Alignment issues of Time signature above the staff
Date: Thu, 16 Apr 2020 11:34:31 -0700
User-agent: Roundcube Webmail/1.4.2

On 2020-04-16 3:06 am, Chen Leo wrote:
For people who understand lilypond's internals, is it possible to
write a custom time-signature-engraver that synchronise with the
barlines and does not add extra space to other staves by just using
scheme?

Let me first clarify I have only skimmed this thread, so I cannot comment on the alignment issue at hand nor whether a custom engraver would help. Rather, I just wanted to speak to your next question:

Or does it have to be written in c++ since a lot of other
files seems to be included in the original time-signature-engraver
file?

There has been a lot of work to enable creating Scheme engravers, though not all functionality in C++ is directly exposed to Scheme. So while you might need to reimplement the logic of some helper functions, I would say most of what is done in C++ can be done in Scheme.

For instance, here is the existing Time_signature_engraver ported to Scheme:

%%%%
\version "2.20.0"

%% Ported from time-signature-engraver.cc:
#(define (Time_signature_engraver_scm context)
  (let ((time-signature #f)
        (last-time-fraction #f)
        (time-cause '()))
    (define (make-time-signature engraver)
      (let ((time-fraction
              (ly:context-property
                context
                'timeSignatureFraction)))
        (and (pair? time-fraction)
             (not (eq? time-fraction last-time-fraction))
             (begin
               (set! time-signature
                 (ly:engraver-make-grob
                   engraver
                   'TimeSignature
                   time-cause))
               (ly:grob-set-property!
                 time-signature
                 'fraction
                 time-fraction)
               (or last-time-fraction
                   (ly:grob-set-property!
                     time-signature
                     'break-visibility
                     (ly:context-property
                       context
                       'initialTimeSignatureVisibility)))
               (let ((denom (cdr time-fraction)))
                 (or (eqv? 1 (logcount denom))
                     (ly:event-warning
                       (ly:grob-property time-signature 'cause)
                       "strange time signature found: ~a/~a"
                       (car time-fraction)
                       denom)))
               (set! last-time-fraction time-fraction)))))
    (make-engraver
      (listeners
        ((time-signature-event engraver event)
         (set! time-cause event)))
      ((process-music engraver)
       (or (ly:grob? time-signature)
           (make-time-signature engraver)))
      ((stop-translation-timestep engraver)
       (and (ly:grob? time-signature)
            (ly:prob? time-cause)
            (let ((measure-position
                    (ly:context-property context 'measurePosition))
                  (partial-busy
                    (ly:context-property context 'partial-busy #f)))
              (and (ly:moment? measure-position)
                   (< 0 (ly:moment-main measure-position))
                   (not partial-busy)
                   (ly:event-warning
                     (ly:grob-property time-signature 'cause)
                     "mid-measure time signature without \\partial"))))
       (set! time-signature #f)
       (set! time-cause '())))))

%% Test:
test = #(define-music-function () ()
  (ly:expect-warning "mid-measure time signature without \\partial")
  (ly:expect-warning "strange time signature found: 3/6")
  #{ { \time 3/4 b'4 4 4
       r4 \time 5/4 b'2 2
       \time 2,3,2 7/8 \repeat unfold 7 b'8
       \compoundMeter #'((3 2 8) (1 2))
         \repeat unfold 5 b'8 b'2
       \time 3/6 R2 } #})

\new Staff \test
\new Staff \with {
  \remove "Time_signature_engraver"
  \consists \Time_signature_engraver_scm
} \test
%%%%


-- Aaron Hill



reply via email to

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