Skip to content

Instantly share code, notes, and snippets.

@mobeets
Last active May 1, 2016 22:29
Show Gist options
  • Save mobeets/e9f261b1246643592c52 to your computer and use it in GitHub Desktop.
Save mobeets/e9f261b1246643592c52 to your computer and use it in GitHub Desktop.
playing music with Overtone on OSX inside Sublime Text 2

This was surprisingly simple given how many things there were to do! (Usually it seems like something breaks when there's this many steps between me and installing something.)

Installations

Making sounds

Create a new leiningen project:

$ lein new myproj
$ cd myproj
$ subl project.clj

Edit your project file by adding Overtone to your project's dependencies, then run:

$ lein deps

Start your project as an interactive session with SublimeREPL.

Make sure your project.clj is the tab in focus and then go to:

Tools -> SublimeREPL -> Clojure -> Clojure

Connect scsynth to your project.

In your REPL session type:

user=> (use 'overtone.core)

Play a saw wave, then stop it.

user=> (definst foo [] (saw 220))
user=> (foo)
user=> #<synth-node[loading]: user/foo 4>
user=> (kill 4) ; kill the synth with ID 4

(Note that 4 will be a different number in your case.)


Next Steps

Auto-start Overtone

Update your project.clj file by adding :main myproj.core right before the :dependencies line. Now it should look something like this:

(defproject myproj "0.1.0-SNAPSHOT"
    :main myproj.core
    :dependencies [ [org.clojure/clojure "1.5.1"]
                [overtone "0.9.1"]])

The myproj.core line corresponds to the file called "src/myproj/core.clj" that lein created for you. This file should already have the (necessary) line at the top that says (ns myproj.core). Now whenever you start up a REPL, the "myproj.core" namespace is loaded.

You just need to add whatever additional commands you want run when you start up your REPL. So to load Overtone, your "src/myproj/core.clj" file should look like this:

(ns myproj.core)

(use 'overtone.core)
(boot-server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment