[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: intercepting implicit/explicit page breaks
From: |
Thomas Morley |
Subject: |
Re: intercepting implicit/explicit page breaks |
Date: |
Sun, 4 Sep 2016 17:07:32 +0200 |
2016-09-04 16:31 GMT+02:00 Knut Petersen <address@hidden>:
> Hi everybody!
>
> I use
>
> #(define (display-breaks grob)
> (if (and (grob::has-interface grob 'paper-column-interface)
> (eq? #t (ly:grob-property grob 'non-musical)))
> (if (eq? 1 (ly:item-break-dir grob))
> (let* ((moment (ly:grob-property grob 'when))(m moment)
> (bar (ly:grob-property grob 'rhythmic-location))(b (car
> bar)))
> (format out "~a new system at bar ~a~%" (format-moment m)
> b)
> ))
> (ly:message "Need NonMusicalPaperColumn grob to determine line
> breaks.")))
>
> activated by
>
> \override NonMusicalPaperColumn #'after-line-breaking = #display-breaks
>
> That reliably gives the moment and bar number of an implicit or explicit
> break,
> but I also need to know if this break is a PAGE break.
>
> I assume the information is not available at the time of the callback used
> above, but
> that isn't a problem as it would be used by a script after lilypond has
> finished.
>
> Any idea where/when to get that information from lilypond?
>
> thx,
> Knut
>
I once made:
#(define* (print-pages-first-bar-numbers layout pages #:optional print-to-file)
;; If `print-to-file' is set #t the output is written to a file
;; otherwise usually displayed in Terminal
(let* ((lines (map (lambda (page) (ly:prob-property page 'lines)) pages))
;; list of systems of each pages
(sys
(map
(lambda (line)
(append-map
(lambda (l)
(let ((system-grob (ly:prob-property l 'system-grob)))
(if (not (null? system-grob))
(list system-grob)
system-grob))
)
line))
lines))
;; list of rhythmic-locations of first sys
;; returning a BarNumber and a moment, the moment is usually zero
(sys-rhythmic-location
(map
(lambda (s)
(if (and (not (null? s)) (ly:grob? (car s)))
(grob::rhythmic-location (car s))
#f))
sys))
(start-bar-numbers
(map
(lambda (r-l)
(if (pair? r-l)
(car r-l)
#f))
sys-rhythmic-location))
(formatted-output
(map
(lambda (page b-nr)
(if b-nr
(format #f "page ~a starts with BarNumber ~a\n" page b-nr)
(format #f "page ~a contains no music\n" page))
)
(iota (length pages) 1 1)
start-bar-numbers)))
(if (not (null? start-bar-numbers))
(if print-to-file
(let* ((output-name (ly:parser-output-name))
(outfilename (format "~a-page-first-bars.log" output-name))
(outfile (open-output-file outfilename)))
(if (output-port? outfile)
(begin
(format #t "\n\tprinting to ~a" outfilename)
(for-each
(lambda (i) (display i outfile))
formatted-output))
(ly:warning
(_ "Unable to open output file ~a to print the information")
outfilename))
(close-output-port outfile))
(for-each display formatted-output)))))
\paper {
#(define (page-post-process layout pages)
(print-pages-first-bar-numbers layout pages #f))
}
{ c''1 \break d'' \pageBreak e'' }
Intended was to get the first BarNumber of every page, you may extend
it to get BarNumbers at line-break.
If you don't need to rely on the info of your initial code in order to
base some other action on it, post-processing sounds preferable to me.
Cheers,
Harm