Hello, everyone, and welcome to the EmacsConf.
I am Jonathan. In this talk, I'm going
to demonstrate ways of producing sheet
music in Emacs
using Lilypond, and maybe also convince
you to use Emacs for writing your scores.
I'll start with an overview of the
syntax for those who are new to using
text-based notation
as a shallow dive into the deep pond of
lilies and Lilypond,
and move on to showcase some of its
functionalities using Org Mode
and lilypond-mode. One disclaimer,
however: I am not a Lilypond developer.
So what is Lilypond? Lilypond is
a file format and music engraving system
for producing high-quality sheet music.
It translates textual representations of
music to graphical objects.
It's similar to LaTeX in that its
input format describes the visual
layouts of the score,
using commands to define musical
expressions.
Commands begin with a backslash.
For example,
the formatter command, as shown on the
left, yields its graphical equivalents on
the right,
the fermata symbol over the low B and
so on and so forth.
It's also fully extensible, like Emacs,
allowing users to extend
and override Lilypond's functionalities
using the Scheme
scripting language. It can be used for
early and contemporary music
tablature, vocal music lead sheets,
and so on.
Above all, it works with Emacs.
In fact,
Lilypond ships with Emacs Lisp libraries,
including a major mode for editing
Lilypond files.
So the input files are similar to
source files.
They contain expressions formed with
curly braces,
comments that start with the percent
sign, and the code is indented.
Notes are entered using lowercase
letters, and rests with the letter r.
In this case, the lowercase r or r4
is the equivalence of a crotchet or
quarter note rest.
Durations are entered using numbers and
dots after the note name.
If you do not specify one, the previous
duration is used.
You can also tie notes together using
the tilde symbol (~).
In fact, you can input chords, lyrics,
embellishments, and a lot more.
I encourage you to read the manual for
more information.
Now let's switch to a terminal window.
With Lilypond installed, let's create
a test file with the extension
.ly and open it in Emacs.
At the top of the file is the version
statement, which tells Lilypond which
version to use when compiling the file.
Here I'm using version 2.20.0.
I've added the clef and time signature.
Let's add some notes.
I'm going to close this now and
compile the file by running
lilypond followed by the file name.
So now let's view the output.
Okay. So here's a more complex example
for randomizing note sequences.
The idea is to create new reading
materials each time the code blocks are
evaluated.
As usual, we begin with a header.
I've added the title
and composer. Then we add the note
sequences to use in the composition.
In this case, sn is a note name just like
a b c d and so on, and stands for snare drum,
the percussion instruments.
Now here's a function that's going to
shuffle the notes in the table.
Finally, we expand the notes inside
the Lilypond source block.
So whatever the function returns is
expanded inside the drums block.
Now let's press C-c C-c to view
the results.
Okay. And if I run this again, it should
create a new composition.
Great. You can also audition a piece
using the midi command,
which creates a midi file of the score.
Note also that the ob library--
sorry, the ob-lilypond library comes
with two modes.
The one I'm using now is called
arrange mode
and is useful for assembling
complete scores.
The basic mode on the other hand allows
you to mix text and music
by embedding Lilypond snippets and
export them using typical Org Mode
commands.
Now to demonstrate the basic mode in
action. I'm going to export this document
to a PDF file.
In this case, the
:file header argument is required, so you
have to provide one
and include the file name.
Again, you can run the code and view
the results.
Here it is. So now let's
export this to a PDF file.
And here it is, what it generates.
Now I'm going to show you the workflow I
used to produce music books in Emacs,
combining Lilypond and LaTeX for a
perfect marriage.
I begin by sketching the first draft of the
manuscript using pencil and paper.
Then I move to Emacs to input the notes
in a git repository.
This is a typical source file. It begins
with a stylesheet
where I set variables and layout
settings, although in general, there's no
need for tweaking the layout
unless you have specific requirements to
do so.
The easiest way to compile the file from
Emacs is by pressing C-c C-l,
so let's do this now,
and the compilation buffer will tell you
if there were any errors in the file.
Now to automate the process of compiling
several files and building the PDF,
I use GNU Make, so all I have to do is
open the shell
and run the make command. Don't worry,
I'll provide a link to the source code
on the last slide.
As I moved forward with the project, I
found at least two things missing.
One, I had no access to a metronome,
at least not from the editor,
so I built one for casual use and made
it available in the MELPA repository.
I also missed bar numbers in the source file.
This is useful when going back and forth
between input and output files without
getting lost.
So I wrote a command for toggling bar
numbers, which I hope you can see on the left.
Also, some expressions are difficult or
slow to write on the keyboard--
accents and tuplets, for example--so I use
template expansion extensively for this purpose,
mainly yasnippet.
So what do I think? Well, I think
Lilypond can be a sharp paradigm shift
for people used to GUI alternatives, but
the results are impressive.
You don't have to dive too deeply to
start using Lilypond.
Likewise, the ability to extend the
software, I think, is especially appealing
for music professionals,
enthusiasts, composers, and the academic
community:
for example, allowing users to create
alternative notation systems required in
non-Western music traditions
and other non-conventional requirements.
Also, Lilypond and Emacs both have
extensive and well-written manuals
and active communities of users.
But if you're still not sure where to
start and when to wedge your feet in the deep
but warm pond of lilies, Lilypond, and
Lilypond users,
I invite you to contribute to my
Lilypond projects,
which you can do so from the links on
the screen.
So, thank you all. I look forward to your
comments, and I hope you enjoy the rest
of the conference.