lilypond-user
[Top][All Lists]
Advanced

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

Re: Using one identifier or another


From: Dan Eble
Subject: Re: Using one identifier or another
Date: Mon, 18 Aug 2008 03:01:45 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Johan Vromans <jvromans <at> squirrel.nl> writes:

> 
> Hi,
> 
> In a template file I want to check if a particular identifier has been
> defined, and act accordingly.

These two functions should help.  (Suggestions for improvement would be
appreciated.)  You will either need to define your optional music to be empty
when it is not required, as in this example, or provide a function to create
empty music if it is not already defined.  (It's hard to tell from your example
what your needs are.)

\version "2.11.52"

#(define-public (music-empty? m)
   (let ((void-music (ly:music-property m 'void)))
     (or (and (not (null? void-music)) void-music)
         (and (null? (ly:music-property m 'element))
              (null? (ly:music-property m 'elements))))))

ifThenElse =
#(define-music-function
   (parser location if-music then-music else-music)
   (ly:music? ly:music? ly:music?)

   (if (music-empty? if-music)
       else-music
       then-music))


aNotes = \relative c' { e1 }
bNotes = \relative c' { c1 }
cNotes = { }

\book
{
  \score
  {
    \ifThenElse \aNotes
    {
      \time 2/2
      \partcombine \aNotes \bNotes
    } {
      \time 1/1
      \bNotes
    }
  }

  \score
  {
    \ifThenElse \cNotes
    {
      \time 2/2
      \partcombine \cNotes \bNotes
    } {
      \time 1/1
      \bNotes
    }
  }
}





reply via email to

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