2013-05-17

Hallelujah -- Adventures in LilyPond 5: Lyrics and a twist

Finally, adding words

To complete the lead sheet, I add the lyrics for the song.  It's quite straightforward.  The only things I need to remember is to 1) set the input mode to \lyricmode to distinguish from note input, 2) to split up syllables, and 3) to add double underscores to extend syllables:

firstVerseWords = \lyricmode {
    I heard there was a sec -- ret chord
    that Da -- vid played and it pleased the Lord,
    but you don't real -- ly care for mu -- sic, do ya?
    It goes like this: the fourth, the fifth,
    the mi -- nor fall, the ma -- jor lift.
    The baff -- led king com -- po -- sing Hal -- le -- lu -- jah
}

    \lyricmode {
        O __ O __ A __
    }

So!  I'm done with the song (this is the point in time when I wrote the latest blog post: I've been blogging in parallell with working on the song).  Print it out and distribute it to the choir members, and...

Crash and burn

Remember that I used two different sets of notes as source material?  And that I selected a verse (the last one) that I didn't have any notes for?  Turns out that I made a couple of minor mistakes merging the notes, causing errors in rhythm that were possible to sing past with only brief hiccups during rehearsal.  I'm usually quite meticulous; three errors in transcription in a 39-measure song is quite a negative record for me.  Oops.

Worse, in one measure I thought I needed to have a 4-8-8-8-8-4-8-4. rhythm to the lyrics "even though it all went wrong, I'll".  And boy, did it all go wrong.  The piano stopped, the choir leader went WHAT.  I had tried to sing through the notes as I went along, but in this place I must have sung something else than what I put down as notes, because this is unsingable.  The choir leader quickly saw that a plain 4-8-4-8-4-8-4-8 rhythm worked and went through with the rehearsals, but I was mortified to say the least.

This project was my pride and joy: how could I have been so sloppy?  Well, I did spend a lot of time comparing notes, but I made the basic mistake of comparing with an early version of my own notes(!), so some early errors were preserved to the end.  I kept meaning to go back and compare with the notes my choir leader had given me to work from, but I never did: hence the small mistakes.

The big mistake was caused by trying to do something I hadn't really done before: joining new lyrics with existing music.  Cohen's lyrics are sometimes quirky when it comes to rhythm and I had already discovered that I needed to be flexible.  For most of the verse, I managed to get it right, but in this one measure, I overdid it and failed badly.

The moral of this would seem to be: "don't get cocky".  I was ambitious and enthusiastic, which are nice things to be but perhaps conducive to being speedy and careless.  I kept thinking I was working on something New and Improved, so I was less inclined than usual to look back to the prior art, and even prepared to do some experimenting on my own.  Ah well, lesson learned I hope.

"And even though it all went wrong, I'll stand before the Lord of Song, with nothing on my tongue but Hallelujah"...




2013-05-13

Hallelujah -- Adventures in LilyPond 4: Notes

Adding music

I define three commands: \sopMusic, \altoMusic, and \bassMusic, to collect and transpose the notes for the different voices.  They are similar and very simple.

sopMusic = \transpose g a {
    \relative c' {
        \global

        \firstVerse
        \refrS

        \secondVerseS
        \refrS

        \thirdVerseS
        \refrS

        \bar "|."
    }
}


The \global command could alternatively be inserted before the \relative block; it doesn't really matter which.  Notes can be entered as absolute (no special command needed) or relative (inside a \relative block): in this case I choose to enter the notes relative to middle c (c').  At the end of the song, I insert a double bar line.

The commands \firstVerse, \refrS, \secondVerseS and so on are defined earlier and contain different parts of the notes (in this case the (unison) notes for the first verse, the soprano notes for the refrain, and the soprano notes for the second verse).  It isn't strictly necessary to break up the notes like this, but I find that it 1) becomes more readable and 2) makes it possible to reuse snippets (such as the notes for the first verse in all three voices)

