This package provides a way to keep Lilypond running in the background as a server. It then extends the lyp compile
command to compile user files by sending requests to the running Lilypond instance. The server can also be connected to using telnet
or from any programming language by opening a TCP port.
Because Lilypond is just too damn slow...
Install using lyp:
$ lyp install lys
To compile files using the server command, use the lyp compile
command and add the -s
or --server
option:
$ lyp compile -s myfile.ly
You can of course add any other Lilypond option you wish for, e.g.:
$ lyp compile -s --png myfile.ly
The server is started automatically. You can kill it at any time by the usual means.
The server listens on port 1225 (by default). Clients can connect and pass arbitrary scheme expressions. For example, to typeset a lilypond file, a client can send (lys:compile dir opts...)
where pwd is the current working directory and opts is a list of command line options:
(lys:compile "/home/sharon" "--png" "myfile")
Small files compile in 0.3-0.4s (on a modern laptop). Generally one can expect to shave 0.5-0.6s off compilation time.
To start a server, run the following lilypond script:
\require "lys"
% listen on port 1225 ("ly" in numbers)
#(lys:start-server)
% to specifiy the listening port:
#(lys:start-server 12321)
Or alternatively, run from the shell:
$ lilypond -r lys -e "#(lys:start-server)"
Commands can be sent to the server by piping to nc
:
$ echo "(lys:compile-file \"~\" \"myfile.ly\")" | nc localhost 1225
See also the included example client.
Usage: lyp:close
Normally, a connection to the server stays open until the client disconnects. A client connecting through nc
can ask the server to shutdown the connection by sending (lyp:close)
.
Usage: lys:compile-file pwd opt ...
Compile a lilypond file, where pwd
is the client's working directory, and opt is one or more lilypond command line options. lys:compile-file
currently handles all of lilypond's command line options except --loglevel
and --include
.
Example: (lys:compile-file "/Users/dudu" "--png" "myfile.ly")
Usage: lys:stdin-eval-loop
Start an evaluate loop on stdin. This can be used to start a long-running slave lilypond process that evaluates arbitrary scheme expressions received on stdin.
Usage: lys:spawn expr ...
Fork and evaluate a sequence of expressions in the child process. Returns the child pid.
Example: (lys:spawn (lys:compile-file "/Users/dudu" "--png" "myfile.ly"))
Usage: lys:typeset-slice music filename
Compile the given music variable into to the given output filename.
Example: (lys:typeset myMusic "my-music")
Usage: lys:typeset-slice music start-moment end-moment filename
Compile a range of the given music variable between two moments and output to the given filename. The moments are specified as lists that are converted into ly:moment.
Example: (lys:typeset-slice myMusic '(3 1) '(6 1) "music3-6")