Thanks so much for thinking along. In the current setup that would still
require users to change their Lilypond code. Your example did give me an
idea though: if there would be something like $currentscore, the problem
of getting access to the score header would be solved...
cheers
Maurits
Op 28-03-2024 om 11:40 schreef Timothy Lanfear:
On 27/03/2024 22:03, Maurits Lamers wrote:
Hi Timothy,
Thanks so much for your answer! With $defaultheader I can indeed get
the main/global header fields in the initialize stage of the
engraver, which is already a very important step. I looked up where
$defaultheader is defined, and tried toplevel-scores and
toplevel-bookparts as well as $current-book and $current-bookpart but
these sadly do not contain any info (yet) when in the initialize step
of the score context engraver.
Your solution for the score level headers is sadly unusable for me,
as the concept of the braille conversion as a simple include only
addition doesn't allow me to require users to create variables to get
references to these score blocks. It should work without any
user-side change to the Lilypond code the user delivers.
I tried to see what the difference is between what
(ly:translator-context engraver) returns and what the value is of
your \myscore variable, and see that the first is #<Context Score>
where \myscore is #<Score>. Is there any way that I would be able to
get the value #<Score> from somewhere inside that initialize step of
the engraver?
That would allow me to use the (ly:score-header) function, and get
things that way.
The best I can come up with is this, which requires an explicit \book
and insertion of some code inside the \book.
\version "2.24.0"
Header_export =
#(lambda (context)
(make-engraver
((initialize translator)
(ly:message "Print global headers with engraver\n")
(printheader $defaultheader))))
#(define (headerfield header field)
(if (and header (module-defined? header field))
(ly:message "header field: ~a — value: ~a \n" field (module-ref
header field))))
#(define (printheader header)
(headerfield header 'opus)
(headerfield header 'title)
(headerfield header 'piece))
\layout { \context { \Score \consists \Header_export } }
\header {
title = "Title"
opus = "Op 1"
}
\book {
\score { \header { piece = "Piece 1" } { c'1 } }
\score { \header { piece = "Piece 2" } { c'1 } }
#(for-each (lambda (s) (printheader (ly:score-header s))) (reverse
(ly:book-scores $current-book)))
}