Hi all, > Hi Eric, > > I feel like this may be a job for a custom engraver…? > > My intuition says a “New_page_engraver” could be built — by people much more > Scheme-capable than I — which would “know” that a new page had started, and > set/engrave things accordingly. > > Best, > Kieren. > __________________________________________________ > > My work day may look different than your work day. Please do not feel > obligated > to read or respond to this email outside of your normal working hours.
it is technically possible to evaluate whether something is in the first system
of the page.
The problem is that this information is only available very late into the
layouting process,
that is to say:
Spacing wishes ->
Line breaking ->
Line Layout ->
Page breaking
This means that at the point you know something is on top of the page the
layout is set in
stone — of course we could technically extend Lilypond to do even another
spacing iteration
after page breaking, which is going to make things very much more complicating
(we’d be
having pure-unpure stuff extended to 3 levels of pureness).
Here you have some example code that allows to place hooks into System grob
details to
change things depending on page position and number. This way grobs can (in
'after-line-breaking)
register a call into their system that would then update things very late into
the process.
We see 3 examples:
1. Coloring depending on position on page
2. Clef only at first system of page (showcases the spacing problem)
3. Prefix page number to bar numbers
%%%
\layout {
\context {
\Score
\override System.stencil =
#(lambda (grob)
(define (numeric-and-equal? x y)
(and
(number? x) (number? y) (= x y)))
(let* ((pnr (ly:grob-property grob 'page-number))
(siblings (ly:spanner-broken-into (ly:grob-original grob)))
(siblings
(filter
(lambda (sib)
(numeric-and-equal? pnr (ly:grob-property sib 'page-number)))
siblings))
(det (ly:grob-property grob 'details))
(top-handlers (assoc-get 'top-on-page-handlers det '()))
(middle-handlers (assoc-get 'middle-on-page-handlers det '()))
(bottom-handlers (assoc-get 'bottom-on-page-handlers det '())))
(cond
((eq? grob (car siblings))
(for-each (lambda (h) (h pnr)) top-handlers))
((eq? grob (car (reverse siblings)))
(for-each (lambda (h) (h pnr)) bottom-handlers))
(else
(for-each (lambda (h) (h pnr)) middle-handlers)))))
}
}
{
\temporary\override NoteHead.after-line-breaking =
#(grob-transformer
'after-line-breaking
(lambda (grob _)
(let* ((system (ly:grob-system grob))
(det (ly:grob-property system 'details))
(top-handlers (assoc-get 'top-on-page-handlers det '()))
(middle-handlers (assoc-get 'middle-on-page-handlers det '()))
(bottom-handlers (assoc-get 'bottom-on-page-handlers det '())))
(ly:grob-set-nested-property!
system '(details top-on-page-handlers)
(cons
(lambda (pnr)
(ly:grob-set-property! grob 'color red))
top-handlers))
(ly:grob-set-nested-property!
system '(details middle-on-page-handlers)
(cons
(lambda (pnr)
(ly:grob-set-property! grob 'color green))
middle-handlers))
(ly:grob-set-nested-property!
system '(details bottom-on-page-handlers)
(cons
(lambda (pnr)
(ly:grob-set-property! grob 'color blue))
bottom-handlers)))))
c1\break
c1\break
c1\pageBreak
c1\break
c1
}
{
\temporary\override Staff.Clef.after-line-breaking =
#(grob-transformer
'after-line-breaking
(lambda (grob _)
(let* ((system (ly:grob-system grob))
(det (ly:grob-property system 'details))
(middle-handlers (assoc-get 'middle-on-page-handlers det '()))
(bottom-handlers (assoc-get 'bottom-on-page-handlers det '())))
(ly:grob-set-nested-property!
system '(details middle-on-page-handlers)
(cons
(lambda (pnr)
(ly:grob-suicide! grob))
middle-handlers))
(ly:grob-set-nested-property!
system '(details bottom-on-page-handlers)
(cons
(lambda (pnr)
(ly:grob-suicide! grob))
bottom-handlers)))))
\repeat unfold 600 c'16
}
{
\temporary\override Score.BarNumber.after-line-breaking =
#(grob-transformer
'after-line-breaking
(lambda (grob _)
(let* ((system (ly:grob-system grob))
(det (ly:grob-property system 'details))
(top-handlers (assoc-get 'top-on-page-handlers det '()))
(middle-handlers (assoc-get 'middle-on-page-handlers det '()))
(bottom-handlers (assoc-get 'bottom-on-page-handlers det '()))
(handler
(lambda (pnr)
(ly:grob-set-property!
grob
'text
(make-concat-markup
(list
(make-right-align-markup
(make-concat-markup
(list
(number->string pnr)
"/")))
(ly:grob-property grob 'text))))
(ly:grob-set-property!
grob
'stencil
(ly:unpure-call (grob-transformer 'stencil (lambda (_ orig)
orig)) grob)
))))
(ly:grob-set-nested-property!
system '(details top-on-page-handlers)
(cons
handler
top-handlers))
(ly:grob-set-nested-property!
system '(details middle-on-page-handlers)
(cons
handler
middle-handlers))
(ly:grob-set-nested-property!
system '(details bottom-on-page-handlers)
(cons
handler
bottom-handlers)))))
\repeat unfold 400 c'4
}
%%%
Cheers,
Tina
signature.asc
Description: This is a digitally signed message part.
