Monday, February 10, 2020

LilyPond: LaTeX for Music

I've written in the past about \(\LaTeX\), the markup language which allows you to typeset math beautifully. This weekend I finally got around to teaching myself LilyPond, which is pretty much (as the title says) \(\LaTeX\) for music: it's a markup language which allows typesetting (or “engraving”) beautiful musical scores.

Now, I'm hardly the most musical person around; my musical education has been haphazard, much of that due, I will freely admit, to my childhood disdain for practicing things. I had a few months of violin lessens when I was about ten (right before moving internationally, which didn't help), and I taught myself to play the harmonica a bit from books in my teens (though I haven't touched it in years). I've always enjoyed listening to classical music, and I'm familiar with a lot of the terms and names for various markings, but that's about it; I can just barely read sheet music at a glacial pace.

So I was rather pleasantly surprised to discover that I took to writing LilyPond code like a fish to water after a few hours spent reading the (exceedingly well-formatted) documentation. (I think I'm just a sucker for markup languages in general; HTML, \(\LaTeX\), even SVG could be considered a form of visual markup language even if I never actually engage with the underlying code.) In less than an hour I'd managed to reproduce the short piece by Beethoven below, which, while certainly not that complex (it only runs for about 40 seconds), is also no “Twinkle, Twinkle, Little Star.” (Part of that time was that I had to look up how to handle repeats, which wasn't covered by the documentation I'd read up that point.)


I had to guess on the tempo, as the sheet music I copied it from didn't have one listed and I was going off the speed I'd heard it played. Looking up tempo names led me to the interesting fact that the pace represented by “allegretto” changed between the 18th and 19th centuries; originally it was considered to be just above andante, but it ‘moved up’ and is now considered just a bit under allegro. I realized that my conception of it has more in common with the 18th century view, and having listened to a lot of Beethoven's music (and the tempos he called allegretto) I feel like he'd probably be fine with it. I added a BPM measure to make it explicit, anyway.

All in all, I had a surprising amount of fun engraving music, and I'm itching to do more (though at this point I guess I'll mostly just be copying existing music). LilyPond is supposed to handle lyrics quite well, so it'd be interesting to try some vocal music, perhaps. I've been using a very nice editor for LilyPond called Frescobaldi, which acts as a GUI and handles a lot of the little things. It has a really nice preview feature where mousing over or selecting any note in the score has the corresponding part of the code highlighted, and vice versa. We'll see where I go with this in the future, I guess! A hui hou!

No comments:

Post a Comment

Think I said something interesting or insightful? Let me know what you thought! Or even just drop in and say "hi" once in a while - I always enjoy reading comments.