% Copyright © 2026 by CPDL
% This edition can be fully distributed, duplicated, performed, and recorded
% See https://cpdl.org/wiki/index.php/ChoralWiki:CPDL for terms and conditions

\version "2.25.34" % If you run an earlier version of LilyPond, you may encounter spacing issues
% See https://lilypond.org/doc/v2.25/Documentation/changes/new-for-specialist-notation
% Helpful reference: https://wiki.lilypond.community/wiki/Category:Ancient_notation

%%%  HEADERS
\header {
  dedication = \markup \italic {
    Dedicated to my mother; she raises others up when they fall }
  title = "ALMA REDEMPTORIS MATER"
  subtitle = \markup \column \normal-weight \italic {
    \vspace #-0.25
    \line { Simple Tone, Mode V }
  }
  subsubtitle = \markup \override #'(baseline-skip . 2) \center-column {
    \vspace #-0.6
    \line { Anthem of the Blessed Virgin }
    \line \normal-weight { from Vespers of Saturday before the
      \concat { 1 \super st } Sunday of Advent to
      \concat { 2 \super nd } Vespers of Candlemas }
    \vspace #0.4
  }
  poet = \markup \fontsize #-1 \override #'(baseline-skip . 2) \column {
    \line { Medieval text; attributed to Blessed Hermann of Reichenau }
    \line { (1013–1054); translated by Gabriel Ellsworth, after the ASB }
  }
  composer = \markup \fontsize #-1 \override #'(baseline-skip . 2) \right-column {
    \line { Origin of simple tone unknown; }
    \line { possibly \concat { 17 \super th } century }
  }
  copyright = \markup \fontsize #-1 \wordwrap {
    Copyright © 2026 by CPDL. This edition can be fully distributed, duplicated, performed, and recorded.
    \with-url #"https://www.cpdl.org/wiki/index.php/ChoralWiki:CPDL"
    { For the terms of the CPDL copyright license, see cpdl.org. }
    Engraved by Gabriel Ellsworth. Sources: \italic { Liber Usualis } \concat { N \super o } 801 (1963), p. 277;
    \italic { The Anglican Service } \concat { \italic Book , } p. 730.
    To request a translation in another language, please contact me via email or CPDL.
  }
  tagline = \markup \fontsize #-1.5 \center-column {
    \vspace #0.2
    \line { Created with free software (LilyPond $(lilypond-version) and Frescobaldi);
      last revised on \concat { 27 \super th } February 2026 (George Herbert, Priest) }
  }
} % end of \header block

%  header for Advent section
headerAdvent = \markuplist {
  \fill-line { \concat {
    "¶ "
    \italic "During Advent, the following Versicles and Collect are used after the Anthem." }
  }
} % end of \markuplist block 

%  header for Christmas section
headerChristmas = \markuplist {
  \fill-line { \concat {
    "¶ "
    \italic "But from the First Evensong of Christmas to Candlemas, use the following instead of the above." }
  }
} % end of \markuplist block


%%%  PAPER AND TOP-LEVEL LAYOUT
\paper {
  #(set-paper-size "letter") % engrave output on 8.5- x 11-inch paper
  top-margin = 0.25\in
  left-margin = 0.4\in % to get (closer to) the default margins of version 2.24
  right-margin = 0.4\in % to get (closer to) the default margins of version 2.24
  page-count = 1 % forces all content to fit on one page
}

%%  Top-level \layout block (applies to all scores in this file):
\layout {
  indent = 0 % was in gregorian.ly
  ragged-last = ##f % stretches the last system of each score to the width of the page
  \context {
    \Staff
    \omit TimeSignature
  }
  \context {
    \Voice
    \remove Stem_engraver
  }
  \context {
    \Lyrics
    % See https://lists.gnu.org/archive/html/lilypond-user/2025-07/msg00016.html
    \consists Bar_engraver
    \hide BarLine
    % Cause all lyric hyphens to display:
    \override LyricHyphen.minimum-distance = #0.44
  }
}


%%%  MUSIC AND LYRICS

%%  music for the incipit
incipitMusic = \relative c {
  \clef "vaticana-do3"
  \once \override VaticanaVoice.Episema.Y-offset = #-2.6
  \[ c \episemInitium \episemFinis e \pes f
     \once \override NoteHead.extra-offset = #'( 0.2 . 0 )
     g
     \once \override NoteHead.extra-offset = #'( 0.2 . 0 )
     \pes a \]
  \augmentum g
  % Add some white space before the modern staff:
  \stopStaff \hideNotes g
}

