lilypond-user
[Top][All Lists]
Advanced

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

Re: Detecting first and last pages of a score


From: Leah Velleman
Subject: Re: Detecting first and last pages of a score
Date: Sat, 7 Sep 2019 00:34:45 -0400

This is a very interesting approach! It wouldn't have occurred to me to handle it like this — thank you for taking the time to spell it out and code it up. I'll give it a try!

Thanks,
LV

On Fri, Sep 6, 2019 at 8:01 PM Thomas Morley <address@hidden> wrote:
Am Sa., 7. Sept. 2019 um 01:42 Uhr schrieb Thomas Morley
<address@hidden>:
>
> Am Fr., 6. Sept. 2019 um 23:55 Uhr schrieb David Kastrup <address@hidden>:
>
> > > On 06/09/19 17:00, David Kastrup wrote:
> > (short of some
> > multi-pass algorithm writing out table-of-content like information on
> > each run)
>
> David,
>
> we have a prob-property 'last-in-score, iiuc it's set far too late to
> be of any use here.
> But maybe a point to start?
>
> Leah,
>
> below a multi-pass-function as David mentioned, not exactly what you
> requested, though maybe a hint for someone to drop in...
> Likely better to go for the table-of-content, for now you need to
> mantain the first argument for `writeBookTwice´ yourself.

Found a way to avoid manually mantaing:

writeBookTwice =
#(define-void-function (book) (ly:book?)

   ;; Get all titles from score-headers
   (define headers
     (reverse
       (map
         (lambda (l) (assoc-get 'title l ""))
         (map
           (lambda (mod)
             (if (module? mod)
                 (ly:module->alist mod)
                 '()))
           (map ly:score-header (filter ly:score? (ly:book-scores book)))))))
   ;; Set the variable `page-post-process´ in the book-paper to the procedure
   ;; `scores-and-pages´
   (module-define!
     (ly:output-def-scope (ly:book-paper book))
     'page-post-process
     (lambda (layout pages)
       (scores-and-pages layout pages)))

   ;; First run of the book, in order to find the pages where new scores start
   (ly:book-process
      book
      $defaultpaper
      $defaultlayout
      (ly:parser-output-name))

   ;; clear book-paper's `page-post-process´
   (module-set!
     (ly:output-def-scope (ly:book-paper book))
     'page-post-process
     '())

   ;; Insert page-headers refering to the found pages/scores
   (ly:output-def-set-variable!
      (ly:book-paper book)
      'oddHeaderMarkup
      (myOddHeaderMarkup
       (assign-pages-header
         (ly:output-def-lookup $defaultpaper 'pages-and-scores  '())
         headers)))

   (ly:output-def-set-variable!
      (ly:book-paper book)
      'evenHeaderMarkup
      (myEvenHeaderMarkup
       (assign-pages-header
         (ly:output-def-lookup $defaultpaper 'pages-and-scores  '())
         headers)))

   ;; Rerun the book with the found values
   (ly:book-process
      book
      $defaultpaper
      $defaultlayout
      (ly:parser-output-name))

   ;; Clear `pages-and-scores´ in $defaultpaper
   (ly:output-def-set-variable!
     $defaultpaper
     'pages-and-scores
     '()))

\writeBookTwice
\book {
...
}

Cheers,
  Harm

reply via email to

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