lilypond-user
[Top][All Lists]
Advanced

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

Re: how to reference paper variables in a music function


From: Thomas Morley
Subject: Re: how to reference paper variables in a music function
Date: Thu, 29 Nov 2018 21:49:05 +0100

Am Do., 29. Nov. 2018 um 09:34 Uhr schrieb Jeff Olson <address@hidden>:
>
> I have a complex Mutopia submission that requires different formatting
> for A4 and Letter sized paper (it's too tight on the page to trust
> lilypond's spacing algorithms on the same source without paper specific
> tweaks).
>
> So I'd like to define a music function (see "ifLetter" below) that can
> sense the paper choice and select either of two music definitions
> accordingly.
>
> In the demo below, I'd like to switch output between music-one (one
> system) and music-two (two systems) depending upon which paper size is
> set.  But I'm just guessing about how to reference the documented
> variable "paper-width" to compare to the value 8.5\in.  In the attempt
> below, the condition always evaluates to ##f and produces two systems on
> letter size paper (I want music-one for letter paper).
>
> I'd prefer testing a variable whose value was "letter" (rather than 8.5
> inches) but I couldn't find such a variable documented (paper-size?,
> default-paper-size?).
>
> I've seen ly:output-def-lookup, but that requires a props or layout that
> is not obvious how to access within a music function.
>
> The code below produces the expected results when the condition (eqv?
> 'paper:paper-width (* 8.5 25.4))is rewritten as(eqv? 1 1) or (eqv? 1 2).
>
> BTW, documented spacing examples suggest that the construct (* 8.5 in)
> should be effective in scheme, but I get a compile error indicating that
> "in" is unbound, so I've written in 25.4 as a literal.
>
> BTW2, I've similarly been unable to access the paper variable page-count
> within a music function.
>
> Thx,
> Jeff
> --
> \version "2.18.2"
>
> \paper{
>    page-count = #1
>    %#(set-paper-size "a4")      %uncomment to test specific paper size
>    #(set-paper-size "letter")  %uncomment to test specific paper size
> }
>
> music-one = { a b c d e f g }
> music-two = { a b c d \break e f g }
>
> ifLetter =
> #(define-music-function (parser location musL musE) (ly:music? ly:music?)
>     (if (eqv? 'paper:paper-width (* 8.5 25.4)) musL musE )
>     )
>
> \score { \ifLetter \music-one \music-two }

There are several paper-variables, ofcourse accessible _in_ \paper:

%% to have access to 'pretty-print' it's not part of \paper but
present in ly-files
#(define pretty-print pretty-print)

\paper {
   page-count = #1
   #(set-paper-size "letter")
   #(pretty-print
      (list
        in
        page-count
        paper-width
        papersizename))
}

=> (25.4 1 215.9 "letter")

Looking from elsewhere you need to go for (ly:output-def-lookup
$defaultpaper ...):

#(pretty-print
  (list
    (ly:output-def-lookup $defaultpaper 'in)
    (ly:output-def-lookup $defaultpaper 'page-count)
    (ly:output-def-lookup $defaultpaper 'paper-width)
    (ly:output-def-lookup $defaultpaper 'papersizename)))

=> (25.4 () 210.0 "a4")

So your function could be:

\paper {
   page-count = #1
   #(set-paper-size "letter")
}

music-one = { a^"one" b c d e f g }
music-two = { a^"two" b c d \break e f g }

ifLetter =
#(define-music-function (parser location musL musE) (ly:music? ly:music?)
    (if (equal? (ly:output-def-lookup $defaultpaper 'papersizename) "letter")
        musL musE))

\score { \ifLetter \music-one \music-two }


Cheers,
  Harm



reply via email to

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