%%  Alma Redemptoris Mater music
chant = \relative c' {
  \key c \major

  % first system:
  \omit Score.BarNumber % The score has transparent bar numbers, but
  % including them in this system could cause spacing issues above the first system
  \time 15/4 c2( e4 f g a) g2 g4 g\ictus a b\ictus c g2 | \bar ","
  \time 11/4 e4 e\ictus e f\ictus e d\ictus e f\ictus a g2 | \bar ","
  
  % second system:
  \time 6/4 a4 c b\ictus a g2 | \bar ","
  \undo \omit Score.BarNumber % helps with vertical spacing between systems
  \time 7/4 e4 f\ictus e d\ictus e g2 | \bar ","
  \time 10/4 e4 f g\ictus a c\ictus b d\ictus c c2 | \bar "||"
  \break % forces a system break after “populo”
  
  % third system:
  \time 7/4 c4 b\ictus c c\ictus d g,2\ictus | \bar ","
  \time 7/4 c4 b\ictus a g\ictus f e2 | \bar ","
  \time 12/4 e4 e a\ictus g f\ictus e d( e) f2( e) | \bar "||"
  \time 11/4 c'4 b\ictus a g2\ictus
  \break % forces a system break after “prius”
  
  % fourth system:
  a4 g e\ictus f g2 | \bar ","
  \time 8/4 a4 a c\ictus a g\ictus f e2\ictus | \bar ","
  \time 7/4 f4 e\ictus g g\ictus a g2 | \bar ","
  \time 13/4 c4 b\ictus c a( g) a f e( d) c1 |
  \fine
}


%%  Helper functions for lyrics

% Adjust the horizontal alignment point on a lyric item:
lyrSAX = \tweak LyricText.self-alignment-X \etc
% See https://lilypond.org/doc/v2.25/Documentation/snippets/text-_002d-lyrics-alignment

% Adjust the horizontal alignment point associated with a lyric item’s *parent*
% (the note column to which the lyric is linked):
lyrPAX = \tweak LyricText.parent-alignment-X \etc
% The value #-1 means aligned in the X direction on the parent’s left edge,
% #0 on the parent’s center, and #1 on the parent’s right edge.
% Greater absolute values are possible.
% For example, \lyrPAX #5 in the code below
% aligns the "Gracious Mother …" lyric with a point that is 5 units
% to the right of the center of the note column.
% A unit is half the parent’s width;
% therefore, the "Gracious Mother …" lyric appears even farther to the right
% than the note column’s right edge.
% See https://lilypond.org/doc/v2.25/Documentation/internals/self_002dalignment_002dinterface

% Helper function for bolded lyrics:
boldLyrics = \override Lyrics.LyricText.font-series = #'bold
normalLyrics = \revert Lyrics.LyricText.font-series

% Helper function for proper alignment of baselines
% between regular lyric items and lyrics in \markup blocks:
#(define-markup-command (alignToBaseLine layout props content) (markup?)
   (let ((stil (interpret-markup layout props content))
         (no-descender (interpret-markup layout props "i")))
     (ly:make-stencil
      (ly:stencil-expr stil)
      (ly:stencil-extent stil X)
      (cons (car (ly:stencil-extent no-descender Y))
            (cdr (ly:stencil-extent stil Y))))))
% Source: https://lists.gnu.org/archive/html/lilypond-user/2026-01/msg00193.html

