# Trees, Music and Lilypond

In this post I write about some hierarchical aspects of typesetting music with LilyPond. In a way the elements that form a musical score can be split into pieces that stand in a hierarchical relation. We can make use of this relationship to do interesting stuff such as creating templates and injecting tweaks into a score without touching the music source itself. For my personal use I have developed several tools that help me manage my projects in a structured manner. Recently I made them publicly available and today I’ll start introducing them on this blog. This first post is about the theory behind the implementation which I will describe in following articles. Continue reading

# What You “Miss” When Using Version Control

Recently I stumbled over this list about “How I save documents” – it’s German but you’ll surely get the point.

It is meant to be funny, but actually it’s a comprehensive documentation of one of the reasons why using plain text and version control rocks. When presented with this list scholars or other people usually respond with telling sighs of recognition – while my personal recognition has actually faded away and has to be actively pulled from a very distant past

I realized that while having written so much about version control on Scores Of Beauty we don’t have an article yet telling you concisely why you should use it as your bread-and-butter tool for daily work. So today I’m going to give you a list of things you will miss and eventually forget when you switch your toolkit to using version control.

# Slur shapes and transposed parts: Use tags!

Many contemporary music scores are engraved in concert pitch for easier reading. Parts for transposing instruments must (obviously) be transposed. This may cause slurs and ties to be shaped differently between the score and the parts. In most cases, LilyPond’s d default slur and tie positioning will be attractive enough. If so, there’s no particular problem: LilyPond will calculate the slur/tie shape based on the notes actually being processed at the time.

It does present a problem if the default shape needs to be modified using the \shape command. \shape specifies the alteration in terms of moving the Bezier curve’s control points away from their default positions:

\shape #'((dx0 . dy0) (dx1 . dy1) (dx2 . dy2) (dx3 . dy3)) Slur

To make a downward slur deeper, for instance, you would push the
middle control points down:

\shape #'((0 . 0) (0 . -1) (0 . -1) (0 . 0)) Slur

If transposition should cause the slur to flip upward, this modification will flatten the curve instead. This is quite likely to look wrong, perhaps even unreadable.

I recently ran into this problem in one bar of a trio d’anches that I’m close to finishing. This bar contains a melodic phrase that spans 2.5 octaves in the space of five notes before leaping down a major tenth, under a slur. (Note that the notes themselves are contained in a music variable, and the score only refers to the variable. This is standard practice for any LilyPond project where a score and parts must be generated. It makes it possible to enter the notes once, and lay them out in a score or in parts as needed.)

music = \relative c' {
\tupletSpan 1*6/8
\tuplet 4/3 {
cis4 f,! ( d' e cis' b'2 g,4 )
}
\tupletSpan \default
}

{ \time 12/8 \music }

(click to enlarge)

The slur is pretty close, although it makes me a little physically uncomfortable to look at it. There is not enough space above the B, and the shape also disguises the sharp downward leap in the last note.

To fix it, push the third control point up (positive Y offset), and the last control point down.

music = \relative c' {
\tupletSpan 1*6/8
\tuplet 4/3 {
cis4
\shape #'((0 . 0) (0 . 0) (0 . 1.2) (0 . -0.5)) Slur
f,! ( d' e cis' b'2 g,4 )
}
\tupletSpan \default
}

{ \time 12/8 \music }

(click to enlarge)

What happens if we use that music in a transposed part, however?

music = \relative c' {
\tupletSpan 1*6/8
\tuplet 4/3 {
cis4
\shape #'((0 . 0) (0 . 0) (0 . 1.2) (0 . -0.5)) Slur
f,! ( d' e cis' b'2 g,4 )
}
\tupletSpan \default
}

