Tweaks and overrides

Changing defaults

Tweaking output


Adding an ottava marking to a single voice

If you have more than one voice on the staff, setting octavation in one voice transposes the position of notes in all voices for the duration of the ottava bracket. If the octavation is only intended to apply to one voice, the Ottava_spanner_engraver should be moved to Voice context.

\layout{
\context{
\Staff
\removeOttava_spanner_engraver
}
\context{
\Voice
\consistsOttava_spanner_engraver
}
}
{
\clefbass
<<{<gd'>1~q2<c'e'>}
\\
{
r2.
\ottava-1
<b,,,b,,>4~|
q2
\ottava0
<ce>2
}
>>
}

[image of music]


Adding links to objects

To add a link to a grob stencil you can use add-link as defined here. It works both with \override and \tweak.

Drawback: point-and-click is disturbed for the linked grobs.

Limitation: Works for PDF only.

The linked objects are colored with a separate command. Note that the links are not displayed and are not clickable from inside the LSR.

#(define(add-linkurl-strg)
(lambda(grob)
(let*((stil(ly:grob-propertygrob'stencil)))
(if(ly:stencil?stil)
(let*((x-ext(ly:stencil-extentstilX))
(y-ext(ly:stencil-extentstilY))
(url-expr`(url-link,url-strg,x-ext,y-ext))
(new-stil
(ly:stencil-add
(ly:make-stencilurl-exprx-exty-ext)
stil)))
(ly:grob-set-property!grob'stencilnew-stil))))))
%%%% test
%% For easier maintenance of this snippet the URL is formatted to use the
%% actually used LilyPond version.
%% Of course a literal URL would work as well.
#(definemajor.minor-version
(string-join(take(string-split(lilypond-version)#\.)2)"."))
urlI=
#(format#f
"http://lilypond.org/doc/v~a/Documentation/notation/writing-pitches"
major.minor-version)
urlII=
#(format#f
"http://lilypond.org/doc/v~a/Documentation/notation/rhythms"
major.minor-version)
urlIII=
#(format#f
"http://lilypond.org/doc/v~a/Documentation/notation/note-heads"
major.minor-version)
urlIV=
#(format#f
"http://lilypond.org/doc/v~a/Documentation/notation/beams"
major.minor-version)
urlV=
#(format#f
"http://lilypond.org/doc/v~a/Documentation/notation/note-head-styles"
major.minor-version)
urlVI=
#(format#f
"http://lilypond.org/doc/v~a/Documentation/notation/writing-pitches"
major.minor-version)
\relativec'{
\keycis\minor
\once\overrideStaff.Clef.color=#green
\once\overrideStaff.Clef.after-line-breaking=
#(add-linkurlI)
\once\overrideStaff.TimeSignature.color=#green
\once\overrideStaff.TimeSignature.after-line-breaking=
#(add-linkurlII)
\once\overrideNoteHead.color=#green
\once\overrideNoteHead.after-line-breaking=
#(add-linkurlIII)
cis'1
\once\overrideBeam.color=#green
\once\overrideBeam.after-line-breaking=
#(add-linkurlIV)
cis8disefisgis2
<gis,
\tweakAccidental.color#green
\tweakAccidental.after-line-breaking#(add-linkurlVI)
\tweakcolor#green
\tweakafter-line-breaking#(add-linkurlV)
\tweakstyle#'harmonic
bis
dis
fis
>1
<cis,cis'e>
}

[image of music]


Adding markups in a tablature

By default markups does not show in a tablature.

To make them appear, simply use the command \revert TabStaff.TextScript.stencil

%% http://lsr.di.unimi.it/LSR/Item?id=919
% by P.P.Schneider on June 2014
high={r4r8<gc'>qr8r4}
low={c4r4c8r8g,8b,}
pulse={s8^"1"s^"&"s^"2"s^"&"s^"3"s^"&"s^"4"s^"&"}
\score{
\newTabStaff{
\repeatunfold2<<\high\\\low\\\pulse>>
}
\layout{
\context{
\TabStaff
\clefmoderntab
\revertTextScript.stencil
\overrideTextScript.font-series=#'bold
\overrideTextScript.font-size=#-2
\overrideTextScript.color=#red
}
\context{
\Score
proportionalNotationDuration=#(ly:make-moment1/8)
}
}
}

[image of music]


Adding timing marks to long glissandi

Skipped beats in very long glissandi are sometimes indicated by timing marks, often consisting of stems without noteheads. Such stems can also be used to carry intermediate expression markings.

If the stems do not align well with the glissando, they may need to be repositioned slightly.

glissandoSkipOn={
\overrideNoteColumn.glissando-skip=##t
\hideNoteHead
\overrideNoteHead.no-ledgers=##t
}
glissandoSkipOff={
\revertNoteColumn.glissando-skip
\undo\hideNoteHead
\revertNoteHead.no-ledgers
}
\relativec''{
r8f8\glissando
\glissandoSkipOn
f4gaa8\noBeam
\glissandoSkipOff
a8
r8f8\glissando
\glissandoSkipOn
g4a8
\glissandoSkipOff
a8|
r4f\glissando\<
\glissandoSkipOn
a4\f\>
\glissandoSkipOff
b8\!r|
}

[image of music]


Adjusting grace note spacing

The space given to grace notes can be adjusted using the spacing-increment property of Score.GraceSpacing.

graceNotes={
\grace{c4c8c16c32}
c8
}
\relativec''{
c8
\graceNotes
\overrideScore.GraceSpacing.spacing-increment=#2.0
\graceNotes
\revertScore.GraceSpacing.spacing-increment
\graceNotes
}

[image of music]


Adjusting lyrics vertical spacing

This snippet shows how to bring the lyrics line closer to the staff.

% Default layout:
<<
\newStaff\newVoice=melody\relativec'{
c4def
g4fed
c1
}
\newLyrics\lyricstomelody{aaaaaaaaaaaaaaaaaa}
\newStaff{
\newVoice=melody\relativec'{
c4def
g4fed
c1
}
}
% Reducing the minimum space below the staff and above the lyrics:
\newLyrics\with{
\overrideVerticalAxisGroup.nonstaff-relatedstaff-spacing=
#'((basic-distance.1))
}
\lyricstomelody{aaaaaaaaaaaaaaaaaa}
>>

[image of music]


Altering the length of beamed stems

Stem lengths on beamed notes can be varied by overriding the beamed-lengths property of the details of the Stem. If a single value is used as an argument, the length applies to all stems. When multiple arguments are used, the first applies to eighth notes, the second to sixteenth notes and so on. The final argument also applies to all notes shorter than the note length of the final argument. Non-integer arguments may also be used.

\relativec''{
\overrideStem.details.beamed-lengths=#'(2)
a8[a]a16[a]a32[a]
\overrideStem.details.beamed-lengths=#'(81012)
a8[a]a16[a]a32[a]r8
\overrideStem.details.beamed-lengths=#'(8)
a8[a]
\overrideStem.details.beamed-lengths=#'(8.5)
a8[a]
\revertStem.details.beamed-lengths
a8[a]a16[a]a32[a]r16
}

[image of music]


Alternative bar numbering

Two alternative methods for bar numbering can be set, especially for when using repeated music.

\relativec'{
\setScore.alternativeNumberingStyle=#'numbers
\repeatvolta3{c4def|}
\alternative{
{c4def|c2d\break}
{f4gab|f4gab|f2a|\break}
{c4def|c2d}
}
c1\break
\setScore.alternativeNumberingStyle=#'numbers-with-letters
\repeatvolta3{c,4def|}
\alternative{
{c4def|c2d\break}
{f4gab|f4gab|f2a|\break}
{c4def|c2d}
}
c1
}

[image of music]


Analysis brackets above the staff

Simple horizontal analysis brackets are added below the staff by default. The following example shows a way to place them above the staff instead.

\layout{
\context{
\Voice
\consists"Horizontal_bracket_engraver"
}
}
\relativec''{
\once\overrideHorizontalBracket.direction=#UP
c2\startGroup
d2\stopGroup
}

[image of music]


Analysis brackets with labels

Text markup may be added to analysis brackets through the text property of the HorizontalBracketText grob. Adding different texts to brackets beginning at the same time requires the \tweak command.

Bracket text will be parenthesized after a line break.

\paper{tagline=##f}
\layout{
\context{
\Voice
\consists"Horizontal_bracket_engraver"
\overrideHorizontalBracket.direction=#UP
}
}
{
\once\overrideHorizontalBracketText.text="a"
c''\startGroupd''\stopGroup
\once\overrideHorizontalBracketText.text="a'"
e''\startGroupd''\stopGroup|
c''-\tweakHorizontalBracketText.text
\markup\bold\huge"b"\startGroup
-\tweakHorizontalBracketText.text"a"\startGroup
d''\stopGroup
e''-\tweakHorizontalBracketText.text"a'"\startGroup
d''\stopGroup\stopGroup|
c''-\tweakHorizontalBracketText.textfoo\startGroup
d''e''f''|\break
g''a''b''c'''\stopGroup
}

[image of music]


Asymmetric slurs

Slurs can be made asymmetric to match an asymmetric pattern of notes better.

slurNotes={d,8(a'dfaf'd,a)}
\relativec'{
\stemDown
\slurUp
\slurNotes
\once\overrideSlur.eccentricity=#3.0
\slurNotes
}

[image of music]


Caesura ("railtracks") with fermata

A caesura is sometimes denoted by a double “railtracks” breath mark with a fermata sign positioned above. This snippet shows an optically pleasing combination of railtracks and fermata.

\relativec''{
c2.
% construct the symbol
\overrideBreathingSign.text=\markup{
\override#'(direction.1)
\override#'(baseline-skip.1.8)
\dir-column{
\translate#'(0.155.0)
\center-align\musicglyph"scripts.caesura.curved"
\center-align\musicglyph"scripts.ufermata"
}
}
\breathec4
% set the breathe mark back to normal
\revertBreathingSign.text
c2.\breathec4
\bar"|."
}

[image of music]


Changing a single note’s size in a chord

Individual note heads in a chord can be modified with the \tweak command inside a chord, by altering the font-size property.

Inside the chord (within the brackets < >), before the note to be altered, place the \tweak command, followed by font-size and define the proper size like #-2 (a tiny note head).

\relativec'{
<\tweakfont-size#+2cegc
\tweakfont-size#-2e>1
^\markup{Atinye}_\markup{Abigc}
}

[image of music]


Changing beam thickness and spacing

To make beams thicker or thinner alter the Beam.beam-thickness property. To adjust the spacing between beams alter the Beam.length-fraction property.

\relativef'{
\time1/8
\overrideBeam.beam-thickness=#0.4
\overrideBeam.length-fraction=#0.8
c32ccc
\revertBeam.beam-thickness% 0.48 is default thickness
\revertBeam.length-fraction% 1.0 is default spacing
c32ccc
\overrideBeam.beam-thickness=#0.6
\overrideBeam.length-fraction=#1.3
c32ccc
}

[image of music]


Changing form of multi-measure rests

If there are ten or fewer measures of rests, a series of longa and breve rests (called in German “Kirchenpausen” - church rests) is printed within the staff; otherwise a simple line is shown. This default number of ten may be changed by overriding the expand-limit property.

\relativec''{
\compressMMRests{
R1*2|R1*5|R1*9
\overrideMultiMeasureRest.expand-limit=#3
R1*2|R1*5|R1*9
}
}

[image of music]


Changing properties for individual grobs

The \applyOutput command allows the tuning of any layout object, in any context. It requires a Scheme function with three arguments.

#(define(mc-squaredgrobgrob-origincontext)
(let((sp(ly:grob-propertygrob'staff-position)))
(ly:grob-set-property!
grob'stencil
(grob-interpret-markupgrob
#{\markup\lower#0.5
#(casesp
((-5)"m")
((-3)"c ")
((-2)#{\markup\teeny\bold2#})
(else"bla"))#}))))
\relativec'{
<dfgb>2
\applyOutputVoice.NoteHead#mc-squared
<dfgb>2
}

[image of music]


Changing text and spanner styles for text dynamics

The text used for crescendos and decrescendos can be changed by modifying the context properties crescendoText and decrescendoText.

The style of the spanner line can be changed by modifying the 'style property of DynamicTextSpanner. The default value is 'dashed-line, and other possible values include 'line, 'dotted-line and 'none.

\relativec''{
\setcrescendoText=\markup{\italic{cresc.poco}}
\setcrescendoSpanner=#'text
\overrideDynamicTextSpanner.style=#'dotted-line
a2\<a
a2a
a2a
a2a\mf
}

[image of music]


Changing the default text font family

The default font families for text can be overridden with make-pango-font-tree.

%{
You may have to install additional fonts.
Red Hat Fedora
 dejavu-fonts-all
Debian GNU/Linux, Ubuntu
 fonts-dejavu-core
 fonts-dejavu-extra
%}
\paper{
% change for other default global staff size.
myStaffSize=#20
%{
 run
 lilypond -dshow-available-fonts
 to show all fonts available in the process log.
 %}
#(definefonts
(make-pango-font-tree"DejaVu Serif"
"DejaVu Sans"
"DejaVu Sans Mono"
(/myStaffSize20)))
}
{
g'''4^\markup{
DejaVuSerif:\boldbold
\italicitalic
\italic\bold{bolditalic}
}
g4_\markup{
\override#'(font-family.sans){
DejaVuSans:\boldbold
\italicitalic
\italic\bold{bolditalic}
}
}
g''2^\markup{
\override#'(font-family.typewriter){
DejaVuSansMono:\boldbold
\italicitalic
\italic\bold{bolditalic}
}
}
}

[image of music]


Changing the staff size

Though the simplest way to resize staves is to use #(set-global-staff-size xx), an individual staff’s size can be changed by scaling the properties 'staff-space and fontSize.

<<
\newStaff{
\relativec''{
\dynamicDown
c8\ffccccccc
}
}
\newStaff\with{
fontSize=#-3
\overrideStaffSymbol.staff-space=#(magstep-3)
}{
\clefbass
c8cccc\fccc
}
>>

[image of music]


Changing the tempo without a metronome mark

To change the tempo in MIDI output without printing anything, make the metronome mark invisible.

\score{
\newStaff\relativec'{
\tempo4=160
c4egb
c4bdc
\setScore.tempoHideNote=##t
\tempo4=96
d,4fisacis
d4cised
}
\layout{}
\midi{}
}

[image of music]


Changing the text for sustain markings

Staff.pedalSustainStrings can be used to set the text used for pedal down and up. Note that the only valid strings are those found in the list of pedal glyphs - the values used this snippet constitute an exhaustive list.

sustainNotes={c4\sustainOnde\sustainOff\sustainOnf\sustainOff}
\relativec'{
\sustainNotes
\setStaff.pedalSustainStrings=#'("P""P-""-")
\sustainNotes
\setStaff.pedalSustainStrings=#'("d""de""e")
\sustainNotes
\setStaff.pedalSustainStrings=#'("M""M-""-")
\sustainNotes
\setStaff.pedalSustainStrings=#'("Ped""*Ped""*")
\sustainNotes
}

[image of music]


Controlling spanner visibility after a line break

The visibility of spanners which end on the first note following a line break is controlled by the after-line-breaking callback ly:spanner::kill-zero-spanned-time.

For objects such as glissandos and hairpins, the default behaviour is to hide the spanner after a break; disabling the callback will allow the left-broken span to be shown.

Conversely, spanners which are usually visible, such as text spans, can be hidden by enabling the callback.

\paper{ragged-right=##t}
\relativec''{
\overrideHairpin.to-barline=##f
\overrideGlissando.breakable=##t
% show hairpin
\overrideHairpin.after-line-breaking=##t
% hide text span
\overrideTextSpanner.after-line-breaking=
#ly:spanner::kill-zero-spanned-time
e2\<\startTextSpan
% show glissando
\overrideGlissando.after-line-breaking=##t
f2\glissando
\break
f,1\!\stopTextSpan
}

[image of music]


Controlling the vertical ordering of scripts

The vertical ordering of scripts is controlled with the 'script-priority property. The lower this number, the closer it will be put to the note. In this example, the TextScript (the sharp symbol) first has the lowest priority, so it is put lowest in the first example. In the second, the prall trill (the Script) has the lowest, so it is on the inside. When two objects have the same priority, the order in which they are entered determines which one comes first.

\relativec'''{
\once\overrideTextScript.script-priority=#-100
a2^\prall^\markup{\sharp}
\once\overrideScript.script-priority=#-100
a2^\prall^\markup{\sharp}
}

[image of music]


Controlling tuplet bracket visibility

The default behavior of tuplet bracket visibility is to print a bracket unless there is a beam of the same length as the tuplet.

To control the visibility of tuplet brackets, set the property 'bracket-visibility to either #t (always print a bracket), 'if-no-beam (only print a bracket if there is no beam), or #f (never print a bracket). The latter is in fact equivalent to omitting the TupletBracket object altogether from the printed output.

music=\relativec''{
\tuplet3/2{c16[de}f8]
\tuplet3/2{c8de}
\tuplet3/2{c4de}
}
\newVoice{
\relativec'{
\overrideScore.TextMark.non-musical=##f
\textMark"default"\music
\overrideTupletBracket.bracket-visibility=#'if-no-beam
\textMark\markup\typewriter"'if-no-beam"\music
\overrideTupletBracket.bracket-visibility=##t
\textMark\markup\typewriter"#t"\music
\overrideTupletBracket.bracket-visibility=##f
\textMark\markup\typewriter"#f"\music
\omitTupletBracket
\textMark\markup\typewriter"omit"\music
}
}

[image of music]


Creating a delayed turn

Creating a delayed turn, where the lower note of the turn uses the accidental, requires several overrides. The outside-staff-priority property must be set to #f, as otherwise this would take precedence over the avoid-slur property. Changing the fraction 2/3 adjusts the horizontal position.

\relativec''{
\after2*2/3\turnc2(d4)r|
\after4\turnc4.(d8)
\after4
{
\once\setsuggestAccidentals=##t
\once\overrideAccidentalSuggestion.outside-staff-priority=##f
\once\overrideAccidentalSuggestion.avoid-slur=#'inside
\once\overrideAccidentalSuggestion.font-size=-3
\once\overrideAccidentalSuggestion.script-priority=-1
\once\hideNotes
cis8\turn\noBeam
}
d4.(e8)
}

[image of music]


Creating custom key signatures

LilyPond supports custom key signatures. In this example, print for D minor with an extended range of printed flats.

\newStaff\with{
\overrideStaffSymbol.line-count=#8
\overrideKeySignature.flat-positions=#'((-7.6))
\overrideKeyCancellation.flat-positions=#'((-7.6))
% presumably sharps are also printed in both octaves
\overrideKeySignature.sharp-positions=#'((-6.7))
\overrideKeyCancellation.sharp-positions=#'((-6.7))
\overrideClef.stencil=#
(lambda(grob)(grob-interpret-markupgrob
#{\markup\combine
\musicglyph"clefs.C"
\translate#'(-3.-2)
\musicglyph"clefs.F"
#}))
clefPosition=#3
middleCPosition=#3
middleCClefPosition=#3
}
{
\keyd\minor
fbes,fbes,
}

[image of music]


Creating double-digit fingerings

Creating fingerings larger than 5 is possible.

\relativec'{
c1-10
c1-50
c1-36
c1-29
}

[image of music]


Creating text spanners

The \startTextSpan and \stopTextSpan commands allow the creation of text spanners as easily as pedal indications or octavations. Override some properties of the TextSpanner object to modify its output.

\paper{ragged-right=##f}
\relativec''{
\overrideTextSpanner.bound-details.left.text=#"bla"
\overrideTextSpanner.bound-details.right.text=#"blu"
a4\startTextSpan
b4c
a4\stopTextSpan
\overrideTextSpanner.style=#'line
\once\overrideTextSpanner.bound-details.left.stencil-align-dir-y=#CENTER
a4\startTextSpan
b4c
a4\stopTextSpan
\overrideTextSpanner.style=#'dashed-line
\overrideTextSpanner.bound-details.left.text=
\markup{\draw-line#'(0.1)}
\overrideTextSpanner.bound-details.right.text=
\markup{\draw-line#'(0.-2)}
\once\overrideTextSpanner.bound-details.right.padding=#-2
a4\startTextSpan
b4c
a4\stopTextSpan
\setStaff.middleCPosition=#-13
\overrideTextSpanner.dash-period=#10
\overrideTextSpanner.dash-fraction=#0.5
\overrideTextSpanner.thickness=#10
a4\startTextSpan
b4c
a4\stopTextSpan
}

[image of music]


Cross-staff chords - beaming problems workaround

Sometimes it is better to use stems from the upper staff for creating cross-staff chords, because no problems with automatic beam collision avoidance then arise. If the stems from the lower staff were used in the following example, it would be necessary to change the automatic beam collision avoidance settings so that it doesn’t detect collisions between staves using \override Staff.Beam.collision-voice-only = ##t

\newPianoStaff<<
\newStaff=up
\relativec'{
<<
{r4
\overrideStem.cross-staff=##t
\overrideStem.length=#19% this is in half-spaces,
% so it makes stems 9.5 staffspaces long
\overrideStem.Y-offset=#-6% stems are normally lengthened
% upwards, so here we must lower the stem by the amount
% equal to the lengthening - in this case (19 - 7) / 2
% (7 is default stem length)
eee}
{s4
\changeStaff="bottom"
\overrideNoteColumn.ignore-collision=##t
c,cc
}
>>
}
\newStaff=bottom
\relativec'{
\clefbass
\voiceOne
g8agagaga
}
>>

[image of music]


Cross staff stems

This snippet shows the use of the Span_stem_engraver and \crossStaff to connect stems across staves automatically.

The stem length need not be specified, as the variable distance between noteheads and staves is calculated automatically.

\layout{
\context{
\PianoStaff
\consists"Span_stem_engraver"
}
}
{
\newPianoStaff<<
\newStaff{
<bd'>4rd'16\>e'8.g8r\!
e'8f'g'4e'2
}
\newStaff{
\clefbass
\voiceOne
\autoBeamOff
\crossStaff{<eg>4e,g16a8.c8}d
\autoBeamOn
g8fg4c2
}
>>
}

[image of music]


Custodes

Custodes may be engraved in various styles.

\layout{ragged-right=##t}
\newStaff\with{\consists"Custos_engraver"}\relativec'{
\overrideStaff.Custos.neutral-position=#4
\overrideStaff.Custos.style=#'hufnagel
c1^"hufnagel"\break
<da'f'>1
\overrideStaff.Custos.style=#'medicaea
c1^"medicaea"\break
<da'f'>1
\overrideStaff.Custos.style=#'vaticana
c1^"vaticana"\break
<da'f'>1
\overrideStaff.Custos.style=#'mensural
c1^"mensural"\break
<da'f'>1
}

[image of music]


Customizing fretboard fret diagrams

Fret diagram properties can be set through 'fret-diagram-details. For FretBoard fret diagrams, overrides are applied to the FretBoards.FretBoard object. Like Voice, FretBoards is a bottom level context, therefore can be omitted in property overrides.

\include"predefined-guitar-fretboards.ly"
\storePredefinedDiagram#default-fret-table\chordmode{c'}
#guitar-tuning
#"x;1-1-(;3-2;3-3;3-4;1-1-);"
%shorthand
oo=#(define-music-function
(grob-pathvalue)
(list?scheme?)
#{\once\override$grob-path=#value#})
<<
\newChordNames{
\chordmode{c1|c|c|d}
}
\newFretBoards{
% Set global properties of fret diagram
\overrideFretBoards.FretBoard.size=#'1.2
\overrideFretBoard.fret-diagram-details.finger-code=#'in-dot
\overrideFretBoard.fret-diagram-details.dot-color=#'white
\chordmode{
c
\ooFretBoard.size#'1.0
\ooFretBoard.fret-diagram-details.barre-type#'straight
\ooFretBoard.fret-diagram-details.dot-color#'black
\ooFretBoard.fret-diagram-details.finger-code#'below-string
c'
\ooFretBoard.fret-diagram-details.barre-type#'none
\ooFretBoard.fret-diagram-details.number-type#'arabic
\ooFretBoard.fret-diagram-details.orientation#'landscape
\ooFretBoard.fret-diagram-details.mute-string#"M"
\ooFretBoard.fret-diagram-details.label-dir#LEFT
\ooFretBoard.fret-diagram-details.dot-color#'black
c'
\ooFretBoard.fret-diagram-details.finger-code#'below-string
\ooFretBoard.fret-diagram-details.dot-radius#0.35
\ooFretBoard.fret-diagram-details.dot-position#0.5
\ooFretBoard.fret-diagram-details.fret-count#3
d
}
}
\newVoice{
c'1|c'|c'|d'
}
>>

[image of music]


Customizing markup fret diagrams

Fret diagram properties can be set through 'fret-diagram-details. For markup fret diagrams, overrides can be applied to the Voice.TextScript object or directly to the markup.

<<
\chords{c1|c|c|d}
\newVoice="mel"{
\textLengthOn
% Set global properties of fret diagram
\overrideTextScript.size=#'1.2
\overrideTextScript.fret-diagram-details.finger-code=#'in-dot
\overrideTextScript.fret-diagram-details.dot-color=#'white
%% C major for guitar, no barre, using defaults
% terse style
c'1^\markup{\fret-diagram-terse"x;3-3;2-2;o;1-1;o;"}
%% C major for guitar, barred on third fret
% verbose style
% size 1.0
% roman fret label, finger labels below string, straight barre
c'1^\markup{
% standard size
\override#'(size.1.0){
\override#'(fret-diagram-details.(
(number-type.roman-lower)
(finger-code.in-dot)
(barre-type.straight))){
\fret-diagram-verbose#'((mute6)
(place-fret531)
(place-fret452)
(place-fret353)
(place-fret254)
(place-fret131)
(barre513))
}
}
}
%% C major for guitar, barred on third fret
% verbose style
% landscape orientation, arabic numbers, M for mute string
% no barre, fret label down or left, small mute label font
c'1^\markup{
\override#'(fret-diagram-details.(
(finger-code.below-string)
(number-type.arabic)
(label-dir.-1)
(mute-string."M")
(orientation.landscape)
(barre-type.none)
(xo-font-magnification.0.4)
(xo-padding.0.3))){
\fret-diagram-verbose#'((mute6)
(place-fret531)
(place-fret452)
(place-fret353)
(place-fret254)
(place-fret131)
(barre513))
}
}
%% simple D chord
% terse style
% larger dots, centered dots, fewer frets
% label below string
d'1^\markup{
\override#'(fret-diagram-details.(
(finger-code.below-string)
(dot-radius.0.35)
(dot-position.0.5)
(fret-count.3))){
\fret-diagram-terse"x;x;o;2-1;3-2;2-3;"
}
}
}
>>

[image of music]


Display bracket with only one staff in a system

If there is only one staff in one of the staff types ChoirStaff or StaffGroup, by default the bracket and the starting bar line will not be displayed. This can be changed by overriding collapse-height to set its value to be less than the number of staff lines in the staff.

Note that in contexts such as PianoStaff and GrandStaff where the systems begin with a brace instead of a bracket, another property has to be set, as shown on the second system in the example.

\score{
\newStaffGroup<<
% Must be lower than the actual number of staff lines
\overrideStaffGroup.SystemStartBracket.collapse-height=#4
\overrideScore.SystemStartBar.collapse-height=#4
\newStaff{
c'1
}
>>
}
\score{
\newPianoStaff<<
\overridePianoStaff.SystemStartBrace.collapse-height=#4
\overrideScore.SystemStartBar.collapse-height=#4
\newStaff{
c'1
}
>>
}

[image of music]


Displaying grob ancestry

When working with grob callbacks, it can be helpful to understand a grob’s ancestry. Most grobs have parents which influence the positioning of the grob. X- and Y-parents influence the horizontal and vertical positions for the grob, respectively. Additionally, each parent may have parents of its own.

Unfortunately, there are several aspects of a grob’s ancestry that can lead to confusion:

For example, the System grob can be both parent (on the Y-side) and grandparent (twice on the X-side) to a VerticalAlignment grob.

This macro prints (to the console) a textual representation of a grob’s ancestry.

When called this way:

{ \once \override NoteHead.before-line-breaking = #display-ancestry c }

The following output is generated:

NoteHead
X,Y: NoteColumn
 X: PaperColumn
 X,Y: System
 Y: VerticalAxisGroup
 X: NonMusicalPaperColumn
 X,Y: System
 Y: VerticalAlignment
 X: NonMusicalPaperColumn
 X,Y: System
 Y: System
%% http://lsr.di.unimi.it/LSR/Item?id=622
%% see also http://www.lilypond.org/doc/v2.18/Documentation/snippets/tweaks-and-overrides#tweaks-and-overrides-displaying-grob-ancestry
%% Remark:
%% grob::name is in the source since 2.19.x could be deleted during next LSR-upgrade
#(define(grob::namegrob)
(assq-ref(ly:grob-propertygrob'meta)'name))
#(define(get-ancestrygrob)
(if(not(null?(ly:grob-parentgrobX)))
(list(grob::namegrob)
(get-ancestry(ly:grob-parentgrobX))
(get-ancestry(ly:grob-parentgrobY)))
(grob::namegrob)))
#(define(format-ancestrylstpadding)
(string-append
(symbol->string(carlst))
"\n"
(let((X-ancestry
(if(list?(cadrlst))
(format-ancestry(cadrlst)(+padding3))
(symbol->string(cadrlst))))
(Y-ancestry
(if(list?(caddrlst))
(format-ancestry(caddrlst)(+padding3))
(symbol->string(caddrlst)))))
(if(equal?X-ancestryY-ancestry)
(string-append
(format#f"~&")
(make-stringpadding#\space)
"X,Y: "
(if(list?(cadrlst))
(format-ancestry(cadrlst)(+padding5))
(symbol->string(cadrlst))))
(string-append
(format#f"~&")
(make-stringpadding#\space)
"X: "X-ancestry
"\n"
(make-stringpadding#\space)
"Y: "Y-ancestry
(format#f"~&"))))
(format#f"~&")))
#(define(display-ancestrygrob)
(format(current-error-port)
"~3&~a~2%~a~&"
(make-string36#\-)
(if(ly:grob?grob)
(format-ancestry(get-ancestrygrob)0)
(format#f"~a is not a grob"grob))))
\relativec'{
\once\overrideNoteHead.before-line-breaking=#display-ancestry
f4
\once\overrideAccidental.before-line-breaking=#display-ancestry
\once\overrideArpeggio.before-line-breaking=#display-ancestry
<fasc>4\arpeggio
}

[image of music]


Dotted harmonics

Artificial harmonics using \harmonic do not show dots. To override this behavior, set the context property harmonicDots.

\relativec'''{
\time3/4
\keyf\major
\setharmonicDots=##t
<besf'\harmonic>2.~
<besf'\harmonic>4.<ae'\harmonic>8(<gisdis'\harmonic><gd'\harmonic>)
<fiscis'\harmonic>2.
<besf'\harmonic>2.
}

[image of music]


Drawing boxes around grobs

The print-function can be overridden to draw a box around an arbitrary grob.

\relativec''{
\overrideTextScript.stencil=
#(make-stencil-boxer0.10.3ly:text-interface::print)
c'4^"foo"
\overrideStem.stencil=
#(make-stencil-boxer0.050.25ly:stem::print)
\overrideScore.RehearsalMark.stencil=
#(make-stencil-boxer0.150.3ly:text-interface::print)
b8
\revertStem.stencil
\revertFlag.stencil
c4.c4
\mark\default
c1
}

[image of music]


Drawing circles around various objects

The \circle markup command draws circles around various objects, for example fingering indications. For other objects, specific tweaks may be required: this example demonstrates two strategies for rehearsal marks and measure numbers.

\relativec'{
c1
\setScore.rehearsalMarkFormatter=
#(lambda(markcontext)
(make-circle-markup(format-mark-numbersmarkcontext)))
\mark\default
c2d^\markup{
\override#'(thickness.3){
\circle\finger2
}
}
\overrideScore.BarNumber.break-visibility=#all-visible
\overrideScore.BarNumber.stencil=
#(make-stencil-circler0.10.25ly:text-interface::print)
}

[image of music]


Dynamics custom text spanner postfix

Postfix functions for custom crescendo text spanners. The spanners should start on the first note of the measure. One has to use -\mycresc, otherwise the spanner start will rather be assigned to the next note.

% Two functions for (de)crescendo spanners where you can explicitly
% give the spanner text.
mycresc=
#(define-music-function(mymarkup)(markup?)
(make-music'CrescendoEvent
'span-directionSTART
'span-type'text
'span-textmymarkup))
mydecresc=
#(define-music-function(mymarkup)(markup?)
(make-music'DecrescendoEvent
'span-directionSTART
'span-type'text
'span-textmymarkup))
\relativec'{
c4-\mycresc"custom cresc"c4c4c4|
c4c4c4c4|
c4-\mydecresc"custom decresc"c4c4c4|
c4c4\!c4c4
}

[image of music]


Dynamics text spanner postfix

Custom text spanners can be defined and used with hairpin and text crescendos. \< and \> produce hairpins by default, \cresc etc. produce text spanners by default.

% Some sample text dynamic spanners, to be used as postfix operators
crpoco=
#(make-music'CrescendoEvent
'span-directionSTART
'span-type'text
'span-text"cresc. poco a poco")
\relativec'{
c4\crescd4e4f4|
g4a4\!b4\crpococ4|
c4d4e4f4|
g4a4\!b4\<c4|
g4\dima4b4\decrescc4\!
}

[image of music]


Extending a TrillSpanner

For TrillSpanner, the minimum-length property becomes effective only if the set-spacing-rods procedure is called explicitly.

To do this, the springs-and-rods property should be set to ly:spanner::set-spacing-rods.

\relativec'{
\keyc\minor
\time2/4
c16(as')c,-.des-.
\once\overrideTrillSpanner.minimum-length=#15
\once\overrideTrillSpanner.springs-and-rods=#ly:spanner::set-spacing-rods
\afterGracees4
\startTrillSpan{d16[(\stopTrillSpanes)]}
c(c'gescg'esd
\hideNotes
c8)
}

[image of music]


Extending glissandi across repeats

A glissando which extends into several \alternative blocks can be simulated by adding a hidden grace note with a glissando at the start of each \alternative block. The grace note should be at the same pitch as the note which starts the initial glissando. This is implemented here with a music function which takes the pitch of the grace note as its argument.

Note that in polyphonic music the grace note must be matched with corresponding grace notes in all other voices.

repeatGliss=#(define-music-function(grace)
(ly:pitch?)
#{
% the next two lines ensure the glissando is long enough
% to be visible
\once\overrideGlissando.springs-and-rods
=#ly:spanner::set-spacing-rods
\once\overrideGlissando.minimum-length=#3.5
\once\hideNotes
\grace$grace\glissando
#})
\score{
\relativec''{
\repeatvolta3{c4def\glissando}
\alternative{
{g2d}
{\repeatGlissfg2e}
{\repeatGlissfe2d}
}
}
}
music=\relativec'{
\voiceOne
\repeatvolta2{
gabc\glissando
}
\alternative{
{d1}
{\repeatGlissc\once\omitStringNumbere12円}
}
}
\score{
\newStaffGroup<<
\newStaff<<
\newVoice{\clef"G_8"\music}
>>
\newTabStaff<<
\newTabVoice{\clef"moderntab"\music}
>>
>>
}

[image of music]


Fine-tuning pedal brackets

The appearance of pedal brackets may be altered in different ways.

\paper{ragged-right=##f}
\relativec''{
c2\sostenutoOnc
c2\sostenutoOffc
\once\overrideStaff.PianoPedalBracket.shorten-pair=#'(-7.-2)
c2\sostenutoOnc
c2\sostenutoOffc
\once\overrideStaff.PianoPedalBracket.edge-height=#'(0.3)
c2\sostenutoOnc
c2\sostenutoOffc
}

[image of music]


Flat Ties

The function takes the default Tie.stencil as an argument, calculating the result relying on the extents of this default.

Further tweaking is possible by overriding Tie.details.height-limit or with \shape. It’s also possible to change the custom-definition on the fly.

%% http://lsr.di.unimi.it/LSR/Item?id=1031
#(define((flared-tiecoords)grob)
(define(pair-to-listpair)
(list(carpair)(cdrpair)))
(define(normalize-coordsgoodsxydir)
(map
(lambda(coord)
;(coord-scale coord (cons x (* y dir)))
(cons(*x(carcoord))(*ydir(cdrcoord))))
goods))
(define(my-c-p-spointsthick)
(make-connected-path-stencil
points
thick
1.0
1.0
#f
#f))
;; outer let to trigger suicide
(let((sten(ly:tie::printgrob)))
(if(grob::is-live?grob)
(let*((layout(ly:grob-layoutgrob))
(line-thickness(ly:output-def-lookuplayout'line-thickness))
(thickness(ly:grob-propertygrob'thickness0.1))
(used-thick(*line-thicknessthickness))
(dir(ly:grob-propertygrob'direction))
(xex(ly:stencil-extentstenX))
(yex(ly:stencil-extentstenY))
(lenx(interval-lengthxex))
(leny(interval-lengthyex))
(xtrans(carxex))
(ytrans(if(>dir0)(caryex)(cdryex)))
(uplist
(mappair-to-list
(normalize-coordscoordslenx(*leny2)dir))))
(ly:stencil-translate
(my-c-p-suplistused-thick)
(consxtransytrans)))
'())))
#(defineflare-tie
(flared-tie'((0.0)(0.1.0.2)(0.9.0.2)(1.0.0.0))))
\layout{
\context{
\Voice
\overrideTie.stencil=#flare-tie
}
}
\paper{ragged-right=##f}
\relativec'{
a4~a
\overrideTie.height-limit=4
a'4~a
a'4~a
<a,,ceaceace>~q
\break
a'4~a
\once\overrideTie.details.height-limit=14
a4~a
\break
a4~a
\once\overrideTie.details.height-limit=0.5
a4~a
\break
a4~a
\shape#'((0.0)(0.0.4)(0.0.4)(0.0))Tie
a4~a
\break
a4~a
\once\overrideTie.stencil=
#(flared-tie'((0.0)(0.1.0.4)(0.9.0.4)(1.0.0.0)))
a4~a
a4~a
\once\overrideTie.stencil=
#(flared-tie'((0.0)(0.06.0.1)(0.94.0.1)(1.0.0.0)))
a4~a
}

[image of music]


Force a cancellation natural before accidentals

The following example shows how to force a natural sign before an accidental.

\relativec'{
\keyes\major
bescdes
\tweakAccidental.restore-first##t
eis
}

[image of music]


Forcing horizontal shift of notes

When the typesetting engine cannot cope, the following syntax can be used to override typesetting decisions. The units of measure used here are staff spaces.

\relativec'<<
{
<dg>2<dg>
}
\\
{
<bf'>2
\once\overrideNoteColumn.force-hshift=#1.7
<bf'>2
}
>>

[image of music]


Fret diagrams explained and developed

This snippet shows many possibilities for obtaining and tweaking fret diagrams.

<<
\chords{
a2a
\repeatunfold3{
cccdd
}
}
\newVoice="mel"{
\textLengthOn
% Set global properties of fret diagram
\overrideTextScript.size=#1.2
\overrideTextScript.fret-diagram-details.finger-code=#'below-string
\overrideTextScript.fret-diagram-details.dot-color=#'black
%% A chord for ukulele
a'2^\markup{
\override#'(fret-diagram-details.(
(string-count.4)
(dot-color.white)
(finger-code.in-dot))){
\fret-diagram"4-2-2;3-1-1;2-o;1-o;"
}
}
%% A chord for ukulele, with formatting defined in definition string
% 1.2 * size, 4 strings, 4 frets, fingerings below string
% dot radius .35 of fret spacing, dot position 0.55 of fret spacing
a'2^\markup{
\override#'(fret-diagram-details.(
(dot-color.white)
(open-string."o"))){
\fret-diagram"s:1.2;w:4;h:3;f:2;d:0.35;p:0.55;4-2-2;3-1-1;2-o;1-o;"
}
}
%% These chords will be in normal orientation
%% C major for guitar, barred on third fret
% verbose style
% roman fret label, finger labels below string, straight barre
c'2^\markup{
% 110% of default size
\override#'(size.1.1){
\override#'(fret-diagram-details.(
(number-type.roman-lower)
(finger-code.below-string)
(barre-type.straight))){
\fret-diagram-verbose#'((mute6)
(place-fret531)
(place-fret452)
(place-fret353)
(place-fret254)
(place-fret131)
(barre513))
}
}
}
%% C major for guitar, barred on third fret
%% Double barre used to test barre function
% verbose style
c'2^\markup{
% 110% of default size
\override#'(size.1.1){
\override#'(fret-diagram-details.(
(number-type.arabic)
(dot-label-font-mag.0.9)
(finger-code.in-dot)
(fret-label-font-mag.0.6)
(fret-label-vertical-offset.0)
(label-dir.-1)
(mute-string."M")
(xo-font-magnification.0.4)
(xo-padding.0.3))){
\fret-diagram-verbose#'((mute6)
(place-fret531)
(place-fret452)
(place-fret353)
(place-fret254)
(place-fret131)
(barre425)
(barre513))
}
}
}
%% C major for guitar, with capo on third fret
% verbose style
c'2^\markup{
% 110% of default size
\override#'(size.1.1){
\override#'(fret-diagram-details.(
(number-type.roman-upper)
(dot-label-font-mag.0.9)
(finger-code.none)
(fret-label-vertical-offset.0.5)
(xo-font-magnification.0.4)
(xo-padding.0.3))){
\fret-diagram-verbose#'((mute6)
(capo3)
(open5)
(place-fret451)
(place-fret352)
(place-fret253)
(open1))
}
}
}
%% simple D chord
d'2^\markup{
\override#'(fret-diagram-details.(
(finger-code.below-string)
(dot-radius.0.35)
(string-thickness-factor.0.3)
(dot-position.0.5)
(fret-count.3))){
\fret-diagram-terse"x;x;o;2-1;3-2;2-3;"
}
}
%% simple D chord, large top fret thickness
d'2^\markup{
\override#'(fret-diagram-details.(
(finger-code.below-string)
(dot-radius.0.35)
(dot-position.0.5)
(top-fret-thickness.7)
(fret-count.3))){
\fret-diagram-terse"x;x;o;2-1;3-2;2-3;"
}
}
% These chords will be in landscape orientation
\overrideTextScript.fret-diagram-details.orientation=#'landscape
%% C major for guitar, barred on third fret
% verbose style
% roman fret label, finger labels below string, straight barre
c'2^\markup{
% 110% of default size
\override#'(size.1.1){
\override#'(fret-diagram-details.(
(number-type.roman-lower)
(finger-code.below-string)
(barre-type.straight))){
\fret-diagram-verbose#'((mute6)
(place-fret531)
(place-fret452)
(place-fret353)
(place-fret254)
(place-fret131)
(barre513))
}
}
}
%% C major for guitar, barred on third fret
%% Double barre used to test barre function
% verbose style
c'2^\markup{
% 110% of default size
\override#'(size.1.1){
\override#'(fret-diagram-details.(
(number-type.arabic)
(dot-label-font-mag.0.9)
(finger-code.in-dot)
(fret-label-font-mag.0.6)
(fret-label-vertical-offset.0)
(label-dir.-1)
(mute-string."M")
(xo-font-magnification.0.4)
(xo-padding.0.3))){
\fret-diagram-verbose#'((mute6)
(place-fret531)
(place-fret452)
(place-fret353)
(place-fret254)
(place-fret131)
(barre425)
(barre513))
}
}
}
%% C major for guitar, with capo on third fret
% verbose style
c'2^\markup{
% 110% of default size
\override#'(size.1.1){
\override#'(fret-diagram-details.(
(number-type.roman-upper)
(dot-label-font-mag.0.9)
(finger-code.none)
(fret-label-vertical-offset.0.5)
(xo-font-magnification.0.4)
(xo-padding.0.3))){
\fret-diagram-verbose#'((mute6)
(capo3)
(open5)
(place-fret451)
(place-fret352)
(place-fret253)
(open1))
}
}
}
%% simple D chord
d'2^\markup{
\override#'(fret-diagram-details.(
(finger-code.below-string)
(dot-radius.0.35)
(dot-position.0.5)
(fret-count.3))){
\fret-diagram-terse"x;x;o;2-1;3-2;2-3;"
}
}
%% simple D chord, large top fret thickness
d'2^\markup{
\override#'(fret-diagram-details.(
(finger-code.below-string)
(dot-radius.0.35)
(dot-position.0.5)
(top-fret-thickness.7)
(fret-count.3))){
\fret-diagram-terse"x;x;o;2-1;3-2;2-3;"
}
}
% These chords will be in opposing-landscape orientation
\overrideTextScript.fret-diagram-details.orientation=#'opposing-landscape
%% C major for guitar, barred on third fret
% verbose style
% roman fret label, finger labels below string, straight barre
c'2^\markup{
% 110% of default size
\override#'(size.1.1){
\override#'(fret-diagram-details.(
(number-type.roman-lower)
(finger-code.below-string)
(barre-type.straight))){
\fret-diagram-verbose#'((mute6)
(place-fret531)
(place-fret452)
(place-fret353)
(place-fret254)
(place-fret131)
(barre513))
}
}
}
%% C major for guitar, barred on third fret
%% Double barre used to test barre function
% verbose style
c'2^\markup{
% 110% of default size
\override#'(size.1.1){
\override#'(fret-diagram-details.(
(number-type.arabic)
(dot-label-font-mag.0.9)
(finger-code.in-dot)
(fret-label-font-mag.0.6)
(fret-label-vertical-offset.0)
(label-dir.-1)
(mute-string."M")
(xo-font-magnification.0.4)
(xo-padding.0.3))){
\fret-diagram-verbose#'((mute6)
(place-fret531)
(place-fret452)
(place-fret353)
(place-fret254)
(place-fret131)
(barre425)
(barre513))
}
}
}
%% C major for guitar, with capo on third fret
% verbose style
c'2^\markup{
% 110% of default size
\override#'(size.1.1){
\override#'(fret-diagram-details.(
(number-type.roman-upper)
(dot-label-font-mag.0.9)
(finger-code.none)
(fret-label-vertical-offset.0.5)
(xo-font-magnification.0.4)
(xo-padding.0.3))){
\fret-diagram-verbose#'((mute6)
(capo3)
(open5)
(place-fret451)
(place-fret352)
(place-fret253)
(open1))
}
}
}
%% simple D chord
d'2^\markup{
\override#'(fret-diagram-details.(
(finger-code.below-string)
(dot-radius.0.35)
(dot-position.0.5)
(fret-count.3))){
\fret-diagram-terse"x;x;o;2-1;3-2;2-3;"
}
}
%% simple D chord, large top fret thickness
d'2^\markup{
\override#'(fret-diagram-details.(
(finger-code.below-string)
(dot-radius.0.35)
(dot-position.0.5)
(top-fret-thickness.7)
(fret-count.3))){
\fret-diagram-terse"x;x;o;2-1;3-2;2-3;"
}
}
}
>>

[image of music]


Generating custom flags

The stencil property of the Flag grob can be set to a custom scheme function to generate the glyph for the flag.

#(define-public(weight-flaggrob)
(let*((stem-grob(ly:grob-parentgrobX))
(log(-(ly:grob-propertystem-grob'duration-log)2))
(is-up?(eqv?(ly:grob-propertystem-grob'direction)UP))
(yext(ifis-up?(cons(*log-0.8)0)(cons0(*log0.8))))
(flag-stencil(make-filled-box-stencil'(-0.4.0.4)yext))
(stroke-style(ly:grob-propertygrob'stroke-style))
(stroke-stencil(if(equal?stroke-style"grace")
(make-line-stencil0.2-0.9-0.40.9-0.4)
empty-stencil)))
(ly:stencil-addflag-stencilstroke-stencil)))
% Create a flag stencil by looking up the glyph from the font
#(define(inverted-flaggrob)
(let*((stem-grob(ly:grob-parentgrobX))
(dir(if(eqv?(ly:grob-propertystem-grob'direction)UP)"d""u"))
(flag(retrieve-glyph-flag""dir""grob))
(line-thickness(ly:staff-symbol-line-thicknessgrob))
(stem-thickness(ly:grob-propertystem-grob'thickness))
(stem-width(*line-thicknessstem-thickness))
(stroke-style(ly:grob-propertygrob'stroke-style))
(stencil(if(null?stroke-style)
flag
(add-stroke-glyphflagstem-grobdirstroke-style"")))
(rotated-flag(ly:stencil-rotate-absolutestencil18000)))
(ly:stencil-translaterotated-flag(cons(-(/stem-width2))0))))
snippetexamplenotes=
{
\autoBeamOffc'8d'16c'32d'64\acciaccatura{c'8}d'64
}
{
\time1/4
\textMark"Normal flags"
\snippetexamplenotes
\textMark"Custom flag: inverted"
\overrideFlag.stencil=#inverted-flag
\snippetexamplenotes
\textMark"Custom flag: weight"
\overrideFlag.stencil=#weight-flag
\snippetexamplenotes
\textMark"Revert to normal"
\revertFlag.stencil
\snippetexamplenotes
}

[image of music]


Glissandi can skip grobs

NoteColumn grobs can be skipped over by glissandi.

\relativec'{
a2\glissando
\once\overrideNoteColumn.glissando-skip=##t
f''4d,
}

[image of music]


Hairpins with different line styles

Hairpins can take any style from line-interface - dashed-line, dotted-line, line, trill or zigzag.

\relativec'{
c2\<c\!
\overrideHairpin.style=#'dashed-line
c2\<c\!
\overrideHairpin.style=#'dotted-line
c2\<c\!
\overrideHairpin.style=#'line
c2\<c\!
\overrideHairpin.style=#'trill
c2\<c\!
\overrideHairpin.style=#'zigzag
c2\<c\!
\revertHairpin.style
c2\<c\!
}

[image of music]


Horizontally aligning custom dynamics (e.g. "sempre pp", "piu f", "subito p")

Some dynamic expressions involve additional text, like “sempre pp”. Since dynamics are usually centered under the note, the \pp would be displayed way after the note it applies to.

To correctly align the “sempre pp” horizontally so that it is aligned as if it were only the \pp, there are several approaches:

\paper{
ragged-right=##f
indent=2.5\cm
}
% Solution 1: Using a simple markup with a particular halign value
% Drawback: It's a markup, not a dynamic command, so \dynamicDown
% etc. will have no effect
semppMarkup=\markup{\halign#1.4\italic"sempre"\dynamic"pp"}
% Solution 2: Using a dynamic script & shifting with
% \once \override ...X-offset = ..
% Drawback: \once \override needed for every invocation
semppK=
#(make-dynamic-script
(markup#:line
(#:normal-text
#:italic"sempre"
#:dynamic"pp")))
% Solution 3: Padding the dynamic script so the center-alignment
% puts it at the correct position
% Drawback: the padding really reserves the space, nothing else can be there
semppT=
#(make-dynamic-script
(markup#:line
(#:normal-text
#:italic"sempre"
#:dynamic"pp"
#:hspace7.1)))
% Solution 4: Dynamic, setting the dimensions of the additional text to 0
% Drawback: To lilypond "sempre" has no extent, so it might put
% other stuff there => collisions
% Drawback: Also, there seems to be some spacing, so it's not exactly the
% same alignment as without the additional text
semppM=
#(make-dynamic-script
(markup#:line
(#:with-dimensions'(0.0)'(0.0)
#:right-align
#:normal-text
#:italic"sempre"
#:dynamic"pp")))
% Solution 5: Dynamic with explicit shifting inside the scheme function
semppG=
#(make-dynamic-script
(markup#:hspace0
#:translate'(-18.85.0)
#:line(#:normal-text
#:italic"sempre"
#:dynamic"pp")))
% Solution 6: Dynamic with explicit alignment. This has only effect
% if one sets X-offset!
% Drawback: One needs to set DynamicText.X-offset!
% Drawback: Aligned at the right edge of the additional text,
% not at the center of pp
semppMII=
#(make-dynamic-script
(markup#:line(#:right-align
#:normal-text
#:italic"sempre"
#:dynamic"pp")))
\newStaffGroup<<
\newStaff="s"\with{instrumentName=\markup\column{Normal}}
<<
\relativec''{
\keyes\major
c4\ppc\pcc|c\ffcc\ppc
}
>>
\newStaff="sMarkup"\with{
instrumentName=\markup\column{Normalmarkup}
}
<<
\relativec''{
\keyes\major
c4-\semppMarkupc\pcc|c\ffcc-\semppMarkupc
}
>>
\newStaff="sK"\with{
instrumentName=\markup\column{Explicitshifting}
}
<<
\relativec''{
\keyes\major
\once\overrideDynamicText.X-offset=#-9.2
c4\semppKc\pcc
c4\ffc
\once\overrideDynamicText.X-offset=#-9.2
c4\semppKc
}
>>
\newStaff="sT"\with{
instrumentName=\markup\column{Rightpadding}
}
<<
\relativec''{
\keyes\major
c4\semppTc\pcc|c\ffcc\semppTc
}
>>
\newStaff="sM"\with{
instrumentName=\markup\column{Setdimension"to zero"}
}
<<
\relativec''{
\keyes\major
c4\semppMc\pcc|c\ffcc\semppMc
}
>>
\newStaff="sG"\with{
instrumentName=\markup\column{Shiftinsidedynamics}
}
<<
\relativec''{
\keyes\major
c4\semppGc\pcc|c\ffcc\semppGc
}
>>
\newStaff="sMII"\with{
instrumentName=\markup\column{Alignmentinsidedynamics}
}
<<
\relativec''{
\keyes\major
% Setting to ##f (false) gives the same result
\overrideDynamicText.X-offset=#0
c4\semppMIIc\pcc|c\ffcc\semppMIIc
}
>>
>>
\layout{\overrideStaff.InstrumentName.self-alignment-X=#LEFT}

[image of music]


How to change fret diagram position

If you want to move the position of a fret diagram, for example, to avoid collision, or to place it between two notes, you have various possibilities:

1) modify #’padding or #’extra-offset values (as shown in the first snippet)

2) you can add an invisible voice and attach the fret diagrams to the invisible notes in that voice (as shown in the second example).

If you need to move the fret according with a rythmic position inside the bar (in the example, the third beat of the measure) the second example is better, because the fret is aligned with the third beat itself.

harmonies=\chordmode
{
a8:13
% THE FOLLOWING IS THE COMMAND TO MOVE THE CHORD NAME
\once\overrideChordNames.ChordName.extra-offset=#'(10.0)
b8:13s2.
% THIS LINE IS THE SECOND METHOD
s4s4b4:13
}
\score
{
<<
\newChordNames\harmonies
\newStaff
{a8^\markup{\fret-diagram"6-x;5-0;4-2;3-0;2-0;1-2;"}
% THE FOLLOWING IS THE COMMAND TO MOVE THE FRET DIAGRAM
\once\overrideTextScript.extra-offset=#'(10.0)
b4.~^\markup{\fret-diagram"6-x;5-2;4-4;3-2;2-2;1-4;"}b4.a8\break
% HERE IS THE SECOND METHOD
<<
{a8b4.~b4.a8}
{s4s4s4^\markup{\fret-diagram"6-x;5-2;4-4;3-2;2-2;1-4;"}
}
>>
}
>>
}

[image of music]


Inserting a caesura

Caesura marks can be created by overriding the 'text property of the BreathingSign object.

A curved caesura mark is also available.

\relativec''{
\overrideBreathingSign.text=\markup{
\musicglyph"scripts.caesura.straight"
}
c8e4.\breatheg8.e16c4
\overrideBreathingSign.text=\markup{
\musicglyph"scripts.caesura.curved"
}
g8e'4.\breatheg8.e16c4
}

[image of music]


Keep change clefs full sized

When a clef is changed, the clef sign displayed is smaller than the initial clef. This can be overridden with full-size-change.

\relativec'{
\clef"treble"
c1
\clef"bass"
c1
\clef"treble"
c1
\overrideStaff.Clef.full-size-change=##t
\clef"bass"
c1
\clef"treble"
c1
\revertStaff.Clef.full-size-change
\clef"bass"
c1
\clef"treble"
c1
}

[image of music]


Line arrows

Arrows can be applied to text-spanners and line-spanners (such as the Glissando).

\relativec''{
\overrideTextSpanner.bound-padding=#1.0
\overrideTextSpanner.style=#'line
\overrideTextSpanner.bound-details.right.arrow=##t
\overrideTextSpanner.bound-details.left.text=#"fof"
\overrideTextSpanner.bound-details.right.text=#"gag"
\overrideTextSpanner.bound-details.right.padding=#0.6
\overrideTextSpanner.bound-details.right.stencil-align-dir-y=#CENTER
\overrideTextSpanner.bound-details.left.stencil-align-dir-y=#CENTER
\overrideGlissando.bound-details.right.arrow=##t
\overrideGlissando.arrow-length=#0.5
\overrideGlissando.arrow-width=#0.25
a8\startTextSpangisa4b\glissandob,
g'4c\stopTextSpanc2
}

[image of music]


Making an object invisible with the ’transparent property

Setting the transparent property will cause an object to be printed in “invisible ink”: the object is not printed, but all its other behavior is retained. The object still takes up space, it takes part in collisions, and slurs, ties and beams can be attached to it.

This snippet demonstrates how to connect different voices using ties. Normally, ties only connect two notes in the same voice. By introducing a tie in a different voice, and blanking the first up-stem in that voice, the tie appears to cross voices.

\relative{
\time2/4
<<
{
\once\hideStem
\once\overrideStem.length=#8
b'8~8\noBeam
\once\hideStem
\once\overrideStem.length=#8
g8~8\noBeam
}
\\
{
b8gge
}
>>
}

[image of music]


Making glissandi breakable

Setting the breakable property to #t in combination with after-line-breaking allows a glissando to break if it occurs at a line break:

glissandoSkipOn={
\overrideNoteColumn.glissando-skip=##t
\hideNoteHead
\overrideNoteHead.no-ledgers=##t
}
\relativec''{
\overrideGlissando.breakable=##t
\overrideGlissando.after-line-breaking=##t
f1\glissando|
\break
a4r2.|
f1\glissando
\once\glissandoSkipOn
\break
a2a4r4|
}

[image of music]


Manually controlling beam positions

Beam positions may be controlled manually, by overriding the positions setting of the Beam grob.

\relativec'{
\time2/4
% from upper staff-line (position 2) to center (position 0)
\overrideBeam.positions=#'(2.0)
c8c
% from center to one above center (position 1)
\overrideBeam.positions=#'(0.1)
c8c
}

[image of music]


Measure-centered bar numbers

For film scores, a common convention is to center bar numbers within their measure. This is achieved through setting the centerBarNumbers context property to true. When this is used, the type of the bar number grobs is CenteredBarNumber rather than BarNumber.

This example demonstrates a number of settings: the centered bar numbers are boxed and placed below the staves.

\layout{
\context{
\Score
centerBarNumbers=##t
barNumberVisibility=#all-bar-numbers-visible
\overrideCenteredBarNumber.stencil
=#(make-stencil-boxer0.10.25ly:text-interface::print)
\overrideCenteredBarNumberLineSpanner.direction=#DOWN
}
}
\newStaffGroup<<
\newStaff\relativec'{
d4-.f8(ed4)bes'->|
d,-.f8(ed4)cis'->|
g-.f8(de4)g->|
a,1->|
}
\newStaff\relativec{
\clefbass
d4f8ed2~|
4f8ed2~|
442|
a1|
}
>>

[image of music]


Mensurstriche layout (bar lines between the staves)

Mensurstriche, bar lines between but not through staves, can be printed by setting measureBarType to "-span|" and using a grouping context that allows span bars, such as StaffGroup.

\layout{
\context{
\Staff
measureBarType="-span|"
}
}
music=\fixedc''{
c1
d2\sectione2
f1\fine
}
\newStaffGroup<<
\newStaff\music
\newStaff\music
>>

[image of music]


Modifying the Ottava spanner slope

It is possible to change the slope of the Ottava spanner.

\relativec''{
\overrideStaff.OttavaBracket.stencil=#ly:line-spanner::print
\overrideStaff.OttavaBracket.bound-details=
#`((left.((Y.0)
(attach-dir.,LEFT)
(padding.0)
(stencil-align-dir-y.,CENTER)))
(right.((Y.5.0); Change the number here
(padding.0)
(attach-dir.,RIGHT)
(text.,(make-draw-dashed-line-markup
(cons0-1.2))))))
\overrideStaff.OttavaBracket.left-bound-info=
#ly:horizontal-line-spanner::calc-left-bound-info-and-text
\overrideStaff.OttavaBracket.right-bound-info=
#ly:horizontal-line-spanner::calc-right-bound-info
\ottava#1
c1
c'''1
}

[image of music]


Moving dotted notes in polyphony

When a dotted note in the upper voice is moved to avoid a collision with a note in another voice, the default is to move the upper note to the right. This behaviour can be over-ridden by using the prefer-dotted-right property of NoteCollision.

\newStaff\relativec'<<
{
f2.f4
\overrideStaff.NoteCollision.prefer-dotted-right=##f
f2.f4
\overrideStaff.NoteCollision.prefer-dotted-right=##t
f2.f4
}
\\
{e4eeeeeeeeeee}
>>

[image of music]


Moving slur positions vertically

The vertical position of a slur can be adjusted using the positions property of Slur. The property has 2 parameters, the first referring to the left end of the slur and the second to the right. The values of the parameters are not used by LilyPond to make an exact movement of the slur - instead it selects what placement of the slur looks best, taking into account the parameter values. Positive values move the slur up, and are appropriate for notes with stems down. Negative values move downward slurs further down.

\relativec'{
\stemDown
e4(a)
\overrideSlur.positions=#'(1.1)
e4(a)
\overrideSlur.positions=#'(2.2)
e4(a)
\overrideSlur.positions=#'(3.3)
e4(a)
\overrideSlur.positions=#'(4.4)
e4(a)
\overrideSlur.positions=#'(5.5)
e4(a)
\overrideSlur.positions=#'(0.5)
e4(a)
\overrideSlur.positions=#'(5.0)
e4(a)
\stemUp
\overrideSlur.positions=#'(-5.-5)
e4(a)
\stemDown
\revertSlur.positions
e4(a)
}

[image of music]


Nesting staves

The property systemStartDelimiterHierarchy can be used to make more complex nested staff groups. The command \set StaffGroup.systemStartDelimiterHierarchy takes an alphabetical list of the number of staves produced. Before each staff a system start delimiter can be given. It has to be enclosed in brackets and takes as much staves as the brackets enclose. Elements in the list can be omitted, but the first bracket takes always the complete number of staves. The possibilities are SystemStartBar, SystemStartBracket, SystemStartBrace, and SystemStartSquare.

\newStaffGroup
\relativec''<<
\overrideStaffGroup.SystemStartSquare.collapse-height=#4
\setStaffGroup.systemStartDelimiterHierarchy
=#'(SystemStartSquare(SystemStartBrace(SystemStartBracketa
(SystemStartSquareb))c)d)
\newStaff{c1}
\newStaff{c1}
\newStaff{c1}
\newStaff{c1}
\newStaff{c1}
>>

[image of music]


Overriding articulations by type

Sometimes you may want to affect a single articulation-type. Although it is always possible to use \tweak, it might become tedious to do so for every single sign of a whole score. The following shows how to tweak articulations with a list of custom settings. One use-case might be to create a style sheet.

With 2.16.2 and above it is possible to put the proposed function, \customScripts, into a \layout-block.

% Code by David Nalesnik and Thomas Morley
#(define(custom-script-tweaksls)
(lambda(grob)
(let*((type(ly:event-property
(ly:grob-propertygrob'cause)
'articulation-type))
(tweaks(assoc-reflstype)))
(iftweaks
(for-each
(lambda(x)(ly:grob-set-property!grob(carx)(cdrx)))
tweaks)))))
customScripts=
#(define-music-function(settings)(list?)
#{
\overrideScript.before-line-breaking=
#(custom-script-tweakssettings)
#})
revertCustomScripts=\revertScript.before-line-breaking
%%%%%%%%%%%%%
% Example:
%%%%%%%%%%%%%
% Predefine a list of desired tweaks.
#(definemy-settings-1
'(
(staccato.((color.(100))
(padding.0.5)))
(accent.((font-size.0)
(color.(100))))
(tenuto.((rotation.(4500))
(padding.2)
(font-size.10)))
(staccatissimo.((padding.1)
(color.(100))))
(segno.((font-size.0)
(color.(100))))
))
#(definemy-settings-2
'(
(staccato.((color.(010))))
(accent.((font-size.4)
(color.(010))
(padding.1.5)))
(tenuto.((font-size.10)))
(staccatissimo.((padding.2)
(color.(010))))
(coda.((color.(010))
(padding.1)))
))
one=
\relativec''{
f1--
\customScripts#my-settings-1
f-.f-!f->f--f-!\segno
\revertCustomScripts
f->f-.
}
two=
\relativec'{
f1--
\customScripts#my-settings-2
f-.f-!f->f--->f-!
f->f-.\coda
}
\newStaff<<
\newVoice{\voiceOne\one}
\newVoice{\voiceTwo\two}
>>

[image of music]


Overriding articulations of distinct type

Sometimes you may want to affect a single articulation type. Although it is always possible to use \tweak, it might become tedious to do so for every single sign of a whole score. The following shows how to tweak articulations with a list of custom settings. One use case might be to create a style sheet.

With 2.16.2 it is possible to put the proposed function, \customScripts, into a \layout block.

% Code by David Nalesnik and Thomas Morley
#(define(custom-script-tweaksls)
(lambda(grob)
(let*((type(ly:prob-property
(ly:grob-propertygrob'cause)
'articulation-type))
(tweaks(assoc-reflstype)))
(iftweaks
(for-each
(lambda(x)(ly:grob-set-property!grob(carx)(cdrx)))
tweaks)))))
customScripts=
#(define-music-function(settings)(list?)
#{
\overrideScript.before-line-breaking=
#(custom-script-tweakssettings)
#})
revertCustomScripts={\revertScript.before-line-breaking}
%%%%%%%%%%%%%
% Example:
%%%%%%%%%%%%%
% Predefine a list of desired tweaks.
#(definemy-settings-1
'(
("staccato".((color.(100))(padding.0.5)))
("accent".((font-size.0)(color.(100))))
("tenuto".((rotation.(4500))(padding.2)(font-size.10)))
("staccatissimo".((padding.1)(color.(100))))
("segno".((font-size.0)(color.(100))))
))
#(definemy-settings-2
'(
("staccato".((color.(010))))
("accent".((font-size.4)(color.(010))(padding.1.5)))
("tenuto".((font-size.10)))
("staccatissimo".((padding.2)(color.(010))))
("coda".((color.(010))(padding.1)))
))
one=
\relativec''{
f1--
\customScripts#my-settings-1
f-.f-!f->f--f-!\segno
\revertCustomScripts
f->f-.
}
two=
\relativec'{
f1--
\customScripts#my-settings-2
f-.f-!f->f--->f-!
f->f-.\coda
}
\newStaff<<
\newVoice{\voiceOne\one}
\newVoice{\voiceTwo\two}
>>

[image of music]


Percent repeat count visibility

Percent repeat counters can be shown at regular intervals by setting the context property repeatCountVisibility.

\relativec''{
\setcountPercentRepeats=##t
\setrepeatCountVisibility=#(every-nth-repeat-count-visible5)
\repeatpercent10{c1}\break
\setrepeatCountVisibility=#(every-nth-repeat-count-visible2)
\repeatpercent6{c1d1}
}

[image of music]


Positioning arpeggios

If you need to extend or shorten an arpeggio, you can modify the upper and lower start positions independently.

\relativec'{
<cegb>1\arpeggio
\once\overrideArpeggio.positions=#'(-5.0)
<cegb>1\arpeggio
\once\overrideArpeggio.positions=#'(0.5)
<cegb>1\arpeggio
\once\overrideArpeggio.positions=#'(-5.5)
<cegb>1\arpeggio
}

[image of music]


Positioning multi-measure rests

Unlike ordinary rests, there is no predefined command to change the staff position of a multi-measure rest symbol of either form by attaching it to a note. However, in polyphonic music multi-measure rests in odd-numbered and even-numbered voices are vertically separated.

The positioning of multi-measure rests can be controlled as follows:

\relativec''{
% Multi-measure rests by default are set under the fourth line
R1
% They can be moved using an override
\overrideMultiMeasureRest.staff-position=#-2
R1
\overrideMultiMeasureRest.staff-position=#0
R1
\overrideMultiMeasureRest.staff-position=#2
R1
\overrideMultiMeasureRest.staff-position=#3
R1
\overrideMultiMeasureRest.staff-position=#6
R1
\revertMultiMeasureRest.staff-position
\break
% In two Voices, odd-numbered voices are under the top line
<<{R1}\\{a1}>>
% Even-numbered voices are under the bottom line
<<{a1}\\{R1}>>
% Multi-measure rests in both voices remain separate
<<{R1}\\{R1}>>
% Separating multi-measure rests in more than two voices
% requires an override
<<{R1}\\{R1}\\
\once\overrideMultiMeasureRest.staff-position=#0
{R1}
>>
% Using compressed bars in multiple voices requires another override
% in all voices to avoid multiple instances being printed
\compressMMRests
<<
\revertMultiMeasureRest.direction
{R1*3}
\\
\revertMultiMeasureRest.direction
{R1*3}
>>
}

[image of music]


Positioning text markups inside slurs

Text markups need to have the outside-staff-priority property set to false in order to be printed inside slurs.

\relativec''{
\overrideTextScript.avoid-slur=#'inside
\overrideTextScript.outside-staff-priority=##f
c2(^\markup{\halign#-10\natural}d4.)c8
}

[image of music]


Printing bar numbers inside boxes or circles

Bar numbers can also be printed inside boxes or circles.

\relativec'{
% Prevent bar numbers at the end of a line and permit them elsewhere
\overrideScore.BarNumber.break-visibility=#end-of-line-invisible
\setScore.barNumberVisibility=#(every-nth-bar-number-visible4)
% Increase the size of the bar number by 2
\overrideScore.BarNumber.font-size=#2
% Draw a box round the following bar number(s)
\overrideScore.BarNumber.stencil
=#(make-stencil-boxer0.10.25ly:text-interface::print)
\repeatunfold5{c1}
% Draw a circle round the following bar number(s)
\overrideScore.BarNumber.stencil
=#(make-stencil-circler0.10.25ly:text-interface::print)
\repeatunfold4{c1}\bar"|."
}

[image of music]


Printing metronome and rehearsal marks below the staff

By default, metronome and rehearsal marks are printed above the staff. To place them below the staff simply set the direction property of MetronomeMark or RehearsalMark appropriately.

\layout{
indent=0
ragged-right=##f
}
{
% Metronome marks below the staff
\overrideScore.MetronomeMark.direction=#DOWN
\tempo8.=120
c''1
% Rehearsal marks below the staff
\overrideScore.RehearsalMark.direction=#DOWN
\mark\default
c''1
}

[image of music]


Printing note names with and without an octave marker

The NoteNames context can be used to print the text value of notes. The printOctaveNames property turns on or off the representation of the octave of the note.

scale=\relativec'{
a4bcd
e4fga
}
\newStaff{
<<
\scale
\contextNoteNames{
\setprintOctaveNames=##f
\scale
}
>>
R1
<<
\scale
\contextNoteNames{
\setprintOctaveNames=##t
\scale
}
>>
}

[image of music]


Printing tuplet brackets on the note head side

Whichever option you choose for controlling the tuplet bracket visibility, it will show or hide the tuplet bracket irrespectively of tuplet bracket placement (stem side or note head side). However, when placing the tuplet bracket on the note head side some authors recommend always printing the tuplet bracket. The option visible-over-note-heads can be used to achieve this.

music=\relativec''{
\tupletNeutral\tuplet3/2{c16[de}f8]
\tupletUp\tuplet3/2{c8de}
}
\newVoice{
\relativec'{
\time2/4
\overrideTupletBracket.visible-over-note-heads=##t
\overrideScore.TextMark.non-musical=##f
{\textMark\markup"default"\music}
\overrideTupletBracket.bracket-visibility=#'if-no-beam
{\textMark\markup\typewriter"'if-no-beam"\music}
}
}

[image of music]


Proportional strict notespacing

If strict-note-spacing is set spacing of notes is not influenced by bars or clefs within a system. Rather, they are placed just before the note that occurs at the same time. This may cause collisions.

\relativec''<<
\overrideScore.SpacingSpanner.strict-note-spacing=##t
\setScore.proportionalNotationDuration=#(ly:make-moment1/16)
\newStaff{
c8[c\clefaltocc\grace{d16}c8c]c4
c2\grace{c16[c16]}c2
}
\newStaff{
c2\tuplet3/2{c8\clefbasscis,,c}c4
c1
}
>>

[image of music]


Removing brace on first line of piano score

This snippet removes the first brace from a PianoStaff or a GrandStaff.

It may be useful when cutting and pasting the engraved image into existing music.

It uses \alterBroken.

someMusic={
\once\overrideStaff.Clef.stencil=##f
\once\overrideStaff.TimeSignature.stencil=##f
\repeatunfold3c1\break
\repeatunfold5c1\break
\repeatunfold5c1
}
\score{
\newPianoStaff
<<
\newStaff="right"\relativec''\someMusic
\newStaff="left"\relativec'{\clefF\someMusic}
>>
\layout{
indent=75
\context{
\PianoStaff
\alterBrokentransparent#'(#t)SystemStartBrace
}
}
}

[image of music]


Removing connecting bar lines on StaffGroup, PianoStaff, or GrandStaff

By default, bar lines in StaffGroup, PianoStaff, or GrandStaff groups are connected between the staves, i.e. a SpanBar is printed. This behaviour can be overridden on a staff-by-staff basis.

\relativec'{
\newStaffGroup<<
\newStaff{
e1|e
\once\overrideStaff.BarLine.allow-span-bar=##f
e1|e|e
}
\newStaff{
c1|c|c
\once\overrideStaff.BarLine.allow-span-bar=##f
c1|c
}
\newStaff{
a1|a|a|a|a
}
>>
}

[image of music]


Removing the first empty line

The first empty staff can also be removed from the score by setting the VerticalAxisGroup property remove-first. This can be done globally inside the \layout block, or locally inside the specific staff that should be removed. In the latter case, you have to specify the context (Staff applies only to the current staff) in front of the property.

The lower staff of the second staff group is not removed, because the setting applies only to the specific staff inside of which it is written.

\layout{
\context{
\Staff\RemoveEmptyStaves
% To use the setting globally, uncomment the following line:
% \override VerticalAxisGroup.remove-first = ##t
}
}
\newStaffGroup<<
\newStaff\relativec'{
e4fga\break
c1
}
\newStaff{
% To use the setting globally, comment this line,
% uncomment the line in the \layout block above
\overrideStaff.VerticalAxisGroup.remove-first=##t
R1\break
R
}
>>
\newStaffGroup<<
\newStaff\relativec'{
e4fga\break
c1
}
\newStaff{
R1\break
R
}
>>

[image of music]


Rest styles

Rests may be used in various styles.

\newStaff\relativec{
\omitScore.TimeSignature
\cadenzaOn
\overrideStaff.Rest.style=#'mensural
r\maxima^\markup\typewriter{mensural}
r\longar\brever1r2r4r8r16s32s64s128s128
\bar""
\break
\overrideStaff.Rest.style=#'neomensural
r\maxima^\markup\typewriter{neomensural}
r\longar\brever1r2r4r8r16s32s64s128s128
\bar""
\break
\overrideStaff.Rest.style=#'classical
r\maxima^\markup\typewriter{classical}
r\longar\brever1r2r4r8r16r32r64r128s128
\bar""
\break
\overrideStaff.Rest.style=#'z
r\maxima^\markup\typewriter{z-style}
r\longar\brever1r2r4r8r16r32r64r128s128
\bar""
\break
\overrideStaff.Rest.style=#'default
r\maxima^\markup\typewriter{default}
r\longar\brever1r2r4r8r16r32r64r128s128
}

[image of music]


Rhythmic slashes

In “simple” lead-sheets, sometimes no actual notes are written, instead only “rhythmic patterns” and chords above the measures are notated giving the structure of a song. Such a feature is for example useful while creating/transcribing the structure of a song and also when sharing lead sheets with guitarists or jazz musicians.

The standard support for this using \repeat percent is unsuitable here since the first beat has to be an ordinary note or rest.

This example shows two solutions to this problem, by redefining ordinary rests to be printed as slashes. (If the duration of each beat is not a quarter note, replace the r4 in the definitions with a rest of the appropriate duration).

% Macro to print single slash
rs={
\once\overrideRest.stencil=#ly:percent-repeat-interface::beat-slash
\once\overrideRest.thickness=#0.48
\once\overrideRest.slope=#1.7
r4
}
% Function to print a specified number of slashes
comp=#(define-music-function(count)(integer?)
#{
\overrideRest.stencil=#ly:percent-repeat-interface::beat-slash
\overrideRest.thickness=#0.48
\overrideRest.slope=#1.7
\repeatunfold$count{r4}
\revertRest.stencil
#}
)
\score{
\relativec'{
c4def|
\rs\rs\rs\rs|
\comp#4|
}
}

[image of music]


Separating key cancellations from key signature changes

By default, the accidentals used for key cancellations are placed adjacent to those for key signature changes. This behavior can be changed by overriding the 'break-align-orders property of the BreakAlignment grob.

The value of 'break-align-orders is a vector of length 3, with quoted lists of breakable items as elements. This example only modifies the second list, moving key-cancellation before staff-bar; by modifying the second list, break alignment behavior only changes in the middle of a system, not at the beginning or the end.

\newStaff{
\overrideScore.BreakAlignment.break-align-orders=
##((left-edgeambitusbreathing-signclefstaff-bar
key-cancellationkey-signaturetime-signaturecustos)
(left-edgeambitusbreathing-signclefkey-cancellation
staff-barkey-signaturetime-signaturecustos)
(left-edgeambitusbreathing-signclefkey-cancellation
key-signaturestaff-bartime-signaturecustos))
\keydes\major
c'1
\bar"||"
\keybes\major
c'1
}

[image of music]


Setting hairpin behavior at bar lines

If the note which ends a hairpin falls on a downbeat, the hairpin stops at the bar line immediately preceding. This behavior can be controlled by overriding the 'to-barline property.

\relativec''{
e4\<e2.
e1\!
\overrideHairpin.to-barline=##f
e4\<e2.
e1\!
}

[image of music]


Setting system separators

System separators can be inserted between systems. Any markup can be used, but \slashSeparator has been provided as a sensible default.

\paper{
system-separator-markup=\slashSeparator
line-width=120
}
notes=\relativec'{
c1|c\break
c1|c\break
c1|c
}
\book{
\score{
\newGrandStaff<<
\newStaff\notes
\newStaff\notes
>>
}
}

[image of music]


Showing the same articulation above and below a note or chord

By default, LilyPond does not allow the same articulation (e.g., an accent, a fermata, a flageolet, etc.) to be displayed above and below a note. For example, c4_\fermata^\fermata only shows a fermata below. The fermata above gets simply ignored.

However, one can stick scripts (just like fingerings) inside a chord, which means it is possible to have as many articulations as desired. This approach has the advantage that it ignores the stem and positions the articulation relative to the note head. This can be seen in the case of the flageolets in the snippet. To mimic the behaviour of scripts outside a chord, 'add-stem-support would be required.

The solution is thus to write the note as a chord and add the articulations inside of <...>, using the direction modifiers ^ and _ as appropriate.

\relativec'{
<>^"Wrong"
c2_\fermata^\fermata% The second fermata is ignored!
<ed'>2^\flageolet_\flageolet
\stopStaffs1\startStaff
<>^"Works if written inside a chord"
<e_\flageoletd'^\flageolet>2
<e_\flageoletd'^\flageolet>2
<e_\flageolet^\flageolet>2
<e_\fermata^\fermata>2
}

[image of music]


String number extender lines

Make an extender line for string number indications, showing that a series of notes is supposed to be played all on the same string.

stringNumberSpanner=
#(define-music-function(StringNumber)(string?)
#{
\overrideTextSpanner.style=#'solid
\overrideTextSpanner.font-size=#-5
\overrideTextSpanner.bound-details.left.stencil-align-dir-y=#CENTER
\overrideTextSpanner.bound-details.left.text=
\markup{\circle\number$StringNumber}
#})
\relativec{
\clef"treble_8"
\stringNumberSpanner"5"
\textSpannerDown
a8\startTextSpan
bcdef\stopTextSpan
\stringNumberSpanner"4"
g\startTextSpana
bes4ag2\stopTextSpan
}

[image of music]


Suppressing warnings for clashing note columns

If notes from two voices with stems in the same direction are placed at the same position, and both voices have no shift or the same shift specified, the error message ‘warning: ignoring too many clashing note columns’ will appear when compiling the LilyPond file. This message can be suppressed by setting the 'ignore-collision property of the NoteColumn object to #t. Please note that this does not just suppress warnings but stops LilyPond trying to resolve collisions at all and so may have unintended results unless used with care.

ignore=\overrideNoteColumn.ignore-collision=##t
\relativec'{
\newStaff<<
\newVoice{\ignore\stemDownf2g}
\newVoice{c2\stemDownc,}
>>
}

[image of music]


Time signature in parentheses

The time signature can be enclosed within parentheses.

\relativec''{
\overrideStaff.TimeSignature.stencil=#(lambda(grob)
(bracketify-stencil(ly:time-signature::printgrob)Y0.10.20.1))
\time2/4
a4b8c
}

[image of music]


Time signature in parentheses - method 3

Another way to put the time signature in parenthesis

\relativec''{
\overrideStaff.TimeSignature.stencil=#(lambda(grob)
(parenthesize-stencil(ly:time-signature::printgrob)0.10.40.40.1))
\time2/4
a4b8c
}

[image of music]


Time signature printing only the numerator as a number (instead of the fraction)

Sometimes, a time signature should not print the whole fraction (for example, 7/4), but only the numerator (digit 7 in this case). This can be easily done by using \override Staff.TimeSignature.style = #'single-digit to change the style permanently. By using \revert Staff.TimeSignature.style, this setting can be reversed. To apply the single-digit style to only one time signature, use the \override command and prefix it with a \once.

\relativec''{
\time3/4
c4cc
% Change the style permanently
\overrideStaff.TimeSignature.style=#'single-digit
\time2/4
c4c
\time3/4
c4cc
% Revert to default style:
\revertStaff.TimeSignature.style
\time2/4
c4c
% single-digit style only for the next time signature
\once\overrideStaff.TimeSignature.style=#'single-digit
\time5/4
c4cccc
\time2/4
c4c
}

[image of music]


Tuplet bracket and change staff

This snippet shows how to set a tuplet starting in a lower staff and finishing in the upper one.

aigues=\relativec'{
\time6/8
s4.
\stemDown
c16[bes'e]
\stemUp
gce
\stemDown
g8
}
basses=\relativec{
\time3/4
\clefF
\tweakpositions#'(4.5.9.5)
\tweakedge-height#'(1.-1)
\tuplet7/6{
c16[bes'e]
\changeStaff=md
\stemUp
g[ceg]
}
s4.s8
}
\newPianoStaff
\with{\omitTimeSignature}
<<
\newStaff=md\aigues
\newStaff=mg\basses
>>

[image of music]


Tweaking clef properties

Changing the Clef glyph, its position, or the ottavation does not change the position of subsequent notes on the staff. To get key signatures on their correct staff lines middleCClefPosition must also be specified, with positive or negative values moving middle C up or down respectively, relative to the staff’s center line.

For example, \clef "treble_8" is equivalent to setting the clefGlyph, clefPosition (the vertical position of the clef itself on the staff), middleCPosition and clefTransposition. Note that when any of these properties (except middleCPosition) are changed a new clef symbol is printed.

The following examples show the possibilities when setting these properties manually. On the first line, the manual changes preserve the standard relative positioning of clefs and notes, whereas on the second line, they do not.

{
% The default treble clef
\keyf\major
c'1
% The standard bass clef
\setStaff.clefGlyph=#"clefs.F"
\setStaff.clefPosition=#2
\setStaff.middleCPosition=#6
\setStaff.middleCClefPosition=#6
\keyg\major
c'1
% The baritone clef
\setStaff.clefGlyph=#"clefs.C"
\setStaff.clefPosition=#4
\setStaff.middleCPosition=#4
\setStaff.middleCClefPosition=#4
\keyf\major
c'1
% The standard choral tenor clef
\setStaff.clefGlyph=#"clefs.G"
\setStaff.clefPosition=#-2
\setStaff.clefTransposition=#-7
\setStaff.middleCPosition=#1
\setStaff.middleCClefPosition=#1
\keyf\major
c'1
% A non-standard clef
\setStaff.clefPosition=#0
\setStaff.clefTransposition=#0
\setStaff.middleCPosition=#-4
\setStaff.middleCClefPosition=#-4
\keyg\major
c'1\break
% The following clef changes do not preserve
% the normal relationship between notes, key signatures
% and clefs:
\setStaff.clefGlyph=#"clefs.F"
\setStaff.clefPosition=#2
c'1
\setStaff.clefGlyph=#"clefs.G"
c'1
\setStaff.clefGlyph=#"clefs.C"
c'1
\setStaff.clefTransposition=#7
c'1
\setStaff.clefTransposition=#0
\setStaff.clefPosition=#0
c'1
% Return to the normal clef:
\setStaff.middleCPosition=#0
c'1
}

[image of music]


Tweaking grace layout within music

The layout of grace expressions can be changed throughout the music using the functions add-grace-property and remove-grace-property.

The following example undefines the Stem direction for this grace, so that stems do not always point up, and changes the default note heads to crosses.

\relativec''{
\newStaff{
$(remove-grace-property'Voice'Stem'direction)
$(add-grace-property'Voice'NoteHead'style'cross)
\newVoice{
\acciaccatura{f16}g4
\grace{d16e}f4
\appoggiatura{f,32ga}e2
}
}
}

[image of music]


Using alternative flag styles

Alternative styles of flag on eighth and shorter notes can be displayed by overriding the stencil property of Flag. Valid values are modern-straight-flag, old-straight-flag and flat-flag.

testnotes={
\autoBeamOff
c8d16c32d64\acciaccatura{c8}d64r4
}
\score{
\relativec'{
\time2/4
\testnotes
\overrideFlag.stencil=#modern-straight-flag
\testnotes
\overrideFlag.stencil=#old-straight-flag
\testnotes
\overrideFlag.stencil=#flat-flag
\testnotes
\revertFlag.stencil
\testnotes
}
\layout{
indent=0
\context{
\Score
\overrideNonMusicalPaperColumn.line-break-permission=##f
}
}
}

[image of music]


Using ly:grob-object to access grobs with \tweak

Some grobs can be accessed "laterally" from within another grob’s callback. These are usually listed as "layout objects" in the "Internal properties" section of a grob-interface. The function ly:grob-object is used to access these grobs.

Demonstrated below are some ways of accessing grobs from within a NoteHead callback, but the technique is not limited to NoteHeads. However, the NoteHead callback is particularly important, since it is the implicit callback used by the \tweak command.

The example function defined below ("display-grobs") is probably not that useful, but it demonstrates that the grobs are indeed being accessed.

Example console output:

#Grob Accidental () #Grob Stem

#(define(notehead-get-accidentalnotehead)
;; notehead is grob
(ly:grob-objectnotehead'accidental-grob))
#(define(notehead-get-arpeggionotehead)
;; notehead is grob
(let((notecolumn(notehead-get-notecolumnnotehead)))
(ly:grob-objectnotecolumn'arpeggio)))
#(define(notehead-get-notecolumnnotehead)
;; notehead is grob
(ly:grob-parentnoteheadX))
#(define(notehead-get-stemnotehead)
;; notehead is grob
(let((notecolumn(notehead-get-notecolumnnotehead)))
(ly:grob-objectnotecolumn'stem)))
#(define(display-grobsnotehead)
;; notehead is grob
(let((accidental(notehead-get-accidentalnotehead))
(arpeggio(notehead-get-arpeggionotehead))
(stem(notehead-get-stemnotehead)))
(format(current-error-port)"~2&~a\n"(make-string20#\-))
(for-each
(lambda(x)(format(current-error-port)"~a\n"x))
(listaccidentalarpeggiostem))))
\relativec'{
%% display grobs for each note head:
%\override NoteHead.before-line-breaking = #display-grobs
<c
%% or just for one:
\tweakbefore-line-breaking#display-grobs
es
g>1\arpeggio
}

[image of music]


Using PostScript to generate special note head shapes

When a note head with a special shape cannot easily be generated with graphic markup, PostScript code can be used to generate the shape. This example shows how a parallelogram-shaped note head is generated.

parallelogram=
#(ly:make-stencil(list'embedded-ps
"gsave
 currentpoint translate
 newpath
 0 0.25 moveto
 1.3125 0.75 lineto
 1.3125 -0.25 lineto
 0 -0.75 lineto
 closepath
 fill
 grestore")
(cons01.3125)
(cons-.75.75))
myNoteHeads=\overrideNoteHead.stencil=\parallelogram
normalNoteHeads=\revertNoteHead.stencil
\relativec''{
\myNoteHeads
g4d'
\normalNoteHeads
<f,\tweakstencil\parallelogrambe>4d
}

[image of music]


Using the \tweak command to tweak individual grobs

With the \tweak command, every grob can be tuned directly. Here are some examples of available tweaks.

\relativec'{
\time2/4
\setfingeringOrientations=#'(right)
<
\tweakfont-size#3c
\tweakcolor#redd-\tweakfont-size#8-4
\tweakstyle#'crossg
\tweakduration-log#2a
>2
}

[image of music]


Vertically aligned dynamics and textscripts

All DynamicLineSpanner objects (hairpins and dynamic texts) are placed with their reference line at least 'staff-padding from the staff, unless other notation forces them to be farther. Setting 'staff-padding to a sufficiently large value aligns the dynamics.

The same idea, together with \textLengthOn, is used to align the text scripts along their baseline.

music=\relativec'{
a'2\pb\f
e4\pf\f\>g,b\p
c2^\markup{\hugegorgeous}c^\markup{\hugefantastic}
}
{
\music
\break
\overrideDynamicLineSpanner.staff-padding=#3
\textLengthOn
\overrideTextScript.staff-padding=#1
\music
}

[image of music]


Vertically aligning ossias and lyrics

This snippet demonstrates the use of the context properties alignBelowContext and alignAboveContext to control the positioning of lyrics and ossias.

\paper{
ragged-right=##t
}
\relativec'<<
\newStaff="1"{c4cs2}
\newStaff="2"{c4cs2}
\newStaff="3"{c4cs2}
{\skip2
<<
\lyrics{
\setalignBelowContext=#"1"
lyrics4below
}
\newStaff\with{
alignAboveContext=#"3"
fontSize=#-2
\overrideStaffSymbol.staff-space=#(magstep-2)
\remove"Time_signature_engraver"
}{
\tuplet6/4{
\overrideTextScript.padding=#3
c8[^"ossia above"dedef]
}
}
>>
}
>>

[image of music]


Vertically centering paired figured bass extenders

Where figured bass extender lines are being used by setting useBassFigureExtenders to true, pairs of congruent figured bass extender lines are vertically centered if figuredBassCenterContinuations is set to true.

<<
\relativec'{
c8cbbaac16cbb
c8cbbaac16cbb
c8cbbaaccbb
}
\figures{
\setuseBassFigureExtenders=##t
<6+43>4<643>8r
<6+43>4<643>8<43+>16r
\setfiguredBassCenterContinuations=##t
<6+43>4<643>8r
<6+43>4<643>8<43+>16r
\setfiguredBassCenterContinuations=##f
<6+43>4<643>8r
<6+43>4<643>8<43+>8
}
>>

[image of music]


<< Back to Documentation Index

LilyPond — Snippets v2.24.4 (stable-branch).

AltStyle によって変換されたページ (->オリジナル) /