[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: scheme function that conditionally sets several variables in \paper?
From: |
Thomas Morley |
Subject: |
Re: scheme function that conditionally sets several variables in \paper? |
Date: |
Sat, 15 Nov 2014 23:58:30 +0100 |
2014-11-09 18:36 GMT+01:00 Paul Morris <address@hidden>:
> Greetings all,
>
> Is there currently a way to get the scheme function below (a minimal
> example) to do what it's trying to do, namely return a paper block with
> several parts that are conditionally added or omitted?
>
> I have tried various combinations of # and $ for introducing the scheme
> expressions, and read about nesting \paper inside of \paper here:
> http://lilypond.1069038.n5.nabble.com/Conditionally-setting-variables-in-paper-section-td149984.html#a150005
>
> Maybe there's a way to dynamically create the paper block in scheme and
> return that? I didn't find anything on how to do that (and \displayMusic
> only works on music), so it seems this is unexplored territory at the
> frontiers of what's possible, or maybe I'm just missing something.
>
> Background: this is for my "scale vertical spacing" code in openlilylib[1]
> and it would be nice to only change the variables that need changing. It
> currently works, but by setting the whole group of paper variables, some are
> just set to the defaults rather than new/scaled values.
>
> [1]
> https://github.com/PaulMorris/openlilylib/blob/vert-scaling-refactor/notation-snippets/scale-vertical-spacing/definitions.ily
>
> Thanks,
> -Paul
>
>
> %% SNIPPET %%
> \version "2.19.13"
>
> myPaperFunction =
> #(define-scheme-function (parser location arg) (list?)
> #{
> \paper {
> $(if (assq-ref arg 'system-system)
> #{ \paper { system-system-spacing = #(assq-ref arg
> 'system-system) } #})
>
> $(if (assq-ref arg 'score-system)
> #{ \paper { score-system-spacing = #(assq-ref arg 'score-system)
> } #})
>
> $(if (assq-ref arg 'markup-system)
> #{ \paper { markup-system-spacing = #(assq-ref arg
> 'markup-system) } #})
>
> $(if (assq-ref arg 'score-markup)
> #{ \paper { score-markup-spacing = #(assq-ref arg 'score-markup)
> } #})
>
> $(if (assq-ref arg 'markup-markup)
> #{ \paper { markup-markup-spacing = #(assq-ref arg
> 'markup-markup) } #})
>
> $(if (assq-ref arg 'top-system)
> #{ \paper { top-system-spacing = #(assq-ref arg 'top-system) }
> #})
>
> $(if (assq-ref arg 'top-markup)
> #{ \paper { top-markup-spacing = #(assq-ref arg 'top-markup) }
> #})
>
> $(if (assq-ref arg 'last-bottom)
> #{ \paper { last-bottom-spacing = #(assq-ref arg 'last-bottom) }
> #})
> }
> #})
>
> \myPaperFunction
> #'((system-system . 2)
> (score-system . 1.5)
> ;; (markup-system . 2)
> ;; (score-markup . 2)
> ;; (markup-markup . 2)
> (top-system . 2)
> (top-markup . 3)
> (last-bottom . 2))
>
>
> % EXAMPLE MUSIC
> global = { \key c \major \time 4/4 }
> somenotes = \repeat unfold 48 { c8[ c] }
> chordNames = \chordmode { \global \repeat unfold 12 { c1:m } }
> melody = \relative c'' { \global \somenotes }
> verse = \lyricmode { \repeat unfold 48 { la la } }
> right = \relative c'' { \global \somenotes }
> left = \relative c' { \global \somenotes }
> \score {
> <<
> <<
> \new ChordNames \chordNames
> \new Staff { \melody }
> \addlyrics { \verse }
> >>
> \new PianoStaff <<
> \new Staff = "right" { \right }
> \new Staff = "left" { \clef bass \left }
> >>
> >>
> \layout { }
> }
Hi Paul,
maybe something at the lines of:
my-paper-settings =
#'((system-system-spacing . (padding . 10))
;(score-system-spacing . (padding . 0))
;(markup-system-spacing . (padding . 0))
;(score-markup-spacing . (padding . 0))
;(markup-markup-spacing . (padding . 0))
(top-system-spacing . (padding . 10))
;(top-markup-spacing . (padding . 0))
(ragged-last-bottom . #f)
(last-bottom-spacing . (padding . 10))
)
foo =
#(define-scheme-function (parser location lst)(list?)
(let* ((paper (ly:parser-lookup parser '$defaultpaper)))
(for-each
(lambda (x)
(ly:output-def-set-variable!
paper
(car x)
(if (pair? (cdr x))
(list (cdr x))
(cdr x))))
lst)))
\foo \my-paper-settings
% EXAMPLE MUSIC
global = { \key c \major \time 4/4 }
somenotes = \repeat unfold 48 { c8[ c] }
chordNames = \chordmode { \global \repeat unfold 12 { c1:m } }
melody = \relative c'' { \global \somenotes }
verse = \lyricmode { \repeat unfold 48 { la la } }
right = \relative c'' { \global \somenotes }
left = \relative c' { \global \somenotes }
\score {
<<
<<
\new ChordNames \chordNames
\new Staff { \melody }
\addlyrics { \verse }
>>
\new PianoStaff <<
\new Staff = "right" { \right }
\new Staff = "left" { \clef bass \left }
>>
>>
\layout { }
}
Cheers,
Harm