-
Notifications
You must be signed in to change notification settings - Fork 10
LilyPond
Henning Hraban Ramm edited this page Jan 25, 2021
·
5 revisions
GNU LilyPond is the musical counterpart to TeX, a command-based note engraver.
A setup as own module "t-lilyfilter" can look like this:
\startmodule[lilyfilter]
\def\LILYTEMP{lilytemp} % subdirectory for LilyPond files
\def\ParseLilypondFile#1% #1 is the name of the output file
{\ctxlua{thirddata.parselilypondfile("#1")}}
\startluacode
thirddata = thirddata or {}
-- create temp folder if missing
if not lfs.isdir("\LILYTEMP") then
lfs.mkdir("\LILYTEMP")
end
function thirddata.parselilypondfile(name)
-- include all systems (pages)
-- name is like \LILYTEMP/mainfile-temp-lilypond-21.pdf
logs.report("LILYPOND","name='" .. name .. "'")
local scname = string.gsub(name, '%.pdf$', '-systems.count')
local syco = tonumber(io.loaddata(scname)) or 0
for nr = 1, syco do
logs.report("LILYPOND","including system no." .. nr)
context("\\externalfigure[" .. string.gsub(name, '%.pdf$', '-' .. nr) .. "]")
end
end
\stopluacode
\usemodule[filter]
\defineexternalfilter[lilypond]
[continue=yes,
cache=yes,
readcommand=\ParseLilypondFile,
directory=\LILYTEMP/,
output={\externalfilterbasefile.pdf},
filtercommand={lilypond -dbackend=eps -ddelete-intermediate-files -o"\LILYTEMP/\externalfilterbasefile/" "\externalfilterinputfile"},]
% More possible options of LilyPond see lily.scm
\stopmodule
Beware, this works only with ConTeXt MkIV, since it uses Lua.
It includes single note lines (systems) to leave the page breaking to ConTeXt.
Tested with LilyPond 2.16 to 2.20
See also the LilyPond page in ConTeXt wiki.