>> Thanks a lot! However, below you can find one case (using your >> second, improved version) where it is failing: the key signature at >> the beginning of a line gets canceled, which is incorrect.. > > Ofcourse, I should have thought of this. > > I'll have a look - my holidays ended, though :(( Not sure when I'm > able to continue, probably the upcoming weekend
Attached is my solution – in very bad Scheme, I think :-) The idea is to make `supressRedundantKeySigs' set an `is-redundant' flag in the redundant grob instead of calling `ly:grob-suicide!'. A modified stencil function for KeySignature can now check this flag together with `ly:item-break-dir' to suppress the grob if necessary. I would be glad if someone could polish the code... Werner
suppressRedundantTimeSig = #(lambda (ctx) (let ((time-sig '())) `((acknowledgers (time-signature-interface . ,(lambda (engraver grob source-engraver) (set! time-sig (cons grob time-sig))))) (finalize . ,(lambda (trans) (reduce (lambda (elem prev) (if (equal? (ly:grob-property elem 'fraction) (ly:grob-property prev 'fraction)) (begin (ly:grob-suicide! elem) prev) elem)) '() (reverse time-sig)) (set! time-sig '())))))) #(set-object-property! 'is-redundant 'backend-type? boolean?) suppressRedundantKeySig = #(lambda (ctx) (let ((key-sig '())) `((acknowledgers (key-signature-interface . ,(lambda (engraver grob source-engraver) (let* ((cause (ly:grob-property grob 'cause))) (if (and (ly:stream-event? cause) (eq? (grob::name grob) 'KeySignature)) (set! key-sig (cons (list grob (cons (ly:prob-property cause 'tonic) (ly:prob-property cause 'pitch-alist))) key-sig))))))) (finalize . ,(lambda (trans) (reduce (lambda (elem prev) (if (equal? (cdr elem) (cdr prev)) (begin (ly:grob-set-property! (car elem) 'is-redundant #t) elem) elem)) '() (reverse key-sig)) (set! key-sig '())))))) \score { \relative c' { \key d \major \time 2/2 d1 | \key d \major \time 2/2 d1 \break | \key d \major \time 2/2 d1 | d1 \break | \key d \major \time 2/2 d1 | \key d \minor \time 2/2 d1 | \key d \minor \time 3/4 d2. | } \layout { \context { \Score \consists #suppressRedundantTimeSig \consists #suppressRedundantKeySig \override KeySignature.stencil = #(lambda (grob) (let* ((is-redundant? (eq? (ly:grob-property grob 'is-redundant) #t)) (at-bol? (eq? (ly:item-break-dir grob) 1))) (if is-redundant? (if at-bol? (ly:key-signature-interface::print grob) empty-stencil) (ly:key-signature-interface::print grob)))) } } } % eof
_______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user