Next: , Previous: Ancient notation, Up: Top


Contexts and engravers

adding-a-figured-bass-above-or-below-the-notes.ly

When writing a figured bass, here's a way to specify if you want your figures to be placed above or below the bass notes, by defining the BassFigureAlignmentPositioning #'direction property (exclusively in a Staff context). Choices are #UP (or #1), #CENTER (or #0) and #DOWN (or #-1).

As you can see here, this property can be changed as many times as you wish. Use \once \override if you dont want the tweak to apply to the whole score.

bass = { \clef bass g4 b, c d e d8 c d2}
continuo = \figuremode {
         < _ >4 < 6 >8   
   \once \override Staff.BassFigureAlignmentPositioning #'direction = #CENTER
         <5/>  < _ >4 
   \override Staff.BassFigureAlignmentPositioning #'direction = #UP
         < _+ > < 6 >
   \set Staff.useBassFigureExtenders = ##t
   \override Staff.BassFigureAlignmentPositioning #'direction = #DOWN
         < 4 >4. < 4 >8 < _+ >4
       } 
\score {
    << \new Staff = bassStaff \bass 
    \context Staff = bassStaff \continuo >>
}

[image of music]

adding-an-extra-staff.ly

You can add (possibly temporarily) an extra staff after the beginning of a piece.

\score {
	<<
		\new Staff \relative c''{ c1 c c c c }
		\new StaffGroup \relative c''{ 
			\new Staff 
			c1 c
			<< c1 \new Staff { c1 } >>
			c
		}
	>>
  	\layout {
		
		\context{
			\Score

		}
	}
}





[image of music]

adding-and-extra-staff-at-a-line-break.ly

When adding a new Staff at a line break, LilyPond will unfortunately add some extra space at the end of the line before the break (to fit in a key signature change, which will never be printed anyway). The workaround is to add a setting of Staff.explicitKeySignatureVisibility as is shown in the example. In version 2.10 and earlier, you have to do a similar setting for the time signatures, see the example.

\score {
  \new StaffGroup \relative c''{ 
    \new Staff 
    \key f \major
    c1 c^"Unwanted extra space" \break 
    << { c1 c }
       \new Staff { 
         \key f \major
         c1 c 
       } 
    >>
    c1 c^"Fixed here" \break 
    << { c1 c }
       \new Staff { 
         \once \set Staff.explicitKeySignatureVisibility = #end-of-line-invisible 
         %The next line is not needed in 2.11.x or later:
         \once \override Staff.TimeSignature #'break-visibility = #end-of-line-invisible 
        \key f \major
         c1 c 
       } 
    >>
  }
}

[image of music]

changing-time-signatures-inside-a-polymetric-section-using--compressmusic.ly

The measureLength variable, together with measurePosition, determines when a barline is needed. However, when using \compressMusic, the scaling of durations makes it difficult to change time signatures without making a mess of it.

Therefore, measureLength has to be set manually, using the ly:make-moment callback. The second argument has to be the same as the second argument of \compressMusic.

\layout {
 \context { \Score
    \remove "Timing_translator"
    \remove "Default_bar_line_engraver"
 }
 \context {
   \Staff
   \consists "Timing_translator"
   \consists "Default_bar_line_engraver"
 }
}

<<
 \new Staff {
   \compressMusic #'( 8 . 5 ) {
     \time 6/8
     \set Timing.measureLength = #(ly:make-moment 3 5)
     b8 b b b b b
     \time 2/4
     \set Timing.measureLength = #(ly:make-moment 2 5)
     b4 b
     }
   }
 \new Staff {
   \clef bass
   \time 2/4
   c2 d e f  }
 >>

[image of music]

chant-or-psalms-notation.ly

This form of notation is used for the chant of the Psalms, where verses aren't always the same length.

