lilypond-user
[Top][All Lists]
Advanced

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

Re: More complex preprocessing with scheme


From: Jean Abou Samra
Subject: Re: More complex preprocessing with scheme
Date: Tue, 28 Sep 2021 20:17:13 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

Le 27/09/2021 à 17:05, Andrew Zah a écrit :
Hi all,

Is it possible to do something like have lilypond evaluate a Scheme file in order to do more complicated preprocessing of song files?

Ultimately I'd like to have a template and then include files like so, based on some logic:

% ...
\bookpart {
 \tocItem \markup "$SONG"
 \include "$FILE"
 % etc.
}
% ...

I know it's possible to achieve this with external tools, but I'd like to be able to simply run `lilypond` with some flags to change the output.

Thanks,
Andrew


Hi Andrew,

What you expect is not 100% clear to me.
This file structure can be achieved with
just variables, for example included1.ly
defining

  song = "LilyPond song"

and main.ly having

  \tocItem \markup \song

or any kind of Scheme code:

  \tocItem \markup #(string-upcase song)

To include a file of which the name is in
a variable, use

file = "/path/to/file.ly"

#(ly:parser-include-string
   (string-append "\\include \"" file "\""))

To read environement variables, use Guile's
getenv function.

https://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Runtime-Environment.html#Runtime-Environment

In general, you can read parameters set from the
command line with the -e option. See

https://lilypond.org/doc/v2.22/Documentation/usage/command_002dline-usage#basic-command-line-options-for-lilypond

The typical way to construct or preprocess input would
be to define a syntax function as described at

https://lilypond.org/doc/v2.22/Documentation/extending/scheme-functions

With this approach, you're not compiling a central
.ly file anymore. You define the function in
included.ly as

  myFunc =
  #(define-scheme-function (...) (...)
     ...)

and you call it in an file you want:

  \include "included.ly"
  \myFunc ...

Best,
Jean



reply via email to

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