< Return to Video

36C3 Wikipaka WG: LilyPond: programming beautiful musical scores

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

more » « less
Video Language:
English
Duration:
10:13

English subtitles

Revisions