lilypond-user
[Top][All Lists]
Advanced

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

Re: Accessing header information for use in a Scheme script


From: Thomas Morley
Subject: Re: Accessing header information for use in a Scheme script
Date: Sat, 20 Feb 2016 20:56:07 +0100

2016-02-17 23:35 GMT+01:00 Rafael Ramirez Morales
<address@hidden>:

> A couple of follow-up questions:
> Is there a cleaner approach to my second hack (for the copyright notice)?

It's not really clear to me what you want to achieve, so no proposal
currently ..

> Is there a Scheme way to set the header variables?

There is a certain problem.
$defaultheader will be #f if no \header is set before called.

See the terminal-output (in a fresh and blank file) of:

\version "2.19.36"
#(write-me "\n$defaultheader is: " $defaultheader)
\header {}

opposed to the output of (again in a fresh and blank file):

\version "2.19.36"
\header {}
#(write-me "\n$defaultheader is: " $defaultheader)

So you have to take care when you call $defaultheader...


Otoh, you can do like below, play around with it.

%% snippet-start

#(define $defaultheader (make-module))

#(module-define! $defaultheader 'composer "J.S.Bach")

#(newline)
#(pretty-print (list "test-1:" (ly:module->alist $defaultheader)))

%{
\header {
  arranger = "ARRANGER"
}

#(pretty-print (list "test-2" (ly:module->alist $defaultheader)))
%}

%{
#(module-define! $defaultheader 'subtitle "SUBTITLE")

#(pretty-print (list "test-3" (ly:module->alist $defaultheader)))
%}

%{
my-header-entries =
#'((title . "MY-TITLE")
   (subtitle . "MY-SUBTITLE")
   (dedication . "MY-DEDICATION")
   (composer . "MYSELF")
   )

#(for-each
  (lambda (e)
    (module-define! $defaultheader (car e) (cdr e)))
  my-header-entries)

#(pretty-print (list "test-4" (ly:module->alist $defaultheader)))
%}

%% some output to print
\markup \fill-line { \center-column { \draw-hline TEST } }

%% snippet-end


Though, I can't find any documentation about:
make-module, module-define! and the like.

Although, they must been defined in guile.
Try in guile:

(use-modules (ice-9 pretty-print))
(for-each
  (lambda (e)
    (pretty-print
      (cons (string-upcase (symbol->string (procedure-name e)))
            (procedure-source e))))
  (list make-module module-define!))

Regarding the output I also see even more undocumented procedures, eg.
`and-map', etc, etc.

>
> Oh, and one last thing...
> Is this code you wrote snippet worthy?
> I obviously find it most useful, but I'm personally convinced it could be of
> interest to others as well.

Nothing in it requires 2.19.-features, so no reason not to put it in the LSR.
You know, you can do it youself ;)
And I may approve it ;)

Cheers,
  Harm



reply via email to

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