Posts Overtone: Basic Setup become a patron
Post
Cancel

Overtone: Basic Setup

Overtone: Live Coding Software

If you haven’t come across Overtone yet, it is a live coding software that enables you to create and control sound using Clojure programming language. Today we’re going to take a look at the process of setting up the project so that you can start experimenting with it. Although setup may be easy for more experienced programmers, it could be quite difficult to some out there who don’t have as much experience. Don’t worry, after reading this post you should be able to create a project where you can experiment with Overtone successfully.

Prerequisites

Before we begin make sure that you have the following installed:

  • Java (Clojure runs on top of Java Virtual Machine, so it is necessary that you have it). You probably already have this, if not, visit this link for more info.
  • Leiningen, which is a Clojure project management tool. This is not necessary, but it eases the process of managing Clojure projects a lot. It is de facto the default tool. Leiningen has Clojure as a dependency, so your package manager should install it automatically.
  • If you’re on linux, make sure you either installed JACK or PipeWire to handle audio processing. I wrote in my previous blog post about the differences, and why I recommend PipeWire. According to Overtone Wiki no specific audio setup is required for Windows or MacOS operating systems.
  • If you choose PipeWire to handle your audio, make sure you install a package containing jack_lsp cli program. Without it you would get an error when you try to use Overtone. In my case, on Arch linux, it’s the jack-example-tools, on Fedora it’s called jack-audio-connection-kit-example-clients. If your head is already spinning from all this, just use JACK on Linux or Windows/Mac OS.
  • A patchbay GUI program to easily connect various audio sources to playback devices. If you have PipeWire install qpwgraph, if you have JACK installled carla is a good choice. You’ll see at the end of this article why we need this.

Installation and Setup

Now that we have everything we need to get started, fire up your terminal and type lein new my-overtone-project which will create a new directory with necessary files for basic Clojure project. In your text editor of choice open the project.clj file that is located in the root of newly created my-overtone-project directory. You will see several lines that are defining the project (for description on what they do read the Leiningen tutorial). The line we’re interested in starts with :dependencies. It should look like this:

1
:dependencies [[org.clojure/clojure "1.10.3"]]

The Clojure version will be set by Leiningen when you create the project, so it can differ from what you see in this article depending on when you’re reading it. Now, edit the :dependencies section as follows:

1
2
:dependencies [[org.clojure/clojure "1.10.3"]
               [overtone "0.10.6"]]

What we’ve done here is we added overtone package as a dependency of our project, which means that Leiningen will take care for us to download it from Clojars and include it in our project. Next, go back to your terminal, change directory to the root of your project my-overtone-project and type lein repl. With that command Leiningen will first download all the dependencies that are needed, and then it will start a Clojure REPL (see the link for more info about what REPL is). When the process is done you should see the prompt my-overtone-project.core=> which means that everything went OK and that REPL is waiting for your input. Test if Clojure works with some of the basic fuctions, for example:

1
2
3
4
5
my-overtone-project.core=> (+ 3 8)
11
my-overtone-project.core=> (map inc [2 3 4 5 6])
(3 4 5 6 7)
my-overtone-project.core=>

