efroymson

Sunday, April 12, 2020

Abjad and Lilypond: Tools for Algorithmic Composition: First Look

Lilypond, which for some reason I keep calling Lilypad by mistake, is a TeX like tool for engraving beautiful sheet music.  Unlike Finale or Sibelius it does not use WYSIWYG mouse and keyboard input.  Rather you enter source code in a text editor, and use Lilypond to render it.

The advantages of that more than make up for the lack of point and click instant gratification.  What advantages?  Well there is the quality of the output, which is at least on par with those other programs, and maybe better.  More importantly for someone who wishes to do Algorithmic Composition is the simple fact that it expects a text file in a specific format as input.

Sounds like something that a computer program should be able to generate amirite?  Indeed, that is the purpose of Abjad.  Abjad is an extensive library of routines and objects that allow Python code to generate music that is in the Lilypond format, and thus can be beautifully rendered as sheet music for a performer.

I've been working on Electronic Music for some years, but only recently have I been given the opportunity to work with a live musician playing an Orchestra instrument.  It is one thing to program a sequencer to generate MIDI that is fed directly into another instrument, quite another to be able to hand some music to a musician with the expectation that they will be able to read and perform it.

Whenever I say "yes" to a project like that, it is always a bit like jumping off a cliff, and hoping that I will find water in which I can swim beneath.  Abjad and Lilypond are indeed sufficient water, and I have started swimming.  I don't want to go into much depth about them, partly because I still don't know much, but also because if you follow the links to the projects you will find a wealth of examples.  I found the Ligeti score example particularly helpful for my purposes.

One thing I do want to mention is some confusion with the word "Note".  That may seem silly, but bear with me.  A note might refer to a note in the scale: ABCDEFG, to a note on the piano keyboard: say A below Middle C, or to a  Midi note: Say note 66.  In Midi for example you can send a NoteOn and a NoteOff, but the notion of a quarter note is non-existent (though in Midifiles of course there are temporal delays, so duration can be represented).

In Lilypond and Abjad a Note is a combination of a piano or Midi type note, and a duration. It is possible to specify notes either by name, say c' or by number.  For algorithmic composition the number representation is much simpler.  Somewhat annoyingly (to me) the number assigned to Middle C is zero, so even if you are doing a simple piece of piano music you will have to deal with negative integers.  Yes I know that they were already well used by the 1500s, but if Leibniz thought they were "invalid", and Pascal "regarded the subtraction of 4 from 0 as utter nonsense" then maybe I am in good company.

In any event getting started is simple enough, the example at the Abjad front page includes these simple lines:
duration = abjad.Duration(1, 4)
notes = [abjad.Note(pitch, duration) for pitch in range(8)]

There is more to it, but you can see how easy it is to create an ascending chromatic scale of quarter notes.  Adding time and key signatures is a tiny bit more complicated, but the examples work through all of that as well.

tl;dr: Abjad and Lilypond are fantastic tools that let you create beautiful engravings of your musical ideas.  Strongly recommended!

1 Comments:

  • mbrsi.org is no longer, it seems. I hope Abjad is still out there somewhere, because this sounds like a fun combo!

    By Blogger Nils, at 02 September, 2022 02:35  

Post a Comment

<< Home