Difference between revisions of "LilyPond"

From Wiki
Jump to navigation Jump to search
m (→‎Setup: the fact that it doesn't work with ruby is not true any more)
m (→‎Developer's Corner: some unimportant cosmetics)
Line 144: Line 144:
 
== Developer's Corner ==
 
== Developer's Corner ==
  
For information how the integration works, please check the module code and its pdf version (both available from [http://modules.contextgarden.net/t-lilypond]).  Unlike lilypond-book for LaTeX, the module does not use a precompiling step and thus can react to local width changes and the like, even if the lilypond code is stored in a buffer.
+
For information how the integration works, please check the module code and its pdf version (both available from [[modules:t-lilypond|LilyPond on Modules]]).  Unlike lilypond-book for LaTeX, the module does not use a precompiling step and thus can react to local width changes and the like, even if the lilypond code is stored in a buffer.
  
 
Things that have not been implemented yet include:
 
Things that have not been implemented yet include:

Revision as of 20:49, 26 August 2007

< Graphics | Using Graphics >

LilyPond is a great music engraver, and you can include LilyPond in ConTeXt source using the lilypond module.

Setup

  • First you need a working LilyPond installation (version 2.8+) plus dependencies like GhostScript.
  • Include the lilypond module
\usemodule[lilypond]
  • If you want, you can change the default settings using \setuplilypond
  • If you need lyrics with accented characters (e.g. umlauts), you must typeset in UTF-8 encoding (see Encodings_and_Regimes), because LilyPond doesn't understand anything else. And you need to use UTF-8 without BOM (byte order marker), because ConTeXt doesn't understand that.

options

option values default meaning
staffsize number (pt) 20 height of the staff
time yes/no yes count the time (i.e. show time signature, draw bars, split the staff)?
clef yes/no yes show the clef?
align yes/no depends on fragment ragged-right = (not align)
fragment yes/no no typeset only a snippet (instead of a whole line)?
barnumbers yes/no no show measure numbers?
seriffont "name" "Century Schoolbook L" serif font (e.g. for Lyrics and \markup)
sansfont "name" "LMSans10" sans serif font (e.g. for chords)
monofont "name" "Bitstream Vera Sans Mono" monospace font (normally not used)

Snippets

There are some notes \lilypond{ \relative{bes a c b} } embedded in this line.

Sections

E.g. for a songbook you want to place big chunks of LilyPond output (i.e. note staffs) in your text. It behaves like any other graphics, especially similar to embedded MetaPost code:

\section{A Tune}

\startlilypond
\relative {
	\repeat volta 2 {
		\partial 4 e4 |
		a2 c4 d |
		e2 f4 e |
		d2. c4 |
		b4. c8 d4 e |
		a,2 c4 d |
		e2 f4 e |
		g,2 a |
		\partial 2. b2. |
	}
	\repeat volta 2 {
		\partial 4 r4 |
		f' g f d |
		e f e c |
		a b c d |
		e2. e4 |
		f g f8 e d4 |
		e f e c |
		a c b8 a g4 |
	}
	\alternative {
		{ \partial 2. g2. }
		{ \partial 2. a2. }
	}
}
\stoplilypond

There's nothing to say about this tune yet; my friend heard it from Lúnasa.
\section{Starlight (round)}

\startlilypond
<<
\context Staff = onlyone <<
	\clef treble
	\key a \major
	\time 6/8
	\context Voice = one {
		\relative c'' {
			a4.^\markup{1.} e' |
			e8( d cis) b4. |
			e4.^\markup{2.} d4 d8 |
			cis( b) a b4 e,8 |
			a4 a8 gis( a) b |
			cis4 cis8 b( cis d) |
			cis( d) e e4 e,8 |
			fis4 fis8 gis4.
		}
	}
>>
\lyricsto one \new Lyrics {
	\lyricmode {
		Star -- light, star -- bright,
		first star I see to -- night;
		I wish I may, I wish I might
		have the wish I wish to -- night.
	}
}
>>

\stoplilypond

Font hints

LilyPond depends on the fonts that pango/fontconfig can find. But not even all of those will work, e.g. no fonts from the TeX tree (don't know why), only one face per font file etc. Therefore it doesn't use ConTeXt's font setup.

If you want to know which fonts of your system LilyPond can see with which names, try

lilypond -dshow-available-fonts any

(The 3rd parameter is necessary, but can be anything.)

LilyPond's default text font is Century Schoolbook. You can use it in ConTeXt like this:

\starttypescript[wiki][songbook]
\usetypescript [serif] [schoolbook] [\defaultencoding]
\definetypeface	[songbook] [rm] [serif] [schoolbook] [default] [encoding=\defaultencoding]
\definetypeface [songbook] [ss] [sans]  [default][default] [encoding=ec]
\definetypeface [songbook] [tt] [mono]  [default][default] [encoding=ec]
\stoptypescript

\usetypescript [wiki] [songbook]
\setupbodyfont[songbook, rm, 8.5pt]


Developer's Corner

For information how the integration works, please check the module code and its pdf version (both available from LilyPond on Modules). Unlike lilypond-book for LaTeX, the module does not use a precompiling step and thus can react to local width changes and the like, even if the lilypond code is stored in a buffer.

Things that have not been implemented yet include:

  • make lilypond call back on ConTeXt for included TeX (cf. [1])
  • get information from lilypond about the baseline, for run-in music fragments
  • tell lilypond how much space is left on the first page
  • check and probably work on proper multi-page music

To remember:

  • see LilyPond Docs!
  • How do we handle version/syntax changes of LilyPond?

--Christopher Creutzig after ideas by Hraban

Older Workarounds

Beware: These relate to the old version of the module and older versions of LilyPond (earlier than 2.7)! Nowadays, LilyPond and epstopdf get called via texmfstart, that works without patching!

LilyPond is not found

Calling lilypond from command line in Windows fails. (Seems like a bug in lilypond.)

You have two options:

  • modify the module, so that lilypond is called with the whole path (C:/prog/lilypond/usr/bin/lilypond for example instead of lilypond alone).
  • place a lilypond.bat somewhere in your search path, calling
c:/prog/lilypond/usr/bin/lilypond %1 %2 %3 %4 %5 %6 %7 %8 %9

Calling lilypond from ConTeXt via shell exit (write18) in MacOS X also fails, even if the shell's path is right. (Seems more like write18 wouldn't use the environment.) Modify the module (try which lilypond to get its path).

LilyPond 2.7.26 comes without a command line "version", at least in the MacOS X edition, i.e. the lilypond.sh script is missing. Here's it's relevant content:

#!/bin/sh
## where was the app installed?
INSTALLDIR=/Applications

if [ "$1" == "--print-appdir" ]; then
  echo "$INSTALLDIR/LilyPond.app/"
  exit 0
fi

# where to put the output
export LILYPOND_DESTDIR=pwd

# run the program
python "$INSTALLDIR/LilyPond.app/Contents/Resources/lilycall.py" \
  "$INSTALLDIR/LilyPond.app/" $@

Save this as lilypond.sh, make it executable and symlink it into a directory on your path, e.g.

chmod a+x lilypond.sh
sudo ln -s lilypond.sh /usr/local/bin/lilypond

LilyPond stops with an 'Unbound variable' error

The LilyPond module as of 2005-09-12 uses some commands in its header that work only with LilyPond 2.6 (at least no more with 2.7.25); replace "ly:parser-print-score" with "print-score-with-defaults" and "ly:music-scorify" with "scorify-music" for LilyPond 2.7 series.