stemon = { \override Staff.Stem #'transparent = ##f }
stemoff = { \override Staff.Stem #'transparent = ##t }

\score {
\new Staff \with {\remove "Time_signature_engraver" }
{
	\key g \minor
	\set Score.timing = ##f
	\stemoff a'\breve bes'4 g'4
	\stemon a'2 \bar "||"
	\stemoff a'\breve g'4 a'4
	\stemon f'2 \bar "||"
	\stemoff a'\breve^\markup { \italic flexe }
	\stemon g'2 \bar "||"
}
\layout { raggedright = ##t}
}

[image of music]

creating-blank-staves.ly

To create blank staves, you must generate empty measures, removing also from the Score context the Bar_number_engraver, and from the Staff context the Time_signature_engraver, the Clef_engraver and the Bar_engraver.

#(set-global-staff-size 20)

\score {
  { 
    \repeat unfold 12 { s1 \break } 
  }
  \layout {
    indent = 0\in
    \context {
      \Staff
      \remove Time_signature_engraver
      \remove Clef_engraver
      \remove Bar_engraver
    }
    \context {
      \Score
      \remove Bar_number_engraver
    }
  }
}

\paper {
  #(set-paper-size "letter")
  raggedlastbottom = ##f
  linewidth = 7.5\in
  leftmargin = 0.5\in
  bottommargin = 0.25\in
  topmargin = 0.25\in
}

[image of music]

engravers-one-by-one.ly

The notation problem, creating a certain symbol, is handled by plugins. Each plugin is called an Engraver. In this example, engravers are switched on one by one, in the following order:

- note heads

- staff symbol,

- clef,

- stem,

- beams, slurs, accents,

- accidentals, bar lines, time signature, and key signature.

Engravers are grouped. For example, note heads, slurs, beams etc. form a Voice context. Engravers for key, accidental, bar, etc. form a Staff context.

You may only see the first example in this document; please download this snippet and run it from your own computer.

%% sample music
topVoice =  \relative c' {
  \key d\major
  es8([ g] a[ fis])
  b4
  b16[-. b-. b-. cis-.]
  d4->
}

botVoice =  \relative c' {
  \key d\major
  c8[( f] b[ a)]
  es4
  es16[-. es-. es-. fis-.]
  b4->
}

hoom =  \relative c {
  \key d \major
  \clef bass
  g8-. r
  r4 
  fis8-.
  r8
  r4
  b'4->
}

pah =  \relative c' {
  r8 b-.
  r4
  r8 g8-.
  r16 g-. r8
  \clef treble
  fis'4->
}

%
% setup for Request->Element conversion. Guru-only
%

MyStaff =\context {
  \type "Engraver_group"
  \name Staff

  \description "Handles clefs, bar lines, keys, accidentals.  It can contain
@code{Voice} contexts."

  
  \consists "Output_property_engraver"	
  
  \consists "Font_size_engraver"

  \consists "Volta_engraver"
  \consists "Separating_line_group_engraver"	
  \consists "Dot_column_engraver"

  \consists "Ottava_spanner_engraver"
  \consists "Rest_collision_engraver"
  \consists "Piano_pedal_engraver"
  \consists "Piano_pedal_align_engraver"
  \consists "Instrument_name_engraver"
  \consists "Grob_pq_engraver"
  \consists "Forbid_line_break_engraver"
  \consists "Axis_group_engraver"

  \consists "Pitch_squash_engraver"

  \override VerticalAxisGroup #'minimum-Y-extent = #'(-6 . 6)
  extraVerticalExtent = ##f
  verticalExtent = ##f 
  localKeySignature = #'()

				% explicitly set instrument, so we don't get 
				% weird effects when doing instrument names for
				% piano staves

  instrumentName = #'()
  shortInstrumentName = #'()
  
  \accepts "Voice"
}


MyVoice = \context {
  \type "Engraver_group"
  \name Voice

  \description "
    Corresponds to a voice on a staff.  This context handles the
    conversion of dynamic signs, stems, beams, super- and subscripts,
    slurs, ties, and rests.

    You have to instantiate this explicitly if you want to have
    multiple voices on the same staff."

  localKeySignature = #'()
  \consists "Font_size_engraver"
  
				% must come before all
  \consists "Output_property_engraver"	
  \consists "Arpeggio_engraver"
  \consists "Multi_measure_rest_engraver"
  \consists "Text_spanner_engraver"
  \consists "Grob_pq_engraver"
  \consists "Note_head_line_engraver"
  \consists "Glissando_engraver"
  \consists "Ligature_bracket_engraver"
  \consists "Breathing_sign_engraver"
				% \consists "Rest_engraver"
  \consists "Grace_beam_engraver"
  \consists "New_fingering_engraver"
  \consists "Chord_tremolo_engraver"
  \consists "Percent_repeat_engraver"
  \consists "Slash_repeat_engraver"

%{
  Must come before text_engraver, but after note_column engraver.

%}
  \consists "Text_engraver"
  \consists "Dynamic_engraver"
  \consists "Fingering_engraver"

  \consists "Script_column_engraver"
  \consists "Rhythmic_column_engraver"
  \consists "Cluster_spanner_engraver"
  \consists "Tie_engraver"
  \consists "Tie_engraver"
  \consists "Tuplet_engraver"
  \consists "Note_heads_engraver"
  \consists "Rest_engraver"

  \consists "Skip_event_swallow_translator"
}


\score {
  \topVoice
  \layout {
    \context { \MyStaff }
    \context { \MyVoice }
  }
}


MyStaff = \context {
    \MyStaff
    \consists "Staff_symbol_engraver"
}

\score {
  \topVoice
  \layout {
      \context { \MyStaff }
      \context { \MyVoice }
            }
}

MyStaff = \context {
    \MyStaff
    \consists "Clef_engraver"
    \remove "Pitch_squash_engraver"
}

