SMuFL Fonts in LilyPond

In the context of developing new software for music notation, Steinberg proposed a new font standard, Standard Music Font Layout SMuFL, and delivered a corresponding new music font called Bravura. The development progress of the upcoming notation program is covered on the Steinberg blog Making Notes. For me personally, I am a bit skeptical whether all their goals can be met but this article is only about Bravura and the SMuFL standard.

Bravura is currently the only font following the proposed standard, but chances are that more fonts will follow. Fortunately Bravura has been released as a free font under the SIL Open Font Licence, so it is possible to use it in Free software such as GNU/LilyPond.

The use of fonts in music notation programs is quite different from their use in text processing tools, and in particular it’s less standardized. LilyPond has its own specific way to handle its notation font Feta, for example, because it uses different font versions for different sizes, and because it draws many objects itself rather than printing glyphs from a font. Therefore, it’s not exactly trivial to use other notation fonts with LilyPond. Not long ago Torsten Hämmerle created a Jazz font for use with LilyPond, and now Nathan Ho adapted his technique to make SMuFL fonts available for LilyPond too.

I have included Nathan’s Bravura/SMuFL support package in the openLilyLib snippets repository, and this post gives you an overview about its usage as well as about its implementation.

Usage Example

In order to use Bravura in LilyPond, you should “install” the openLilyLib snippets repository (following the instructions found there). While you can also get it running independently, the following descriptions refer to use from within openLiylLib and assume that you have added the repository’s root directory to LilyPond’s include path.

An additional prerequisite is to copy the font itself (Bravura.otf) to the LilyPond font directory as described in the README. It is important to note that SMuFL is still an evolving standard and that you can only use the Bravura font corresponding to the SMuFL version supported by the adaptor package. Therefore it is strongly recommended to use the font file provided in the repository.

Now you’re ready to activate the new font with:

\include "custom-music-fonts/smufl/definitions.ily"
{
  \bravuraOn
  % music goes here
}

To access single glyphs from the font, two commands are provided in analogy to LilyPond’s \musicglyph and \char commands. They allow you to insert glyphs by their name or their code point, respectively, while the standard LilyPond commands still return glyphs from Feta (LilyPond’s default font). This also allows you to mix both fonts in the same score. These two commands return the treble clef:

\smuflglyph #"gClef"
\smuflchar ##xE050

Now it is time for a complete example. Let’s look at the example document from the openLilyLib snippets repository. It uses the same music twice, once in the default style and once with the Bravura music font.

\version "2.18.0"

\include "definitions.ily"

music = \relative c' {
  \clef alto
  \time 3/4
  c4-.(\f\< d4-. es4-.) |
  \time 4/4
  fis8.---\trill\sfz\> e!16\downbow d16->\niente r16 r8 c2-\prall |
  \time 2/2
  \clef treble
  r2-\fermata c8( eeh8)-^ \tuplet 3/2 { eeh8( gisih8 b')-! } |
}

<<
  \new Staff \with { instrumentName = "Feta" } \music
  \new Staff \with { \bravuraOn instrumentName = "Bravura" } \music
>>

And this is what it looks like:

Bravura example (click to enlarge)

Example for Bravura used with LilyPond. The first staff is done with the default font Feta, the second one with Bravura (click to enlarge).

How This is Achieved Internally

For readers who are interested in how things works internally, let’s look at the code for smufl rests as an example from the definitions.ily file.

By including the definition, two functions are defined for rests: The function smufl-duration-name returns the part of the name in the smufl naming scheme that stands for the (logarithmic) duration.

#(define (smufl-duration-name log)
   (list-ref
    '("Longa" "DoubleWhole" "Whole" "Half" "Quarter" "8th" "16th"
      "32nd" "64th" "128th" "256th" "512th" "1024th")
    (+ log 2)))

The smufl-rest function takes the duration of the graphical object of the rest to be drawn, appends it to the word “rest” (e.g. “restHalf”) to form the full glyphname in SMuFL, and returns this smuflglyph as markup.

