Hi all,

It would be quite nice to be able to use \fromproperty #'header:piece in
oddHeaderMarkup and evenHeaderMarkup, so that the title of the current
movement will display in the page header. Unfortunately, after investigating
the Lilypond source code, I can't see how to make that work, because it
requires the markup command knowing the top system of the current page and
what score it belongs to. That information isn't included in either the
layout or props argument to a markup function.

But! Lilypond has a table of contents feature that is able to find out what
page a particular musical moment happens on, and to print it in a markup.
I've copied and hacked that code to come up with the following very rough
snippet:

\version "2.18.2"

#(define-markup-command (curent-toc-section layout props)
  ()
  (ly:stencil-add (ly:make-stencil
   `(delay-stencil-evaluation
     ,(delay (ly:stencil-expr
              (let* ((table (ly:output-def-lookup layout 'label-page-table))
                      (curr (chain-assoc-get 'page:page-number props))
                      (prevs (filter (lambda (item) (<= curr (cdr item)))
table))
                      (winpage  (apply min (map cdr prevs)))
                      (winner (filter (lambda (item) (eq? (cdr item)
winpage)) prevs))
                      (wintext (cdr (assoc-get (caar winner) (toc-items))))
                      (winmarkup (interpret-markup layout props
                                   (car wintext)))
                     )
                 (display winner)
                 (interpret-markup layout props
                                   (car wintext))
                ))))
   )))


\paper {
  evenHeaderMarkup = \markup { \curent-toc-section " " }
  oddHeaderMarkup = \markup { \curent-toc-section " " }
}

\score {
  \new Staff {
    s1
    \pageBreak
    s1
    \tocItem "Title 1"
  }
}

\score {
  \new Staff {
    s1
    \pageBreak
    s1
    \tocItem "Title 2"
  }
}

The idea here is to put a table of contents entry at the very end of the
music for each movement score, so that the page header reflects the first
system of the page. This behavior can almost certainly be improved, so that
the snippet can coexist with an actual table of context listing movement
beginning pages. Maybe the page header should just reflect if a new movement
starts on that page.

I'd much appreciate feedback on this snippet. In particular, I don't quite
understand how the delayed evaluation part of the code works — I just copied
that from the definition of page-ref in define-markup-commands.scm. It seems
silly to define a whole new stencil when in the end it's just a plain old
markup. For page numbers, it's fine to make the stencil the same size every
time using a template, but since my snippet is for movement titles, and
might be used within text flow, it really ought to have a flexible stencil
extent. Currently, the returned stencil has null extent, since I cut out the
fixed-extent code from page-ref.



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to