% %% Insert "℣. " before the text of a versicle %%
% The Unicode for the versicle symbol (℣) is U+2123
% The standard Unicode for a normal space is U+0020
versicle = \markup \concat { \char ##x2123 . \char ##x0020 }

% %% Insert "℟. " before the text of a response %%
response = \markup \concat { \char ##x211F . \char ##x0020 }

%%  Alma Redemptoris Mater Latin lyrics
verba = \lyricmode {
  \boldLyrics
  Ál --
  \lyrSAX #-0.3 \markup \concat { ma \char ##x2006 * } % n.b. Unicode U+2006 is a *six-per-em space*
  Re -- demp -- tó -- ris Má -- ter,
  quae pér -- vi -- a caé -- li pór -- ta má -- nes,
  Et stél -- la má -- ris,
  suc -- cúr -- re ca -- dén -- ti
  súr -- ge -- re qui cú -- rat pó -- pu -- lo:
  Tu quae ge -- nu -- í -- sti,
  na -- tú -- ra mi -- rán -- te,
  tú -- um sán -- ctum Ge -- ni -- tó -- rem:
  Vír -- go prí -- us ac po -- sté -- ri -- us,
  Ga -- bri -- é -- lis ab ó -- re
  sú -- mens íl -- lud Á -- ve,
  pec -- ca -- tó -- rum mi -- se -- ré -- re.
  \normalLyrics
}

%%  Alma Redemptoris Mater English translation
words = \lyricmode {
  \override LyricText.font-shape = #'italic
  
  % Set the alignment point on English lyric text items to be the *left edge* of the lyric item:
  \override LyricText.self-alignment-X = #LEFT
  
  \lyrPAX #5 "Gracious Mother of our Redeemer,"4*15
  \lyrPAX #-3 "for ever abiding Heaven’s gateway,"4*11
  \lyrPAX #-2 "and star of the sea,"4*6
  \lyrPAX #1 "O succor the people, who, though falling, strive to rise again."4*17
  
  "Thou Maiden who, to nature’s amazement, barest thy holy Creator;"4*26
  "Virgin both"4*5
  \lyrPAX #-3 "before and after"4*6
  \lyrPAX #2 "Gabriel’s mouth gave thee that “Ave”;"4*15
  \lyrPAX #-5 "have compassion on us sinners."4*13
}

%%  Versicles and Collect for use during Advent
%  music
musicAdvent = \relative c' {
  \key c \major
  \textMark \markup \fontsize #-1 \italic Officiant:
  \time 7/4 f1 f4 d2 | \bar "||"
  \textMark \markup \fontsize #-1 \italic \bold People:
  \time 8/4 f1 f4 d4 e2 | \bar "||"
  \textMark \markup \fontsize #-1 \italic Officiant:
  \time 4/4 f4 d e2 | \bar ","
  \cadenzaOn f1
}

%  collect
collectAdvent = \lyricmode {
  \set fontSize = #-1
  
  \lyrSAX #-0.75
  \markup \override #'(baseline-skip . 2.2)
    \general-align #Y #DOWN
    {
      \concat { \versicle
        \column {
          \left-align {
            \line \alignToBaseLine { The Angel of the }
            \line \alignToBaseLine { Lord announced unto }
          }
        }
      }
  }
  Ma -- ry.
  
  \lyrSAX #-0.75
  \markup \override #'(baseline-skip . 2.2)
    \general-align #Y #DOWN
    {
      \concat { \response
        \column {
          \left-align {
            \line \bold \alignToBaseLine { And she }
            \line \bold \alignToBaseLine { conceived by the }
          }
        }
      }
  }
  \boldLyrics Ho -- ly Ghost.
  
  \normalLyrics
  \lyrSAX #0.3 \markup \concat { \versicle Let } 
  us pray:
  \lyrSAX #-0.9 "We beseech thee, …"
}

%  collect continued as markup
collectAdventA = \markup \justify {
  … O Lord, pour thy grace into our hearts:
  that, as we have known the incarnation of
  thy Son Jesus Christ (announced) by the
  message of an angel (to the Virgin Mary),
}
collectAdventB = \markup \justify {
  so by his
  % Note the thin space (U+2009) before “cross”:
  \concat { \char ##x2629 \char ##x2009 cross }
  and passion we may be brought
  unto the glory of his resurrection.
  Through the same Christ our Lord.
}

%%  congregational Amen (to be used twice)
%  music
musicAmen = \relative c' {
  \key c \major
  \time 1/1024 s1024 | \bar ","
  \time 4/4 d2 e2 |
  \fine
}

%  lyrics
lyricsAmen = \lyricmode {
  \set fontSize = #-1
  \boldLyrics A -- men.
}

%%  Versicles and Collect for use during Christmas
%  music
musicChristmas = \relative c' {
  \key c \major
  \textMark \markup \fontsize #-1 \italic Officiant:
  \time 9/4 f1 f4 f d4 d2 | \bar "||"
  \textMark \markup \fontsize #-1 \italic \bold People:
  \time 7/4 f1 d4 e2 | \bar "||"
  \textMark \markup \fontsize #-1 \italic Officiant:
  \time 4/4 f4 d e2 | \bar ","
  \cadenzaOn f1
}

%  collect
collectChristmas = \lyricmode {
  \set fontSize = #-1
  
  \lyrSAX #-0.8
  \markup \override #'(baseline-skip . 2.2)
    \general-align #Y #DOWN
    {
      \concat { \versicle
        \column {
          \line \alignToBaseLine { After Childbearing, }
          \line \alignToBaseLine { O Virgin, thou didst remain }
        }
      }
  }
  in -- vi -- o -- late.
  
  \lyrSAX #-0.75
  \markup \override #'(baseline-skip . 2.2)
    \general-align #Y #DOWN
    {
      \concat { \response
        \column {
            \line \bold \alignToBaseLine { Intercede }
            \line \bold \alignToBaseLine { for us, O Mother }
        }
      }
  }
  \boldLyrics of God.
  
  \normalLyrics
  \lyrSAX #0.4 \markup \concat { \versicle Let }
  us pray:
  \lyrSAX #-0.95 
  "O God, …"
}

