lilypond-user
[Top][All Lists]
Advanced

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

Re: #(define (bookGenerator please))


From: Thomas Morley
Subject: Re: #(define (bookGenerator please))
Date: Tue, 28 Jun 2016 01:08:47 +0200

2016-06-28 0:52 GMT+02:00 Thomas Morley <address@hidden>:
> 2016-06-27 18:56 GMT+02:00 Pierre-Luc Gauthier <address@hidden>:
>> Greetings,
>>
>> Sorry about the late follow up (about 7 months later).
>>
>> The orchestra I work with came down to a halt for the summer and I now
>> have some time to set stuff up for the next season.
>>
>> Many thanks to you Urs and David; your explanations certainly helped
>> me understand more of what was going on especially about quasi-quotes.
>>
>> Here is what I got so far.
>>
>> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>>
>> \version "2.19.44"
>>
>> \language "english"
>>
>> \header {title = "Such title."}
>>
>> scoreA = \score {\header {piece = "Piece A"} a'4}
>>
>> scoreB = \score {\header {piece = "Piece B"} b'4}
>>
>> scores = #(list scoreA scoreB)
>>
>> #(define bookGenerator
>>    (define-void-function
>>     (
>>       scoreList
>>       bookSuffix
>>       ;; header
>>       paperBlock
>>       layoutBlock
>>       )
>>     (list? string? scheme? scheme?) ;; add scheme? here
>>     (let* (
>>             (book (apply ly:make-book
>>                     paperBlock
>>                     #f ;; header
>>                     (reverse scoreList)))
>>             )
>>       (ly:book-process book paperBlock layoutBlock bookSuffix))
>>     ))
>>
>> \bookGenerator
>> \scores
>> "violinI"
>> %\header {instrument = "Violin I"}
>> \paper {}
>> \layout {}
>>
>> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>>
>> It works fine and I am pretty excited about this
>> ¡¡¡So long, 500+ lines of inflexible and unmaintainable book definitions!!!
>> Well, my problem is with the header.
>> I have not found a way to pass a header to the function ly:make-book.
>> I found #f to make the function compile... which obviously is not much
>> of a suitable header.
>>
>> How can I pass a header (and the global header) to ly:make-book?
>
>
> Below two different codings which you may find helpful
>
> (1) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> \version "2.19.44"
>
> \language "english"
>
> bookGenerator =
> #(define-void-function (scoreList bookSuffix) (list? string?)
>   (let* ((book (apply ly:make-book
>                   $defaultpaper
>                   $defaultheader
>                   (reverse scoreList))))
>     (ly:book-process book $defaultpaper $defaultlayout bookSuffix)))
>
> %%%% book-header
> %% referenced as $defaultheader
> %% needs to be defined before new settings are done
> \header { title = "Such title." }
>
> %% header-settings added via scheme:
> %% settings stored in an alist:
> my-header-entries =
> #'((subtitle . "SUBTITLE")
>    (dedication . "DEDICATION")
>    (composer . "MYSELF"))
>
> %% apply them:
> #(for-each
>   (lambda (e) (module-define! $defaultheader (car e) (cdr e)))
>   my-header-entries)
>
> %% print header-settings to terminal
> %#(pretty-print (ly:module->alist $defaultheader))
>
> %%%% book-layout
> %% referenced as $defaultlayout
> \layout {
>   \context {
>   \Staff
>   \override TimeSignature.color = #green
>   }
> }
>
> %%%% book-paper
> %% referenced as $defaultpaper
> \paper { ragged-right = ##f }
>
> %% score-definitions with scoreheader-settings
> scoreA = \score { \header { piece = "Piece A" } a'4 }
> scoreB = \score { \header { piece = "Piece B" } b'4 }
>
> scores = #(list scoreA scoreB)
>
> %% print the book:
> \bookGenerator
>   \scores
>   "violinI"
>
> (2) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> %% you can do a lot with those powerful functions, here another method
> %% `add-score` is a nice function as well
>
> \version "2.19.44"
>
> \language "english"
>
> scoreA = \score { \header { piece = "Piece A" } a'4 }
> scoreB = \score { \header { piece = "Piece B" } b'4 }
>
> \paper { ragged-right = ##f }
>
> \header { title = "Such title two." }
>
> \layout {
>   \context {
>   \Staff
>   \override TimeSignature.color = #green
>   }
> }
>
> bk = \book {}
>
> %% not really needed in this situation :
> #(ly:book-set-header! bk $defaultheader)
>
> %% you could use this in a book-generating function:
> #(for-each
>   add-score
>   (list scoreA scoreB))
>
> \bookOutputName "violinI"

or
(3) %%%%%%%%%%%%%%%%%%%%%%%%%%%


my-other-header-entries =
#'((title . "title")
   (subtitle . "subtitlw")
   (dedication . "dedication")
   (composer . "myself"))

#(define my-defaultheader (make-module))

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

bookGeneratorTwo =
#(define-void-function (scoreList custom-header bookSuffix)
  (list? module? string?)
  (let* ((book (apply ly:make-book
                  $defaultpaper
                  custom-header
                  (reverse scoreList))))
    (ly:book-process book $defaultpaper $defaultlayout bookSuffix)))

scoreA = \score { \header { piece = "Piece A-bis" } ais'4 }
scoreB = \score { \header { piece = "Piece B-bis" } bis'4 }

scores = #(list scoreA scoreB)

\bookGeneratorTwo
  \scores
  #my-defaultheader
  "violinI-bis"



A plethora of possibilities ...

Cheers,
  Harm



reply via email to

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