The LilyPond Snippet Repository ♪♫

What's this? Searching the LSR Browse by date Contributing Snippet database Browsing items 0−19 out of 948

„Schleifer“ ornament implemented as modified grace note

Implementation by Martin Straeten of the Schleifer ornament as used by Johann Sebastian Bach, contributed to the user mailing list here. In this case, it functions like a set of (always?) two grace notes, hence using a modified grace note to represent it in LilyPond makes sense.

Code styling and user interface by Simon Albrecht 2024.

„Schleifer“ ornament implemented as modified grace note

(Correctly aligned) different dispersions of text in different stanzas

If different stanzas of a song have different amount of syllables the dispersion of the text may differ from stanza to stanza. This snippets shows a possibility how notes of the second stanza can be printed as cue notes when they differ from the notes of the first stanza. The lyrics of the different stanzas are aligned correctly according to the voice of the respective stanza.

(Correctly aligned) different dispersions of text in different stanzas

[OBSOLETE] Adding a QR code

This snippet lets you draw a QR-code, for example to provide a link to the composer's, or the music editor's website.

Actually encoding the URL into a QR-code is not done here (this just draws the QR-code from a grid of "black" or "white" values), but see the code for a short Python snippet you can use to avoid having to fill for each small square if it's black or white.

This snippet is obsolete starting from LilyPond 2.25.3, which adds a \qr-code markup command that takes a URL directly instead of a grid of "black" and "white" values. It is used like \markup \qr-code #10 "https://lilypond.org".

[OBSOLETE] Adding a QR code

A function to repeatedly print a given pattern with different notes

This snippet describes a function \changePitch, to repeatedly print a given rhythm with different notes. Its syntax is
\changePitch \pattern \newnotes
This will replace notes in \pattern by notes in \newnotes. If the note-count in \newnotes is greater, the pattern is copied repeatedly. Rests or skips are allowed, and the function also works for chords. More detailed documentation (in pdf format), and also the most recent "changePitch.ly" can be found here.

A function to repeatedly print a given pattern with different notes

Abbreviating bass note changes

A common practice in lead sheets is to abbreviate chord changes when only the bass note is changed. s, Cmaj7, Cmaj7/B would be written as Cmaj7, /B, for example. There is no simple way to do this in LilyPond, but it is possible to use a whiteout hack like snippet #309 to accomplish the desired effect.

Abbreviating bass note changes

Abbreviations for articulations

Some articulations may be entered using an abbreviation.

Abbreviations for articulations

Absolute positioning of markup elements (laying out tables)

Positioning markup elements relative to one another is complicated by the fact that the compiler will automatically place each element after the previous one, and you have to take this into account when positioning each element. The \combine command helps, but it can only take two arguments.

The \overlay-markup command takes a list of markup elements, it becomes much easier to lay out complex markup into specific arrangements, such as tables.

Absolute positioning of markup elements (laying out tables)

Acciaccatura markup

Here is a solution to print an acciaccatura in markup (for example, to give an execution hint for an appoggiatura, as found in baroque music).

Acciaccatura markup

Accidental adjustments for single-voice polyphony

LilyPond currently does not consider simultaneous notes to automatically determine the correct accidentals; it only looks at previous notes and key signatures. As a consequence, it is necessary to do some manual adjustments.

Unfortunately, these adjustments are quite complex. The Scheme code in this snippet provides a new engraver custom_accidental_placement_engraver that introduces a details subproperty flag called capture for the Accidental grob. If this flag is set, the current voice captures the accidental so that it is no longer aligned with the other accidentals in a note column. Together with other properties (force-hshift and ignore-collision) it is possible to achieve the desired result.

Accidental adjustments for single-voice polyphony

Accordion register symbols

Accordion register symbols are available as \markup as well as as standalone music events (as register changes tend to occur between actual music events). Bass registers are not overly standardized. The available commands can be found in 'Discant symbols' in the Notation Reference.

Accordion register symbols

Accordion-discant symbols

This snippet has been obsoleted by predefined markup commands, see 'Discant symbols' in the Notation Reference. It's still useful as a simple demonstration of how to combine symbols: the placement of the symbols added with \markup can be tweaked by changing the \translate-scaled arguments. \translate-scaled is used here rather than \translate in order to let the positioning of the symbol parts adapt to changes of font-size.

Accordion-discant symbols

Add wings to all repeat barlines (simple version)

After switching from Sibelius, I missed having all my repeat barlines have "wings" on them. It's not documented in the Lilypond documentation, but it's not too hard to accomplish. Just add this inside your Staff:

\set Score.startRepeatType = #"[|:" \set Score.endRepeatType = #":|]" \set Score.doubleRepeatType = #":|][|:"

Add wings to all repeat barlines (simple version)

Adding a figured bass above or below the notes

When writing a figured bass, you can place the figures 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).

This property can be changed as many times as you wish. Use \once \override if you don't want the override to apply to the whole score.

Adding a figured bass above or below the notes

Adding a laissezVibrer tie to only one note of a chord [obsolete in 2.23]

Sometimes it is required to apply a laissezVibrer tie to a specific note in a chord, for instance in a piano fingering where one finger of a chord should temporarily act as a pivot while the other fingers are moving to the the next chord. Here is a way to achieve it.

Adding a laissezVibrer tie to only one note of a chord [obsolete in 2.23]

Adding a Special Post Event Function to Implement Precise MIDI Velocity Value Control

This is a small hack to output MIDI file with precise velocity value control. This snippet adds a post event function \vel which enables you to set MIDI velocity value directly on any note event. This is accomplished by overriding dynamicAbsoluteVolumeFunction.

Adding a Special Post Event Function to Implement Precise MIDI Velocity Value Control

Adding accidentals to a trillspanner

By overriding bound-details, you can insert an accidental after the trill sign in a trillspanner. However, this can look ugly since the accidental isn't aligned. With a few tweaks to the script size and position, you can achieve quite pleasing results.

Adding accidentals to a trillspanner

Adding ambitus per voice

Ambitus can be added per voice. In this case, the ambitus must be moved manually to prevent collisions.

Adding ambitus per voice

Adding an extra staff

An extra staff can be added (possibly temporarily) after the start of a piece.

Adding an extra staff

Adding an extra staff (2)

To add an extra staff after the start of a piece, you can choose between having brackets or braces when you go over a new line:

=> Use PianoStaff instead of StaffGroup or ChoirStaff in the code.

You may wish to remove the clef and not only the key:

=> See both \overrides in the code.

You may wish to remove also the little part of staff at the beginning of the extra staff:

=> Use #'stencil = ##f instead of #'transparent = ##t for both \overrides.

If you want to keep the little beginning of staff, keep at least one #'transparent = ##t.

Adding an extra staff (2)

Adding an extra staff at a line break

When adding a new staff at a line break, some extra space is unfortunately added 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.

Adding an extra staff at a line break

1 2 3 4 5 6 7 8 9 10 Next ⇨