Hi Chen/Aaron,

Thank you so much (Aaron) for posting the example of the time
signature engraver. Based on that and what else I could find in the
docs I took another stab at this. It's still very much a hack, but
*hopefully* addresses most of the issues. The code is attached.

Kevin
\version "2.19.0"

#(define (Time_signature_markup_engraver context)
   (let ((time-sig '())
         (time-sig-copy #f)
         (previous-was-grace #f)) ; to avoid printing twice at grace notes
     (make-engraver
      (acknowledgers
       ((time-signature-interface engraver grob source-engraver)
        (let* ((current-moment (ly:context-current-moment context))
               (grace-nom (ly:moment-grace-numerator current-moment)))
          (if (not (eqv? 0 grace-nom))
              (begin
               (set! previous-was-grace #t)
               (set! time-sig grob))
              (if (and (eqv? 0 grace-nom) previous-was-grace)
                  (begin
                   (set! previous-was-grace #f)
                   (set! time-sig '()))
                  (set! time-sig grob))))))
      ((process-acknowledged engraver)
       (and (not (null? time-sig))
            (let* ((time-sig-copy (ly:engraver-make-grob
                                   engraver
                                   'TextScript
                                   time-sig))
                   (copy-prop (lambda (prop)
                                (ly:grob-set-property!
                                 time-sig-copy
                                 prop
                                 (ly:grob-property time-sig prop))))
                   (prop-list '(fraction style font-size)))
              (map copy-prop prop-list)
              (ly:grob-set-property! time-sig-copy 'stencil
                ly:time-signature::print)
              (ly:grob-set-parent! time-sig-copy Y time-sig)
              (ly:grob-set-parent! time-sig-copy X time-sig)
              (set! time-sig '())
              )))
      ((stop-translation-timestep engraver)
       (set! time-sig-copy #f)))))

#(define (left-align-at-end grob)
   (and (and (ly:item? grob)
             (equal? (ly:item-break-dir grob) LEFT))
        (ly:grob-set-property! grob 'self-alignment-X 1)))

timeSignatures = {
  \tempo 4 = 80
  \time 4/4 s1
  \time 3/8 s4.
  \time 3/4 s2.
  \time 4/4 s1
  \time 2/4 s2
}

\score {
  \layout {
    \context {
      \Score
      \override MetronomeMark.break-align-symbols = #'(clef time-signature)
      \remove "Bar_number_engraver"
    }
    \context {
      \Staff
      \override MultiMeasureRest.spacing-pair = #'(clef . staff-bar)
      \remove "Time_signature_engraver"
    }
    \context {
      \Score
    }
  }
  <<
    \new Dynamics \with {
      \consists "Axis_group_engraver"
      \consists "Time_signature_engraver"
      \override TimeSignature.stencil = ##f
      \override TimeSignature.font-size = #8
      \numericTimeSignature
      \consists \Time_signature_markup_engraver
      \override TextScript.before-line-breaking = #left-align-at-end
    }
    {
      \timeSignatures
    }
   
    \new StaffGroup \with {} <<
   
      \new Staff \with {
        \consists "Bar_number_engraver"
      }    
      \relative c' {
        \textLengthOn
        \time 4/4
        c4 ( _\markup \column {
          "← Objects failed to appear"
          "below the time signature"
          "when using \\textLengthOn"
        }
        \textLengthOff
        d4 e4 f4 )
        \time 3/8
        a'4 ( g8 ) 
        \time 3/4
        R2. 
        \time 4/4
        c1 
        \time 2/4
        a8 ^\markup \column {
          "← Time signature appear twice" 
          "when one staff has a grace note" 
          "as the first note in a bar"
        } g8 f8 e8
      }
   
      \new Staff \relative c' {
        \time 4/4
        R1
        \time 3/8
        R4.
        \clef bass
        \time 3/4
        a,2. \> \startTextSpan 
        \break
        \time 4/4
        c2 _\markup \column {
          "  "
          "↑"
          "Harpin stops below the time signature"
        }
        ^\markup \column {
          "TextSpanner stops below the time signature"
          "↓"
        }
        e2 \! \stopTextSpan
        \clef treble
        \time 2/4
        \acciaccatura f'8 a8 
        g8 f8 e8
      }
   
      \new Staff \relative c' { 
        \clef bass 
        \time 4/4
        R1 
        \time 3/8
        R4. 
        \time 3/4
        R2. 
        \time 4/4
        c1
        \time 2/4
        a8 g8 f8 e8
      }
    >>
  >>
}

Reply via email to