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: Rafael Ramirez Morales
Subject: Re: Accessing header information for use in a Scheme script
Date: Wed, 17 Feb 2016 23:35:17 +0100

YES. Exactly like that! Thank you.

That solves point 1/ & 2/, and with some minor tweaks, I can hack a solution for point 3.

%% BEGIN workcase
#(define header-alist
  (let* ((defaultheader-entries (ly:module->alist $defaultheader))
         (defaults
           '("title-default"
             "instrument-default"
             "tagline-default"
             "Copyright unknown"
             ;; 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)))

#(define use-alist '(
                      ( "Public Domain" . "Free to duplicate, distribute, modify, and perform." ) 
                      ( "Copyright" . "All rights reserved." )
                      )
   )


#(define copyright (assoc-get "copyright" header-alist))
#(if (assoc copyright use-alist)
     (define copyrightUse
       (cdr (assoc copyright use-alist))
       )
     (define copyrightUse "Copyright status not defined. Some or all rights might be reserved.")
     )

\header {
  title="My own title" % Comment out to see the magic ;)
  copyright = "Public Domain" % Comment out or change to "Copyright" to see the magic ;)
}

\markup \with-color #red #(assoc-get "title" header-alist)
\markup \with-color #red #(assoc-get "copyright" header-alist)
\markup \with-color #red #copyrightUse

\header {
  title = #(assoc-get "title" header-alist)
  copyright = #(markup (#:concat (copyright "—" copyrightUse)))
}
%% END workcase

GREAT! It works!

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

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.

On 17 February 2016 at 12:19, Thomas Morley <address@hidden> wrote:
#(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)




--
We are (...) star stuff contemplating the stars (...) We are one species. We are star stuff harvesting star light.
-- Carl Sagan

reply via email to

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