Note collisions

When adding notes in more than one voice to a staff, sometimes notes from different voices need to be set in the same place because they are at the same pitch at the same time in the song.  LilyPond detects these collisions and either merges the notes together, or moves them apart if they can't be merged.  Example (the double backspace is shorthand for voice partition):

\relative c'' <<
    { a2. b4 a1 }
    \\
    { a2. g4 a1 }

>>


The first A notes can be merged, the B and G notes don't collide, and the final A notes collide but can't be merged, so they are moved apart:
To me the second measure looks very confusing.  One solution is to replace one of the colliding notes with a spacer rest:

\relative c'' <<
    { a2. b4 s1 }
    \\
    { a2. g4 a1 }

>>

This works, but now the notes for the first voice have been tampered with and information is lost.  Lyrics can't be connected to the voice, and the voice can't be moved to its own staff.

Another solution is to tell LilyPond to ignore collisions and just engrave the notes on top of each other:

\relative c'' <<
    \override NoteColumn #'ignore-collision = ##t
    { a2. b4 a1 }
    \\
    { a2. g4 a1 }

>>

This creates new problems, such as turning the first note into some kind of double-dotted monstrosity:
The cleanest and best solution is to switch off collision detection just for that specific note:

\relative c'' <<
    { a2. b4

      \once \override NoteColumn #'ignore-collision = ##t
      a1 }
    \\
    { a2. g4 a1 }
>>

This problem occurs in a few places in the ``Hallelujah'' notes, for instance in the first verse.  I define a command for switching collision detection off temporarily, partly to make it less intrusive, and partly because I can then invoke the same command in the other relevant places:

ignore = \once \override NoteColumn #'ignore-collision = ##t

firstVerse = {
    \partial 8 d8 |
    d4 d8 d4 d8 e8 e e4. d8   | d4 d8 d d d e4 e8 e4 e8   |
    e4 e8 e4 e8 e4 d8 d4 c8   | d8 \ignore d1 r4 d8       |
    d4 d8 d4 d8 e4 e8 fis4 d8 | g8 g8 g4. g8 g8 g8 a4. a8 |
    a4 a8 a4 a8 b4 b b8 a     | a4. g2
}


By the way, LilyPond doesn't care that much about whitespace and aligning bar checks, it's just me being pedantic.  Yes, bar checks.  LilyPond calculates the extent of measures and puts in bar lines by itself without needing any specification in the source.  However, by inserting bar checks (|) where I think a measure should end the notes become more readable (I can count bars to get to a specific place in the source) and I will get a warning from LilyPond if my bar placing doesn't add up correctly (which either means I just counted wrong or, worse, that I've messed up a duration somewhere).

