"John Schlomann" <jschlom...@wideopenwest.com> writes:

> David Kastrup [mailto:d...@gnu.org] wrote:
>> 
>> Carl Sorensen <c_soren...@byu.edu> writes:
>> 
>> > From: John Schlomann <jschlom...@wideopenwest.com>
>> > Date: Friday, December 1, 2017 at 1:02 PM
>> > To: <lilypond-user@gnu.org>
>> > Subject: Problem with conditionals in layout
>> >
>> > I’m have a problem including conditionals in a \layout block. The
>> > following code results in error, “syntax error, unexpected
>> > OUTPUT_DEF_IDENTIFIER”.
>> >
>> > The problem is that you are nesting layout blocks with this code,
>> > which is not allowed.
>> 
>> The problem rather is that the layout blocks are defined by copying
>> $defaultlayout at the time he makes his definitions.  It would make
>> more sense to define this kind of stuff with define-scheme-function,
>> like
>> 
>> > According to the Notation Reference 4.2.1 you can have multiple
>> > layout blocks as top-level expressions, and they will all apply.
>> > So move your variables \conditional* above the \score{} block:
>> >
>> >
>> > \version "2.18.2"
>> >
>> >
>> >
>> > #(define conditionalTimeSignature
>> >
>> >   (if #t
>> >
>> >    #{
>> >
>> >      \layout { \context { \Staff \remove "Time_signature_engraver" } }
>> >
>> >    #}
>> >
>> >   )
>> >
>> > )
>> 
>> conditionalTimeSignature =
>> (define-scheme-function (layout location) ()
>>   (if #t
>>     #{ \layout \context { \Staff \remove "Time_signature_engraver" } #}))
>> 
>> Though it probably can be called at top level only in some 2.19 version.  At
>> any rate, calling \layout { ... } will derive from the current layout 
>> definition, so
>> if you use that, you have to store it in some kind of function in order to 
>> have
>> it executed only at the time of use.

Actually, the above does not help with 2.19 either when placed in
another \layout definition since it would imply multiple output
definitions.  The following works (I think I got the first version where
it does):

\version "2.19.2" 

conditionalTimeSignature =
#(define-scheme-function (parser location) ()
  (if #t
   #{
     \context { \Staff \remove "Time_signature_engraver" }
   #}))

conditionalBarNumbers =
#(define-scheme-function (parser location) ()
  (if #t
    #{
      \context { \Score \remove "Bar_number_engraver" }
    #}))

 

\score {
  { c' e' g' c'' }
  \layout {
    \conditionalTimeSignature
    \conditionalBarNumbers
  }
}


This uses a _context_ definition rather than a layout (output)
definition.  An easier technique would be

\version "2.18.2" 

conditionalTimeSignature =
#(if #t
   #{
     \with { \remove "Time_signature_engraver" }
   #}
   #{ \with { } #})

conditionalBarNumbers =
#(if #t
    #{
      \with { \remove "Bar_number_engraver" }
    #}
    #{ \with { } #})

\score {
  { c' e' g' c'' }
  \layout {
    \context { \Score \with \conditionalTimeSignature }
    \context { \Staff \with \conditionalBarNumbers }
  }
}


But it is a bit more cumbersome to use.

-- 
David Kastrup

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to