Changes

Jump to navigation Jump to search
6,262 bytes added ,  20:15, 22 February 2018
m
fix link of filter module
< [[Graphics]] | [[Using Graphics]] > ((Please leave this page orphaned until LilyPond integration is ready!))
[http://www.lilypond.org LilyPond] is a great music engraver, and this page is for future you can include LilyPond integration in ConTeXtsource using [https://github. At com/adityam/filter the moment you can use LilyPond's PDFs as graphics just finefilter 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 ==
* First This works with ConTeXt MkII and MkIV, but takes only the first page of multi-pages scores, and you need a working [httpmust create the folder "lilytemp" manually://www.lilypond.org LilyPond] installation plus dependencies like GhostScript.* see <cmd>setupLilyPond</cmd>
<texcode>\def\readPDFfile#1{\externalfigure[#1]} \usemodule[filter]\defineexternalfilter[lilypond] [continue=yes, readcommand= Snippets \readPDFfile, directory=lilytemp/, % directory for LilyPond's files output={\externalfilterbasefile.pdf}, filtercommand={lilypond -dbackend=eps -ddelete-intermediate-files -o"lilytemp/\externalfilterbasefile" "\externalfilterinputfile"}]</texcode> == Multi Page Filter Setup == This uses Lua and therefore only works with ConTeXt MkIV. It includes all pages of multi-page scores.It doesn’t look into the complete (multi-page) PDF, but reads a "-system.count" auxiliary file written by LilyPond that contains the number of systems (pages) and includes the single-system PDFs.
<texcode>
There are some notes \def\LILYTEMP{lilytemp} % name of folder for LilyPond/buffer files \def\ParseLilypondFile#1% #1 is the name of the output file { \relativectxlua{bes a c bthirddata.parselilypondfile("#1")} } embedded in this line \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 -o"\LILYTEMP/\externalfilterbasefile" "\externalfilterinputfile"}]
</texcode>
== Sections ==
E.g. for == LilyPond Settings == Collect your LilyPond settings in a songbook you want to place big chunks of LilyPond output (i.e. note staffs) ly file, put it in your text. It behaves lilytemp directory and include it from within your lilypond block like any other graphics, especially similar to embedded [[Metapost|MetaPost]] codethis:
<texcode>
\section{A Tune}startlilypond\include "mysettings.ly"...\stoplilypond</texcode>
You can avoid this \startLilyPondinclude 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>\relative startbuffer[lilypond::settings]\include "mysettings.ly"\stopbuffer \defineexternalfilter[lilypond][ ... bufferbefore={lilypond::settings}, ...]</texcode> === Sample Include File === "mysettings.ly" could look like this: <texcode>\repeat volta version "2 {.18.2"#(ly:set-option (quote no-point-and-click))#(set-global-staff-size 14) % --- start of setup for single-line output files ---#(define default-toplevel-book-handler \partial 4 e4 | print-book-with-defaults-as-systems ) a2 c4 d | e2 f4 e |#(define toplevel-book-handler d2 (lambda ( . c4 |rest) b4 (set! output-empty-score-list #f) (apply print-book-with-defaults rest))) #(define toplevel-music-handler (lambda ( . c8 d4 e |rest) a,2 c4 d | (apply collect-music-for-book rest))) e2 f4 e | g,2 a |#(define toplevel-score-handler \partial 2 (lambda ( . b2rest) (apply collect-scores-for-book rest))) #(define toplevel-text-handler (lambda ( . |rest) (apply collect-scores-for-book rest))) #(set! output-empty-score-list #t) % --- stop single-line setup --- \paper { }#(define dump-extents #t) indent = 0\repeat volta 2 {mm ragged-bottom = ##t ragged-last-bottom = ##t print-page-number = ##f line-width = 120\partial 4 r4 |mm oddFooterMarkup = ##f oddHeaderMarkup = ##f' g bookTitleMarkup = ##f d | e scoreTitleMarkup = ##f e c | a b c d |} \layout { #(layout-set-staff-size 14) % beware, this resets fonts! % set fonts for rm / ss / tt #(define fonts (make-pango-font-tree "TeX Gyre Schola" "LMSans10" "LMTypewriter10 Regular" (/ 14 20))) \context { \Score e2. e4 |\remove "Bar_number_engraver" f g f8 e d4 |\override PaperColumn #'keep-inside-line = ##t e f e c | } a c b8 a g4 | % some example settings \context { \Staff \override TimeSignature #'style = #'numbered } \alternative context {\ChordNames { \partial 2. g2. }chordChanges = ##t majorSevenSymbol = \markup{ \partial 2. a2. 7+ }
}
}
\stopLilyPond
There's nothing to say about this tune yet; my friend heard it from Lúnasa.
</texcode>
== Developer's Corner ==Please look up the meaning of settings in [http://lilypond.org/doc/v2.18/Documentation/web/manuals LilyPond’s great documentation]!
I If you’d like to exchange measures like text width between ConTeXt and LilyPond, you could write those into the LilyPond buffer.To give LilyPond measures to ConTeXt, you would need to figure out how write them into a temp file (using Scheme) and read that in again (useing Lua).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 can avoid that if you name your LilyPond snippets: just add <tt>[name=myfunnyname]</tt> to <cmd>startlilypond</cmd>. If you have just one LilyPond's LaTeX integration part per component (e.g. songs in a songbook), you could use <tt>lilypond[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("\LILYTEMP/texsettings.ly", "\\paper { line-bookwidth = " .. string.gsub(number.todimen(tex.dimen.textwidth),"pt","\\pt") .. " } \n") and then adapt your snippets or preamble buffer:<texcode>\include "../mysettings.ly"\include "texsettings.ly"</tttexcode> works You must comment/delete the "line-width" setting in mysettings. It is a different approachly, otherwise it doesn’t work. == Example == Here's an example of placing score snippets in the body of the text, with fonts in the score & body matching:  <texcode>\def\LILYTEMP{lilytemp} % name of folder for LilyPond preprocesses /buffer files \def\ParseLilypondFile#1% #1 is the LaTeX codename 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, replaces LilyPond code with images and runs LaTeX'%.pdf$', '-systems.count') local syco = tonumber(io. Instead with ConTeXtloaddata(scname)) or 0  for nr = 1, texexec would syco do this preprocessing step logs.report("LILYPOND","including system no." .. nr) context("\\setupfloats[location=right,frame=off]\\placefigure[none]{}{\\externalfigure[" .. string.gsub(name, '%.pdf$', '-' .. nr) .. "]}") end end\stopluacode \usemodule[filter]\defineexternalfilter[lilypond] [continue=yes, cache=yes, readcommand=\ParseLilypondFile, directory=\LILYTEMP/, avoiding the need to run different programs yourself 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\definefontfeature[main][protrusion=quality, expansion=quality]\definefontfamily[mainface][rm][Adobe Jenson Pro][features=main]\setupbodyfont[mainface,13pt]\setupalign[hz,hanging] \starttext \input zapf \startlilypond \layout{ indent=0\mm ragged-right = ##f}\paper {myStaffSize = #20 #(define fonts (make-pango-font-tree "Adobe Jenson Pro" "Myriad Pro" "Myriad Pro"I guess I can copy the needed setup (LilyPond stub file/ myStaffSize 20))) from line-width=6\in oddFooterMarkup=##f oddHeaderMarkup=##f bookTitleMarkup = ##f scoreTitleMarkup = ##f }melody = \relative c'' { \clef treble \key c \major \time 4/4  a b c d} text = \lyricmode {Aaa Bee Cee Dee} upper = \relative c'' { \clef treble \key c \major \time 2/4  a4 b c d} lower = \relative c { \clef bass \key c \major \time 2/4  a2 c} \score { << \new Voice = "mel" { \autoBeamOff \melody } \new Lyrics \lyricsto mel \text \new PianoStaff <tt< \new Staff = "upper" \upper \new Staff = "lower" \lower >> >>lilypond-book \layout { \context { \Staff \RemoveEmptyStaves } }} \stoplilypond\input tufte \stoptext</tttexcode> (a messy Python script).
I don't yet know how to prepare <cmd>setupLilyPond</cmd>. It should be able to:* set the text font (default should be ConTeXt's bodyfont instead of LilyPond's)* set line width* set staff and text size* access most other layout parameters== Too many open files ==
LilyPond uses fontconfig for font search. At With bigger projects and the above setup you might run into "too many open files" errors, at least on MacOS X it's very restricted what kind of fonts it can use in Linux, OSX and other Unix- only single-style TrueType (including dfont)like OSes. I didn't manage yet to use fonts from Ask your shell about the TeX tree. (That doesn't seem to be fontconfig's fault - open files maximum and set it writes appropriate font cache files everywhere.)higher:
To remember:* see [http://lilypond.org/doc/v2.7/Documentation/out $ ulimit -www/ LilyPond Docs]!n* How do we handle version/syntax changes of LilyPond? 256* !! How do we get clean PDFs (EPS for DVI mode), without anything around the staffs? Is lilypond $ ulimit -S -book's setup enough?n 2048
--[[User:Hraban|Hraban]] 2005-08-20== Deprecation ==
== Workarounds ==The old LilyPond module (t-lilypond) doesn't work any more with recent versions of ConTeXt, therefore we removed its documentation here.
Calling lilypond from command line in Windows fails. (Seems like a bug in lilypond.) You have to modify the module, so that lilypond is called with the whole path (<code>C:/prog/lilypond/usr/bin/lilypond</code> for example instead of <code>lilypond</code> alone).
[[Category:Modules]]
[[Category:Music]]
[[Category:Requests]]

Navigation menu