Lilypond Hymn Template
  • Adam WoodAdam Wood
    Posts: 6,482
    I used to have a Lilypond template for engraving hymns, but I cannot find it again.
    Does anyone have such a thing? I *think* the one I had was made by Aristotle.
  • a_f_hawkins
    Posts: 3,478
    There is a basic one in the lilypond documentaion :- https://lilypond.org/doc/v2.18/Documentation/snippets/templates if you scroll down the page.
  • davido
    Posts: 958
    hymn_layout.ly

    \version "2.18.2"
    \layout {
    indent = 0.0\cm
    ragged-right = ##f
    ragged-last = ##f
    %#(layout-set-staff-size 16)
    \context {
    \Score
    %**** Turns off bar numbering
    \remove "Bar_number_engraver"
    }
    \context {
    \Staff
    \remove "Time_signature_engraver"
    }
    \context {
    \Lyrics
    % **** Prevents lyrics from running too close together
    % \override LyricSpace #'minimum-distance = #0.6
    % **** Makes the text of lyrics a little smaller
    % \override LyricText #'font-size = #0.8
    % **** Moves lines of lyrics closer together
    % \override VerticalAxisGroup #'minimum-Y-extent = #'(-1 . 1)
    }
    }
  • davido
    Posts: 958
    these posts are getting flagged for moderation, sorry
  • davido
    Posts: 958
    hymn_paper_multipage.ly - change to this file for hymns that need 2 or more pages

    \version "2.18.2"

    %%%%%%%%%%%%%%%%%%%%

    %setting the global staff size in a variable placed inside the book block seems to do nothing
    #(set-global-staff-size 16)

    %%%%%%%%%%%%%%%%%%%%

    \paper {
    #(set-paper-size "letter")
    %page-count = #1
    %#(set-paper-size "ustrade")
    top-margin = 0.5\in
    bottom-margin = 0.5\in
    left-margin = 0.5\in
    right-margin = 0.5\in

    }
  • davido
    Posts: 958
    hymn_melody_layout.ly

    \version "2.18.2"

    \layout {
    %#(layout-set-staff-size 16)
    indent = 0.0\cm
    ragged-right = ##f
    ragged-last = ##f
    \context {
    \Score
    % **** Turns off bar numbering
    \remove "Bar_number_engraver"

    }
    \context {
    \Staff
    \remove "Time_signature_engraver"
    }
    }
  • davido
    Posts: 958
    My template is here:https://github.com/magdalenesacredmusic/English-Hymns
    There are some additional files (containing variables) the template calls for, which should be on that page. I'm trying to post them all here too
    Thanked by 1Adam Wood
  • davido
    Posts: 958
    hymn_definitions.ly

    \version "2.18.2"


    %setting the global staff size in a top level variable is the only way to adjust the global size
    %#(set-global-staff-size 16)

    %%%%%%
    %%%%%%
    %%%%%%
    %verse numbers on each line
    vOne = {
    \set stanza = "1."
    \set shortVocalName = "1."
    \override InstrumentName #'X-offset = #3
    \override InstrumentName #'font-series = #'bold
    \override InstrumentName #'font-size = #'0.1
    }

    vTwo = {
    \set stanza = "2."
    \set shortVocalName = "2."
    \override InstrumentName #'X-offset = #3
    \override InstrumentName #'font-series = #'bold
    \override InstrumentName #'font-size = #'0.1
    }

    vThree = {
    \set stanza = "3."
    \set shortVocalName = "3."
    \override InstrumentName #'X-offset = #3
    \override InstrumentName #'font-series = #'bold
    \override InstrumentName #'font-size = #'0.1
    }

    vFour = {
    \set stanza = "4."
    \set shortVocalName = "4."
    \override InstrumentName #'X-offset = #3
    \override InstrumentName #'font-series = #'bold
    \override InstrumentName #'font-size = #'0.1
    }

    vFive = {
    \set stanza = "5."
    \set shortVocalName = "5."
    \override InstrumentName #'X-offset = #3
    \override InstrumentName #'font-series = #'bold
    \override InstrumentName #'font-size = #'0.1
    }

    vSix = {
    \set stanza = "6."
    \set shortVocalName = "6."
    \override InstrumentName #'X-offset = #3
    \override InstrumentName #'font-series = #'bold
    \override InstrumentName #'font-size = #'0.1
    }

    vSeven = {
    \set stanza = "7."
    \set shortVocalName = "7."
    \override InstrumentName #'X-offset = #3
    \override InstrumentName #'font-series = #'bold
    \override InstrumentName #'font-size = #'0.1
    }

    %half bar
    hb = {
    %% This creates a half bar that reaches
    \once \override ChoirStaff.BarLine.bar-extent = #'( -1 . 1 )
    \bar "|"
    }

    qb = {
    %% Set height of bar line to 2 staff-spaces
    \once \override ChoirStaff.BarLine.bar-extent = #'( 1.5 . 2.5 )
    \bar "|"
    }

    divisioMinima = {
    \once \override BreathingSign.stencil = #ly:breathing-sign::divisio-minima
    \once \override BreathingSign.Y-offset = #2
    \breathe
    }
    divisioMaior = {
    \once \override BreathingSign.stencil = #ly:breathing-sign::divisio-maior
    \once \override BreathingSign.Y-offset = #0
    \breathe
    }
    divisioMaxima = {
    \once \override BreathingSign.stencil = #ly:breathing-sign::divisio-maxima
    \once \override BreathingSign.Y-offset = #0
    \breathe
    }
    finalis = {
    \once \override BreathingSign.stencil = #ly:breathing-sign::finalis
    \once \override BreathingSign.Y-offset = #0
    \breathe
    }

    %%%%%%%%%%%%

    hn =
    #(define-music-function
    (parser location note)
    (ly:music?)
    #{
    \once \override Voice.NoteHead #'stencil =
    #ly:text-interface::print
    \once \override Voice.NoteHead #'text =
    \markup \musicglyph #"noteheads.s1"
    %\once \override Voice.Stem #'stencil = ##f
    $note
    #})

    %%%%%%%%%%%%

    i = {
    \override Lyrics.LyricText #'font-shape = #'italic
    }

    bo = {
    \override Lyrics.LyricText #'font-series = #'bold
    }

    plainText = {
    \revert Lyrics.LyricText #'font-shape
    \revert Lyrics.LyricText #'font-series
    }


    %%%%%%%%%%%%

    orAcc = \override Voice.Accidental.stencil = ##f

    revAcc = \revert Voice.Accidental.stencil

    %%%%%%%%%%%%%%%

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

    %%%%%%%%%%%%%

    lal = \once \override LyricText.self-alignment-X = #LEFT

    %%%%%%%%%%%%%%%

    tagIt = \once \override Lyrics.LyricText #'tagged = ##t

    #(define (define-grob-property symbol type? description)
    (if (not (equal? (object-property symbol 'backend-doc) #f))
    (ly:error (_ "symbol ~S redefined") symbol))

    (set-object-property! symbol 'backend-type? type?)
    (set-object-property! symbol 'backend-doc description)
    symbol)

    #(map
    (lambda (x)
    (apply define-grob-property x))

    `(
    (tagged ,boolean? "is this grob marked?")
    (syllables ,array? "the lyric syllables at a timestep")
    ))


    #(define (Lyric_text_align_engraver ctx)
    "If the property 'tagged is set, collect all lyric syllables at that
    timestep in the grob-array 'syllables"
    (let (; We will collect LyricText items here.
    (syl '()))
    (make-engraver
    (acknowledgers
    ((lyric-syllable-interface trans grob source)
    (set! syl (cons grob syl))))
    ((stop-translation-timestep trans)
    ; This ensures that callbacks will have access to all of the LyricText grobs
    ; in a column though any of the LyricText grobs in that column.
    (if (any (lambda (x) (eq? #t (ly:grob-property x 'tagged)))
    syl)
    (for-each (lambda (x)
    (for-each
    (lambda (y)
    (ly:pointer-group-interface::add-grob x 'syllables y))
    syl))
    syl))
    ; clear our cache of syllables in readiness for another group
    (set! syl '())))))

    #(define (X-offset-callback grob)
    (let* (; This is the grob-array we created to hold targeted syllables.
    (target (ly:grob-object grob 'syllables))
    ; Check is necessary because engraver has only created 'syllables
    ; grob-array in response to tag
    (target
    (if (ly:grob-array? target)
    (ly:grob-array->list target)
    '()))
    ; A procedure to determine the size of a text stencil:
    (length (lambda (item)
    (interval-length
    (ly:stencil-extent
    (grob-interpret-markup grob (ly:grob-property item 'text))
    X)))))
    (if (pair? target) ; Do we have a 'syllables grob-array?
    (let ((longest
    (fold
    (lambda (elem prev)
    (if (> (length elem) (length prev)) elem prev))
    (car target)
    target)))
    (if (eq? grob longest)
    ; If our grob has the longest syllable, return its default
    ; value for 'X-offset.
    (ly:self-alignment-interface::aligned-on-x-parent grob)
    ; Otherwise, give it the X-offset value of the longest syllable.
    (ly:grob-property longest 'X-offset)))

    ; If no grob-array, return the default function for 'X-offset
    (ly:self-alignment-interface::aligned-on-x-parent grob))))
  • davido
    Posts: 958
    My template is below.

    \version "2.18.2"
    \include "english.ly"
    \include "hymn_definitions.ly"

    top = \markup {
    \fill-line {
    \column {
    \line {}
    }
    \right-column{
    \line {}
    \line {}
    }
    }
    }

    bottom = \markup {
    \fill-line {
    \null
    \right-column {
    \line {}
    \line {}
    }
    }
    }

    \header {
    tagline = ""
    }

    global = {
    \key g \major
    \time 4/4
    \autoBeamOff
    \set Staff.midiInstrument = "church organ"
    }

    melody = \relative c'' {
    \global


    \bar "|."
    }

    alto = \relative c' {
    \global

    }

    tenor = \relative c' {
    \global

    }

    bass = \relative c {
    \global

    }

    verseOne = \lyricmode {
    \vOne

    }

    verseTwo = \lyricmode {
    \vTwo

    }

    verseThree = \lyricmode {
    \vThree

    }

    verseFour = \lyricmode {
    \vFour

    }

    \book {
    \include "hymn_paper.ly"
    \header {
    tagline = ""
    }
    \top
    \score {
    \new ChoirStaff <<<br /> \new Staff <<<br /> \new Voice = "soprano" { \voiceOne \melody }
    \new Voice = "alto" { \voiceTwo \alto }
    >>
    \new Lyrics \lyricsto soprano \verseOne
    \new Lyrics \lyricsto soprano \verseTwo
    \new Lyrics \lyricsto soprano \verseThree
    \new Lyrics \lyricsto soprano \verseFour
    \new Staff <<<br /> \clef bass
    \new Voice = "tenor" { \voiceOne \tenor }
    \new Voice = "bass" { \voiceTwo \bass }
    >>
    >>
    \midi {
    \context {
    \Score
    tempoWholesPerMinute = #(ly:make-moment 96 4)
    }
    }
    \include "hymn_layout.ly"
    }
    \bottom
    }

    %%%%%%
    %%%%%%
    %%%%%%
    #(define output-suffix "Melody")
    \book {
    \include "lilypond-book-preamble.ly"
    \include "hymn_melody_paper.ly"
    \top
    \score {
    %\transpose c bf,
    <<<br /> \new Voice = "tune" {
    \melody
    }
    \new Lyrics \lyricsto "tune" { \verseOne }
    \new Lyrics \lyricsto "tune" { \verseTwo }
    \new Lyrics \lyricsto "tune" { \verseThree }
    \new Lyrics \lyricsto "tune" { \verseFour}
    >>
    \include "hymn_layout.ly"
    }
    \markup {
    \vspace #0.5
    }
    \bottom
    }
  • davido
    Posts: 958
    My template is below. It will create a 4 part score and a cropped melody only score. I use frescobaldi, and render the melody scores as png files for use in Publisher for worship aids.
    There are additional files referenced in this template which I will post as additional comments below.
    You can see this all in practice at https://github.com/magdalenesacredmusic/English-Hymns

    \version "2.18.2"
    \include "english.ly"
    \include "hymn_definitions.ly"

    top = \markup {
    \fill-line {
    \column {
    \line {}
    }
    \right-column{
    \line {}
    \line {}
    }
    }
    }

    bottom = \markup {
    \fill-line {
    \null
    \right-column {
    \line {}
    \line {}
    }
    }
    }

    \header {
    tagline = ""
    }

    global = {
    \key g \major
    \time 4/4
    \autoBeamOff
    \set Staff.midiInstrument = "church organ"
    }

    melody = \relative c'' {
    \global


    \bar "|."
    }

    alto = \relative c' {
    \global

    }

    tenor = \relative c' {
    \global

    }

    bass = \relative c {
    \global

    }

    verseOne = \lyricmode {
    \vOne

    }

    verseTwo = \lyricmode {
    \vTwo

    }

    verseThree = \lyricmode {
    \vThree

    }

    verseFour = \lyricmode {
    \vFour

    }

    \book {
    \include "hymn_paper.ly"
    \header {
    tagline = ""
    }
    \top
    \score {
    \new ChoirStaff <<<br /> \new Staff <<<br /> \new Voice = "soprano" { \voiceOne \melody }
    \new Voice = "alto" { \voiceTwo \alto }
    >>
    \new Lyrics \lyricsto soprano \verseOne
    \new Lyrics \lyricsto soprano \verseTwo
    \new Lyrics \lyricsto soprano \verseThree
    \new Lyrics \lyricsto soprano \verseFour
    \new Staff <<<br /> \clef bass
    \new Voice = "tenor" { \voiceOne \tenor }
    \new Voice = "bass" { \voiceTwo \bass }
    >>
    >>
    \midi {
    \context {
    \Score
    tempoWholesPerMinute = #(ly:make-moment 96 4)
    }
    }
    \include "hymn_layout.ly"
    }
    \bottom
    }

    %%%%%%
    %%%%%%
    %%%%%%
    #(define output-suffix "Melody")
    \book {
    \include "lilypond-book-preamble.ly"
    \include "hymn_melody_paper.ly"
    \top
    \score {
    %\transpose c bf,
    <<<br /> \new Voice = "tune" {
    \melody
    }
    \new Lyrics \lyricsto "tune" { \verseOne }
    \new Lyrics \lyricsto "tune" { \verseTwo }
    \new Lyrics \lyricsto "tune" { \verseThree }
    \new Lyrics \lyricsto "tune" { \verseFour}
    >>
    \include "hymn_layout.ly"
    }
    \markup {
    \vspace #0.5
    }
    \bottom
    }
  • davido
    Posts: 958
    hymn_paper.ly

    \version "2.18.2"

    %%%%%%%%%%%%%%%%%%%%

    %setting the global staff size in a variable placed inside the book block seems to do nothing
    #(set-global-staff-size 16)

    %%%%%%%%%%%%%%%%%%%%

    \paper {
    #(set-paper-size "letter")
    page-count = #1
    %#(set-paper-size "ustrade")
    top-margin = 0.5\in
    bottom-margin = 0.5\in
    left-margin = 0.5\in
    right-margin = 0.5\in

    }
  • davido
    Posts: 958
    hymn_melody_paper.ly


    \version "2.18.2"

    %%%%%%%%%%%

    \paper {
    indent=0\mm
    line-width=4.5\in
    oddFooterMarkup=##f
    oddHeaderMarkup=##f
    bookTitleMarkup = ##f
    scoreTitleMarkup = ##f

    }

    %%%%%%%%%%%

    #(set-global-staff-size 16)

    %%%%%%%%%%%