36C3 preroll music
Herald: Welcome back to the WikipakaWG,
live from Congress, wir haben Lucas da,
Lucas is back, Lucas was just here 15
minutes ago, and now he's going to talk
about LilyPond. LilyPond is like LaTeX but
for music notes and I hope you will have
fun!
Lucas: Yeah. Thank you. Yeah, so I just
want to talk a bit about LilyPond, which
is a really cool program, in my opinion,
to turn basically plain text input, such
as the code you can see up here, into
beautifully typeset musical scores, such
as down here, and that's actually the
result of this code up here, so you can
try to find what belongs to what or
something. And, yeah, it’s free software
obviously, it takes plain text as input,
which means you can put the code in a git
repository and add comments and stuff,
it's all very nice, the output is PDF, or
MIDI if you want to listen back to it, or
you can even integrate it into LaTeX or
Texinfo documents, such as these slides,
which are created with LaTeX beamer and
LilyPond in them, which is really funny
combination and it works perfectly well.
So let's just start with some of the
syntax elements in a LilyPond file, and
it's pretty straightforward to make a note
with a certain note name, you write that
note name, so this is (I think) the
American note names, I'm not sure if the
English ones use different ones, but
ABCDEFGA are the note names, and you write
the letter and you get a note in return,
and the relative mode here means that each
note is going to be as close as possible
to the previous one, for example this A
here at the beginning and the one at the
end, that's the same input, but you can
see they resulted in different notes, so
this is one octave higher than the
original one, because that's the note
that's closest to the preceding note, and
to control the duration of a note, you put
a number after it, for example this is a
quarter note, so you put a number four
after it, this is a sixteenth note, so you
put a sixteen after it, and if it's a
dotted note, such like this one, you put a
literal dot after it. So there's a fair
bit of ASCII art in there, which is kind
of cute, and if it's more complicated,
like the triplets here at the end, you
write something like this \tuplet, so
that's kind of inspired by LaTeX syntax,
this backslashes and braces business, so
this started out, actually, as a – I
assume horrible – hack to make actually
LaTeX produce these scores, and then
eventually they realized that's not going
to work, we should actually write this as
a dedicated program in C or C++ (I don't
remember which one), but the syntax kind
of stayed similar, at least, in
remembrance of that. And let's go back to
a bit more syntax, as I said, in relative
mode the notes try to stay close together,
for example if I would just write C after
this G, it would be the upper C up here,
because that's closer than the lower C
down here, and to get the lower C, which
is correct in this melody (if you can
identify it that's an Easter Egg for you),
I put a comma after it, and to then jump
back to the upper G instead of the lower
one, I put an apostrophe after it, which
depending on the font – in this one it
works really well, it's kind of the same
character, just at the bottom and at the
top the line. In German the apostrophe is
also sometimes called the Hochkomma, the
upper comma, so it kind of makes sense
that you have these two characters to jump
up and down between octaves, and then you
start to get a feel eventually when you
need them and when you don't need them.
But otherwise you can just compile your
LilyPond code as often as you want and see
if it's right or not, because it doesn't
take that long. And if you need to modify
the notes further, so if you have flat or
sharp notes, you can teach LilyPond to
understand “G sharp”, for example, but no
one will understand your score, because
the standard notation in LilyPond is to
add either an -is or an -es to the end of
the note, which is exactly what these
notes are called in German, which is very
convenient if you're German, like me – the
manual says it's Dutch notation or
something – so fis means the F sharp, but
what's important is, this doesn't
literally mean: put an F and then put a
sharp right in front of it, it means,
logically, in the music, there's an F
sharp, but then LilyPond can look, for
example here it just puts an F, because
the F sharp is already part of the key
signature, this whole snippet is in B
minor, so it has to have… no, it's in E
minor, sorry, so it has to have F sharp
already and we don't need to put one here.
On the other hand, here we have an F, and
in the syntax, in the input that's just an
F, but then LilyPond knows, because the
key signature has an F sharp, it actually
needs to put a natural sign here to cancel
that out. So what you put in is kind of
the logical, real music, so to speak, and
then it's LilyPond’s job to figure out,
where do I need to put these accidentals,
where do I need to put these natural
signs, and this depends even on which
century’s style you're trying to emulate
and which instrument, like sometimes these
things are in parentheses and sometimes
they're not, but in general all of this is
LilyPond’s job, you put in just the music
and LilyPond makes a beautiful score for
you, that's the job, at least. If that
doesn't work out, you can tweak the
output, and here I have some… a bit
sillier tweaks, for example I wanted a
larger note head, for some reason, and the
note head is a character in a special font
which LilyPond ships and embeds in this
PDF file, and if I say, I would like to
add 4 to the font size, then I get a
larger note head, at least for this one
note. Or I can say I would like the color
of all the note heads to be in dark red
now, or this tie, which would normally be
downwards, like this one, it should now go
upwards, because I've overridden it here,
and I can even say – so this tie is
actually a cubic Bezier curve, so it's
going to have four control points, and I
would like to add these four pairs of
offsets to the four control points, to
make this kind of looping shape – that's
obviously very silly, but sometimes this
can be useful, like if you have a score
where you have a long… articulation bow
(I'm not sure what it's called in English,
actually), but this kind of thing over a
long period of notes, where it makes like
a Z shape or an S shape, and LilyPond
can't figure that out by itself, then you
can tell it, I would like the curve to
look exactly like this, and kind of tweak
the output as much as you want. And you
can actually go even further than this –
does anyone in the audience recognize this
kind of syntax here? This kind of –
(audience member: Lisp!) Yes! Lisp, it is
a dialect of Lisp called Scheme, so you
can embed whole Scheme programs in your
score, so here I've said the color of each
stem should be controlled by this lambda,
this anonymous function, which takes a
graphical object, in this case that's
going to be the stem, and compare the
direction of that to “up”, if it's “up”,
then return red, otherwise return blue, so
now I have a score where all the stems are
blue if they point down and red if they
point up, which is completely pointless,
but it's very funny. And you can go much
further than this, like, this is some
monstrosity I wrote because I wanted to
have this score, where you can see, in the
right hand, here, you have the same notes
twice, once in the baseline and then one
octave higher, and it's just always one
octave higher, and for some reason I could
not be bothered to actually add the second
note to each of the eight chords here,
which would have taken, like, two minutes
at most, and instead I spent, like, one
and a half hours putting together this
code, which takes an arbitrary melody and
goes through it and for each note creates
a copied note which is somewhere here,
yeah, it creates a copy of the note, then
sets the pitch to something else and
copies some of the articulations but not
others, so this has a second tie here but
it should not have a second fermata sign,
and in the end you have this function and
you can even put it on StackOverflow or
something, and that kind of represents
what I really like about LilyPond, that it
represents this whole spectrum between
just simple music transcription and full-
blown programming, so if I get home at the
end of the day, and I'm really tired and
don't have much mental capacity, I can
just take some public domain score and
transcribe it and just say, this is a D,
this is an F sharp, this is a quarter
note, and so on, and it doesn't take much
work, but if I want, if I feel up to it or
if I want to have some fun, then I can
also do the whole programming thing and
write monsters like this and completely
bend the score to my will, make it look
exactly how I want to, and that's what I
find really neat about LilyPond, and if
you want to find out more about that,
there are two manuals here, they're really
well written, I basically read them front
to back a while ago, and they have lots of
examples as well. The LilyPond snippet
repository is even cooler, it's just a
huge collection of tiny snippets of
LilyPond code, and all of them are CC0, so
you can use them however you want without
worrying about attribution or anything,
and you can even try it out in your
browser, on lilybin.com, without
installing anything, and if you're
wondering, “wait, doesn't that mean I'm
running arbitrary code on someone else's
computer?” – it's not my computer,… I
don't know, knock yourself out, I guess,
but that's all I have already, I'm out of
time, but thank you for indulging me!
applause
postroll music
Subtitles created by c3subtitles.de
in the year 2020. Join, and help us!