lilypond-user
[Top][All Lists]
Advanced

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

Re: arbitrary repeat counter


From: Jean Abou Samra
Subject: Re: arbitrary repeat counter
Date: Wed, 1 Jun 2022 14:51:29 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1

Le 01/06/2022 à 12:25, Simon Bailey a écrit :
Hi,

with a little bit of digging through your manual, i have solved some
of my questions:

#(define (counter-stencil grob)
    (let* ((counter (ly:grob-property grob 'text)))  ; get the value of
the counter
      (ly:stencil-aligned-to
        (grob-interpret-markup grob
          (markup counter "!")) ; print the counter back with !
        Y
        CENTER)))

This basically replicates the behaviour of the regular percent counter
and adds an exclamation mark. so now i can just add some if/mod/div
magic and it should do what I want. Getting there… ;)



Well, you have two possible approaches. The one you sketch above is
the backend approach: override the measure counter's alignment so
it aligns within the first measure rather than the whole span.
The other is the translation approach: arrange to create the
counter so that it has the right bound you want from the start.
I think that is simpler in this case, so I'd do something like

\version "2.22.2"

newRepeatMarker = #(make-music 'MeasureCounterEvent 'mark-new-repeat #t)

repeatCounting =
#(define-music-function (n music) (index? ly:music?)
   #{
     \startMeasureCount
     \repeat unfold #n { \newRepeatMarker #music }
   #})

#(define (My_counter_engraver context)
   (let ((count 1)
         (count-here #f)
         (spanner #f)
         (spanner-to-end #f))
     (make-engraver
      (listeners
       ((measure-counter-event engraver event)
        (cond
         ((eqv? LEFT (ly:event-property event 'span-direction))
          (set! count 1))
         ((ly:event-property event 'mark-new-repeat #f)
          (set! count-here #t)))))
      ((process-music engraver)
       (if count-here
           (let ((col (ly:context-property context 'currentCommandColumn)))
             (set! spanner (ly:engraver-make-grob engraver 'MeasureCounter '()))
             (ly:spanner-set-bound! spanner LEFT col)
             (ly:grob-set-property! spanner 'count-from count)
             (set! count (1+ count)))))
      (acknowledgers
       ((bar-line-interface engraver grob source-engraver)
        (if spanner-to-end
            (let ((col (ly:context-property context 'currentCommandColumn)))
             (ly:spanner-set-bound! spanner-to-end RIGHT col)
             (ly:engraver-announce-end-grob engraver spanner-to-end '())
             (set! spanner-to-end #f)))))
      ((stop-translation-timestep engraver)
       (if spanner
           (set! spanner-to-end spanner))
       (set! spanner #f)
       (set! count-here #f)))))

\layout {
  \context {
    \Staff
    \consists #My_counter_engraver
  }
}

\new Staff \relative c' {
  \repeatCounting 4 { c4. 8 r4 8 r | d4. 4. 4 | 1 }
}


Best,
Jean




reply via email to

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