Cool! We get the expected output from the functions called. Now, let’s try if Overtone works. In the REPL, type (use 'overtone.live). If evertyhing is allright you should get a message similar to this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
my-overtone-project.core=> (use 'overtone.live)
--> Loading Overtone...
Mar 28, 2022 5:12:50 PM clojure.lang.Reflector invokeMatchingMethod
WARNING: Can't listen to midi device: {:description "Scarlett 2i4 USB, USB MIDI, Scarlett 2i4 USB", :vendor "ALSA (http://www.alsa-project.org)", :sinks 0, :sources 2147483647, :name "USB [hw:0,0,0]", :overtone.studio.midi/full-device-key [:midi-device "ALSA (http://www.alsa-project.org)" "USB [hw:0,0,0]" "Scarlett 2i4 USB, USB MIDI, Scarlett 2i4 USB" 0], :info #object[com.sun.media.sound.MidiInDeviceProvider$MidiInDeviceInfo 0x1051cd0a "USB [hw:0,0,0]"], :overtone.studio.midi/dev-num 0, :device #object[com.sun.media.sound.MidiInDevice 0x28f753fc "[email protected]"], :version "5.16.15-arch1-1"}
javax.sound.midi.MidiUnavailableException: No such device
  **********************************************************
       WARNING: JVM argument TieredStopAtLevel=1 is active, and may
       lead to reduced performance. This happens to currently be the
       default lein setting:

       https://github.com/technomancy/leiningen/pull/1230

       If you didn't intend this JVM arg to be specified, you can turn
       it off in your project.clj file or your global
       ~/.lein/profiles.clj file by adding the key-val

       :jvm-opts ^:replace []
       **********************************************************
--> Booting internal SuperCollider server...
JackDriver: client name is 'Overtone'
SC_AudioDriver: sample rate = 48000.000000, driver's block size = 256
--> Connecting to internal SuperCollider server...
--> Connection established

    _____                 __
   / __  /_  _____  _____/ /_____  ____  ___
  / / / / | / / _ \/ ___/ __/ __ \/ __ \/ _ \
 / /_/ /| |/ /  __/ /  / /_/ /_/ / / / /  __/
 \____/ |___/\___/_/   \__/\____/_/ /_/\___/

   Collaborative Programmable Music. v0.10.6


Hello Savo. Do you feel it? I do. Creativity is rushing through your veins today!

nil
my-overtone-project.core=>

It started successfully! Don’t worry about the warnings at the first half of this snippet (can’t listen to midi device and JVM argument one). It is normal if you didn’t spend time setting up some other parameters, and it does not prevent us from starting our exploration path with Overtone, so we’ll ignore it for now. The important things start at --> Booting internal SuperCollider server... line. If everything after that is without errors you should be fine. One more thing before we try to produce some sounds: Overtone doesn’t connect it’s inputs or outputs to available sound devices automatically, so we need to do it manually. The easiest way is to do this through our patchbay app. In my case, it’s qpwgraph, and when I open it up i can see that none of my Overtone ins or outs are connected.

Pathcbay Disconnected: Patchbay Disconnected

The visual representation of your patchbay could be a little different, but it will be similar enough so you can manage to connect overtone with your audio card. Now, I can just hover over out_1 in Overtone section with my mouse, left-click-and-drag to my main audio device left channel (in my case that’s Scarlett 2i4 USB:playback_FL). Now, the same method should be aplied to out_2 and it should be connected to right channel of the audio device.

Pathcbay Connected: Patchbay Connected

Try Overtone!

We are finally ready to test if our overtone setup works. Go back to the terminal window where you previously started the REPL, and type the following (demo (saw 440)) and press enter.
Whoa! Did you hear that? That buzzing sound was created by the short code above. The saw 440 function call is responsible for creating that type of sound (called saw, we’ll see in future posts why) with the frequency of 440Hz. The demo function is responsible for playing the saw sound we defined. Now, let’s make something little cooler. How about playing multiple frequencies at the same time? Type the following in the same terminal window where you tried previous code snippet: (demo (saw [261.63 329.63])). Sounds better, right? Now, if you wonder why I used those exact frequencies you can look at this note-frequency-chart and you will see that I used C4 and E4 notes, which are in harmony. Don’t worry if it doesn’t make sense now, in future blog posts I will write about basic concepts of music theory as we explore further what Overtone has to offer.

What’s next?

The basic setup described in this article is enough to get everything started, but it’s not very practical to type lines of code in terminal and execute them one by one, especially for live coding. In the next article I will cover setting up an editor with Clojure development environment so we can truly use the power that Clojure has to offer.

This post is licensed under CC BY 4.0 by the author.