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: Wed, 17 Feb 2016 12:19:43 +0100

2016-02-17 2:19 GMT+01:00 Rafael Ramirez Morales
<address@hidden>:
> Hello,
>
> I'm trying to access the information of the values in the \header section.
>
> I would like to use these values (if defined) to generate automatically a
> markup.
>
> More specifically, given a value for the copyright in the header, I wanted
> to generate a variable with the copyright notice (in the example, define a
> copyrightUse variable with preset text.)
>
> %% BEGIN miniscript
>
> #(define license-alist '(
>                           ( "Public Domain" . "free to duplicate,
> distribute, modify, and perform" )
>                           ( "Copyright" . "All rights reserved." )
>                           )
>    )
>
> #(if (assoc 'copyright license-alist)
>      (define copyrightUse
>        (cdr (assoc copyright license-alist)))
>      (define copyrightUse "Unknown copyright status. Some or all rights
> reserved."))
>
> %% END miniscript
>
> The miniscript works so long as the 'copyright variable is manually defined
> (as a string) elsewhere. What I would like is to get the value for
> 'copyright directly from the header.
>
> I have tried many things, including the fromproperty approach and the ideas
> in the snippet in the repositories markupWithHeader... to no avail. Alas, it
> seems the header variables get wrapped up is something that I have not been
> able to unravel in order to reach the naked value.
>
> The basic idea (which I would like to apply to any header field) would be:
> 1/ test if the variable is defined in header or not.
> If not defined, maybe propose a default value.
> 2/ test if the variable is markup or not.
> If it is markup, probably leave it as-is...
> 3/ If the variable is a string, get that value and proceed to compare said
> value to, for example, a list of standard values, and then go crazy making
> derived markups or other subroutines based on this information.
>
> If anyone has a solution, idea, or a solid push in a good direction, my very
> badly banged head would greatly appreciate.

Something like below?

\version "2.19.36"

\header {
  title = \markup \italic "Titel"
}

#(define license-alist
  (let* ((defaultheader-entries (ly:module->alist $defaultheader))
         (defaults
           '("title-default"
             "instrument-default"
             "tagline-default"
             "copyright-default"
             ;; to be continued
             ))
;; if you want a subset use below
;; otherwise probably (map car defaultheader-entries)
         (entries
           '(title
             instrument
             tagline
             copyright
             ;; to be continued
             )))
  (map
    (lambda (e d)
      (cons (symbol->string e)
        (if (assoc-get e defaultheader-entries)
            (markup->string (assoc-get e defaultheader-entries))
            d)))
    entries
    defaults)))

%#(display-scheme-music license-alist)

\markup \with-color #red #(assoc-get "title" license-alist)



Cheers,
  Harm



reply via email to

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