You want to read it within GNU Emacs and Org-mode.
Install GNU Emacs
If you are using Debian,
~$ apt-get install emacs will do.
To install Emacs from sources, you can download it from here or clone the git mirror:
~$ git clone git://git.savannah.gnu.org/emacs.git
The beginning of your Emacs configuration should contain this to add
marmelade to the list of known repositories for Emacs libraries:
(require 'package) (add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/")) (package-initialize)
C-c C-v C-t to tangle all Emacs Lisp code blocks from this
file into a new
emacs.el file in the same directory.
When done, go check this new
You can use this
emacs.el to load the minimal configuration needed
for this tutorial.
Install Cider (was “nrepl.el”)
Now run Emacs like this:
~$ emacs -l /path/to/overtone-intro/emacs.el
In Emacs, get the list of packages:
M-x list-packages RET
cider from that list.
Note: This will also install
Install the latest version of Org-mode:
~$ git clone git://orgmode.org/org-mode.git ~$ cd org-mode ~$ make autoloads
This will compile Emacs Lisp files in the
org-loaddefs.el, containing the necessary autoloads.
This simple Org configuration should do:
(add-to-list 'load-path "~/install/git/org-mode/") (require 'org) ;; We only need Emacs Lisp and Clojure in this tutorial: (org-babel-do-load-languages 'org-babel-load-languages '((emacs-lisp . t) (clojure . t))) ;; Use cider as the clojure execution backend (setq org-babel-clojure-backend 'cider) ;; Let's have pretty source code blocks (setq org-edit-src-content-indentation 0 org-src-tab-acts-natively t org-src-fontify-natively t org-confirm-babel-evaluate nil)
;; Cider configuration (require 'cider) (setq nrepl-hide-special-buffers t cider-repl-pop-to-buffer-on-connect nil cider-popup-stacktraces nil cider-repl-popup-stacktraces t)
leiningen is the de facto standard for running Clojure projects.
Check the very simple installation instructions.
Supercollider is the audio synthetizer.
You need it to play sounds with Overtone.
On Debian, you can install SuperCollider the usual way:
For other platforms, see the supercollider downloads page.
In this tutorial, we will play piano, so we need the sc3-plugins.
If you want to compile supercollider and sc3-plugins from sources, check this page from the Overtone wiki.
Overtone as a dependency in project.clj
Previously, we hit
C-c C-v C-t to tangle Emacs Lisp code blocks into
C-c C-v C-t tangles all blocks in the buffer,
we also created
project.clj, which is needed in order to run
and to let
cider interact with
(defproject overtone-intro "1.0" :dependencies [[org.clojure/clojure "1.5.1"] [overtone "0.9.1"]])
overtone-intro directory, run
~$ lein deps to load all
During the live demo, I used these keybindings:
;; Useful keybindings when using Clojure from Org (org-defkey org-mode-map "\C-x\C-e" 'cider-eval-last-sexp) (org-defkey org-mode-map "\C-c\C-d" 'cider-doc)
They allow to execute a Clojure source code block by hitting
after a Clojure sexp, and to get a Clojure docstring by hitting
C-d after a symbol.
If you don’t use these keybindings, executing source code blocks is
done by hitting
C-c C-c on the
This is an overview of my configuration:
The tutorial should work with older versions of Emacs, but you need to install Org-mode from its master branch to use cider.
Also, remember to hit
TAB for (un)folding a section or a source code
Connect to the repl
To connect the current Org buffer to a repl, run
M-x cider-jack-in RET
… and wait until you get a confirmation message in the minibuffer.
Do this now, you’ll need it soon.
A quick intro to Org Babel
To get a gist of what Org Babel is, hit
C-c C-c on the
Emacs minibuffer displays the output: yeah!
You can bind variables in Babel source code blocks—hit
C-c C-c on
the code blocks below:
(message (number-to-string n))
(-> n inc (+ m))
Okay, you get it: hit
C-c C-c on code blocks to execute them.
(map clojure.string/upper-case x)
A quick intro to Overtone
Overtone: loading and booting
Note: I’m using GNU/Linux, and I didn’t take the time to configure jackd properly. You may want to use this instead:
(use 'overtone.live) (boot-internal-server)
Overtone: playing/fooling around
Note: the first time you use the
overtone.inst.piano namespace, it
will load quite a lot of files from freesound.org – you may want to
do this within a bare
lein repl in order to make sure the process is
Play a simple midi note:
(doseq [note (chord :C3)] (piano note))
(doseq [note (chord :E3 :minor)] (piano note))
(defn play-chord [chord] (doseq [note chord] (piano note))) (play-chord (chord :A3 :minor))
(let [time (now)] (at time (play-chord (chord :C3 :major))) (at (+ 1000 time) (play-chord (chord :C3 :major7))) (at (+ 2000 time) (play-chord (chord :E3 :minor))) (at (+ 3000 time) (play-chord (chord :A2 :minor))))
definst are the two entry points for creating sounds
and instruments – go check their docstrings, they explain a lot.
(defsynth bar [freq 440] (out 0 (sin-osc freq))) (bar 500) (kill bar) (stop) (definst beep [note 60] (let [sound-src (sin-osc (midicps note)) env (env-gen (perc 0.01 1.0) :action FREE)] ; sam uses :free (* sound-src env))) (beep 60) (defsynth pad1 [freq 110 amp 1 gate 1 out-bus 0] (out out-bus (* (saw [freq (* freq 1.01)]) (env-gen (adsr 0.01 0.1 0.7 0.5) :gate gate :action FREE)))) (pad1) (stop) ;; Let's try something a bit crazy (for [i (range 200)] (at (+ (now) (* i 20)) (beep i)))
Some more copy-and-paste from overtone’s wiki:
(map piano [60 63 67]) (map piano (map note [:C3 :E4 :G4])) (map piano (map note [:C#5 :E4 :G4])) (map piano (map note [:Cb2 :E4 :G4])) (definst steel-drum [note 60 amp 0.8] (let [freq (midicps note)] (* amp (env-gen (perc 0.01 0.2) 1 1 0 1 :action FREE) (+ (sin-osc (/ freq 2)) (rlpf (saw freq) (* 1.1 freq) 0.4))))) (steel-drum (note :E3)) (map steel-drum (map note [:E3 :D#4]))
Overtone: loading .wav samples
;; Hint: adapt this to your own .wav files (def noa (sample "/path/to/a/file.wav")) (let  (noa) (Thread/sleep 3000) (piano (note :Cb3)) (piano 68)) (stop)
Overtone: using freesound.org
You can download samples directly from freesound.org via Overtone:
(def snare (sample (freesound-path 26903))) (snare) (def clic (sample (freesound-path 406))) (clic) (def steam (sample (freesound-path 30628))) (steam) (def clap (sample (freesound-path 48310))) (clap) (def clap2 (sample (freesound-path 132676))) (clap2) (def boom (sample (freesound-path 80401))) (boom)
Why I love this?
- I love sounds.
- I love Org+Cider reactivity: evaluating Clojure sexps is fast.
- I love building (mostly random) sounds so fast, it feels like sculpting music.
If you run into issues while following this tutorial, please report them on github.