%  collect continued as markup
collectChristmasA = \markup \justify {
  … who by the fruitful virginity of Blessed Mary
  hast bestowed upon mankind the reward of
  eternal salvation:
}
collectChristmasB = \markup \justify {
  Grant, we beseech thee, that we may
  know the help of her intercession
  through whom we have been accounted worthy
  to receive the Author of our life,
  Jesus Christ thy Son our Lord.
}


%%%  SCORES

%%  Alma Redemptoris Mater score
anthemScore = \score {
  % score-specific layout:
  \layout {
    indent = 13
    incipit-width = 13
    \context {
      \Score
      % Transparent (invisible/hidden) bar numbers help with spacing between systems:
      \override BarNumber.break-visibility = ##(#t #t #t)
      \hide BarNumber
      \override SpacingSpanner.packed-spacing = ##t % from gregorian.ly
      % (helps with note spacing within the incipit)
    }
    \context {
      \Staff
      \consists Custos_engraver % adds custodes to this score
      \override Custos.style = #'medicaea % changes style of custodes; default is vaticana
    }
  } % end of score-specific \layout block
  
  % incipit:
  \new Staff \with {
    \incipit
    \new VaticanaStaff = "incipit" \incipitMusic
    instrumentName = ""
  }
  
  % modern staff:
  <<
    % Use normal note spacing in the modern staff:
    \override Score.SpacingSpanner.packed-spacing = ##f
    \new Voice = "melody" \chant
    \new Lyrics = "Latin" \lyricsto melody \verba
    \new Lyrics = "English"
      % Make the spacing algorithm ignore the lengths of
      % English lyrics when laying out the page:
      \with { \override LyricText.X-extent = #'(0 . 0) }
      % See https://lists.gnu.org/archive/html/lilypond-user/2025-11/msg00029.html
      \words
  >>
} % end of \score block

%%  Versicle, response, and collect for use during Advent
%  score (as markup)
versiclesAdvent = \markup \score {
  <<
    \new Voice = "firstversicle" \musicAdvent
    \new Lyrics \lyricsto "firstversicle" \collectAdvent
  >>
}

%  Amen score (as markup)
amen = \markup \score {
  \new Staff <<
    \new Voice = "congregation" \musicAmen
    \new Lyrics \lyricsto "congregation" \lyricsAmen
  >>
  % score-specific layout:
  \layout {
    ragged-last = ##t % draws the system at its natural width (no stretching)
    \omit Staff.Clef
  }
}

% continuation of collect (as markup)
collectBlockAdvent = \markup \override #'(word-space . 2)
  \override #'(baseline-skip . 2.5)
  \line {
    \hspace #4.2
    \override #'(line-width . 50) \collectAdventA
    \hspace #2
    \override #'(line-width . 40) \collectAdventB
    \hspace #1.3
    \column {
      \vspace #0.7
      \amen
  }
}


%%  Versicle, response, and collect for use during the Forty Days of Christmas
%  score (as markup)
versiclesChristmas = \markup \score {
  <<
    \new Voice = "secondversicle" \musicChristmas
    \new Lyrics \lyricsto "secondversicle" \collectChristmas
  >>
}

% continuation of collect (as markup)
collectBlockChristmas = \markup \override #'(word-space . 2)
  \override #'(baseline-skip . 2.5)
  \line {
    \hspace #4.7
    \override #'(line-width . 35.5) \collectChristmasA 
    \hspace #2
    \override #'(line-width . 54) \collectChristmasB 
    \hspace #1.3
    \column {
      \vspace #0.7
      \amen 
  }
}


%%%%  OUTPUT (PAGE CONTENTS TO RENDER)
%  anthem
\anthemScore

%  Advent section (with included \markup for header)
\markuplist {
  \vspace #1
  \headerAdvent
  \vspace #0.2
  \versiclesAdvent
  \vspace #0.7
  \collectBlockAdvent
}

%  Christmas section (with included \markup for header)
\markuplist {
  \vspace #1
  \headerChristmas
  \vspace #0.2
  \versiclesChristmas
  \vspace #0.7
  \collectBlockChristmas
}
%%%%  END OF OUTPUT
% Copyright © 2026 by CPDL