lilypond-devel
[Top][All Lists]
Advanced

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

Manual bar number visibility


From: Dan Eble
Subject: Manual bar number visibility
Date: Sun, 6 Jul 2014 21:40:49 -0400

I’ve been using the following functions for a while (maybe since 2.12?) but now 
I’m trying to update to 2.18 and they’ve stopped working.  I suppose the 
problem is directly related to this warning:

    warning: cannot find property type-check for `visibleBarNumbers' 
(translation-type?).  perhaps a typing error?
    warning: skipping assignment

but I’m not sure what to do about that.  Any ideas?  \barNumber adds the 
current or next bar number to a set (visibleBarNumbers) which is later checked 
by the BarNumber break-visibility callback.  Numbers in the set are printed.

barNumber =
#(define-music-function (parser location) ()
   (let ((m (make-music 'ApplyContext)))

     (define (force-bar-number ctx)
       (let* ((barnum-table (ly:context-property ctx 'visibleBarNumbers)))

         (if (not (hash-table? barnum-table)) ; first use in this score?
             (begin
               ; create the set of visible bar numbers
               (set! barnum-table (make-hash-table 16))
               (ly:context-set-property! ctx 'visibleBarNumbers barnum-table)))

         (let* ((barnum (ly:context-property ctx 'currentBarNumber))
                (measurePos (ly:context-property ctx 'measurePosition))
                (measureLen (ly:context-property ctx 'measureLength))
                (mid-measure (and (ly:moment<? ZERO-MOMENT measurePos)
                                  (ly:moment<? measurePos measureLen))))
           (if mid-measure
               (set! barnum (1+ barnum)))

           (hash-set! barnum-table barnum #t)
           )))

     (set! (ly:music-property m 'procedure) force-bar-number)

     (context-spec-music m 'Score)))

manualBarNumbersOn =
#(define-music-function (parser location) ()
   (define (set-properties ctx)
     (let ()

       ; this special formatter is necessary for string->number to
       ; work in the visibility callback below
       (define (bar-number-formatter barnum measure-pos alt-number ctx)
         (number->string barnum))

       (define (bar-number-break-visibility-callback grob)
         (let ((barnum-table (ly:context-property ctx 'visibleBarNumbers))
               (barnum (string->number (ly:grob-property grob 'text))))
           (if (and (hash-table? barnum-table)
                    (hash-ref barnum-table barnum))
               end-of-line-invisible
               begin-of-line-visible
               )))

       (ly:context-set-property! ctx 'barNumberFormatter bar-number-formatter)
       (ly:context-pushpop-property ctx 'BarNumber 'break-visibility
                                    bar-number-break-visibility-callback)
       ))

   (context-spec-music (make-apply-context set-properties) 'Score))

Thanks,
— 
Dan




reply via email to

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