The LilyPond Snippet Repository ♪♫

What's this? Searching the LSR Browse by date Contributing Snippet database Browsing items 230−239 out of 940

Coloring grobs and notational elements using a sophisticated music function

Some scholarly or ‘urtext’ editions use grey color to indicate editorial additions. I find this very elegant, so I wrote a function to easily use this in a score. Instead of writing \override [Context.]Grob.color = #grey …some music… \revert [Context.]Grob.color, it allows to simply write \ed [Context.]Grob [#color] { …some music } (or omit the {}, if it’s only for one note or rest). Note that in v2.18 there is a shortcoming here: a single rest or multi measure rest will need to be enclosed in braces. This doesn’t hold anymore with v2.19, at the least since 2.19.8.

The color may be optionally specified to use another than the default color (defined as editorsColor).

In order to conveniently address more complex notational elements (and to save typing with long grob names), the function also permits using shortcuts such as \ed Note { …some music } . Some are predefined, but others may be easily added.

Coloring grobs and notational elements using a sophisticated music function

Coloring individual staff lines

Staff lines can be colored independently by overriding the default stencil for StaffSymbol.

The StaffSymbol callback color-staff-lines takes a set of colors (using LilyPond's predefined colors or the functions x11-color and rgb-color) which are applied to each staff line in turn starting with the fifth line (for a standard staff), or each item in the list for custom staves defined with line-positions. To signal that a particular line between colored lines should remain black, use #f.

Coloring individual staff lines

Coloring notes depending on their pitch

It is possible to color note heads depending on their pitch and/or their names: the function used in this example even makes it possible to distinguish enharmonics.

Coloring notes depending on their pitch

Coloring notes depending on their pitch (alternate version)

It is possible to color note heads depending on their pitch and/or their names: the function used in this example even makes it possible to distinguish enharmonics.

This is an alternate version of the original snippet found here: http://lsr.di.unimi.it/LSR/Item?id=572 This version achieves the same result by using different code that some may find easier to understand. (It uses case rather than an association list to assign the colors.)

Coloring notes depending on their pitch (alternate version)

Coloring objects

LilyPond gives you the ability to assign different colors to any grob in your score, such as NoteHeads, Alterations, Beams and so on, by simply overriding the #'color property and choosing your color (as explained in the Notation Reference, it is possible to obtain about any color).

Coloring objects

Coloring staves

The following example demonstrates how to print individual staves with a colored background.

Coloring staves

Coloring successive intervals

This scheme engraver searches for specified successive intervals in a voice, e.g. a minor third. If the interval occurs somewhere, the note heads of both notes defining the interval are colored. The engraver can be added to every Voice context.

Usage: \color_interval_engraver #intervaldefs #debug? #intervals-given

intervaldefs: alist containing information about semitonical distances for certain intervals, diatonical distance is calculated in the engraver using `string-diatonic-semi-tonic-list`, relying on the key.

debug?: (optional) boolean, if true, output information about the processed pitches

intervals-given: list of the form


#`((interval1 ,dir1 enh1 ,color1)
   (interval2 ,dir2 enh2 ,color2)
    ...
   (intervalN ,dirN enhN ,colorN))
with

intervalN: string - specifying the interval to search after

dirN: integer - UP (=1) DOWN (=-1) or 0 (up and down)

enhN: boolean - search for enharmonically equivalent intervals, too?

colorN: lilypond color value, see NR A.7. Example:

\layout {
   \context {
     \Voice
     \consists \color_interval_engraver #intervaldefs
       #`(("2--" ,UP #f ,green)
          ("3+" ,DOWN #t ,blue))
   }
}
Debug mode:

With debug? set to #t, the engraver does output

Warnings:

The engraver tries to provide helpful warning messages when fed with invalid input or if other issues prevent the engraver from working correctly.

Some examples:

Coloring successive intervals

Combining a time signature glyph and a default time signature

In mensural notation, you can find double time signatures, such as mensural 6/4 followed by the classical time signature 3/2 (in ternary white notation for instance). This scheme function, adapted from the http://lsr.di.unimi.it/LSR/Item?id=192 snippet, allows you to do so.

The glyph argument is the name of the glyph in the Feta font. This means that in fact this function can include any glyph. The baseline-skip value can be adjusted to your needs, as well as the font-size specifications.

Combining a time signature glyph and a default time signature

Combining beam and slur in one keystroke

If a vocal part contains many short note values and melismata, and melismata are shown by both beams and slurs, there are many instances of d([ b)] for example. To save tedious keystrokes, it’s very convenient to redefine [ and ] so they provoke both the beam and the slur. Alternatively, the slurs may be omitted as in the second example, to avoid misinterpretations (performers might take the slur as an indication for dynamics and articulation, even if it’s only intended to provide information on melismata) or to get a clearer, less crowded look.

Combining beam and slur in one keystroke

Combining dynamics with markup texts

Some dynamics may involve text indications (such as più forte or piano subito). These can be produced using a \markup block.

Combining dynamics with markup texts

⇦ Previous 21 22 23 24 25 26 27 28 29 30 Next ⇨