Re: Conditionally skip an entire
Tina Petzel <[email protected]>
| Newsgroups | gmane.comp.gnu.lilypond.general |
|---|---|
| Message-ID | <[email protected]> |
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
signature.asc
(application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQS0sdUK2Lu8of48K2+FHhaCPe7BywUCaoC2YAAKCRCFHhaCPe7B y4mBAQD1CUDMBdmou6ZHP++plqDgAGmoiM7opJSbZNk8SV+i/QEA64FdyPv4oCd6 aA8Y6Ea63bTRx26OAMDWkVf2hMzB8gs= =jnmV -----END PGP SIGNATURE-----