git.fiddlerwoaroof.com
Raw Blame History
\begin{lilypond}
\language "english"

#(set-global-staff-size 14)
#(set! paper-alist (cons '("my size" . (cons (* 4.5 in) (* 7 in))) paper-alist))

#(define (rest-score r)
   (let ((score 0)
         (yoff (ly:grob-property-data r 'Y-offset))
         (sp (ly:grob-property-data r 'staff-position)))
     (if (number? yoff)
       (set! score (+ score 2))
       (if (eq? yoff 'calculation-in-progress)
         (set! score (- score 3))))
     (and (number? sp)
          (<= 0 2 sp)
          (set! score (+ score 2))
          (set! score (- score (abs (- 1 sp)))))
     score))


#(define (merge-rests-on-positioning grob)
   (let* ((can-merge #f)
          (elts (ly:grob-object grob 'elements))
          (num-elts (and (ly:grob-array? elts)
                         (ly:grob-array-length elts)))
          (two-voice? (= num-elts 2)))
     (if two-voice?
       (let* ((v1-grob (ly:grob-array-ref elts 0))
              (v2-grob (ly:grob-array-ref elts 1))
              (v1-rest (ly:grob-object v1-grob 'rest))
              (v2-rest (ly:grob-object v2-grob 'rest)))
         (and
           (ly:grob? v1-rest)
           (ly:grob? v2-rest)          
           (let* ((v1-duration-log (ly:grob-property v1-rest 'duration-log))
                  (v2-duration-log (ly:grob-property v2-rest 'duration-log))
                  (v1-dot (ly:grob-object v1-rest 'dot))
                  (v2-dot (ly:grob-object v2-rest 'dot))
                  (v1-dot-count (and (ly:grob? v1-dot)
                                     (ly:grob-property v1-dot 'dot-count -1)))
                  (v2-dot-count (and (ly:grob? v2-dot)
                                     (ly:grob-property v2-dot 'dot-count -1))))
             (set! can-merge
               (and 
                 (number? v1-duration-log)
                 (number? v2-duration-log)
                 (= v1-duration-log v2-duration-log)
                 (eq? v1-dot-count v2-dot-count)))
             (if can-merge
               ;; keep the rest that looks best:
               (let* ((keep-v1? (>= (rest-score v1-rest)
                                    (rest-score v2-rest)))
                      (rest-to-keep (if keep-v1? v1-rest v2-rest))
                      (dot-to-kill (if keep-v1? v2-dot v1-dot)))
                 ;; uncomment if you're curious of which rest was chosen:
                 ;;(ly:grob-set-property! v1-rest 'color green)
                 ;;(ly:grob-set-property! v2-rest 'color blue)
                 (ly:grob-suicide! (if keep-v1? v2-rest v1-rest))
                 (if (ly:grob? dot-to-kill)
                   (ly:grob-suicide! dot-to-kill))
                 (ly:grob-set-property! rest-to-keep 'direction 0)
                 (ly:rest::y-offset-callback rest-to-keep)))))))
     (if can-merge
       #t
       (ly:rest-collision::calc-positioning-done grob))))

\paper {
  #(set-paper-size "my size")
}





\parallelMusic #'(soprano alto tenor bass) {
  g8.( a16) g8 e4.       | e8.( f16) e8 e4.         | r4.          r8 g8 g | r4.         r8 c,8 c |
  g8.( a16) g8 e4.       | e8.( f16) e8 e4.         | r4.          r8 g8 g | r4.         r8 c8 c |
  d'4 d8 b4.             | r8 d8 e f( e d)          | r8 f8 g a( g f)      | r8 c8 c c4.         |
  c4 c8 g4.              | r8 c8 d e( d c)          | r8 e8 f g( f e)      | r8 c8 c c4.         |
  \break
  
  \slurDashed a4 a8 c8.( b16) a8   |
  \slurDashed r8 c8 f a8.( g16) f8 |
  \slurDashed r8 f8 f f( g) a      |
  \slurDashed r8 f8 f f f f          |
  g8.( a16) g8 e4.     | e8.( f16) e8 c4.       | c8( c) c g4.        | c'8( c) c c,4.    |
  a4 a8 c8.( b16) a8   | r8 c8 f a8.( g16) f8   | r8 f8 f f( g) a    | r8 f8 f f f f     |
  g8.( a16) g8 e4.     | e8.( f16) e8 c4.       | c8( c) c g4.      | c'8 c c, c4. |


  \slurSolid d'4 d8 f8. d16 b8      |
  \slurSolid r8 d8 g b a g            |
  \slurSolid r8 b8 b d c d                  |
  \slurSolid r8 g'8 g g g f       |
  c4.( e4.)               | g4. e4.                  | g,4. c               | e'4. c              |
  c8.( g16) e8 g8. f16 d8 | r8 e16( d) c8 b8. a16 b8 | r8 c c g g f         | r8 g'8 g g g, g     |
  c2.                     | c2.                      | e2.                  | c2.                 |
}

\score {
  \header{
  }

  \new ChoirStaff  \with {
    \override RestCollision.positioning-done = #merge-rests-on-positioning
  } <<
    \new Staff = "female" {
      \time 6/8
      \key c \major
      \new Voice = "women" <<
        \relative c'' {
          {\voiceOne \soprano}
        }
        \new Voice = "altos" {\relative c' { \voiceTwo \alto }}
      >>
    }
    \new Lyrics {
      \lyricsto "women" {
        \set stanza = #"1. "
        \skip 1 \skip 1 \skip 1 \skip 1 \skip 1 \skip 1
        All is calm, __ __ __ all is bright __ __ __
        Round yon 
        Vir -- gin

        \set ignoreMelismata = ##t
        mo -- ther

        and child,
        Ho -- ly
        
        in -- fant
        
        so
        
        ten -- der and mild,
        \unset ignoreMelismata

        Sleep in hea -- ven -- ly peace, __
        Sleep __ in hea -- ven -- ly peace.
      }
    }
    \new Lyrics {
      \lyricsto "women" {
        \set stanza = #"2. "
        Si -- lent Night, Ho -- ly Night,

        Shep -- herds quake, __ at the sight; __
        Glo -- ries stream __ from 

        \set ignoreMelismata = ##t
        hea -- ven
        \unset ignoreMelismata

        a -- far, Heav'n -- ly hosts __ sing

        \set ignoreMelismata = ##t
        Al -- le -- lu -- ia;
        \unset ignoreMelismata

        Christ, the Sa -- vior is born, __ Christ, __ the Sa -- vior, is born.
      }
    }
    \new Lyrics {
      \lyricsto "women" {
        \set stanza = #"3. "
        \skip 1 \skip 1 \skip 1 \skip 1 \skip 1 \skip 1
        Son of God, __ love's pure light __
        Ra -- diant beams from

        \set ignoreMelismata = ##t
        thy ho -- ly face,
        \unset ignoreMelismata

        With the dawn of
        
        \set ignoreMelismata = ##t
        re -- deem -- ing grace,
        \unset ignoreMelismata

        Je -- sus, Lord, at thy birth, __
        Je -- sus, Lord, at thy birth.
      }
    }

    \new Staff = "male" {
      \clef "bass"
      \relative c' {
        \time 6/8
        \key c \major
        \new Voice = "men" <<
          {\voiceOne \tenor}
          \new Voice = "basses" { \voiceTwo \bass }
        >>
      }
    }
    \new Lyrics {
      \lyricsto "men" {
        Si --  lent, Ho -- ly,
      }
    }
  >>

  \layout {
    indent = 0.0\cm
    \context {
      \Lyrics
      \override LyricText #'font-size = #-2
    }
  }
  \midi { }
}

\version "2.18.2"  % necessary for upgrading to future LilyPond versions.
\end{lilypond}