lilypond-user
[Top][All Lists]
Advanced

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

Re: if/then/else in Lilypond with config file


From: Johan Vromans
Subject: Re: if/then/else in Lilypond with config file
Date: Sun, 22 Jun 2014 15:59:47 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux)

Hartmut Leister <address@hidden> writes:

> Is there a possibility to do something like this?
>
>     if( custom_cfg_flag)
>     {
>         % default score combination
>         % (e.g. with header and chords)
>     }
>     else
>     {
>         % some other combination
>         % (e.g. only melody)
>     }

I use a technique similar to this to produce (guitar) scores with and
without capo.

An include file defined a specific symbol, or not. 

It capo is wanted, the file contains a single line:

  withCapo = 1

Otherwise, it is empty, leaving the symbol withCapo undefined.

In the code I use

  \ifDefinedThenElse #'withCapo

    { % code for the capo case
    }

    { % code for the non-capo case
    }


The definition of ifDefinedThenElse is quite simple:

  %% \ifDefinedThenElse symbol expression else-expression
  %%
  %% If the symbol is defined, returns the expression.
  %% Otherwise, returns the else-expression.

  ifDefinedThenElse =
  #(define-music-function (parser location sym music else) (symbol? ly:music? 
ly:music?)
    (if (defined? sym)
     music else))

  %% Example:
  %%
  %% \ifDefinedThen #'leadWords  \lyricsto lead \ifDefined #'leadWords

HTH,

-- Johan



reply via email to

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