2013-05-09

Hallelujah -- Adventures in LilyPond 2: Fundamentals

The following are some of the issues that came up when putting ``Hallelujah'' together (and are fairly typical for writing music with LilyPond).


Paper size, margins and number of pages

Like many choirs, we use A4 paper copied with recto pages on the left and verso pages on the right (i.e. the inner margin becomes the outer), so we can read two-paged music from a two-page spread.  A4 size is standard in LilyPond, so I don't have to set that.  Setting the margins is easy using a \paper block:

\paper {
    two-sided = ##t
    inner-margin = 10 \mm
    outer-margin = 20 \mm
}

 

If the music spans over a single page or more than two pages, the following is more generally useful (even if it leaves only a barely wide enough margin for the holes, and a slightly too big margin on the opposite paper edge):

\paper {
    left-margin = 15 \mm
    right-margin = 15 \mm
}


With these settings, ``Hallelujah'' becomes a little over two pages in length, but by reducing the music size a bit it will fit on two pages.  It's a little bit confusing (to me, at least) how this actually is supposed to be specified, but I've found that setting fontSize in a global or \score-local \layout block will do the job (the notes and symbols are glyphs in a font, not graphical objects per se).

\layout {
    \set fontSize = #-2
}


(The ``tiny'' font (-2) is a fairly small font, but still readable.  I wouldn't select any smaller number.)

Note the inconsistency in syntax (\set vs no \set): LilyPond sometimes can't quite make up its mind about syntax.  It's still better than Visual Basic :)

Keeping score


LilyPond is very relaxed about input format.  Simply writing


\relative c' { c d e f g }

\addlyrics { Foo bar baz qux blarg }
 


will give you the music

But if you want to get anything done, you'll want to be as strict and structured as you can and write the notes ``top-down'', i.e. start with a score and add distinct parts of content to it.  The basic template for a SAB arrangement, with chords and with the sopranos and the altos singing the same lyrics, is as follows (a more complete and generic SATB template can be found in the LilyPond documentation here):

\score {
    \new ChoirStaff <<
        \new ChordNames { \theChords }
        \new Staff = "women" <<
            \new Voice = "sopranos" {
                \voiceOne << \sopMusic >>
            }
            \new Voice = "altos" {
                \voiceTwo << \altoMusic >>
            }
        >>
        \new Lyrics = "altos"
        \new Staff = "men" <<
            \clef bass
            \new Voice = "basses" {
                \voiceTwo << \bassMusic >>
            }
        >>
        \new Lyrics = "basses"
        \context Lyrics = "altos" \lyricsto "altos" \sopaltWords
        \context Lyrics = "basses" \lyricsto "basses" \bassWords
    >>
}


Basically, the parts enclosed by << ... >> happen in parallel, while the parts enclosed in { ... } happen in sequence.  The template defines a score as having a choir staff with a line for chord names, a staff with two voices (stems going in different directions) a line for lyrics, another staff with a single voice, and finally another line for lyrics.  This aggregate will automatically be broken up into and repeated over as many systems as are needed.

In this score, \theChords, \sopMusic, \altoMusic, \bassMusic, \sopaltWords, and \bassWords are references to things (notes, lyrics etc) defined elsewhere.

To be continued.

Edit: took out references to \global.  They will reappear in the next part.

No comments:

Post a Comment