\version "2.10.10"

\include "english.ly"
\include "../mrlUtil.ly"
\include "../mrlSwash.ly"

#(ly:set-option 'point-and-click #f)

headerMarkup = \markup { "Gibbons:" \italic "The Queenes Command" } 

#(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 "Adobe Garamond Pro"
                          "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)," "xx" }
    title = \markup { \medium \italic \makeSwashMarkupG "The Queenes Command" }
    %title = \markup { \medium \italic \simple #(applySwashG "The Queenes Command") }
    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
#})
)

autobeamSetting = {
    #(override-auto-beam-setting '(end 1 8 6 4) 3 4)
    #(override-auto-beam-setting '(end 1 8 6 4) 6 4)
}

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 followVoice = ##t
  
  \set subdivideBeams = ##t
     
  #(ly:export (set-accidentals-properties #f '(Staff (same-octave . 0))
				   '(Staff (any-octave . 0)) 'Staff))
                   
  \autobeamSetting
  
  %\override NoteHead #'style = #'baroque
  \key c \major
  \time 6/4
  \repeat unfold 8
  {
      s1.*4
      \bar "||"
  }
  \bar "|."
}

up = \change Staff = treble
down = \change Staff = bass

voiceI = 
    \relative e'' {
        \context Voice = "I"
        \set fingeringOrientations = #'(up)
        \orn e4.-2 f8 g4 a2  g4 |
        \orn f4. g8 e4 \orn d2-3 d4-2 |
        \orn e4. g8 c,4-1 \orn b4.-3 d8 f,4-1 |
        \orn e4.-3 g8 d4 \orn c2.-3 |
        
        << { s4*5 g''4-3-5 | 
             f2-5 e4 d2.-4 } \\
           { \autobeamSetting \orn e8 d e f g e a a, c <d-1> e8 c  |
             r8 d8 a b c a b a b c \orn b g } >> |
        \orn e'8 g d f \orn e c \orn b d a c \orn b g |
        \orn a8 c \orn e, g d f \orn e4 c2 |
        
        \orn f'4-3 a a, \orn c-3 f, f' |
        \orn e4 g g, \orn c-5 c, c' |
        \orn b4-3 d f,-1 \orn e-2 c' \orn b |
        c4. g8 a4 \orn g2 e4 |
        
        \orn f'8 e f g a a, \orn c b c d c f, |
        \orn e'8 d e f \orn e c g' g, \orn c d \orn c g |
        \orn b a b c d f, e c' \orn b a b d, |
        c'4. g8 a4 \orn g2 e4 |
        
        e'16-4 d c b c d e-1 f g e f g a g f e d-3 c b c d e-1 f g |
        f16 e d-3 c b a-4 g f e f g a b a g fs g-1 a b c d-1 e f d |
        e16-2 g-4 f e d-1 f-4 e d c e d c b d c b a c b a g bf a g |
        f16 a g f e g f e d f e d e4 c2 |
        
        \orn e'4. f8 g4 a2 g4 |
        \orn f2 e4 \orn d2 d4 |
        \orn e4 g c, \orn b d f, |
        \orn e4 g d e c2 |
        
        f'16-4 e d c d e f-4 g-1 a-4 g f e f-4 e d c d e f d-1 g-4 f e d |
        e16-4 d c b c d e-1 f g e f g a g f e f-4 e d c d-4 c b a |
        b16-5 a g fs g-1 a b c d-1 e f g a-5 g f e d c-4 b a g f-4 e d |
        e16-3 d c-1 b-2 c-1 d e f g f e d \orn e4 c2 |
        
        \orn f'4 a a, \orn c f, f' |
        \orn e4 g g, \orn c c, c' |
        \orn b4 d f, \orn e g d |
        \orn e2. <g, c e>2. \fermata |
    }
    
    
voiceIII =
    \relative g, {
        \context Voice = "III"
        \voiceOne
        \set fingeringOrientations = #'(down)
        <g c>2. a4.-5-3 b8 c4 |
        a4. b8 c4 <b d>2. |
        g2 c4 d g d |
        r4 c4 \orn b <g c>2. |
        
        <g c>2. c2. |
        s2. d2 g4 |
        g,2 c4 d2 g4 |
        r4 c,4 b <g c>2. |
        
        r4 f'4 c r4 f c |
        r4 c4 g r4 c g |
        r4 g'4 d r4 g d |
        c2. c2. |
        
        r4 f4 c r4 f c |
        r4 c4 g r4 c g |
        r4 g'4 d r4 g d |
        c2. c2. |
        
        <g c>2. c-4-2-1 |
        a4. b8 c4 d2 g4 |
        g,2 c4 d2 g4 |
        r4 c,4 b <g c>2. |
        
        \stemNeutral
        \clef treble
        c''8-1 b16 a g-1 f e d 
        \clef bass
        c-1 b a g-1 f e d c-1 b a g-1 f e f g a-3 |
        b16 c d-4 e f g a-3 b 
        \clef treble
        c d-4 e f g a-3 b c d-2 c-1 b a g-1 f e d |
        \clef bass
        c16-1 b-4 c d e-1 d c b-4 c-1 d-4 e f g g, f'-1 e d c-1 b a g-1 f e d |
        c16-5 g'-1 f e d c-1 b a g-1 f e d c2 c4 |
        \stemUp
        
        r4 f'4 c r4 f c |
        r4 c4 g r4 c g |
        r4 g'4 d r4 g d |
        r4 c4 g r4 c g |
        
        \oneVoice
        r8 d16-4 e f e d c d e f g a-3 g a bf a-1 g f e f g a b-2 |
        c8 b16 a g-4 a-1 g f e f-1 e d c8-4 d16 e f g-4 a b c d-4 e f |
        g16 g, f'-1 e d c-1 b a g-1 f e d c g'-1 a-3 b c d-4 e f g a-3 b g |
        c8-1 b16 a g-4 a g f e f e d \voiceOne c2.\fermata |
    }
    

voiceIV =
    \relative c, {
        \context Voice = "IV"
        \voiceTwo
        c4. d8 e4 f2 e4 |
        d2 c4 g'2. |
        c,2. g'2. |
        c,2 g'4 c,2 c4 |
        
        c4. d8 e4 f2 e4 |
        d2 c4 g'2. |
        c,2. g'2. |
        c,2 g'4 c,2 c4 |
        
        f2. f |
        c2. c |
        g'2. g |
        r4 c,4 f e c2 |
        
        f2. f |
        c2. c |
        g'2. g |
        r4 c,4 f e c2 |
        
        c4. d8 e4 <f a>2 <e g>4 |
        d2 c4 g'2. |
        c,2. g'2. |
        c,2 g'4 c,2 c4 |
        
        s1.*4
        
        f2. f |
        c2. c |
        g'2. g |
        c,2. c |
        
        s1.*3
        s2. r4 c2\fermata |
    }
    
    
theMusic =  
\context PianoStaff <<
    \context Staff = "treble" <<
        \removeWithTag #'lower \global 
        \clef treble
        \voiceI
    >>
    \context Staff = "bass" <<
        \global
        \clef bass
        \voiceIII
        \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
      %\override NoteHead #'style = #'baroque
    }
    \context {
      \Staff
      %\remove "Time_signature_engraver"
    }
  }
}

\score {
  %\unfoldRepeats 
  \removeWithTag #'scoreOnly \theMusic
  
  \midi {
    \context {
      \Score
      tempoWholesPerMinute = #(ly:make-moment 120 4)
      }
    }



 }
