\version "2.10.10"

\include "english.ly"
\include "../mrlUtil.ly"

#(ly:set-option 'point-and-click #f)

headerMarkup = \markup { "Gibbons:" \italic "Fantazia" } 

#(set-global-staff-size 20)

\paper {
  #(set-paper-size "letter")
  top-margin = .3\in
  bottom-margin = .4\in
  left-margin = .75\in
  line-width = 7\in
  between-system-padding = 0.05\in
  page-top-space = 0.0\in
  %ragged-last-bottom = ##t
  
      oddHeaderMarkup = \markup
    \fill-line {
      ""
      \on-the-fly #not-first-page \headerMarkup
      \on-the-fly #print-page-number-check-first \fromproperty #'page:page-number-string
    }

    evenHeaderMarkup = \markup
    \fill-line {
      \on-the-fly #print-page-number-check-first \fromproperty #'page:page-number-string
      \on-the-fly #not-first-page \headerMarkup
      ""
    }
    
    myStaffSize = #20
  #(define fonts
    (make-pango-font-tree "Junicode"
                          "Sans"
                          "Mono"
                           (/ myStaffSize 20)))
}

%smallCapsACode = #smallCapsACodeLL
%oldStyleZeroCode = #oldStyleZeroCodeLL

\header {
    composer = \markup { \realCaps "Orlando Gibbons" 
        \oldStyleNum { "(1583–1625)" } }
    %subtitle = ""
    %poet = ""
    opus = \markup { \italic "Parthenia" \oldStyleNum "(1612/13)," "xvii" }
    title = \markup { \medium \italic "Fantazia of Foure Parts" }
    copyright = \markup { \smaller \center-align {
        "Edition copyright © 2007 by Michael Lauer."
        "This edition may be freely distributed, duplicated, performed, or recorded." } } 
}


