lilypond-user
[Top][All Lists]
Advanced

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

Re: When (in seconds) does each page begin?


From: Thomas Morley
Subject: Re: When (in seconds) does each page begin?
Date: Tue, 2 Jun 2020 12:30:31 +0200

Am Di., 2. Juni 2020 um 10:19 Uhr schrieb Valentin Villenave
<valentin@villenave.net>:
>
> On 5/30/20, Matt Wallis <m7956@acumen-it.co.uk> wrote:
> > But I'd still like to know how to find out when a page of a score begins
>
> Well, there is something to be done with the 'page-number and
> 'rank-on-page properties, as demonstrated in this regtest:
> https://git.savannah.gnu.org/cgit/lilypond.git/plain/input/regression/multi-measure-rest-reminder.ly
>
> The problem is that the page-breaking algorithm runs fairly late in
> the process, so whenever I try adding that to the aforementioned
> Grob_metadata_engraver, either ly:grob-system doesn’t return anything
> or it remains stuck on 0.  (The regtest I mentioned works around that
> in a pretty convoluted way, by creating a new grob and then suiciding
> it.)
>
> You might want to have a look; maybe your guess’s gonna be better than mine.
>
> Cheers,
> -- V.
>

I think best bet would be to post-process the final file.
We already have a post-process-hook (see Application Usage). Below I
use it to print the first BarNumber of each page. If you know the used
\tempo it should be straight forward to calculate the passed seconds.
Ofcourse any calculation of passed time fails if multiple scores are
in the file. The provided procedure is not able to distinguish.

Here the code (example _has_ multiple scores)
Output is done in terminal, output to a .log-file is possible as well,
see comment.

\version "2.19.32"

#(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))
}

%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLE
%%%%%%%%%%%%%%%%%%%%%%%

\header { title = "TITLE" }

\pageBreak

\score {
    \new Staff {
        \repeat unfold 2 {
          \time 4/4 c''1
          \time 3/4 d''2.
          \time 3/8 e''8 8 8
          \pageBreak
        }
    }
}

\markup "MARKUP"

\pageBreak

\score {
    \new Staff {
        \repeat unfold 2 {
          \time 4/4 c''1
          \time 3/4 d''2.
          \time 3/8 e''8 8 8
          \pageBreak
        }
    }
}

Cheers,
  Harm



reply via email to

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