\version "2.22.1"                         % please include a version statement. 
                                          % to find version, type "lilypond -v" from the command line
#(ly:set-option 'anti-alias-factor '8)    % improves resolution when PNG files are output 
#(set-global-staff-size 58)               % you will want to play with this setting
#(set! paper-alist (cons '("my size" . (cons (* 200 in) (* 5.71 in))) paper-alist))  % defining custom paper size

\header { tagline = ##f }                 % suppresses the printing of a default footer text at bottom of page 

\paper{
  #(set-paper-size "my size")   % paper-size must be set to the custom size we defined, above       
  top-margin = 0\in             % I frequently tweak the top margin to get the spacing correct 
  bottom-margin = 0\in          % when margins are not defined, they revert to default values 
  left-margin = 0\in            % right-margin can also be defined
  system-count = #1             % set this to #1 to suppress line breaks, keeping music on one line
  %%line-width = 35\in          % commented out.  Uncommenting with force output to this width
  ragged-right = ##t            % prevents music lines from stretching out to the right margin.  
}

\layout {                  % the layout block overrided defaults about document layout. 
  indent = 10.15\in        % 10.15 inches is about the length of a video frame, allowing title to be displayed, alone   
  \numericTimeSignature    % My preference is "4/4" rather than the default "C". Comment out if you like "C" 
  \context {               
    \Score
    proportionalNotationDuration = #(ly:make-moment 1/5)    % this fraction determines note spacing.    
    \override SpacingSpanner.uniform-stretching = ##t       % must be set to ##t for proportional scores
  }
  \override Score.SpacingSpanner.strict-note-spacing = ##t  % ##t tends to crowd barlines.  Try ##f if barlines too crowded.
  \override Score.BarLine.extra-offset = #'(-0 . 0)         % adjusts bar lines by X and Y amount.  May need to play with
  \override Staff.VerticalAxisGroup.default-staff-staff-spacing = % adjust 3 values, below, to change vertical spacing.
  #'((basic-distance . 3.3)    
     (minimum-distance . 3.3)  
     (padding . 3.3))         
  \override Score.RehearsalMark.X-offset = #-8              % In these two lines, the rehearsal mark is moved to the
  \override Score.RehearsalMark.Y-offset = #-9.5            %    left and down, creating the title.  Adjust if necessary. 
  \override Score.RehearsalMark.Y-extent = ##f              % keeps the moved rehearsal mark (title) from
  \override Score.RehearsalMark.X-extent = ##f              %    unintentionally shifting the the music around
  \override Staff.InstrumentName.self-alignment-X = #RIGHT  % keeps the instrument name justified right
  \override Score.SystemStartBar.collapse-height = #40      % CHECK ON THIS. AM I USING/NOT USING system start bar?
  \override Score.StaffSymbol.thickness = #1.5              % at large global-staff-size, staff-lines get too thin.  Adjust.  
  \override Score.NoteHead.Y-extent = #'(-0.5 . 0.5)        % prevents fatter easy heads from changing vertical spacing. 
}

final = { \once\override Score.BarLine.extra-offset = #'(-0 . 0)  \bar "|."} %% fixes position of final barline

melody = \relative c' {     % \relative c' makes all the notes relative to middle c.  Important command
  \key d \major \time 4/4   % key and time signature set
  fis4 e d e | fis4 fis fis2 | e4 e e2 | fis4 fis fis2 |  % duration numbers only needed when change of duration
  fis4 e d e | fis4 fis fis fis | e4 e fis e | d1 \final % \final was defined, above. 
} 

violin = \melody                  % We already defined "melody" above. This is a unison piece  
viola = \melody                   % If there were separate parts, these definitions will contain music. 
cello = \transpose c c, \melody   % the cello needs to be transposed down one octave.  

%% LilyPond is built on top of a computer language called "scheme".  The following is a scheme definition.
%% Later in this file, the command "\violinViolaCello" will be used.  
%% The command takes four "arguments": 1. Title, 2. violinPart, 3. violaPart, 4. celloPart
%% The purpose of this scheme definition is to prevent having to type code in more than once. 
violinViolaCello =
#(define-music-function                        
  (parser location title violinPart violaPart celloPart)   
  (markup? ly:music? ly:music? ly:music?)
  #{  
  <<              % Simultaneous music is enclosed by << and >>
  \new Staff {
  \mark #title    % #title is argument #1.  It is replaced by whatever markup definition is used for the title
  \clef treble
  #violinPart     % #violinPart is argument #2. 
}
  \new Staff {
  \clef alto
  #violaPart      % #violaPart is argument #3
}
  \new Staff {
  \clef bass
  #celloPart      % #celloPart is argument #4 
}
>>                % Here are the closing >> for the simultaneous music 
  #})



redLine = {                                             % this definition will be used in the "mary-overlay.pdf" file
  s8                                                    % adjust the duration to move the red line left or right.  
  \once\override Score.BarLine.color = #red             % makes the barline red.  Change if you wish.  
  \override Score.BarLine.hair-thickness = #3           % adjust to make red line thinner or thicker
  \once\override Score.BarLine.extra-offset = #'(0 . 0) % change first number in case red line needs to move more.  
  \once\override Score.BarLine.transparent = ##f        % makes this the ONLY barline to print in the overlay file 
  \once\override Score.BarNumber.stencil = ##f          % suppresses possible printing of bar number over red line 
  \bar "|"                                              % this is the barline that creates the red line.  
}  

mytitle = \markup \fontsize #6 \sans \line { % adjust fontsize to change size of title    
  \hspace #-24                               % Adjust to fit title between 0 and 10.14 inches horizontally
  \column{                                   % BEGIN column 
    \line {\vspace #0.5 }                    % adjusts vertical position of top line of title
    \line {"Mary Had a"}                     % line 1 of the title
    \line {\vspace #0.2 }                    % slight vertical space added between lines of title 
    \line {"Little Lamb"}                    % line 2 of the title 
  }                                          % END column
}                                            % closing bracket (all brackets must be balanced or LilyPond fails) 

\book {    
  \score {
    \layout {
      \easyHeadsOn \override Score.NoteHead.font-size = #3.3 % makes easy heads FATTER
    }
    \bookOutputSuffix "easy"                                 % output file "mary-easy.pdf" created 
    \violinViolaCello \mytitle \violin \viola \cello         % \violinViolaCello takes 4 "arguments"
  } 
} 

\book {
  \bookOutputSuffix "staff"                                  % output file "mary-staff.pdf" created
  \violinViolaCello \mytitle \violin \viola \cello           % \violinViolaCello takes 4 "arguments"
}

\book {
  \bookOutputSuffix "overlay"                                % output file "mary-overlay.pdf" created
  \score {                                                    
    \layout { \include "disappear.ly" } % 1. put "disappear.ly"  directory with mary.ly, or use "full/path/to/disappear.ly"    
    \violinViolaCello \mytitle { << \violin \redLine >> } \viola \cello % \violin and \redLine are simultaneous music 
  }
}


