Clojure Developers Making Music Together - London Overtone Hackday

The coldest night in London of 2012 so far was the warm up to a symphony of music by a collection of unstoppable Clojure hackers. As it was my first hackday with Overtone there was lots of new things to learn, from setting up the environment to a whole load of interesting music theory.

I also have Gnossiennes No.1 by Erik Satie on an endless loop in my head after having fun playing around with a piano synthesiser.

I cant really cant do justice to how much fun it is working with Overtone. Its like getting your hands on a Stylophone for the first time, just after seeing Rolf Haris demo it on TV! The only difference being you can make much better music with Overtone.

There is something just so ultimately geeky and fun in creating music using a functional programming language like Clojure.

I first tried Overtone at a London Clojurian coding dojo and with the help of the rest of the team we were quickly creating weird and wonderful sounds - although not quite in the same leaguge of

Thanks to some great documentation on the overtone github site it was pretty easy to set up my lubuntu laptop with an audio server, Overtone server and a nice lightweight clojure development environment (emacs, leiningen). I am afraid it will take me a bit longer to absorb music theory!

Setting up the audio for Overtone

In order to get sounds out of your overtone project on Linux, you need to add a few packages.

sudo apt-get install jack-tools ant openjdk-6-jdk fftw3 qjackctl

As you grow your overtone project you may want to switch to a linux kernel set up for real time processing, but to start with this is not necessary. If you do get more involved projects, its probably a good idea to also look at Ubuntu studio which provides a great selection of audio, video and graphics tools.

_Mac OSX already has a suitable sound server, so nothing extra is required. If you are using windows, overtone is supported also (not sure if you need to set anything up though).

Create a new overtone project

An overtone project is just like any other clojure project, with the overtone dependency added.

Create a new clojure project with your build management tool of choice: maven, cake or leiningen. I used leiningen as my tool of choice.

lein new tutorial

Add the Overtone dependencies to the project configuration file tutorial/project.clj

1
2
3
(defproject tutorial "1.0"
:dependencies [[org.clojure/clojure "1.3.0"]
[overtone "0.6.0"]])

With the overtone dependencies added to the project file, used leiningen to download the jars that make up overtone itself.

lein deps

Leiningen will download about 16 jar files for overtone 0.6.0 and places them in the project lib folder. This gives you all the libraries you need to start creating things in overtone, including an appropriate version of clojure.

Fire up your environment

Emacs not only has great support for the Clojure language, its a great way to try out your code by evaluating individual functions (s-expressions).

My preferred way to launch emacs is to change directory to the project top level and fire off emacs with the project file

emacs project.clj &

Using the dynamic environment of Clojure, the REPL, is a great time saver for trying out functions as well as running your project code. To fire up a repl inside emacs I use the new emacs 24 approach, running Meta-x (clojure-jack-in) to start up and connect to a repl using the underlying lein project file.

Meta-x (clojure-jack-in)

I have set up a keyboard shortcut of C-c C-j to make this even easier.

Starting Overtone

For my initial experiments I run an overtone server on my laptop, that way I can also play on the train home. You can also use an external overtone server called the SuperCollider (no not the LHC)

In the repl, I fired up the internal server (dont try to fire off both servers in the same repl, it crashed my repl)

in the REPL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
(use 'overtone.live)
_____ __
/ __ /_ _____ _____/ /_____ ____ ___
/ / / / | / / _ \/ ___/ __/ __ \/ __ \/ _ \
/ /_/ /| |/ / __/ / / /_/ /_/ / / / / __/
\____/ |___/\___/_/ \__/\____/_/ /_/\___/
Programmable Music. v0.6
Hello jr0cket, may this be the start of a beautiful music hacking session...
nil
```
# Defining my first instrument
I soon discovered that it does take a little time to build your instruments. Its like any good programming challenge, there are many ways to do things and there are always lots of surprises. Reading the [getting started guide](https://github.com/overtone/overtone/wiki/Getting-Started) helped me with my first instrument.

(definst annoying-tone [] (saw 220))

1
2
This is a simple and rather annoying tone that uses the saw function to create the sound. To play the sound I simply call its name:

(annoying-tone)
```

The easiest way to end your experiment in sound quickly is to use the (stop) function.

Quickly testing out your instruments with emacs

Many cool things were done at the hack day and it was great fun to play with the Ableon Novation Lauchpad. Its a midi controller that can be used to help you play your instruments and make it easier to turn overtone into a song maker.

I got as far as creating a few basic instruments and borrowing a few others, such as the one to create Jingle Bells!

Thanks to Phil Potter for having the energy to organise this event, Thoughtworks for supporting us with the venue and everyone there for making it a great day.

To have a whole day focused on overtone really helped me accomplish something and its going to be easier now to keep the learning going. All my experiments are now uploaded to my github account.

Hope you find the time to make music with Clojure and Overtone, you will love it.

Thank you.
@jr0cket


This work is licensed under a Creative Commons Attribution 4.0 ShareAlike License, including custom images & stylesheets. Permissions beyond the scope of this license may be available at @jr0cket
Creative Commons License