[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: arbitrary repeat counter
From: |
Simon Bailey |
Subject: |
Re: arbitrary repeat counter |
Date: |
Wed, 1 Jun 2022 14:50:21 +0100 |
Hi Jean,
thanks for that example. Is it supposed to print any numbers? It's not
doing so in 2.23.9 (windows, frescobaldi).
I've come up with a slightly different approach, that's not quite
finished (and not as fancy as creating a new engraver):
#(set-object-property! 'phrase-length 'backend-type? integer?)
#(define (counter-stencil grob)
(let* ((counter (string->number (ly:grob-property grob 'text)))
(phrase-length (ly:grob-property grob 'phrase-length)))
(if (and (eq? (modulo counter phrase-length) 1) (>= counter phrase-length))
(ly:stencil-aligned-to
(grob-interpret-markup grob
(markup (number->string (ceiling (/ counter phrase-length)))))
Y
CENTER))))
\relative c' {
\set countPercentRepeats = ##t
\override PercentRepeatCounter.phrase-length = 4
\override PercentRepeatCounter.stencil = #counter-stencil
\repeat percent 12 { c d e f }
}
I intend to wrap that in a music function that does all the override
magic and will take the music as a parameter (maybe work out the
phrase length from that, or pass it manually) and number of repeats.
Thanks, kind regards,
sb
On Wed, 1 Jun 2022 at 13:51, Jean Abou Samra <jean@abou-samra.fr> wrote:
>
> 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
>
--
Do not meddle in the affairs of trombonists, for they are subtle and
quick to anger.
- arbitrary repeat counter, Simon Bailey, 2022/06/01
- Re: arbitrary repeat counter, Jean Abou Samra, 2022/06/01
- Re: arbitrary repeat counter, Simon Bailey, 2022/06/01
- Re: arbitrary repeat counter, Simon Bailey, 2022/06/01
- Re: arbitrary repeat counter, Jean Abou Samra, 2022/06/01
- Re: arbitrary repeat counter,
Simon Bailey <=
- Re: arbitrary repeat counter, Jean Abou Samra, 2022/06/01
- Re: arbitrary repeat counter, Simon Bailey, 2022/06/01
- Re: arbitrary repeat counter, Jean Abou Samra, 2022/06/01
- Re: arbitrary repeat counter, Simon Bailey, 2022/06/01
- Re: arbitrary repeat counter, Jean Abou Samra, 2022/06/01
- Re: arbitrary repeat counter, Simon Bailey, 2022/06/01
- Re: arbitrary repeat counter, Jean Abou Samra, 2022/06/01
- Re: arbitrary repeat counter, Simon Bailey, 2022/06/01
- Re: arbitrary repeat counter, Jean Abou Samra, 2022/06/01
- Re: arbitrary repeat counter, Simon Bailey, 2022/06/04