This scheme function can be used to produce colored note heads that have a black outline.
The colors are automatically applied based on a given note's name and also (optionally) its alteration (natural, sharp, flat, double sharp, double flat).
What's this? Searching the LSR Browse by date Contributing Snippet database | Browsing items 230−239 out of 949 |
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.
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
.
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.)
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))
withUP
(=1) DOWN
(=-1) or 0 (up and down)
\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
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:Warning: Color_interval_engraver: In interval (2++ 2 #f (0.5 0.5 0.0)), wrong type argument: 2, needs to be a direction.
Warning: Color_interval_engraver: Recoloring note head in Voice N/A, bar number 1
# belongs to intervals ((2 . 3) 1 #f (0.0 1.0 0.0)) and ((3 . 5) -1 #f (1.0 0.0 0.0))
Warning: Adding color_interval_engraver to a Staff context may lead to unexpected results if the Staff contains more than one voice.
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.