Re: lilypond-user Digest, Vol 285, Issue 30

Roman Stawski <[email protected]>
Newsgroups gmane.comp.gnu.lilypond.general
Message-ID <[email protected]>
Hi Tina

Many thanks for these examples. They were exactly what I was looking 
for. (I'd tried something similar but got hung up over passing an entire 
score to a scheme function -- together with some inept coding errors on 
my part).

Keep up the good work !

Best regards

Roman

> Message: 1
> Date: Sat, 15 Aug 2026 20:56:32 +0200
> From: Tina Petzel <[email protected]>
> To: [email protected]
> Subject: Re: Conditionally skip an entire
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset="utf-8"
>
> Hello Roman,
>
>> Hi folks
>>
>> I have a number of lilypond file which each contain several scores, call
>> the scores A, B and C.
>>
>> Depending on a variable set when invoking lilypond I need to generate
>> results which don't necessarily  contain the same scores. For instance a
>> singer might only need A and B, But an instrumentalist might need A, B
>> and C.
>>
>> Is there any way to write a condition at the top level of a lilypond
>> file (the same level as a header or a score block) to conditionally skip
>> or process an entire score.
> Absolutely. Indeed there are multiple ways to achieve this. You could simply
> wrap the scores in a `$(if ... #{ \score { ... } #})`. You can also define a
> nice function like this:
>
> %%%
> featureSet = A,B,D
>
> conditionalScore =
> #(define-scheme-function (tag score) (symbol? ly:score?)
>     (if (member tag featureSet) score))
>
> \conditionalScore A \score {
>    c'
> }
>
> \conditionalScore B \score {
>    d'
> }
>
> \conditionalScore C \score {
>    e'
> }
>
> \conditionalScore D \score {
>    f'
> }
> %%%
>
> This is just one way to do this of course, and there are many more ways to do
> this. You could also e.g. store scores in an alist and have a function that
> prints a selection of these (which would allow you to create multiple sets from
> a single file):
>
> %%%
> scores.A = \score {
>    c'
> }
>
> scores.B = \score {
>    d'
> }
>
> scores.C = \score {
>    e'
> }
>
> scores.D = \score {
>    f'
> }
>
> scoreSet =
> #(define-void-function (set) (symbol-list?)
>     (for-each
>      (lambda (sym)
>        (add-score (assoc-get sym scores)))
>      set))
>
> \book {
>    \scoreSet A,B,C,D
> }
>
> \book {
>    \scoreSet A,C,D
> }
> %%%
>
> This is particularly nice if you want to split your scores into multiple files.
> And still there are still many more ways to achieve this goal.
>
> Cheers,
> Tina
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.