Changes

Jump to navigation Jump to search
1,124 bytes added ,  18:21, 25 January 2021
adapt to current working setup
< [[Graphics]] | [[Using Graphics]] >
[http://lilypond.org LilyPond] is a great music engraver, and you can include LilyPond in ConTeXt source using [[moduleshttps:t-//github.com/adityam/filter|the filter module]] with some setup.This is different from using the lilypond-book preprocessor with LaTeX. (For LaTeX there’s also a package that works similar to our ConTeXt setup here: [https://github.com/jperon/lyluatex lyluatex].)
== Simple Filter Setup ==
directory=lilytemp/, % directory for LilyPond's files
output={\externalfilterbasefile.pdf},
filtercommand={lilypond -dbackend=eps -dno-gs-load-fonts -dinclude-eps-fonts -ddelete-intermediate-files -o"lilytemp/\externalfilterbasefile" "\externalfilterinputfile"}]
</texcode>
directory=\LILYTEMP/,
output={\externalfilterbasefile.pdf},
filtercommand={lilypond -dbackend=eps -dincludeddelete-epsintermediate-fonts -dno-gs-load-fonts files -o"\LILYTEMP/\externalfilterbasefile/" "\externalfilterinputfile"},]
</texcode>
...
\stoplilypond
</texcode>
 