#(define (smufl-rest grob)
   (let* ((duration (ly:grob-property grob 'duration-log))
          (glyphname (string-append "rest" (smufl-duration-name duration))))
     (grob-interpret-markup grob (markup #:smuflglyph glyphname))))

So far nothing has happend to the score, but everything which is needed for rests is now available. By overriding the stencil of rests with the above defined smufl-rest function, the corresponding SMuFL glyph is printed instead of the usual Feta glyph. This change is made on the staff level.

\override Staff.Rest.stencil = #smufl-rest

What \bravuraOn and \smuflOn actually do is override the stencils for a whole range of glyph groups. By only doing these overrides for certain selected stencils some types of symbols can be cherry-picked from the Bravura font. For example, if you prefer the Bravura clefs, this command will let you use them, while all the other symbols are still the default LilyPond (Feta) glyphs:

\override Staff.Clef.stencil = #smufl-clef

Summary

This post has given you a general overview of using SMuFL compliant fonts with LilyPond. There are still open issues with the integration of SMuFL with LilyPond, therefore the use of Bravura in LilyPond cannot be recommended for publication quality scores, yet. But it already looks reasonably good.

In an upcoming post I’ll do some detailed comparisons between LilyPond’s Feta font and Bravura, the only SMuFL font that is currently available.

16 thoughts on “SMuFL Fonts in LilyPond

  1. vvillenave

    Hm, your music example deliberately makes GNU LilyPond look bad as it includes a “n” in the dynamics (of which I have yet to see *any* example anywhere in the real world. I mean, come on).

    Other than that, that font doesn’t look bad; not too sure about the consistency though — some glyphs look bolder (e.g. the C clef, which is really nice BTW), others don’t (the “C” time sig, for example); the trill sign is nicely done, whereas the prall sign is ugly. Not to mention the accidentals (I had to download the PDF to see if the three-quarter-sharp really looked as bad as it seems here — turns out, it does).

    Another thing you failed to mention is that LilyPond’s fonts are internally programmed in MetaFont, a very rich, very elegant (and, to 99,99% of the computer-savvy world, very mysterious) way of depicting glyphs ; while I have no doubt that there can be beautiful fonts done in almost any way possible, I do think that the richness and consistency of our music font is correlated with the use of MetaFont, even though it gets translated (in a rather ugly way, but that’s how things are done) into various PostScript fonts for various sizes.

    Reply
    1. Nathan Ho

      I’ve seen niente quite a few times, but that’s mostly because I regularly deal with contemporary scores. It’s included in the comparison because I was pretty excited to finally have it as a real glyph rather than an italic ‘n’ as I’ve done before. Perhaps it is somewhat dishonest, but the example was made to test LilySMuFL for funky alignments, etc. rather than to compare fonts.

      Reply
    2. Marnen Laibow-Koser

      “I do think that the richness and consistency of our music font is correlated with the use of MetaFont”

      Consistently ugly, perhaps? I find the Feta font rather unattractive (especially the G clef and trill sign). I doubt that the use of MetaFont has anything to do with the aesthetics of the font, though.

      Reply
      1. Joram Berger Post author

        I think the consistency mentioned before is about line widths and the relative size of symbols. This is related to Metafont as it explicitely connects the line widths of glyphs and allows for different shapes designed for different font sizes. This adaption of the stroke widths to pocket scores or large children scores is a nice feature of MetaFont. For sure, this is mostly independent from the look of a single glyph.

        I made the experience that most people like the style they know. This is particularly true for the G clef, because that’s the symbol that sticks out most. This also means that not everyone can be satisfied with the same glyph. Personally, I like Bärenreiter and LilyPond clefs, others are used to Henle, Sibelius or Finale clefs. I haven’t seen the perfect G clef yet – I mean one that really convinced me that this is how it should be. Do you know the perfect G clef?

        Reply
      2. Nathan Ho

        I agree that the Feta G clef is rather oddly proportioned. The top loop is too wide and the entire glyph has a weird counterclockwise tilt.

        Reply
  2. Joram Berger Post author

    You are right with the niente sign. I changed it to what is acutally the case: it is missing in Feta, so it does not show up (even though that is not exactly in line with the example code).

    The uneven sizes made me wonder, too. A more detailed comparison will follow.

    For your last point, I am no expert on Metafont and I wanted to keep the post focused on the user side.

    Reply
  3. vvillenave

    Oh, “n” for niente. Never thought about that. (As you know, LilyPond has circled-ending hairpins for such decrescendos, which I find more convenient.) It still isn’t quite the same as other dynamic glyphs which one can combine: you can see “fpp” or “sfz” but I guess a “nsfp” wouldn’t make much sense.

    Reply
  4. Pingback: Feta and Bravura | Scores of Beauty

  5. Pingback: Using special characters from SMuFL fonts | Scores of Beauty

  6. Pingback: Development diary, part seven | MAKING NOTES

  7. Pingback: LilyPond’s Look & Feel | Scores of Beauty

  8. Robert P.

    Hi,

    This is a great resource. Thanks so much!

    Nathan, I am following your steps (if you do not mind) for my upcoming November 2.0 font, SMuFL-compliant but with also numerous extra characters (and I hope you guys will like “my” G clef…)

    Robert

    Reply
    1. Andrew Griffiths

      Hi Robert,

      Got November 2.0 installed and was very easy. One problem. Trill symbols are fine when using \trill, but when using \startTrillSpan to place a trill with line, the symbols appear as Lilypond default font, not November.

      Any ideas?

      Reply
      1. Robert P.

        Hi Andrew,

        I’m glad installing November 2.0 was smooth, and yes you’re right about the spanned trill!

        I am working on improving the support in LilyPond for the upcoming 2.0.1 maintenance release of November.
        The spanners (trills, pedal sustain, ottaves, …) are more difficult to override. In particular, the trill wiggle (~) seems to be deeply hard-wired. I’m considering several options.

        Here is what’s in sight for 2.0.1:

        1) trill spanner
        2) stem tremolo
        3) ottavas (spanned or not)
        4) arpeggios
        5) piano pedal

        Thanks,
        Robert

        Reply

Leave a Reply

Your email address will not be published. Required fields are marked *