#(define-markup-command (fcol layout props markups) (markup-list?)
  "Print a column of fingering indications--use a reasonable baseline-skip."
  (interpret-markup layout props
    (markup
        (#:left-align
        (#:override '(baseline-skip . 1.5)
            (#:finger (make-center-align-markup markups) ))))))
            
# (define (timesigFn grob)
  (interpret-markup
   (ly:grob-layout grob)
   '(((baseline-skip . 3)))
   (markup
     #:raise 1 (#:center-align (#:bigger #:musicglyph "timesig.mensural64" #:number "3" )) ) ) )
     
     
orn = #(define-music-function (parser location m) (ly:music?)
    (define (addToChord x) 
        (if (eq? (ly:music-property x 'name) 'EventChord)
            (let* ((els (ly:music-property x 'elements))
                   (dur-log (ly:duration-log (ly:music-property (car els) 'duration)))
                   (tremLen (if (< dur-log 3) 16 (expt 2 (+ dur-log 2))))
                   (ev (make-music 'TremoloEvent 'tremolo-type tremLen))
                   (newEls (append els (list ev))))
                  (ly:music-set-property! x 'elements newEls)
                  x)
            x)
        )
    (let* ((added (music-map addToChord m))) 
#{
    \once \override Voice.StemTremolo #'beam-thickness = #.25
    $added
#})
)

cus = #(define-music-function (parser loc m) (ly:music?)
    (define (stencilFn grob) (interpret-markup (ly:grob-layout grob) '(())
            (markup #:musicglyph "custodes.mensural.u0" )))
    (define (note->rest x)
            (if (eq? (ly:music-property x 'name) 'NoteEvent)
                (let* ((p (ly:music-property x 'pitch))
                       (d (ly:music-property x 'duration)))
                      (make-music 'RestEvent 'duration d 'pitch p))
                x))
    (let* ((mr (music-map note->rest m)))
#{
    \new Voice {
        \override Rest #'stencil = #$stencilFn
        $mr
        \revert Rest #'stencil
    }
#}
))

meas = #(define-music-function (parser loc num denom) (integer? integer?)
    (make-sequential-music (list 
        (make-event-chord (list (make-music 'SpacingSectionEvent)))
        (make-time-signature-set num denom)
        (make-skip-music (ly:make-duration 0 0 num denom))
    )))
    
line = {}

global = {
    % main
    %\set Staff.forceClef = ##t
    %\set Staff.forceTime = ##f
    %\set Timing.defaultBarType = ""
    
    \set Staff.midiInstrument = "harpsichord"
    \override Staff.VerticalAxisGroup #'minimum-Y-extent = #'(-1 . 1)
    
    \set subdivideBeams = ##t
     
    #(ly:export (set-accidentals-properties #f '(Staff (same-octave . 0))
                   '(Staff (any-octave . -1)) 'Staff))
                 
    
    \key a \minor
    
    %original barring
    \override Staff.TimeSignature #'stencil = ##f
    \once \override Staff.TimeSignature #'stencil = 
        #(lambda (grob) (interpret-markup
            (ly:grob-layout grob) '(())
            (markup #:fontsize 2 #:musicglyph "timesig.mensural22")))
            
    %\override Score.SpacingSpanner #'common-shortest-duration = #(ly:make-moment 1 4)
    
    \meas #4 #1
    \meas #3 #1
    \meas #4 #1
    \meas #5 #1
    \meas #3 #1
    \line 
    \meas #5 #1
    \meas #5 #1
    \meas #4 #1
    \meas #5 #1
    \line
    \meas #4 #1
    \meas #3 #1
    \meas #2 #1
    \meas #4 #1
    \meas #4 #1
    \line
    \meas #4 #1
    \meas #4 #1
    \meas #6 #1
    \meas #5 #1
    \line
    \meas #5 #1
    \meas #5 #1
    \meas #4 #1
    \meas #6 #1
    \line
    \meas #4 #1
    \meas #4 #1
    \meas #3 #1
    \meas #4 #1
    \line
    \meas #4 #1
    \meas #3 #1
    \meas #3 #1
    \meas #3 #1
    \line
    \meas #2 #1
    \meas #3 #1
    \meas #3 #1
    \meas #3 #1
    \line
    \meas #4 #1
    \meas #4 #1
    \meas #4 #1
    \meas #3 #1
    \line
    \meas #4 #1
    \meas #5 #1 \bar""
    \meas #2 #1
    
    \bar "|."
}

up = \tag #'scoreOnly { \change Staff = treble }
down = \tag #'scoreOnly { \change Staff = bass }

voiceI = 
    \relative a' {
        \context Voice = "I"
        \voiceOne
        \set fingeringOrientations = #'(up)
        s1*4 |
        s1*3 |
        a1 \orn e2 g \orn c,2. d8 e f4 \orn e c d |
        e4 \orn d e f g2 c,4 d e2. d4 \orn c4 d e2. d8 c \orn b a \orn b4 |
        \orn c4 a a'2 r2 e'2 b d |
        
        \orn g,2. a8 b c4 \orn b g a b2. a4 g a b2. a8 g \orn fs e \orn fs4 |
        gs2 a1 e'2. \orn d8 c a'2 \orn e g \orn c,2. d8 e |
        f4 \orn e c d e2. d4 \orn c d e2. d8 c \orn b a b4 |
        a2 a2. \orn g4 a b c1 b2~ b2. a4 b c |
        
        d2 c2. \orn b8 a b2~ b4 a2 e' d4 e fs |
        g2 fs2. e4 fs g a2. g4 |
        \orn f?4 e e2. d8 c 
        \tag #'scoreOnly { \afterGrace d2\trill { c16[ d] } } 
        \tag #'midiOnly { e16[ d e d e d c d] } | \break
        e4 fs g2 fs e2. e4 d2 c b |
        r4 a2 \orn gs4 a b c2 b4 e2 d4 e fs g2 |
        
        fs1 e4 d2 c4 b a2 g4 fs e2 <ds b'~>4 |
        b'4 a \orn gs a8 b c2. \orn b8 a b1 a2 \orn b |
        e2. d4 b2 c b b2. a4 fs2 gs e'2. d4 s2 |
        d2. c4 a2 c b2. a4 gs2 a gs b~ |
        
        b4 a r4 fs'2 e4 cs2 d d2. c4 a2 b2. a4 |
        fs2 gs a b2. a4 e'2. d4 b2 c d |
        e2 d2. c4 b e2 d8 c a'2. g4 e2 |
        g2. fs4 d e f2 e2. d4 c2. b4 g2 b1 a2~ |
        
        a2 a g2. a8 b c2. b8 a b2~ b2~ |
        b4 a8 g a1 a2 g c2. b8 a b2~ |
        b8 c16 d e2 e d4 b2 <a c>2. \orn b8 a |
        g4 f8 e a4 g8 f e4 fs g a b a8 g fs4 gs a4 g8 f e4 d8 c |
        
        e'4 d8 c b4 a2 b4 gs2 a4 g8 f c'4 b8 a g4 a b cs |
        d4 cs8 b a4 g8 f a4 b c d e fs g fs8 e |
        ds2 e1 ds2 e2~ e4. d8 |
        c4. b8 a4 g8 f e4 f g2 a4 b c2 |
        
        b4 c d c8 b a4 b c b8 a |
        gs4 a b a8 g fs4 g a g8 f e4 a2 gs4 |
        a2 r4 r8 a4 g8 a4 \orn fs r8 d'4 c8 d4 \orn b g~ |
        g8 fs8 g4 \orn e r8 c'4 b8 c4 <f, a>2 <e g> g |
        
        f4 s4 a2 \orn gs4. a8 b4 e4. d8 e4 \orn cs4 r8 a'4 g8 a4 \orn fs d~ |
        d8 c8 d4 \orn b r8 g'4 fs8 g4 <c, e>2 <b d> <a c> b4 e4. d8 c4 |
        f4 e d2 e1 r4 c4 f4. e8 d4 d g4. f8 |
        e4 e a4. g8 f2 e4 d e2 r4 c4 |
        
        d4. c8 b2 c4 g c4. b8 a4 a d b c a4. g8 e8 fs |
        gs4 a2 gs4 a e4 fs4. g8 d4 d g4. fs8 e4 e a f g e e2 |
        <cs e>\breve \fermata |
    }
    
voiceII = 
    \relative e' {
        \context Voice = "II"
        \voiceTwo
        \set fingeringOrientations = #'(up)
       
        \oneVoice
        r1*2 \orn e1 a,2 c |
        \orn g2. a8 b c4 \orn b  g a \orn b c \voiceTwo d2~ | \noBreak
        d4 \orn c8 b a4 b 
        << \cus c2 { 
            \down \voiceOne c2. \orn b4 a2 \orn a2. g4 a b 
        } >> | \break
        \up \voiceTwo c2 c2. b4 a2. g4 e f8 g a4 g e fs gs a2 \orn gs4 |
        s2 d'2 \orn e2. fs4 g2. fs4 |
        
        e1. e2 d1 e4. d8 b4 cs ds e2 \orn ds4 |
        s2 e1 \orn gs2 a d c2. b4 a1 |
        a2 a2. g8 f e4 f8 g a4 g e fs gs a2 gs4 |
        s1 s2 f2 \orn e4 d e fs g2 fs e e~ |
        
        e4 d e fs g1 s2. g4 a b \orn c2 |
        b2. a4 b cs d b c?2 a4 b |
        c2 b2 \cus a2 s2 |
        c2 b2. a8 g a2 b1 g2. fs4 |
        e2 e2. d4 e fs g2 fs4 b2 a4 b cs |
        
        d2 c b a g4 e e2 d4 b b2 |
        e1 e2~ e r2 e2. d4 << \cus b2 b'2~ >> |
        b4 a fs2 gs e2. d4 b2 c d2. d4 a'1 <g~ b>2 |
        g4 fs4 d2 fs2 e1 \orn ds2 e1 e2 g2 |
        
        fs2 fs b2. a4 fs2 g1 fs2. e4 cs2 |
        d1 e2. d4 b2 << \cus c2 a'1 >> g2. fs4 d g~ |
        g8 e8 e4. fs8 b4 gs a2 gs4 a2 d1 c2~ |
        c4 b4 g a b2 a1 \orn gs2 a e2 e2. d4 b2 c |
        
        a2. b4 c b e2. d8 c f2. e8 d e2~ |
        e2 e2. d8 c d2 e s1 d4. e16 f |
        g2 e8 fs16 g a2 fs4 gs2 e2. r4 |
        s2 d2 c4 d e d8 c b4 cs d2 cs4 \cus b4 s2 |
        
        s2 g'4 fs8 e g4 fs e d s2 e4 s4 e4 fs
        << \new Voice { \voiceThree g2 } { d4 e } >> |
        fs2 s2 e4 g8 fs e4 f g a b2~ |
        b4 a8 g fs g e4 r4 d'8 cs b4 a gs a2 gs4 |
        <e a>2 s2*2 d2 c4 d e fs |
        
        g4 fs8 e d4 e f e8 d c4 d |
        e4 d8 c b4 cs d c8 b a4 b c2 r4 e4~ |
        e8 d8 e4 \orn cs a s4*3 d4 s1 |
        s4*3 c4 s2 c2 c <b d> |
        
        s4 e2 d4 e1 s4*3 a4 s1 |
        s4*3 g4 s2 g2 g2 e2 g a4. g8 |
        a8 b c2 b4 c g c4. b8 a2 r4 a4 b4. a8 g4 g |
        c4. b8 a4 a d d4. c8 b a g4 g a4. g8 |
        
        fs2 g4 d e2. e4 fs4. e8 d4 e4. d8 d2 c4 |
        b4 c b2 a2. a4 b4. a8 g4 g c4. b8 a4 b4. a8 a2 gs4 |
        a\breve |
    }
    
voiceIII =
    \relative a {
        \context Voice = "III"
        \oneVoice
        \set fingeringOrientations = #'(down)
        \orn a1 e2 g c,2. d8 e f4 \orn e c d |
        e2. d4 c d e f g2. \orn f8 e |
        d4 e f g \voiceTwo a2 e f2. e4 d e f2 \voiceOne |
        << \cus c'2 e,2 >> \orn e1 a,4 b c2. b4 a b c2 b4 a e'2~ |
        e2 f g a g4. a8 b2 |
        
        e,2. fs8 g a4 g e \orn fs4 g2. fs4 e fs g2 \orn fs4 e <fs b~>2 |
        b4 b4 \orn c2. \orn b8 a b2 r2 f'2 c4. d8 e2 a,2. b8 c |
        d4 c a b c2. b4 a b c2 \orn b4 a b e8 d |
        \orn c4 b c2 d << \cus f a, >> r2 a2. g4 a b c2 b |
        
        a4. b8 c4 d \orn e2 d2. c4 d e \orn fs2 e~ |
        e4 \orn d4 e fs \orn g2 fs2. e4 fs g |
        s1 a2. b4 |
        s1 s2 e,4 fs \orn g2 fs2 e2. d4 |
        c2 b a r4 a2 \orn g4 a b c2 b4 e~ |
        
        e4 d \orn e fs g4. fs8 \orn e d 
        e4. d8 c4 \orn b8 a b4. a8 g4 \orn fs8 e fs4 |
        e1 e2 s1*2 b'2 |
        c2 d e a,1 \orn gs2 a b1 e,4 c' b2~ b2~ |
        b4 a4 fs2. g4 a g \orn fs e <fs b>2. b4 \orn c2. b4 g2 |
        
        a2 b g a b1 a g2 fs~ |
        fs4 e8 d b'2. a4 fs2 g <a c> a e'2. d4 b2 |
        s1*3 e2~ e2~ |
        e4 d4 b2. c4 d c \orn b a b2 a2. g4 e2. fs4 g2 f4 e~ |
        
        e4 d8 c d2 e2 e \orn a1 g2. a8 b |
        c1. \orn b4 a b c8 d e2 d1 |
        r4 g,8 a16 b c4. b16 a \orn b4 a b2 a2. g8 f |
        e4 s4 a4 b s1 s1 s4 b8 a g4 fs |
        
        <gs b>4 a b c b d cs b a b c d s1 |
        r2 a4 b c d \cus e4 s4 c4 b8 a g4 a |
        b2. a8 g fs4 e b'2. c8 d e2 |
        a,2 c4 b8 a g4 f8 e d4 e f e8 d c4 b8 a |
        
        g4 a b c d c8 b a4 g8 f |
        e4 fs g fs8 e d4 e f e8 d c4 s4 e'2 |
        e1 d4 r8 d4 c8 d4 d1 |
        c4 r8 c4 b8 c4 c2~ c2 s1 |
        
        a'8 b c2 \orn b8 a b1 a4 r8 a4 g8 s4 a1 |
        g4 r8 g4 fs8 g4 e4 g1 s2. s1 | 
        s2 g'4. f8 e2 r4 c4 \orn f4. e8 d4. c8 b4 b e4. d8 |
        c4 c f4. e8 d4 d g4. f8 <c e>4. b8 a2~ |
        
        a2 \orn g4. f8 e4 e a4. g8 fs2 g2. f4 e2~ |
        e4 a,4 e'4. d8 cs4 cs d4. c8 b4 b e4. d8 c2 d4 d2 c4  \orn b2 |
        <e, a>\breve \fermata |
    }
    

voiceIV =
    \relative a, {
        \context Voice = "IV"
        \voiceTwo
        s1 * 4 |
        s1 * 3 |
        s1 * 4 |
        a1 e2  f c2. d8 e f4 e c d e1 |
        a2 f c' a e' b |
        
        c4. d8 e2 a,2 c g2. a8 b c4 b g a b1 |
        e1 e1 f2. g4 a2 e f4. g8 a2 |
        d,2 f c2. d8 e f4 e c d e1 |
        a2. g4 f e d2 a1 e'2. d4 e fs g e |
        
        f2 a g2. fs4 g a b c a1 |
        \clef treble b1 b1 a1 |
        \orn a'2 
        \tag #'scoreOnly { \afterGrace g2^\trill { f16[ e] } }
        \tag #'midiOnly { a16[ g a g a g f e] }
        f4 e f2 \clef bass | 
        e2. e4 \orn d2 c2 b1 e,4 fs g2 |
        a2 e4. d8 c4 b a2 e' r1 e2 |
        
        b'2 a g a e1 b |
        c2. b4 a2 \orn a'2. g4 e2 fs g |
        a2 b2~ b e,1 e2~ e2. d4 b2 c d e |
        b1 d2 a b1 e1. e2~ |
        
        e2 ds e fs b,2. b4 c2 d g, a |
        b1 c2 d e1 e1 s1 |
        c'2 d e1 f2. e8 d a2. g4 |
        e1 g2 d e1 a,2 c2. b4 g1 a2 |
        
        f1 e s1 s1 |
        c'2. d8 e f1 e2. e4 f d4. e16 f g4 |
        e1 e a,2. b4 |
        c4 d8 e f4 g a4 g8 fs e4 fs g fs8 e d4 cs8 b a4 b c d |
        
        e1~ e4 d e2 f4 g a b c b8 a g4 fs8 e |
        d4 e f g a2. g8 f e2. d8 c |
        << { b1 b1 e1 } \new Voice { \voiceFour s1. fs2. a4 b2 } >> |
        a,2~ a c bf a1 |
        
        g1 f |
        s1*2 s4 c'8 d e d e4 |
        cs4 a4. g8 a4 fs d s2 b'4 g4. fs8 g4 |
        e4 c s2 a'4 f4. g8 a b c d e f g a b g |
        
        a4. g8 f2 e4 e4. d8 e4 cs a s4 a'4 fs d4. c8 d4 |
        b4 g s2. c4. d8 e f g a b g a b c d e f g e f4. e8 |
        d4 c r4 g4 c4. b8 a2 s2 r4 d,4 g4. fs8 e4 e |
        a4. g8 f4 f bf4. a8 g4 g r4 c,4 f4. e8 |
        
        d4 d r4 g,4 c4. b8 a4 a d4. c8 b4 g a1 |
        e2. e4 a4. g8 fs4 d g4. fs8 e4 e a4. g8 f4 d e1 |
        a,\breve |
    }
    
    
theMusic =  
\context PianoStaff <<
    \context Staff = "treble" <<
        \removeWithTag #'lower \global 
        \clef treble
        \voiceI
        \voiceII
    >>
    \context Staff = "bass" <<
        \global
        \clef bass
        \voiceIII
        \voiceIV
    >>
    >>
    
% a different staff for each voice
midiMusic =  
\context StaffGroup <<
	\context Staff = "treble" <<
	    \removeWithTag #'lower \global 
	    \clef treble
	    \voiceI
	>>
	\context Staff = "treble II" <<
	    \removeWithTag #'lower \global 
	    \clef treble
	    \voiceII 
	>>
	\context Staff = "bass" <<
	    \global
	    \clef bass
        \voiceIII
	>>
	\context Staff = "bass  II" <<
	    \global
	    \clef bass
        \voiceIV
	>>
    >>
    
\score {
  %\removeWithTag #'incipit \theMusic
  \removeWithTag #'midiOnly \theMusic
  \layout {
    \context {
      \Score
      \override MetronomeMark #'transparent = ##t
      \override BarNumber #'padding = #2
      \override BarNumber #'stencil = #bar-number-print
      %\override BarLine #'transparent = ##t
      %\remove "System_start_delimiter_engraver"
    }
    \context {
      \Voice
      \override StemTremolo #'beam-thickness = #.25
      \override Accidental #'cautionary-style = #'smaller  
      %\remove "Note_heads_engraver"
      %\consists "Completion_heads_engraver"
      \override NoteHead #'style = #'baroque
    }
    \context {
      \Staff
      %\remove "Time_signature_engraver"
      \consists "Custos_engraver"
      \override Custos #'style = #'mensural
      \override Custos #'stencil = #(lambda (grob)
          (interpret-markup
               (ly:grob-layout grob)
               '(())
               (markup #:musicglyph "custodes.mensural.u0" )))
      \override Custos #'X-offset = #-3.2
      \override Custos #'extra-offset = #'(1.2 . 0.0)
      \override Custos #'space-alist = #'((right-edge minimum-distance . 0 ))
    }
  }
}

\score {
  %\unfoldRepeats 
  \removeWithTag #'scoreOnly \midiMusic
  
  \midi {
    \context {
      \Score
      tempoWholesPerMinute = #(ly:make-moment 144 4)
      }
    }



 }