\score {
  \topVoice
  \layout {
    \context { \MyStaff }
    \context { \MyVoice }
  }
}

MyVoice = \context {
  \MyVoice
  \consists "Stem_engraver"
}

\score {
  \topVoice
  \layout {
    \context { \MyStaff }
    \context { \MyVoice }
  }
}

MyVoice = \context {
  \MyVoice
  \consists "Beam_engraver"
}

\score {
  \topVoice
  \layout {
    \context { \MyStaff }
    \context { \MyVoice }
  }
}

MyVoice= \context {
  \MyVoice
  \consists "Phrasing_slur_engraver"
  \consists "Slur_engraver"
  \consists "Script_engraver"
}


\score {
  \topVoice
  \layout {
    \context { \MyStaff }
    \context { \MyVoice }
  }
}

MyStaff = \context {
  \MyStaff
  \consists "Bar_engraver"
  \consists "Time_signature_engraver"
}

\score {
  \topVoice
  \layout {
    \context { \MyStaff }
    \context { \MyVoice }
  }
}

MyStaff = \context {
  \MyStaff
  \consists "Accidental_engraver"    
  \consists "Key_engraver"
}
\score {
  \topVoice
  \layout {
    \context { \MyStaff }
    \context { \MyVoice }
  }
}

[image of music]

vocal-ensemble-template-with-lyrics-aligned-below-and-above-the-staves.ly

This template is basically the same as the simple "Vocal ensemble" template, with the exception that here all the lyrics lines are placed using alignAboveContext and alignBelowContext.

global = {
           \key c \major
           \time 4/4
         }
         
         sopMusic = \relative c'' {
           c4 c c8[( b)] c4
         }
         sopWords = \lyricmode {
           hi hi hi hi
         }
         
         altoMusic = \relative c' {
           e4 f d e
         }
         altoWords =\lyricmode {
           ha ha ha ha
         }
         
         tenorMusic = \relative c' {
           g4 a f g
         }
         tenorWords = \lyricmode {
           hu hu hu hu
         }
         
         bassMusic = \relative c {
           c4 c g c
         }
         bassWords = \lyricmode {
           ho ho ho ho
         }
         
         \score {
           \new ChoirStaff <<
              \new Staff = women <<
                 \new Voice =
                   "sopranos" { \voiceOne << \global \sopMusic >> }
                 \new Voice =
                   "altos" { \voiceTwo << \global \altoMusic >> }
              >>
              \new Lyrics \with {alignAboveContext=women} \lyricsto sopranos \sopWords
              \new Lyrics \with {alignBelowContext=women} \lyricsto altos \altoWords
         % we could remove the line about this with the line below, since we want
         % the alto lyrics to be below the alto Voice anyway.
         %    \new Lyrics \lyricsto altos \altoWords
         
              \new Staff = men <<
                 \clef bass
                 \new Voice =
                   "tenors" { \voiceOne <<\global \tenorMusic >> }
                 \new Voice =
                   "basses" { \voiceTwo <<\global \bassMusic >> }
              >>
         
              \new Lyrics \with {alignAboveContext=men} \lyricsto tenors \tenorWords
              \new Lyrics \with {alignBelowContext=men} \lyricsto basses \bassWords
         % again, we could replace the line above this with the line below.
         %    \new Lyrics \lyricsto basses \bassWords
           >>
         
           \layout {
              \context {
                 % a little smaller so lyrics
                 % can be closer to the staff
                 \Staff
                 \override VerticalAxisGroup #'minimum-Y-extent = #'(-3 . 3)
              }
           }
         }
         
         
         \score {
           \new ChoirStaff <<
              \new Staff = women <<
                 \new Voice =
                   "sopranos" { \voiceOne << \global \sopMusic >> }
                 \new Voice =
                   "altos" { \voiceTwo << \global \altoMusic >> }
              >>
         
              \new Lyrics \with {alignAboveContext=women} \lyricsto sopranos \sopWords
              \new Lyrics \lyricsto altos \altoWords
         
              \new Staff = men <<
                 \clef bass
                 \new Voice =
                   "tenors" { \voiceOne <<\global \tenorMusic >> }
                 \new Voice =
                   "basses" { \voiceTwo <<\global \bassMusic >> }
              >>
         
              \new Lyrics \with {alignAboveContext=men} \lyricsto tenors \tenorWords
              \new Lyrics \lyricsto basses \bassWords
           >>
         
           \layout {
              \context {
                 % a little smaller so lyrics
                 % can be closer to the staff
                 \Staff
                 \override VerticalAxisGroup #'minimum-Y-extent = #'(-3 . 3)
              }
           }
         } 

[image of music]



Next: , Previous: Ancient notation, Up: Top

This page is for LilyPond-2.11.40 (development-branch).

Report errors to http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs.

Your suggestions for the documentation are welcome.