You can avoid this \include line following [http://modules.contextgarden.net/dl/t-filter/doc/context/third/filter/filter.txt filter module documentation], section "Prepend and append text".
In short: you can inline your complete LilyPond settings or at least the include line:
 
<texcode>
\startbuffer[lilypond::settings]
\include "mysettings.ly"
\stopbuffer
 
\defineexternalfilter[lilypond][
...
bufferbefore={lilypond::settings},
...]
</texcode>
<texcode>
\version "2.1618.02"
#(ly:set-option (quote no-point-and-click))
#(set-global-staff-size 14)
\override PaperColumn #'keep-inside-line = ##t
}
% some example settings
\context { \Staff
\override TimeSignature #'style = #'numbered
</texcode>
Please look up the meaning of settings in [http://lilypond.org/doc/v2.22/Documentation/web/manuals LilyPond’s great documentation]If you’d like to exchange measures like text width between ConTeXt and LilyPond, you could write those into the LilyPond buffer (see below).
Unfortunately it’s not possible To give LilyPond measures to exchange measures like text width between ConTeXt , you would need to write them into a temp file (using Scheme) and LilyPond read that in again (at least I’ve no idea howusing Lua), so you must define sizes manually. And For the time being this is left as an exercise to the user. ;) Unfortunately you can’t define LilyPond’s text (lyrics) size with an absolute value, but only relative to staff size...
== Named Buffers ==
Normally, your LilyPond snippets just get a running number. If you re-order your scores, each one gets re-rendered.
You might want can avoid that if you name your LilyPond snippets: just add <tt>[name=myfunnyname]</tt> to add {{cmd|startlilypond}}. If you have just one LilyPond part per component (e.g. songs in a songbook), you could use <tt>[name=\currentcomponent]</tt> . == Automatical width adaption == If you want to set your note line width automatically to your current text width, try this:  -- this goes after "create temp folder" io.savedata(or name"\LILYTEMP/texsettings.ly", "\\paper { line-width =mymusic" .. string.gsub(number.todimen(tex.dimen.textwidth) to ,"pt","\\pt") .. " } \n") and then adapt your snippets or preamble buffer:<cmdtexcode>startlilypond\include "../mysettings.ly"\include "texsettings.ly"</cmdtexcode> to avoid unnecessary re You must comment/delete the "line-renderingwidth" setting in mysettings.ly, otherwise it doesn’t work.
== Example ==
 
(TODO: This is old and might contain deprecated or non-working code. Unchecked.)
Here's an example of placing score snippets in the body of the text, with fonts in the score & body matching:
<texcode>
\unprotectdef\LILYTEMP{lilytemp} % name of folder for LilyPond/buffer files
\usemodule[filter]def\ParseLilypondFile#1% #1 is the name of the output file {\ctxlua{thirddata.parselilypondfile("#1")}}
\traceexternalfiltersstartluacode thirddata = thirddata or {}
\defineexternalfilter [lilypond] -- create temp folder if missing [\c!output=\externalfilterbasefile if not lfs.pdf, \c!filtercommand=isdir("\lilypondcommand,LILYTEMP") then lfs.mkdir("\c!continue=\v!yes, \c!readcommand=\readlilypondoutput, %\c!directory=output,LILYTEMP") ] end
% frame=on function thirddata.parselilypondfile(name) -- include all systems (pages) -- name is for testinglike \LILYTEMP/mainfile-temp-lilypond-21.pdf\def\readlilypondoutput#1{\setupfloats[location logs.report("LILYPOND","name=right,frame'" .. name .. "'") local scname =off]\placefigure[]{From \sc{http://lsrstring.dsigsub(name, '%.unimipdf$', '-systems.it/LSR/Search?qcount') local syco =piano}}{\externalfigure[#1]}}tonumber(io.loaddata(scname)) or 0
for nr = 1, syco do logs.report("LILYPOND","including system no." .. nr) context("\def\lilypondcommandsetupfloats[location=right,frame=off]\\placefigure[none]{}{\\externalfigure[" .. string.gsub(name, '% {lilypond -dbackend=eps -dno-gs-load-fonts -dinclude-eps.pdf$', '-fonts \externalfilterinputfile' .. nr) .. "]}") end end\protectstopluacode
\usemodule[filter]\defineexternalfilter[lilypond] [continue=yes, cache=yes, readcommand=\ParseLilypondFile, directory=\LILYTEMP/, output={\externalfilterbasefile.pdf}, filtercommand={lilypond -dbackend=eps -dinclude-eps-fonts -dno-gs-load-fonts -o"\LILYTEMP/\externalfilterbasefile" "\externalfilterinputfile"}]  \setuplayout[textwidth=6in] % matches line-width below\usetypescriptdefinefontfeature[main][protrusion=quality, expansion=quality]\definefontfamily[mainface][rm][Adobe Jenson Pro][palatinofeatures=main]\setupbodyfont[palatinomainface,13pt]\setupalign[hz,hanging]
\starttext
\input zapf
\startlilypond
 
\layout{
indent=0\mm
}
\paper {
myStaffSize = #20 #(define fonts (make-pango-font-tree "palatinoAdobe Jenson Pro" "palatinoMyriad Pro" "palatinoMyriad Pro" (/ myStaffSize 20))) line-width=6\in
oddFooterMarkup=##f
oddHeaderMarkup=##f
scoreTitleMarkup = ##f
}
global melody = \relative c'' { \clef treble
\key c \major
\time 4/4
 
a b c d
}
sopMusic = \relative c'' { c4 c c8[( b)] c4}sopWords text = \lyricmode { hi hi hi hiAaa Bee Cee Dee
}
altoMusic upper = \relative c'' { e4 f d e\clef treble} \key c \majoraltoWords = \lyricmode {time 2/4  ha ha ha haa4 b c d
}
tenorMusic lower = \relative c' { g4 a f g\clef bass}tenorWords = \key c \lyricmode {major hu hu hu hu}\time 2/4
bassMusic = \relative c { c4 a2 c g c}bassWords = \lyricmode { ho ho ho hø
}
\score {
<<
\new ChoirStaff << \new Lyrics = "sopranos" \new Staff = "women" << \new Voice = "sopranosmel" { \voiceOne << autoBeamOff \global \sopMusic >> melody } \new Voice = "altos" { \voiceTwo << \global \altoMusic >> } >> \new Lyrics = "altos" \new Lyrics = "tenors" \new Staff = "men" << \clef bass \new Voice = "tenors" { \voiceOne << \global \tenorMusic >> } \new Voice = "basses" { \voiceTwo << \global \bassMusic >> } >> \new Lyrics = "basses" \context Lyrics = "sopranos" \lyricsto "sopranos" \sopWords \context Lyrics = "altos" \lyricsto "altos" \altoWords \context Lyrics = "tenors" mel \lyricsto "tenors" \tenorWords \context Lyrics = "basses" \lyricsto "basses" \bassWords >>text
\new PianoStaff <<
\new Staff << \set Staff.printPartCombineTexts = ##f "upper" \partcombine << \global \sopMusic >> << \global \altoMusic >> >>upper \new Staff << \clef bass \set Staff.printPartCombineTexts = ##f "lower" \partcombine << \global \tenorMusic >> << \global \bassMusic >> >>lower
>>
>>
\layout {
\context { \Staff \RemoveEmptyStaves }
}
}
 
\stoplilypond
\input zapftufte 
\stoptext
</texcode>
== Too many open files ==
With bigger projects and the above setup you might run into "too many open files" errors, at least in older Linux, OSX and other Unix-like OSes.
Ask your shell about the open files maximum and set it higher:
$ ulimit -n
256
$ ulimit -S -n 2048 == Deprecation == The old LilyPond module (t-lilypond) doesn't work any more with recent versions of ConTeXt, therefore we removed its documentation here.
[[Category:Modules]]

Navigation menu