I've been using this snippet for quite a few years now :

I'm not even sure to whom I stole that.

HTH

\version "2.25.8"

%% define the custom context-property `printMmrRange'
#(define (define-translator-property symbol type? description)
   (if (not (and (symbol? symbol)
                 (procedure? type?)
                 (string? description)))
       (ly:error "error in call of define-translator-property"))
   (if (not (equal? (object-property symbol 'translation-doc) #f))
       (ly:error (G_ "symbol ~S redefined") symbol))

   (set-object-property! symbol 'translation-type? type?)
   (set-object-property! symbol 'translation-doc description)
   symbol)

#(for-each
  (lambda (x)
    (apply define-translator-property x))
  `((printMmrRange
     ,boolean?
     "Print range of a MultiMeasureRest")))

%% define how to format `start' and `stop'
%% for `MultiMeasureRestNumber' in the engraver
%% TODO find a method to set the values for `translate-scaled'
formatMMRNumber =
#(define-scheme-function (start stop)(integer? integer?)
   #{
     \markup
     \center-column {
       #(number->string (- stop start))
       %% value found by try and error
       \translate-scaled #'(0 . -6.5)
       \with-dimensions #empty-interval #empty-interval
       \halign #CENTER
       \normal-text
       \fontsize #-2
       \line {
         \concat {
           "("
           #(number->string start)
           ".."
           #(number->string (1- stop))
           ")"
         }
       }
     }
   #})

#(define (mmr-range-engraver context)
   "Print the range of a @code{MultiMeasureRest}, if the context-property
@code{printMmrRange} is set @code{#t}."
   (let ((print-mmr-nmbr-list '())
         (mmr-bar-numbr-list '()))

     `((acknowledgers
        (multi-measure-interface
         .
         ,(lambda (engraver grob source-engraver)
            (if (eq? (grob::name grob) 'MultiMeasureRestNumber)
                (set! print-mmr-nmbr-list
                      (cons
                       (cons
                        grob
                        (ly:context-property context 'printMmrRange #f))
                       print-mmr-nmbr-list)))
            (if (eq? (grob::name grob) 'MultiMeasureRest)
                (begin
                 (set! mmr-bar-numbr-list
                       (cons
                        (cons
                         grob
                         (ly:context-property context 'currentBarNumber))
                        mmr-bar-numbr-list)))))))
       (finalize
        .
        ,(lambda (trans)
           (for-each
            (lambda (mmr mmr-nmbr)
              (let ((measure-count (ly:grob-property (car mmr) 'measure-count)))
                (if (and (cdr mmr-nmbr) (> measure-count 1))
                    (ly:grob-set-property! (car mmr-nmbr) 'text
                      (formatMMRNumber
                       (cdr mmr)
                       (+ measure-count (cdr mmr)))))))
            mmr-bar-numbr-list
            print-mmr-nmbr-list)
           (set! print-mmr-nmbr-list '())
           (set! mmr-bar-numbr-list '()))))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\layout {
  \context {
    \Voice
    \consists #mmr-range-engraver
    printMmrRange = ##t
  }
}

music = \relative c' {
  c4 d e f
}

flute = \new Staff \with {
  instrumentName = "flute"
}{
  \music
  \compressEmptyMeasures
  R1*4
  \music
  R1*13
  \music
}
oboe = \new Staff \with {
  instrumentName = "oboe"
}{
  \music
  \compressEmptyMeasures
  \repeat unfold 4 {
    \music
  }
  \music
  R1*13
  \music
}

\score {
  <<
    \flute
    \oboe
  >>
  \layout {}
}

\score {
  \flute
  \layout {}
}
\score {
  \oboe
  \layout {}
}

Le dim. 19 nov. 2023, à 23 h 15, Adam M. Griggs
<adammgri...@gmail.com> a écrit :
>
> Hello again list,
>
> Is it possible to configure the bar number engraver so that in addition to 
> its regular behaviour, whatever that may be defined as*, it will also print a 
> bar number after a multi-measure rest?
>
> Thank you.
>
>
> * I usually go with
> \set Score.barNumberVisibility = #(modulo-bar-number-visible 4 1)
> because I detest counting bars up from the start of the system.
>


-- 
Pierre-Luc Gauthier

Reply via email to