{ \time 12/8 \transpose a c' \music }


(click to enlarge)

Now, the slur begins below the top of the stem and just to the right, and it ends quite a bit closer to the notehead than the concert-pitch version. These differences mean that the default curve for A clarinet is much more pronounced. The \shape alteration for concert pitch increases the curvature even further, making the transposed slur look exceptionally “loopy.”

So we need more curvature than the default for concert pitch, and less curvature of the transposed part.

But, in the \shape examples in the LilyPond manuals, it appears that \shape must appear right before the note that initiates the slur or tie to be affected. That is, in normal usage, you can have only one \shape per slur or tie. In this case, the music variable needs to specify both shape modifications, and the music expression that uses the variable should be able to choose which one to use at the time of engraving.

LilyPond has a mechanism to choose between versions of some content: tags. A portion of music (a music expression) can be enclosed in curly braces and associated with a name using the \tag command. If the music variable is used without any tag references, all of the tagged expressions will be kept. Other commands, \keepWithTag and \removeWithTag, can cause certain tagged expressions to be ignored.

music = { \tag #'tagName { ... music expression ... } }

% Elsewhere, in the score
\keepWithTag #'tagName \music

It might not seem to apply to this case, because most uses of \tag will include real music in the expression. Here, all the notes are the same; it would be redundant to put notes inside the tags. Ideally, the tags would include only the content that is different: namely, the \shape alterations. But is that legal? Will it break the \shape calls to put them inside a tag, while the slur itself is outside?

In fact, it is legal. \shape inserts \once \override commands into the expression. These are considered “music,” and may legally appear alone in a tagged expression. The final expression that LilyPond renders includes the override, followed immediately by the slur to affect: no problem.

So the surprisingly simple solution is to write both \shape alterations, each with a different \tag. Then, use \keepWithTag or \removeWithTag to choose which of the \shape calls will be used in this context.

music = \relative c' {
\tupletSpan 1*6/8
\tuplet 4/3 {
cis4
\tag #'scoreOnly { \shape #'((0 . 0) (0 . 0) (0 . 1.2) (0 . -0.5)) Slur }
\tag #'partOnly { \shape #'((-0.5 . 1.5) (0 . 0) (0 . 0) (0 . 1.0)) Slur }
f,! ( d' e cis' b'2 g,4 )
}
\tupletSpan \default
}

\markup \bold "Score in concert pitch"
\score {
\new Staff { \time 12/8 \keepWithTag #'scoreOnly \music }
}

\markup \column { \vspace #1 \bold "Part, transposed for clarinet in A" }
\score {
\new Staff { \time 12/8 \transpose a c' \keepWithTag #'partOnly \music }
}

More on tags: Using tags

More on shape: Modifying shapes

# Polymetrics in Sibelius (vs. LilyPond)

Recently I published an article about polymetric notation to demonstrate how LilyPond provides easy solutions for desires that Finale leaves unfulfilled. Now I got some excerpts from the Sibelius manual showing how that program deals with the task of polymetric notation, and I think this is a good opportunity to have a look at the different approaches to this topic. Continue reading

# The Ring Closes

Oh my, it has been more than a month without anything new on Scores of Beauty – what a shame. OK, we haven’t been lazy in the meantime, but there simply hasn’t been the time to squeeze anything in that could be shared publicly. Maybe I’ll find the time to report about my participation in a conference on “Digital Music Edition” at the university of Berne earlier this month, but for now you’ll have to do with today’s little post about two rings. Continue reading

# The Pleasantry of LilyPonding

Sometimes I wonder why I work with LilyPond. Often it means investing many tedious hours in music typesetting, and any given small issue can take a lot of time and deep research to solve. Yet I still use LilyPond, and I love it. But why? Continue reading

# Les fonctions musicales 4. La récursivité

Traduction d’un article de Urs Liska

Nous conclurons aujourd’hui cette série d’articles sur les fonctions musicales avec LilyPond. J’ai pris soin de prendre mon temps dans les explications, parce que c’est justement ce qui manque à la documentation de Lilypond – par ailleurs excellente. Disons qu’en son temps, j’aurais aimé avoir ce genre d’explications…

Dans le premier article, nous avons vu comment insérer une fonction musicale dans les fichiers source LilyPond. Dans le second, nous avons commencé à écrire une fonction qui colorie une expression musicale donnée avec une couleur de notre choix, en ayant toutefois pratiqué du codage en dur et beaucoup de redondance. Le troisième article a été l’occasion d’aborder la factorisation et l’utilisation des listes. Nous n’avons pas pu atteindre notre but comme souhaité, ce qui sera fait dans ce quatrième article. Continue reading

# Les fonctions musicales 3. Du code réutilisable

Traduction d’un article de Urs Liska

Dans l’article précédent, nous avons écrit une fonction permettant de coloriser une expression musicale avec différentes couleurs choisies. Nous avons pointé du doigt le problème suivant : nous devions modifier chaque propriété manuellement – et d’ailleurs nous n’avons pas pu les identifier toutes. En répétant la fonction \override, nous avons commis des redondances qui vont à l’encontre des bonnes pratiques de programmation. Aujourd’hui, nous allons faire beaucoup mieux et
apprendre à créer du code réutilisable en factorisant et en utilisant des opérations sur les listes. Continue reading

# Independent Meters

Nearly a year ago a post on the Finale Blog triggered a short series of posts about programmatically generating polymetric notation with LilyPond. Now it happened again, but this time with some indignation behind it. Last week I saw a post about Brian Ferneyhough visiting MakeMusic with a comment asking for “a neat way to have bar lines and meters happen by instrument”. I wrote a short comment pointing to my previously mentioned article on Scores of Beauty (although it only shows half of that wish) – and what do you think? My comment was “awaiting moderation” (the normal procedure), but apparently they decided not to “approve” it .

I think that really stinks. While my comment of course wasn’t the type one wants to have on one’s blog, I consider it somewhat pitiful to use the tool of moderation to sweep a “minority report” under the carpet. On Scores of Beauty we only discard real spam, that is (mostly) offers to increase our web traffic or to buy cheap expensive watches etc.

Therefore I felt obliged to write a full (albeit rather short) post about yet another field where Lilypond clearly surpasses Finale: the rock solid rhythmic (re)presentation of the music, which is one of the more interesting strengths of LilyPond. Continue reading

# Les fonctions musicales 2. Commençons à faire quelque chose d’utile !

Traduction d’un article de Urs Liska

Dans l’article précédent, j’ai montré comment insérer du code Scheme dans les fichiers sources LilyPond. Nous avons pu écrire notre première fonction : avouons qu’elle n’était pas très utile. Aujourd’hui, nous allons nous attaquer à des fonctions qui font vraiment quelque chose, et utilisent des paramètres. Continue reading