The story of “string bending” in LilyPond

Guitar bending

String bending is a playing technique for fretted string instruments — typical of blues and rock music — where fretting fingers pull the strings in a direction perpendicular to their vibrating length. This will increase the pitch of a note by any amount, allowing the exploration of microtonality. The animated image on the left shows how a string bending is performed on a guitar.

It requires a specific notation: the bending is usually represented on tablature by an arrowed line and a number showing the pitch alteration step (1/4 for a quarter, 1/2 for a half, 1 for a full bend, etc.). It’s a long standing feature request in LilyPond: issue 1196 was created on July 2010, almost 7 years ago, and collected more than €400 in bounty offers. During these years we’ve been able to draw bendings with the help of an external file written in 2009 by a LilyPond user, Marc Hohl. It worked quite well, but it was a kind of hack and therefore had some important limitations. When I happened to promote LilyPond, especially to tablature users, this missing feature was the “skeleton in the closet”. But something interesting is on the way. Last September Thomas Morley aka Harm, a LilyPond user and contributor, announced that he’s working on a new bending engraver, which overcomes those limitations and will hopefully be included in LilyPond in the near future. Let me tell you the whole story…

bend.ly, a smart hack

I know well the story, because it dates back to when I took my first steps as a LilyPond user. At beginning of 2009 I still was an (unhappy) user of Tuxguitar. I knew LilyPond, but I totally disliked the default tablature look (back then the default and unique tablature output available was what you get currently if you use tabFullNotation). Then I stumbled on an announcement on Tuxguitar forum saying that LilyPond was going to have support for modern tablature, which became the new default output starting with version 2.13.4. Immediately I quit Tuxguitar for LilyPond and never looked back. The author of these changes was Marc Hohl, a user who stepped into LilyPond development for the first time and managed, thanks to the great support from the lilypond-user mailing list (and his own Scheme skills), to bring modern tablature to LilyPond. It was again Marc who, a few months later, on August 2009, announced his first draft of bend.ly, an approach that built upon the engraving of slurs to print bending signs on staff and tablature. Despite the beauty and professional look of the bends, it was a hack and could not be considered for inclusion in the LilyPond source code. The main limitations of bend.ly were:

  • line breaks over bending notes were not supported
  • no easy way to let a hammer-on or pull-off follow a bending
  • need to manually adjust the distance between Staff and TabStaff in order to avoid collisions between the bending interval number and the staff

In order to overcome these limitations, we needed a specific bend engraver, that is a dedicated tool which is able to engrave bends in their own right and not as modified slurs.

In 2013 I decided to move bend.ly into a repository, so we could track the changes needed to make it work with new versions of LilyPond. We chose to use the openLilyLib snippets repository and its first location was notation-snippets/guitar-string-bending. Then it moved to the new location ly/tablature/bending.ily. The maintenance of this file passed on from Marc to Harm, who quickly fixed it every time something broke when using a recent development version of LilyPond.

The new bending engraver

Last September Harm posted the first draft of a new bend engraver, partly based on bend.ly and written entirely in Scheme. Allow me to make a brief “technical” digression. LilyPond input files can contain Scheme code, which can access the internals and change default LilyPond behaviour on the fly, i.e. without having to change the LilyPond binary. That’s why you can find power users of LilyPond who can code in Scheme. But most of the LilyPond engravers, at least so far, have been written in C++, a language used only by developers. The C++ requirement was one of the reasons why Marc could not write a real engraver seven years ago, as he was not able to code in this language. But in recent years the LilyPond internals responsible for building engravers improved, thanks to the great work of the core developer David Kastrup, and now writing an engraver entirely in Scheme is possible (or at least much easier than in the past).

The new bend spanner engraver, though working well already, has not been proposed for inclusion in the LilyPond codebase, because Harm wants to take some more time to refine it before going through the code review process. The code is currently hosted at this git repository and you can get the compressed archive file of the latest version from the release page. If you prefer downloading it with git, here’s the command:

git clone https://pagure.io/lilypond-bend-spanner.git

Move the downloaded folder into a directory which is include-able by LilyPond. Let’s see a simple example:

\version "2.19.55"
\include "bending.ily"

myMusic = \relative {
  <>^"Bend&release + pull-off"
  a8 c d\startBend dis\stopBend\startBend d\stopBend( c) a4 |
  
  <>^"Microtones bending"
  a4\startBend aih\stopBend a\startBend aisih\stopBend |
  
  <>^"Chord bending"
  <g~ d' g>8\startBend <g e' a>\stopBend
  % do not bend a note in a chord
  <\tweak bend-me ##f f a d>8\startBend <f ais dis>\stopBend\startBend <f a d>2\stopBend |
}

\score {
  \new StaffGroup <<
    \new Staff { \clef "treble_8" \myMusic }
    \new TabStaff { \clef "moderntab" \new TabVoice \myMusic }
  >>
  \layout {
    indent = 0
    ragged-right = ##f
    \context {
      % enable microtones
      \Score
      supportNonIntegerFret = ##t
    }
    \context {
      \Staff
      \omit StringNumber
    }
  }
}

And here’s the output:

Simple example of the main features of the bend spanner.

Simple example of the main features of the bend spanner.

More features can be seen in action in the test file test-suite/bend-test.ly, which demonstrates all the current capabilities of this engraver.

Roadmap

What to expect next? There’s not any public roadmap. It’s up to Harm to decide when his work is ready to be reviewed. In the meantime everybody interested in seeing bending included in LilyPond is encouraged to test it and report any feedback on the lilypond-user mailing list. This is going to be a game changer for LilyPond tablature users and I look forward to see this feature in LilyPond!

4 thoughts on “The story of “string bending” in LilyPond

  1. henrik

    I’m looking for the guitar strumming direction notation for down ⼌ and up Ⅴ

    nothing found in Snippet Repository – any help?

    Reply
  2. Federico Bruni Post author

    I would have searched in the Notation Reference manual first:
    http://lilypond.org/doc/v2.19/Documentation/notation/common-notation-for-unfretted-strings.html#bowing-indications

    So bowing is the right keyword, since these signs are mostly used in string (violins, etc.) music.

    Probably we should add an explanation of the strumming directions here:
    http://lilypond.org/doc/v2.19/Documentation/notation/displaying-rhythms.html#index-strumming-rhythms_002c-showing

    Reply
  3. Pete

    Hi Federico,

    First, thank you for all of your time which you devote to Lilypond.

    Re this article, I have been following Lilypond’s history of approaches to string-bending for several years and have been using Marc Hohl’s work to achieve most of what I need. I’ve now begun to use the new engraver which works beautifully in the TabStaff, but I am missing the pointed slurs on the regular Staff.

    How would you suggest that I achieve a provisional implementation? I’m thinking to use one of the following approaches:
    a) use Marc Hohl’s work for the Staff, and Harm’s work for the TabStaff
    b) write my own simple expression which modifies the Slur in the Staff

    Thanks again for all the great effort you put in to making Lilypond wonderful.

    Reply
    1. Federico Bruni Post author

      Hi Pete

      Personally I’d like to have the pointed slurs on Staff, but I’m fine without them because the advantages of the bend engraver greatly compensate this missing feature.
      I did not mention it in the post, as I hoped that it would have become obsolete soon as this feature was included in the new engraver. But we don’t know when it will!

      I would recommend to go with b), if you understand Scheme and you can adapt Marc’s code in the new bend engraver… And if you need help, you’d better ask on lilypond-user mailing list, where Marc Hohl and Harm will read your requests and reply directly to you.

      Reply

Leave a Reply

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