Also note the fis in the next measure.  LilyPond by default uses the Dutch language convention for naming accidentals: -is for sharps and -es for flats.  You can choose between twelve different languages with different note/accidentals naming standards, but I've always used the default one.  For one thing, if I used Swedish naming, the B notes would be H notes, and that's just plain wrong.  (Unless you're J. S. Bach and you want to spell your name in chords.)    


The DRY principle

In programming, the DRY principle ("Don't Repeat Yourself") is a powerful tool used to avoid contradictions.  The principle asserts that every piece of knowledge must have a single representation.  Applying this to LilyPond, this means it's good practice to detect duplicate ranges of notes and bring them together into a single command, which is then invoked in every place where the duplicate notes are used.  For example, both the soprano and the alto voices use the same notes for the first half of their respective second verses.  Instead of having the same notes in both the definitions of \secondVerseS and \secondVerseA, I use the following:

secondVerseFirstHalfSA = {
    r4. d'8 |
    d4 d4. d8 e4 e8 e4 d8  | d4 d8 d4 d8 e4 e8 e4 e8 |
    e4 e8 e4 e8 e4 d8 d c4 | d8 \ignore d1 r4 d8     |
}

secondVerseS = {
    \secondVerseFirstHalfSA
    % ...
}

secondVerseA = {
    \secondVerseFirstHalfSA

    % ... 
}

This means that whatever happens, this particular piece of music will be consistent.  If one voice is correct, the other will also be correct.

Now, in the soprano voice, the second halves of the second and third verses are almost identical: only half a measure in the middle differs.  Maybe this shouldn't bother me, but it does, so by Knuth I will solve it.  I can't use a command to define the relevant notes, but I can use a substitution function:

secondAndThirdVerseSecondHalfS =
#(define-music-function
     (parser location notes)
     (ly:music?)
   #{
    d4 d8 d d d e4 e8 fis4. | g4 g8 g4 g8 #notes |
    a4 a8 a4 a8 b4 b b8 a   | a4. g2
   #})


This function contains the duplicate notes, with a placeholder (#notes) for the differing notes.  It can be used like this:

secondVerseS = {
    \secondVerseFirstHalfSA
    \secondAndThirdVerseSecondHalfS { g8 g a a4 a16 a }
}


Edit: Nnnope.  In the end I had to make some more changes to the second half of the third verse (more about this in part 5), so the secondAndThirdVerseSecondHalfS function isn't viable any more.  The concept is still sound, though.

To be concluded.

2013-05-11

Hallelujah -- Adventures in LilyPond 3: Chords

The definition of global

By convention, LilyPond source files define the command \global, which is then used to insert, well, globally relevant constants at the appropriate places.  In practice, this is typically the key and time signature.  Because I made the basic mistake of writing the music in the key of G, I'll specify G major and rely on the \transpose command to correct it later.

global = {
    \key g \major
    \time 12/8
}


The \global command is then called in each of the \sopMusic, \altoMusic, and \bassMusic definitions.

LilyPond version

Another convention is to add the LilyPond version statement at the top of the source file.  In fact, LilyPond will warn you if you don't.  In theory, this will protect your work if you run a very old source file through the LilyPond compiler, by reverting to old interpretations if the current ones have changed since then.  This is in contrast to say, POV-Ray, where I'm told old source files simply stop working with newer versions of the program.

\version "2.16.2"

I've never had any version problems with LilyPond, but then I always do add the version statement (mostly because I hate warnings).

The chords

With those things out of the way, I could start writing the source for the lead sheet.  Chords first, the backbone of the song.

verseChords = \chordmode {
    g2. e:m g e:m
    c2. d g d
    g2. c4. d e2.:m c4. d
    d2. b:7 e:m e:m
}

refrChords = \chordmode {
    c2. c e:m e:m
    c2. c g d g
}


The command \chordmode tells LilyPond not to try to read the following as notes, which is the default input format, but as chords.  Each of the verses use the same chord sequence, as do the refrains, but I don't have to repeat the chords for each verse/refrain.  By the magic of LilyPond definitions I can define two commands that contain verse chords and refrain chords, and later use the commands three times each.  I believe it's hard to do that in a WYSIWYG music editor.

Most of the chords have a half-measure (6 eights) duration, or the equivalent of a dotted half-note (written as 2. after the chord name).  In a couple of cases the cords have a quarter-measure (3 eights) duration, written as 4. (a dotted quarternote), and in some places a chord lasts for a full measure.  I could have written that as chordname1., but instead I doubled the chords (e.g. e:m e:m).  There is a special syntax for repeating chords, e:m q, which I, for no good reason, don't use here.  I might in the future (it's an old syntax which was gone for a couple of versions and then reintroduced).

So, let's put the chord definitions together and transpose them to A:

theChords = \transpose g a {
    \set chordChanges = ##t

    \chordmode { s8 }
    \verseChords
    \refrChords

    \chordmode { d2. }
    \verseChords
    \refrChords

    \chordmode { d2. }
    \verseChords
    \refrChords
}


Note that I have some additional chords here: a spacer (invisible) chord for the pickup measure in the beginning of the song, and a half-measure D chord joining each refrain to the following verse.  Also, by setting the chordChanges property to true (##t), I instruct LilyPond to leave out chord names except where they change or at the beginning of a new line.  This is very handy and should be the default if you ask me.

Once \theChords is defined, all the chords for the song are put together in a neat package, ready to be dropped into the score.  They are also transposed from G major to A without any brainwork on my part (even I could go from G to A, but LilyPond will happily do transpositions that are much harder).

The lyrics mention four (I, IV, V, vi) of the five chords used as they occur in the song (the fifth one being a III7 chord that is used only once in each verse):

"It [I]goes like this: the [IV]fourth, the [V]fifth, the [vi]minor fall, the [IV]major [V]lift"

One of us, Mr Cohen.  One of us.

To be continued.

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.

2013-05-03

Hallelujah -- Adventures in LilyPond

I really like writing music. Not composing, that's probably beyond my capacity, but creating new sheet music from scribbles or rearranging songs.

As usual, my favorite tool is a non-IDE, non-WYSIWYG program, in this case LilyPond (http://www.lilypond.org/). LilyPond allows me to use gVim (http://www.vim.org/) as editor and to think of the music as text, with the beautiful display of notes as a reward when the work is done. And LilyPond produces really pretty music, IMHO more so than most WYSIWYG tools I've seen so far.

Now, my choir leader asked me to put together a version (Yet Another) of Leonard Cohen's Hallelujah. What he had was SAB notes for five verses, all of them arranged differently. He wanted me to select three verses (and consequently to choose three of the verse arrangements).

The straightforward thing to do would have been to transcribe the existing notes into LilyPond notation and assemble the thing from there, but for some reason I decided to search for existing LilyPond notes for Hallelujah first. I did find some nice notes, but in G major instead of A major which we were going to use (the original is in C major), and in 6/8 time instead of 12/8 (which didn't matter much). It's very easy to transpose notes in LilyPond, but working with text notes in G major and proofreading in A major was a major bother (every note being off by one, as it were).

Because of this, it took me a lot longer than usual to get the notes and chords completely right. At the same time, I was trying to choose three verses that would make a satisfying whole. Jeff Buckley put together the most famous cover, using five verses (''I heard there was a secret chord'', ''Your faith was strong but you needed proof'', ''Baby I've been here before'', ''There was a time when you let me know'', ''Maybe there's a God above''). Cohen's lyrics have two more verses (''You say I took the name in vain'', ''I did my best, it wasn't much''). Basically, all of these verses are good, strong poetry. It's said Cohen wrote 80 verses, presumably not all top notch, before he managed to pare them down into a song.

''I heard there was a secret chord'' isn't one of the best verses, but it's hard to imagine the song without it, so I kept it as the initial verse. I took the unison women's voices arrangement and added men's voices to it, still in unison. The refrain would be the same for all three verses, a full SAB arrangement. For a second verse, I chose ''Baby I've been here before'' in a SA arrangement, without men's voices. The main reason for choosing this verse was the ''Love is not a victory march / It's a cold and it's a broken Hallelujah'' pair of lines. Now I had three or four verses left screaming for attention, but in the end ''I did my best, it wasn't much'' won out. I think it's a very satisfying ending to the song, which may be why most covers leave it out. The first half is sung by the men, with a SA ''O___ O___ A___'' backup. The second half of the verse is a full SAB arrangement: I considered letting the men sing all of it alone, but decided the climax should have as many voices as possible.

I really like this song. Both the music and the lyrics resonate with me on a fundamental level (I realize this isn't a unique sentiment, this being one of the world's most popular songs). Editing it into an arrangement for my choir was a bit of a dream come true. Even though I made labor-increasing mistakes in the beginning, it was very enjoyable and rewarding work.

I dedicate my work on this song to the memory of R.M.